Skip to content

Commit 1cedfbd

Browse files
committed
qa: use clean expansion of LS tarball per fixture instance
Because QA tests can _modify_ the Logstash installation (e.g. those that invoke the plugin manager), it is important that the service wrapper begins with a clean expansion of the logstash tarball.
1 parent 8cd3849 commit 1cedfbd

2 files changed

Lines changed: 47 additions & 11 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def qaBuildPath = "${buildDir}/qa/integration"
414414
def qaVendorPath = "${qaBuildPath}/vendor"
415415

416416
tasks.register("installIntegrationTestGems") {
417-
dependsOn unpackTarDistribution
417+
dependsOn assembleTarDistribution
418418
def gemfilePath = file("${projectDir}/qa/integration/Gemfile")
419419
inputs.files gemfilePath
420420
inputs.files file("${projectDir}/qa/integration/integration_tests.gemspec")

qa/integration/services/logstash_service.rb

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,58 @@ def initialize(settings, api_port = 9600)
5353
if @settings.is_set?("ls_home_abs_path")
5454
@logstash_home = @settings.get("ls_home_abs_path")
5555
else
56-
# use the LS which was just built in source repo
57-
ls_version_file = YAML.load_file(LS_VERSION_FILE)
58-
ls_file = "logstash-" + ls_version_file["logstash"]
59-
# First try without the snapshot if it's there
60-
@logstash_home = File.expand_path(File.join(LS_BUILD_DIR, ls_file), __FILE__)
61-
@logstash_home += "-SNAPSHOT" unless Dir.exist?(@logstash_home)
62-
63-
puts "Using #{@logstash_home} as LS_HOME"
64-
@logstash_bin = File.join("#{@logstash_home}", LS_BIN)
65-
raise "Logstash binary not found in path #{@logstash_home}" unless File.file? @logstash_bin
56+
@logstash_home = clean_expand_built_tarball
6657
end
6758

59+
puts "Using #{@logstash_home} as LS_HOME"
60+
@logstash_bin = File.join("#{@logstash_home}", LS_BIN)
61+
raise "Logstash binary not found in path #{@logstash_home}" unless File.file? @logstash_bin
62+
6863
@default_settings_file = File.join(@logstash_home, LS_CONFIG_FILE)
6964
@monitoring_api = MonitoringAPI.new(api_port)
7065
end
7166

67+
##
68+
# @return [String] the path to a CLEAN expansion of the locally-built tarball
69+
def clean_expand_built_tarball
70+
build_dir = File.expand_path(LS_BUILD_DIR, __FILE__) # source of tarball
71+
target_dir = File.join(build_dir, "qa-fixture")
72+
73+
# find the built tarball matching the current version, preferring non-SNAPSHOT
74+
ls_version = YAML.load_file(LS_VERSION_FILE).fetch("logstash")
75+
candidates = %W(
76+
logstash-#{ls_version}.tar.gz
77+
logstash-#{ls_version}-SNAPSHOT.tar.gz
78+
)
79+
80+
candidates.each do |tarball_candidate|
81+
tarball_candidate_path = File.join(build_dir, tarball_candidate)
82+
if File.exist?(tarball_candidate_path)
83+
expected_untar_directory = File.basename(tarball_candidate, ".tar.gz")
84+
result_logstash_home = File.join(target_dir, expected_untar_directory)
85+
86+
if Dir.exist?(result_logstash_home)
87+
puts "expunging(#{result_logstash_home})"
88+
# FileUtils#rm_rf cannot be used here because it silently fails to remove the bundled jdk on MacOS
89+
expunge_result = `rm -rf #{Shellwords.escape(result_logstash_home)} 2>&1`
90+
fail("ERROR EXPUNGING: #{expunge_result}") unless $?.success?
91+
end
92+
93+
puts "expanding(#{tarball_candidate_path})"
94+
FileUtils.mkdir_p(target_dir) unless Dir.exist?(target_dir)
95+
FileUtils.chdir(target_dir) do
96+
expand_result = `tar -xzf #{Shellwords.escape(tarball_candidate_path)} 2>&1`
97+
fail("ERROR EXPANDING: #{expand_result}") unless $?.success?
98+
end
99+
100+
return result_logstash_home
101+
end
102+
end
103+
104+
fail("failed to find any matching build tarballs (looked for `#{candidates}` in `#{build_dir}`)")
105+
end
106+
private :clean_expand_built_tarball
107+
72108
def alive?
73109
if @process.nil? || @process.exited?
74110
raise "Logstash process is not up because of an error, or it stopped"

0 commit comments

Comments
 (0)