Skip to content

Commit

Permalink
Spec: nginx installer prints commands
Browse files Browse the repository at this point in the history
clean up naming and introduce constants
  • Loading branch information
aramprice committed Jan 9, 2025
1 parent e66ec63 commit 8775482
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/spec/integration_support/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module Constants
BOSH_REPO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
BOSH_REPO_PARENT_DIR = File.expand_path(File.join(BOSH_REPO_ROOT, '..'))
BOSH_REPO_SRC_DIR = File.join(BOSH_REPO_ROOT, 'src')
INTEGRATION_BIN_DIR = File.join(BOSH_REPO_SRC_DIR, 'tmp', 'bin')
BOSH_REPO_SRC_TMP_DIR = File.join(BOSH_REPO_SRC_DIR, 'tmp')
INTEGRATION_BIN_DIR = File.join(BOSH_REPO_SRC_TMP_DIR, 'bin')

SANDBOX_ASSETS_DIR = File.join(BOSH_REPO_SRC_DIR, 'spec', 'assets', 'sandbox')
SANDBOX_CERTS_DIR = File.join(SANDBOX_ASSETS_DIR, 'ca', 'certs')
Expand Down
19 changes: 11 additions & 8 deletions src/spec/integration_support/nginx_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def logfile_path(base_log_path)
end

class NginxInstaller
WORKING_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_DIR, 'tmp', 'integration-nginx-work')
WORK_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_TMP_DIR, 'nginx-work')
EXECUTABLE_PATH = File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, 'sbin', 'nginx')

def prepare
Expand All @@ -110,17 +110,17 @@ def should_compile?

def compile
# Clean up old compiled nginx bits to stay up-to-date
FileUtils.rm_rf(WORKING_DIR)
FileUtils.rm_rf(WORK_DIR)

FileUtils.mkdir_p(WORKING_DIR)
FileUtils.mkdir_p(WORK_DIR)

run_command("echo '#{RUBY_PLATFORM}' > #{IntegrationSupport::Constants::INTEGRATION_BIN_DIR}/platform")

# Make sure packaging script has its own blob copies so that blobs/ directory is not affected
nginx_blobs_path = File.join(IntegrationSupport::Constants::BOSH_REPO_ROOT, 'packages', 'nginx')
run_command("cp -R #{nginx_blobs_path}/. #{File.join(WORKING_DIR)}")
run_command("cp -R #{nginx_blobs_path}/. #{WORK_DIR}")

Dir.chdir(WORKING_DIR) do
Dir.chdir(WORK_DIR) do
packaging_script_path = File.join(IntegrationSupport::Constants::BOSH_REPO_ROOT, 'packages', 'nginx', 'packaging')
run_command("bash #{packaging_script_path}", { 'BOSH_INSTALL_TARGET' => IntegrationSupport::Constants::INTEGRATION_BIN_DIR })
end
Expand All @@ -129,7 +129,10 @@ def compile
private

def run_command(command, environment = {})
io = IO.popen([environment, 'bash', '-c', command])
command = [environment, 'bash', '-c', command]
puts "Running: #{command.join(' ')}"

io = IO.popen(command)

lines =
io.each_with_object("") do |line, collect|
Expand All @@ -140,14 +143,14 @@ def run_command(command, environment = {})
io.close
process_status = $?

raise "Command: #{command.inspect} failed with #{process_status.inspect}" unless process_status.success?
raise "Command: #{command.inspect} failed with #{process_status.inspect}" unless process_status&.success?

lines
end

def blob_has_changed?
blobs_shasum = shasum(File.join(IntegrationSupport::Constants::BOSH_REPO_ROOT, 'blobs', 'nginx'))
sandbox_copy_shasum = shasum(File.join(WORKING_DIR, 'nginx'))
sandbox_copy_shasum = shasum(File.join(WORK_DIR, 'nginx'))

blobs_shasum.sort != sandbox_copy_shasum.sort
end
Expand Down
7 changes: 4 additions & 3 deletions src/spec/integration_support/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@ class Sandbox
attr_accessor :trusted_certs

def self.integration_spec_base_dir
File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_DIR, 'tmp', 'integration-specs')
File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_TMP_DIR, 'integration-specs')
end
private_class_method :integration_spec_base_dir

def self.uaa_service
@uaa_service ||= UaaService.new(uaa_root: File.join(integration_spec_base_dir, 'uaa_root'))
@uaa_service ||= UaaService.new(uaa_root: File.join(integration_spec_base_dir, "uaa_root-pid-#{Process.pid}"))
end
private_class_method :uaa_service


def self.sandbox_pid_root
File.join(integration_spec_base_dir, "pid-#{Process.pid}-sandbox")
File.join(integration_spec_base_dir, "sandbox-pid-#{Process.pid}")
end

def self.sandbox_tmp_dir
Expand Down

0 comments on commit 8775482

Please sign in to comment.