From 3ee1c76983675e22848d9a11c66f054578404178 Mon Sep 17 00:00:00 2001 From: Oscar Barrios Date: Tue, 1 Aug 2023 14:44:20 +0200 Subject: [PATCH] QE: Lazy initialization of Twopence nodes --- .../init_clients/sle_ssh_minion.feature | 5 +- .../features/step_definitions/api_common.rb | 10 +- .../step_definitions/cobbler_steps.rb | 94 ++-- .../step_definitions/command_steps.rb | 347 ++++++++------- .../features/step_definitions/common_steps.rb | 16 +- .../content_lifecycle_steps.rb | 6 +- .../features/step_definitions/docker_steps.rb | 4 +- .../step_definitions/file_management_steps.rb | 16 +- .../step_definitions/navigation_steps.rb | 2 +- .../features/step_definitions/retail_steps.rb | 68 +-- .../features/step_definitions/salt_steps.rb | 88 ++-- .../features/step_definitions/setup_steps.rb | 8 +- .../features/step_definitions/smdba_steps.rb | 60 +-- testsuite/features/support/code_coverage.rb | 6 +- testsuite/features/support/commonlib.rb | 115 ++++- testsuite/features/support/constants.rb | 65 +++ testsuite/features/support/env.rb | 164 +++---- testsuite/features/support/lavanda.rb | 4 +- .../features/support/namespaces/system.rb | 4 +- testsuite/features/support/twopence_env.rb | 43 ++ testsuite/features/support/twopence_init.rb | 412 +++--------------- 21 files changed, 716 insertions(+), 821 deletions(-) create mode 100644 testsuite/features/support/twopence_env.rb diff --git a/testsuite/features/github_validation/init_clients/sle_ssh_minion.feature b/testsuite/features/github_validation/init_clients/sle_ssh_minion.feature index 528d96518940..2c1d74e23103 100644 --- a/testsuite/features/github_validation/init_clients/sle_ssh_minion.feature +++ b/testsuite/features/github_validation/init_clients/sle_ssh_minion.feature @@ -11,12 +11,12 @@ Feature: Bootstrap a Salt host managed via salt-ssh When I follow the left menu "Systems > Bootstrapping" Then I should see a "Bootstrap Minions" text When I check "manageWithSSH" - And I enter the hostname of "opensusessh" as "hostname" + And I enter the hostname of "ssh_minion" as "hostname" And I enter "linux" as "password" And I click on "Bootstrap" And I wait until I see "Successfully bootstrapped host!" text And I follow the left menu "Systems > System List > All" - And I wait until I see the name of "opensusessh", refreshing the page + And I wait until I see the name of "ssh_minion", refreshing the page Scenario: Subscribe the SSH minion to a base channel Given I am on the Systems overview page of this "ssh_minion" @@ -31,4 +31,3 @@ Feature: Bootstrap a Salt host managed via salt-ssh When I click on "Confirm" Then I should see a "Changing the channels has been scheduled." text And I wait until event "Subscribe channels scheduled by admin" is completed - diff --git a/testsuite/features/step_definitions/api_common.rb b/testsuite/features/step_definitions/api_common.rb index 1351498f369f..d54b41b9b66b 100644 --- a/testsuite/features/step_definitions/api_common.rb +++ b/testsuite/features/step_definitions/api_common.rb @@ -14,9 +14,9 @@ end $api_test = if $debug_mode - ApiTestXmlrpc.new($server.full_hostname) + ApiTestXmlrpc.new(get_target('server').full_hostname) else - $product == 'Uyuni' ? ApiTestHttp.new($server.full_hostname, ssl_verify) : ApiTestXmlrpc.new($server.full_hostname) + product == 'Uyuni' ? ApiTestHttp.new(get_target('server').full_hostname, ssl_verify) : ApiTestXmlrpc.new(get_target('server').full_hostname) end ## system namespace @@ -49,7 +49,7 @@ but with activation key with default contact method, I should get an API fault$/) do exception_thrown = false begin - $api_test.system.bootstrap_system($minion.full_hostname, '1-SUSE-KEY-x86_64', true) + $api_test.system.bootstrap_system(get_target('sle_minion').full_hostname, '1-SUSE-KEY-x86_64', true) rescue exception_thrown = true end @@ -80,7 +80,7 @@ end When(/^I wait for the OpenSCAP audit to finish$/) do - @sle_id = $api_test.system.retrieve_server_id($minion.full_hostname) + @sle_id = $api_test.system.retrieve_server_id(get_target('sle_minion').full_hostname) begin repeat_until_timeout(message: 'Process did not complete') do scans = $api_test.system.scap.list_xccdf_scans(@sle_id) @@ -142,7 +142,7 @@ ## channel namespace When(/^I create a repo with label "([^"]*)" and url$/) do |label| - url = "http://#{$server.full_hostname}/pub/AnotherRepo/" + url = "http://#{get_target('server').full_hostname}/pub/AnotherRepo/" assert($api_test.channel.software.create_repo(label, url)) end diff --git a/testsuite/features/step_definitions/cobbler_steps.rb b/testsuite/features/step_definitions/cobbler_steps.rb index de1d03bf3484..8e54bbdf4866 100644 --- a/testsuite/features/step_definitions/cobbler_steps.rb +++ b/testsuite/features/step_definitions/cobbler_steps.rb @@ -11,7 +11,7 @@ end When(/^I restart cobbler on the server$/) do - $server.run('systemctl restart cobblerd.service') + get_target('server').run('systemctl restart cobblerd.service') end Given(/^I am logged in via the Cobbler API as user "([^"]*)" with password "([^"]*)"$/) do |user, pwd| @@ -66,12 +66,12 @@ end When(/^I remove kickstart profiles and distros$/) do - host = $server.full_hostname + host = get_target('server').full_hostname # ------------------------------- # Cleanup kickstart distros and their profiles, if any. # Get all distributions: created from UI or from API. - distros = $server.run('cobbler distro list')[0].split + distros = get_target('server').run('cobbler distro list')[0].split # The name of distros created in the UI has the form: distro_label + suffix user_details = $api_test.user.get_details('testing') @@ -84,17 +84,17 @@ # Remove profiles and distros created with the API. # We have already deleted the profiles from the UI; delete all the remaning ones. - profiles = $server.run('cobbler profile list')[0].split - profiles.each { |profile| $server.run("cobbler profile remove --name '#{profile}'") } - distros_api.each { |distro| $server.run("cobbler distro remove --name '#{distro}'") } + profiles = get_target('server').run('cobbler profile list')[0].split + profiles.each { |profile| get_target('server').run("cobbler profile remove --name '#{profile}'") } + distros_api.each { |distro| get_target('server').run("cobbler distro remove --name '#{distro}'") } end # cobbler reports When(/^I trigger cobbler system record on the "([^"]*)"$/) do |host| space = 'spacecmd -u admin -p admin' system_name = get_system_name(host) - $server.run("#{space} clear_caches") - out, _code = $server.run("#{space} system_details #{system_name}") + get_target('server').run("#{space} clear_caches") + out, _code = get_target('server').run("#{space} system_details #{system_name}") unless out.include? 'ssh-push-tunnel' steps %( Given I am authorized as "testing" with password "testing" @@ -109,28 +109,28 @@ Then(/^the cobbler report should contain "([^"]*)" for "([^"]*)"$/) do |text, host| node = get_target(host) - output, _code = $server.run("cobbler system report --name #{node.full_hostname}:1", check_errors: false) + output, _code = get_target('server').run("cobbler system report --name #{node.full_hostname}:1", check_errors: false) raise "Not found:\n#{output}" unless output.include?(text) end Then(/^the cobbler report should contain "([^"]*)" for cobbler system name "([^"]*)"$/) do |text, name| - output, _code = $server.run("cobbler system report --name #{name}", check_errors: false) + output, _code = get_target('server').run("cobbler system report --name #{name}", check_errors: false) raise "Not found:\n#{output}" unless output.include?(text) end # buildiso When(/^I prepare Cobbler for the buildiso command$/) do tmp_dir = '/var/cache/cobbler/buildiso' - $server.run("mkdir -p #{tmp_dir}") + get_target('server').run("mkdir -p #{tmp_dir}") # we need bootloaders for the buildiso command - out, code = $server.run('cobbler mkloaders', verbose: true) + out, code = get_target('server').run('cobbler mkloaders', verbose: true) raise "error in cobbler mkloaders.\nLogs:\n#{out}" if code.nonzero? end When(/^I run Cobbler buildiso for distro "([^"]*)" and all profiles$/) do |distro| tmp_dir = '/var/cache/cobbler/buildiso' iso_dir = '/var/cache/cobbler' - out, code = $server.run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/profile_all.iso --distro=#{distro}", verbose: true) + out, code = get_target('server').run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/profile_all.iso --distro=#{distro}", verbose: true) raise "error in cobbler buildiso.\nLogs:\n#{out}" if code.nonzero? profiles = %w[orchid flame pearl] @@ -138,10 +138,10 @@ cobbler_profiles = [] profiles.each do |profile| # get all profiles from Cobbler - result_cobbler, code = $server.run("cobbler profile list | grep -o #{profile}", verbose: true) + result_cobbler, code = get_target('server').run("cobbler profile list | grep -o #{profile}", verbose: true) cobbler_profiles.push(result_cobbler) if code.zero? # get all profiles from isolinux.cfg - result_isolinux, code = $server.run("cat #{tmp_dir}/isolinux/isolinux.cfg | grep -o #{profile} | cut -c -6 | head -n 1") + result_isolinux, code = get_target('server').run("cat #{tmp_dir}/isolinux/isolinux.cfg | grep -o #{profile} | cut -c -6 | head -n 1") unless result_isolinux.empty? isolinux_profiles.push(result_isolinux) end @@ -152,17 +152,17 @@ When(/^I run Cobbler buildiso for distro "([^"]*)" and profile "([^"]*)"$/) do |distro, profile| tmp_dir = '/var/cache/cobbler/buildiso' iso_dir = '/var/cache/cobbler' - out, code = $server.run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/#{profile}.iso --distro=#{distro} --profile=#{profile}", verbose: true) + out, code = get_target('server').run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/#{profile}.iso --distro=#{distro} --profile=#{profile}", verbose: true) raise "error in cobbler buildiso.\nLogs:\n#{out}" if code.nonzero? end When(/^I run Cobbler buildiso for distro "([^"]*)" and profile "([^"]*)" without dns entries$/) do |distro, profile| tmp_dir = '/var/cache/cobbler/buildiso' iso_dir = '/var/cache/cobbler' - out, code = $server.run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/#{profile}.iso --distro=#{distro} --profile=#{profile} --exclude-dns", verbose: true) + out, code = get_target('server').run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/#{profile}.iso --distro=#{distro} --profile=#{profile} --exclude-dns", verbose: true) raise "error in cobbler buildiso.\nLogs:\n#{out}" if code.nonzero? - result, code = $server.run("cat #{tmp_dir}/isolinux/isolinux.cfg | grep -o nameserver", check_errors: false) + result, code = get_target('server').run("cat #{tmp_dir}/isolinux/isolinux.cfg | grep -o nameserver", check_errors: false) # we have to fail here if the command suceeds raise "error in Cobbler buildiso, nameserver parameter found in isolinux.cfg but should not be found.\nLogs:\n#{result}" if code.zero? end @@ -174,60 +174,60 @@ tmp_dir = '/var/cache/cobbler/buildiso' iso_dir = '/var/cache/cobbler' source_dir = "/var/cache/cobbler/source_#{param}" - $server.run("mv #{tmp_dir} #{source_dir}") - $server.run("mkdir -p #{tmp_dir}") - out, code = $server.run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/#{param}.iso --distro=#{distro} --#{param} --source=#{source_dir}", verbose: true) + get_target('server').run("mv #{tmp_dir} #{source_dir}") + get_target('server').run("mkdir -p #{tmp_dir}") + out, code = get_target('server').run("cobbler buildiso --tempdir=#{tmp_dir} --iso #{iso_dir}/#{param}.iso --distro=#{distro} --#{param} --source=#{source_dir}", verbose: true) raise "error in cobbler buildiso.\nLogs:\n#{out}" if code.nonzero? end When(/^I check Cobbler buildiso ISO "([^"]*)" with xorriso$/) do |name| tmp_dir = '/var/cache/cobbler' - out, code = $server.run("cat >#{tmp_dir}/test_image <<-EOF + out, code = get_target('server').run("cat >#{tmp_dir}/test_image <<-EOF BIOS UEFI EOF") xorriso = "xorriso -indev #{tmp_dir}/#{name}.iso -report_el_torito 2>/dev/null" iso_filter = "awk '/^El Torito boot img[[:space:]]+:[[:space:]]+[0-9]+[[:space:]]+[a-zA-Z]+[[:space:]]+y/{print $7}'" iso_file = "#{tmp_dir}/xorriso_#{name}" - out, code = $server.run("#{xorriso} | #{iso_filter} >> #{iso_file}") + out, code = get_target('server').run("#{xorriso} | #{iso_filter} >> #{iso_file}") raise "error while executing xorriso.\nLogs:\n#{out}" if code.nonzero? - out, code = $server.run("diff #{tmp_dir}/test_image #{tmp_dir}/xorriso_#{name}") + out, code = get_target('server').run("diff #{tmp_dir}/test_image #{tmp_dir}/xorriso_#{name}") raise "error in verifying Cobbler buildiso image with xorriso.\nLogs:\n#{out}" if code.nonzero? end # xorriso When(/^I cleanup xorriso temp files$/) do - $server.run('rm /var/cache/cobbler/xorriso_*', check_errors: false) + get_target('server').run('rm /var/cache/cobbler/xorriso_*', check_errors: false) end # cobbler settings Given(/^cobbler settings are successfully migrated$/) do - out, code = $server.run('cobbler-settings migrate -t /etc/cobbler/settings.yaml') + out, code = get_target('server').run('cobbler-settings migrate -t /etc/cobbler/settings.yaml') raise "error when running cobbler-settings to migrate current settings.\nLogs:\n#{out}" if code.nonzero? end # cobbler parameters Then(/^I add the Cobbler parameter "([^"]*)" with value "([^"]*)" to item "(distro|profile|system)" with name "([^"]*)"$/) do |param, value, item, name| - result, code = $server.run("cobbler #{item} edit --name=#{name} --#{param}=#{value}", verbose: true) + result, code = get_target('server').run("cobbler #{item} edit --name=#{name} --#{param}=#{value}", verbose: true) puts("cobbler #{item} edit --name #{name} #{param}=#{value}") raise "error in adding parameter and value to Cobbler #{item}.\nLogs:\n#{result}" if code.nonzero? end When(/^I check the Cobbler parameter "([^"]*)" with value "([^"]*)" in the isolinux.cfg$/) do |param, value| tmp_dir = '/var/cache/cobbler/buildiso' - result, code = $server.run("cat #{tmp_dir}/isolinux/isolinux.cfg | grep -o #{param}=#{value}") + result, code = get_target('server').run("cat #{tmp_dir}/isolinux/isolinux.cfg | grep -o #{param}=#{value}") raise "error while verifying isolinux.cfg parameter for Cobbler buildiso.\nLogs:\n#{result}" if code.nonzero? end # backup step When(/^I backup Cobbler settings file$/) do - $server.run('cp /etc/cobbler/settings.yaml /etc/cobbler/settings.yaml.bak 2> /dev/null', check_errors: false) + get_target('server').run('cp /etc/cobbler/settings.yaml /etc/cobbler/settings.yaml.bak 2> /dev/null', check_errors: false) end # cleanup steps When(/^I cleanup after Cobbler buildiso$/) do - result, code = $server.run('rm -Rf /var/cache/cobbler') + result, code = get_target('server').run('rm -Rf /var/cache/cobbler') raise "Error during Cobbler buildiso cleanup.\nLogs:\n#{result}" if code.nonzero? end @@ -235,11 +235,11 @@ cleanup_command = 'rm /var/lib/cobbler/collections/**/*.json 2> /dev/null && ' \ 'rm -r /srv/tftpboot 2> /dev/null && ' \ 'cp /etc/cobbler/settings.yaml.bak /etc/cobbler/settings.yaml 2> /dev/null' - $server.run(cleanup_command.to_s, check_errors: false) - result, code = $server.run('systemctl restart apache') + get_target('server').run(cleanup_command.to_s, check_errors: false) + result, code = get_target('server').run('systemctl restart apache') raise "Error while restarting apache cleanup.\nLogs:\n#{result}" if code.nonzero? - result, code = $server.run('systemctl restart apache && systemctl restart cobblerd') + result, code = get_target('server').run('systemctl restart apache && systemctl restart cobblerd') raise "Error while restarting cobblerd.\nLogs:\n#{result}" if code.nonzero? step %(I wait until "cobblerd" service is active on "server") @@ -248,32 +248,32 @@ # cobbler commands When(/^I copy autoinstall mocked files on server$/) do target_dirs = '/var/autoinstall/Fedora_12_i386/images/pxeboot /var/autoinstall/SLES15-SP4-x86_64/DVD1/boot/x86_64/loader /var/autoinstall/mock' - $server.run("mkdir -p #{target_dirs}") + get_target('server').run("mkdir -p #{target_dirs}") base_dir = File.dirname(__FILE__) + '/../upload_files/autoinstall/cobbler/' source_dir = '/var/autoinstall/' return_codes = [] - return_codes << file_inject($server, base_dir + 'fedora12/vmlinuz', source_dir + 'Fedora_12_i386/images/pxeboot/vmlinuz') - return_codes << file_inject($server, base_dir + 'fedora12/initrd.img', source_dir + 'Fedora_12_i386/images/pxeboot/initrd.img') - return_codes << file_inject($server, base_dir + 'mock/empty.xml', source_dir + 'mock/empty.xml') - return_codes << file_inject($server, base_dir + 'sles15sp4/initrd', source_dir + 'SLES15-SP4-x86_64/DVD1/boot/x86_64/loader/initrd') - return_codes << file_inject($server, base_dir + 'sles15sp4/linux', source_dir + 'SLES15-SP4-x86_64/DVD1/boot/x86_64/loader/linux') + return_codes << file_inject(get_target('server'), base_dir + 'fedora12/vmlinuz', source_dir + 'Fedora_12_i386/images/pxeboot/vmlinuz') + return_codes << file_inject(get_target('server'), base_dir + 'fedora12/initrd.img', source_dir + 'Fedora_12_i386/images/pxeboot/initrd.img') + return_codes << file_inject(get_target('server'), base_dir + 'mock/empty.xml', source_dir + 'mock/empty.xml') + return_codes << file_inject(get_target('server'), base_dir + 'sles15sp4/initrd', source_dir + 'SLES15-SP4-x86_64/DVD1/boot/x86_64/loader/initrd') + return_codes << file_inject(get_target('server'), base_dir + 'sles15sp4/linux', source_dir + 'SLES15-SP4-x86_64/DVD1/boot/x86_64/loader/linux') raise 'File injection failed' unless return_codes.all?(&:zero?) end When(/^I run Cobbler sync (with|without) error checking$/) do |checking| if checking == 'with' - out, _code = $server.run('cobbler sync') + out, _code = get_target('server').run('cobbler sync') raise 'cobbler sync failed' if out.include? 'Push failed' else - _out, _code = $server.run('cobbler sync') + _out, _code = get_target('server').run('cobbler sync') end end When(/^I start local monitoring of Cobbler$/) do cobbler_conf_file = '/etc/cobbler/logging_config.conf' cobbler_log_file = '/var/log/cobbler/cobbler_debug.log' - $server.run("rm #{cobbler_log_file}", check_errors: false) - _result, code = $server.run("test -f #{cobbler_conf_file}.old", check_errors: false) + get_target('server').run("rm #{cobbler_log_file}", check_errors: false) + _result, code = get_target('server').run("test -f #{cobbler_conf_file}.old", check_errors: false) if !code.zero? handler_name = 'FileLogger02' formatter_name = 'JSONlogfile' @@ -294,9 +294,9 @@ "line_number=`awk \"/\\\[logger_root\\\]/{ print NR; exit }\" #{cobbler_conf_file}` && " \ "sed -e \"$(($line_number + 2))s/$/,#{handler_name}/\" -i #{cobbler_conf_file} && " \ "echo -e #{handler_class} >> #{cobbler_conf_file}" - $server.run("#{command} && systemctl restart cobblerd") + get_target('server').run("#{command} && systemctl restart cobblerd") else - $server.run('systemctl restart cobblerd') + get_target('server').run('systemctl restart cobblerd') end # give cobbler a few seconds to come up sleep 3 @@ -305,13 +305,13 @@ Then(/^the local logs for Cobbler should not contain errors$/) do cobbler_log_file = '/var/log/cobbler/cobbler_debug.log' local_file = '/tmp/cobbler_debug.log' - return_code = file_extract($server, cobbler_log_file, local_file) + return_code = file_extract(get_target('server'), cobbler_log_file, local_file) raise 'File extraction failed' unless return_code.zero? file_data = File.read(local_file).gsub!("\n", ',').chop.gsub('"', " ' ").gsub("\\''", '"') file_data = "[#{file_data}]" data_hash = JSON.parse(file_data) output = data_hash.select { |key, _hash| key['levelname'] == 'ERROR' } - $server.run("cp #{cobbler_log_file} #{cobbler_log_file}$(date +\"%Y_%m_%d_%I_%M_%p\")") unless output.empty? + get_target('server').run("cp #{cobbler_log_file} #{cobbler_log_file}$(date +\"%Y_%m_%d_%I_%M_%p\")") unless output.empty? raise "Errors in Cobbler logs:\n #{output}" unless output.empty? end diff --git a/testsuite/features/step_definitions/command_steps.rb b/testsuite/features/step_definitions/command_steps.rb index 7b805f2d68fb..2ac1a2adaa54 100644 --- a/testsuite/features/step_definitions/command_steps.rb +++ b/testsuite/features/step_definitions/command_steps.rb @@ -38,26 +38,26 @@ end Then(/^I turn off disable_local_repos for all clients/) do - $server.run("echo \"mgr_disable_local_repos: False\" > /srv/pillar/disable_local_repos_off.sls") + get_target('server').run("echo \"mgr_disable_local_repos: False\" > /srv/pillar/disable_local_repos_off.sls") step %(I install a salt pillar top file for "salt_bundle_config, disable_local_repos_off" with target "*" on the server) end Then(/^"([^"]*)" should communicate with the server using public interface/) do |host| node = get_target(host) - _result, return_code = node.run("ping -c 1 -I #{node.public_interface} #{$server.public_ip}", check_errors: false) + _result, return_code = node.run("ping -c 1 -I #{node.public_interface} #{get_target('server').public_ip}", check_errors: false) unless return_code.zero? sleep 2 puts "re-try ping" - node.run("ping -c 1 -I #{node.public_interface} #{$server.public_ip}") + node.run("ping -c 1 -I #{node.public_interface} #{get_target('server').public_ip}") end - $server.run("ping -c 1 #{node.public_ip}") + get_target('server').run("ping -c 1 #{node.public_ip}") end Then(/^"([^"]*)" should not communicate with the server using private interface/) do |host| node = get_target(host) - node.run_until_fail("ping -c 1 -I #{node.private_interface} #{$server.public_ip}") + node.run_until_fail("ping -c 1 -I #{node.private_interface} #{get_target('server').public_ip}") # commented out as a machine with the same IP address might exist somewhere in our engineering network - # $server.run_until_fail("ping -c 1 #{node.private_ip}") + # get_target('server').run_until_fail("ping -c 1 #{node.private_ip}") end Then(/^the clock from "([^"]*)" should be exact$/) do |host| @@ -70,27 +70,27 @@ Then(/^it should be possible to reach the test packages$/) do url = 'https://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Test-Packages:/Updates/rpm/x86_64/orion-dummy-1.1-1.1.x86_64.rpm' - $server.run("curl --insecure --location #{url} --output /dev/null") + get_target('server').run("curl --insecure --location #{url} --output /dev/null") end Then(/^it should be possible to use the HTTP proxy$/) do url = 'https://www.suse.com' proxy = "suma2:P4$$wordWith%and&@#{$server_http_proxy}" - $server.run("curl --insecure --proxy '#{proxy}' --proxy-anyauth --location '#{url}' --output /dev/null") + get_target('server').run("curl --insecure --proxy '#{proxy}' --proxy-anyauth --location '#{url}' --output /dev/null") end Then(/^it should be possible to use the custom download endpoint$/) do url = "#{$custom_download_endpoint}/rhn/manager/download/fake-rpm-suse-channel/repodata/repomd.xml" - $server.run("curl --ipv4 --location #{url} --output /dev/null") + get_target('server').run("curl --ipv4 --location #{url} --output /dev/null") end Then(/^it should be possible to reach the build sources$/) do - if $product == 'Uyuni' + if product == 'Uyuni' # TODO: move that internal resource to some other external location log 'Sanity check not implemented, move resource to external network first' else url = 'http://download.suse.de/ibs/SUSE/Products/SLE-SERVER/12-SP4/x86_64/product/media.1/products.key' - $server.run("curl --insecure --location #{url} --output /dev/null") + get_target('server').run("curl --insecure --location #{url} --output /dev/null") end end @@ -99,20 +99,20 @@ url = git_profiles.sub(/github\.com/, "raw.githubusercontent.com") .sub(/\.git#:/, "/master/") .sub(/$/, "/Docker/Dockerfile") - $server.run("curl --insecure --location #{url} --output /dev/null") + get_target('server').run("curl --insecure --location #{url} --output /dev/null") end Then(/^it should be possible to reach the authenticated registry$/) do unless $auth_registry.nil? || $auth_registry.empty? url = "https://#{$auth_registry}" - $server.run("curl --insecure --location #{url} --output /dev/null") + get_target('server').run("curl --insecure --location #{url} --output /dev/null") end end Then(/^it should be possible to reach the not authenticated registry$/) do unless $no_auth_registry.nil? || $no_auth_registry.empty? url = "https://#{$no_auth_registry}" - $server.run("curl --insecure --location #{url} --output /dev/null") + get_target('server').run("curl --insecure --location #{url} --output /dev/null") end end @@ -121,26 +121,26 @@ When(/^I delete these channels with spacewalk\-remove\-channel:$/) do |table| channels_cmd = "spacewalk-remove-channel " table.raw.each { |x| channels_cmd = channels_cmd + " -c " + x[0] } - $command_output, return_code = $server.run(channels_cmd, check_errors: false) + $command_output, return_code = get_target('server').run(channels_cmd, check_errors: false) end When(/^I list channels with spacewalk\-remove\-channel$/) do - $command_output, return_code = $server.run("spacewalk-remove-channel -l") + $command_output, return_code = get_target('server').run("spacewalk-remove-channel -l") raise "Unable to run spacewalk-remove-channel -l command on server" unless return_code.zero? end When(/^I add "([^"]*)" channel$/) do |channel| - $server.run("echo -e \"admin\nadmin\n\" | mgr-sync add channel #{channel}", buffer_size: 1_000_000) + get_target('server').run("echo -e \"admin\nadmin\n\" | mgr-sync add channel #{channel}", buffer_size: 1_000_000) end When(/^I use spacewalk\-common\-channel to add channel "([^"]*)" with arch "([^"]*)"$/) do |child_channel, arch| command = "spacewalk-common-channels -u admin -p admin -a #{arch} #{child_channel}" - $command_output, _code = $server.run(command) + $command_output, _code = get_target('server').run(command) end When(/^I use spacewalk\-repo\-sync to sync channel "([^"]*)"$/) do |channel| command = "spacewalk-repo-sync -c #{channel}" - $command_output, _code = $server.run(command) + $command_output, _code = get_target('server').run(command) end Then(/^I should get "([^"]*)"$/) do |value| @@ -169,7 +169,7 @@ end When(/^I wait for "([^"]*)" to be (uninstalled|installed) on "([^"]*)"$/) do |package, status, host| - if package.include?("suma") && $product == "Uyuni" + if package.include?("suma") && product == "Uyuni" package.gsub! "suma", "uyuni" end node = get_target(host) @@ -195,7 +195,7 @@ When(/^I query latest Salt changes on "(.*?)"$/) do |host| node = get_target(host) - salt = $use_salt_bundle ? "venv-salt-minion" : "salt" + salt = use_salt_bundle ? "venv-salt-minion" : "salt" if host == 'server' salt = 'salt' end @@ -209,12 +209,12 @@ When(/^I query latest Salt changes on Debian-like system "(.*?)"$/) do |host| node = get_target(host) salt = - if $use_salt_bundle + if use_salt_bundle "venv-salt-minion" else "salt" end - changelog_file = $use_salt_bundle ? "changelog.gz" : "changelog.Debian.gz" + changelog_file = use_salt_bundle ? "changelog.gz" : "changelog.Debian.gz" result, return_code = node.run("zcat /usr/share/doc/#{salt}/#{changelog_file}") result.split("\n")[0, 15].each do |line| line.force_encoding("UTF-8") @@ -245,7 +245,7 @@ elsif host.include? 'minion' or host.include? 'build' cmd = 'salt' end - $server.run_until_ok("#{cmd} #{system_name} state.highstate") + get_target('server').run_until_ok("#{cmd} #{system_name} state.highstate") end When(/^I wait until "([^"]*)" service is active on "([^"]*)"$/) do |service, host| @@ -269,7 +269,7 @@ end When(/^I enable product "([^"]*)"$/) do |prd| - list_output, _code = $server.run("mgr-sync list products", check_errors: false, buffer_size: 1_000_000) + list_output, _code = get_target('server').run("mgr-sync list products", check_errors: false, buffer_size: 1_000_000) executed = false linenum = 0 list_output.each_line do |line| @@ -277,14 +277,14 @@ linenum += 1 next unless line.include? prd executed = true - $command_output, _code = $server.run("echo '#{linenum}' | mgr-sync add product", check_errors: false, buffer_size: 1_000_000) + $command_output, _code = get_target('server').run("echo '#{linenum}' | mgr-sync add product", check_errors: false, buffer_size: 1_000_000) break end raise $command_output.to_s unless executed end When(/^I enable product "([^"]*)" without recommended$/) do |prd| - list_output, _code = $server.run("mgr-sync list products", check_errors: false, buffer_size: 1_000_000) + list_output, _code = get_target('server').run("mgr-sync list products", check_errors: false, buffer_size: 1_000_000) executed = false linenum = 0 list_output.each_line do |line| @@ -292,31 +292,31 @@ linenum += 1 next unless line.include? prd executed = true - $command_output, _code = $server.run("echo '#{linenum}' | mgr-sync add product --no-recommends", check_errors: false, buffer_size: 1_000_000) + $command_output, _code = get_target('server').run("echo '#{linenum}' | mgr-sync add product --no-recommends", check_errors: false, buffer_size: 1_000_000) break end raise $command_output.to_s unless executed end When(/^I execute mgr\-sync "([^"]*)" with user "([^"]*)" and password "([^"]*)"$/) do |arg1, u, p| - $command_output, _code = $server.run("echo -e '#{u}\n#{p}\n' | mgr-sync #{arg1}", check_errors: false, buffer_size: 1_000_000) + $command_output, _code = get_target('server').run("echo -e '#{u}\n#{p}\n' | mgr-sync #{arg1}", check_errors: false, buffer_size: 1_000_000) end When(/^I execute mgr\-sync "([^"]*)"$/) do |arg1| - $command_output, _code = $server.run("mgr-sync #{arg1}", buffer_size: 1_000_000) + $command_output, _code = get_target('server').run("mgr-sync #{arg1}", buffer_size: 1_000_000) end When(/^I remove the mgr\-sync cache file$/) do - $command_output, _code = $server.run('rm -f ~/.mgr-sync') + $command_output, _code = get_target('server').run('rm -f ~/.mgr-sync') end When(/^I refresh SCC$/) do refresh_timeout = 600 - $server.run('echo -e "admin\nadmin\n" | mgr-sync refresh', timeout: refresh_timeout) + get_target('server').run('echo -e "admin\nadmin\n" | mgr-sync refresh', timeout: refresh_timeout) end When(/^I execute mgr\-sync refresh$/) do - $command_output, _code = $server.run('mgr-sync refresh', check_errors: false) + $command_output, _code = get_target('server').run('mgr-sync refresh', check_errors: false) end # This function waits for all the reposyncs to complete. @@ -327,7 +327,7 @@ reposync_not_running_streak = 0 reposync_left_running_streak = 0 while reposync_not_running_streak <= 60 - command_output, _code = $server.run('ps axo pid,cmd | grep spacewalk-repo-sync | grep -v grep', check_errors: false) + command_output, _code = get_target('server').run('ps axo pid,cmd | grep spacewalk-repo-sync | grep -v grep', check_errors: false) if command_output.empty? reposync_not_running_streak += 1 reposync_left_running_streak = 0 @@ -354,7 +354,7 @@ reposync_not_running_streak = 0 reposync_left_running_streak = 0 while reposync_not_running_streak <= 60 - command_output, _code = $server.run('ps axo pid,cmd | grep spacewalk-repo-sync | grep -v grep', check_errors: false) + command_output, _code = get_target('server').run('ps axo pid,cmd | grep spacewalk-repo-sync | grep -v grep', check_errors: false) if command_output.empty? reposync_not_running_streak += 1 reposync_left_running_streak = 0 @@ -377,34 +377,34 @@ reposync_left_running_streak = 0 pid = process.split(' ')[0] - $server.run("kill #{pid}", check_errors: false) + get_target('server').run("kill #{pid}", check_errors: false) log "Reposync of channel #{channel} killed" end end Then(/^the reposync logs should not report errors$/) do - result, code = $server.run('grep -i "ERROR:" /var/log/rhn/reposync/*.log', check_errors: false) + result, code = get_target('server').run('grep -i "ERROR:" /var/log/rhn/reposync/*.log', check_errors: false) raise "Errors during reposync:\n#{result}" if code.zero? end Then(/^the "([^"]*)" reposync logs should not report errors$/) do |list| logfiles = list.split(",") logfiles.each do |logs| - _result, code = $server.run("test -f /var/log/rhn/reposync/#{logs}.log", check_errors: false) + _result, code = get_target('server').run("test -f /var/log/rhn/reposync/#{logs}.log", check_errors: false) if code.zero? - result, code = $server.run("grep -i 'ERROR:' /var/log/rhn/reposync/#{logs}.log", check_errors: false) + result, code = get_target('server').run("grep -i 'ERROR:' /var/log/rhn/reposync/#{logs}.log", check_errors: false) raise "Errors during #{logs} reposync:\n#{result}" if code.zero? end end end Then(/^"([^"]*)" package should have been stored$/) do |pkg| - $server.run("find /var/spacewalk/packages -name #{pkg}") + get_target('server').run("find /var/spacewalk/packages -name #{pkg}") end Then(/^solver file for "([^"]*)" should reference "([^"]*)"$/) do |channel, pkg| repeat_until_timeout(timeout: 600, message: "Reference #{pkg} not found in file.") do - _result, code = $server.run("dumpsolv /var/cache/rhn/repodata/#{channel}/solv | grep #{pkg}", check_errors: false) + _result, code = get_target('server').run("dumpsolv /var/cache/rhn/repodata/#{channel}/solv | grep #{pkg}", check_errors: false) break if code.zero? end end @@ -414,22 +414,22 @@ repeat_until_timeout(timeout: 7200, message: 'Channel not fully synced') do # solv is the last file to be written when the server synchronizes a channel, # therefore we wait until it exist - _result, code = $server.run("test -f /var/cache/rhn/repodata/#{channel}/solv", check_errors: false) + _result, code = get_target('server').run("test -f /var/cache/rhn/repodata/#{channel}/solv", check_errors: false) if code.zero? # We want to check if no .new files exists. # On a re-sync, the old files stay, the new one have this suffix until it's ready. - _result, new_code = $server.run("test -f /var/cache/rhn/repodata/#{channel}/solv.new", check_errors: false) + _result, new_code = get_target('server').run("test -f /var/cache/rhn/repodata/#{channel}/solv.new", check_errors: false) unless new_code.zero? break if withpkg.empty? - _result, solv_code = $server.run("dumpsolv /var/cache/rhn/repodata/#{channel}/solv | grep 'repo size: 0 solvables'", check_errors: false) + _result, solv_code = get_target('server').run("dumpsolv /var/cache/rhn/repodata/#{channel}/solv | grep 'repo size: 0 solvables'", check_errors: false) break unless solv_code.zero? end else # maybe a debian repo? - _result, code = $server.run("test -f /var/cache/rhn/repodata/#{channel}/Release", check_errors: false) + _result, code = get_target('server').run("test -f /var/cache/rhn/repodata/#{channel}/Release", check_errors: false) if code.zero? break if withpkg.empty? - _result, solv_code = $server.run("test -s /var/cache/rhn/repodata/#{channel}/Packages", check_errors: false) + _result, solv_code = get_target('server').run("test -s /var/cache/rhn/repodata/#{channel}/Packages", check_errors: false) break if solv_code.zero? end end @@ -449,17 +449,17 @@ end When(/^I execute mgr\-bootstrap "([^"]*)"$/) do |arg1| - $command_output, _code = $server.run("mgr-bootstrap #{arg1}") + $command_output, _code = get_target('server').run("mgr-bootstrap #{arg1}") end When(/^I fetch "([^"]*)" to "([^"]*)"$/) do |file, host| node = get_target(host) - node.run("wget http://#{$server.full_hostname}/#{file}") + node.run("wget http://#{get_target('server').full_hostname}/#{file}") end When(/^I wait until file "([^"]*)" contains "([^"]*)" on server$/) do |file, content| repeat_until_timeout(message: "#{content} not found in file #{file}", report_result: true) do - output, _code = $server.run("grep #{content} #{file}", check_errors: false) + output, _code = get_target('server').run("grep #{content} #{file}", check_errors: false) break if output =~ /#{content}/ sleep 2 "\n-----\n#{output}\n-----\n" @@ -467,13 +467,13 @@ end Then(/^file "([^"]*)" should contain "([^"]*)" on server$/) do |file, content| - output, _code = $server.run("grep -F '#{content}' #{file}", check_errors: false) + output, _code = get_target('server').run("grep -F '#{content}' #{file}", check_errors: false) raise "'#{content}' not found in file #{file}" if output !~ /#{content}/ "\n-----\n#{output}\n-----\n" end Then(/^the tomcat logs should not contain errors$/) do - output, _code = $server.run('cat /var/log/tomcat/*') + output, _code = get_target('server').run('cat /var/log/tomcat/*') msgs = %w[ERROR NullPointer] msgs.each do |msg| raise "-#{msg}- msg found on tomcat logs" if output.include? msg @@ -481,7 +481,7 @@ end Then(/^the taskomatic logs should not contain errors$/) do - output, _code = $server.run('cat /var/log/rhn/rhn_taskomatic_daemon.log') + output, _code = get_target('server').run('cat /var/log/rhn/rhn_taskomatic_daemon.log') msgs = %w[NullPointer] msgs.each do |msg| raise "-#{msg}- msg found on taskomatic logs" if output.include? msg @@ -489,28 +489,28 @@ end Then(/^the log messages should not contain out of memory errors$/) do - output, code = $server.run('grep -i "Out of memory: Killed process" /var/log/messages', check_errors: false) + output, code = get_target('server').run('grep -i "Out of memory: Killed process" /var/log/messages', check_errors: false) raise "Out of memory errors in /var/log/messages:\n#{output}" if code.zero? end When(/^I restart the spacewalk service$/) do - $server.run('spacewalk-service restart') + get_target('server').run('spacewalk-service restart') end When(/^I shutdown the spacewalk service$/) do - $server.run('spacewalk-service stop') + get_target('server').run('spacewalk-service stop') end When(/^I execute spacewalk-debug on the server$/) do - $server.run('spacewalk-debug') - code = file_extract($server, "/tmp/spacewalk-debug.tar.bz2", "spacewalk-debug.tar.bz2") + get_target('server').run('spacewalk-debug') + code = file_extract(get_target('server'), "/tmp/spacewalk-debug.tar.bz2", "spacewalk-debug.tar.bz2") raise "Download debug file failed" unless code.zero? end When(/^I extract the log files from all our active nodes$/) do $nodes.each do |node| # the salt_migration_minion is not available anymore - next if node.nil? || node == $salt_migration_minion + next if node.nil? || node == get_target('salt_migration_minion') STDOUT.puts "Node: #{node.full_hostname}" extract_logs_from_node(node) @@ -527,7 +527,7 @@ base_url = base_url.strip.split('=')[1].delete '"' real_uri = URI.parse(base_url) log 'Real protocol: ' + real_uri.scheme + ' host: ' + real_uri.host + ' port: ' + real_uri.port.to_s - normal_download_endpoint = "https://#{$proxy.full_hostname}:443" + normal_download_endpoint = "https://#{get_target('proxy').full_hostname}:443" expected_uri = URI.parse(type == 'custom' ? $custom_download_endpoint : normal_download_endpoint) log 'Expected protocol: ' + expected_uri.scheme + ' host: ' + expected_uri.host + ' port: ' + expected_uri.port.to_s raise 'Some parameters are not as expected' unless real_uri.scheme == expected_uri.scheme && real_uri.host == expected_uri.host && real_uri.port == expected_uri.port @@ -560,38 +560,38 @@ %w[ipmisim1.emu lan.conf fake_ipmi_host.sh].each do |file| source = File.dirname(__FILE__) + '/../upload_files/' + file dest = '/etc/ipmi/' + file - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? end - $server.run('chmod +x /etc/ipmi/fake_ipmi_host.sh') - $server.run('ipmi_sim -n < /dev/null > /dev/null &') + get_target('server').run('chmod +x /etc/ipmi/fake_ipmi_host.sh') + get_target('server').run('ipmi_sim -n < /dev/null > /dev/null &') end When(/^the server stops mocking an IPMI host$/) do - $server.run('pkill ipmi_sim') - $server.run('pkill fake_ipmi_host.sh || :') + get_target('server').run('pkill ipmi_sim') + get_target('server').run('pkill fake_ipmi_host.sh || :') end When(/^the server starts mocking a Redfish host$/) do - $server.run('mkdir -p /root/Redfish-Mockup-Server/') + get_target('server').run('mkdir -p /root/Redfish-Mockup-Server/') %w[redfishMockupServer.py rfSsdpServer.py].each do |file| source = File.dirname(__FILE__) + '/../upload_files/Redfish-Mockup-Server/' + file dest = '/root/Redfish-Mockup-Server/' + file - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? end - $server.run('curl --output DSP2043_2019.1.zip https://www.dmtf.org/sites/default/files/standards/documents/DSP2043_2019.1.zip') - $server.run('unzip DSP2043_2019.1.zip') + get_target('server').run('curl --output DSP2043_2019.1.zip https://www.dmtf.org/sites/default/files/standards/documents/DSP2043_2019.1.zip') + get_target('server').run('unzip DSP2043_2019.1.zip') cmd = "/usr/bin/python3 /root/Redfish-Mockup-Server/redfishMockupServer.py " \ - "-H #{$server.full_hostname} -p 8443 " \ + "-H #{get_target('server').full_hostname} -p 8443 " \ "-S -D /root/DSP2043_2019.1/public-catfish/ " \ "--ssl --cert /etc/pki/tls/certs/spacewalk.crt --key /etc/pki/tls/private/spacewalk.key " \ "< /dev/null > /dev/null 2>&1 &" - $server.run(cmd) + get_target('server').run(cmd) end When(/^the server stops mocking a Redfish host$/) do - $server.run('pkill -e -f /root/Redfish-Mockup-Server/redfishMockupServer.py') + get_target('server').run('pkill -e -f /root/Redfish-Mockup-Server/redfishMockupServer.py') end When(/^I install a user-defined state for "([^"]*)" on the server$/) do |host| @@ -600,22 +600,22 @@ file = 'user_defined_state.sls' source = File.dirname(__FILE__) + '/../upload_files/' + file dest = "/srv/salt/" + file - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? # generate top file and copy it to server script = "base:\n" \ " '#{system_name}':\n" \ " - user_defined_state\n" path = generate_temp_file('top.sls', script) - return_code = file_inject($server, path, '/srv/salt/top.sls') + return_code = file_inject(get_target('server'), path, '/srv/salt/top.sls') raise 'File injection failed' unless return_code.zero? `rm #{path}` # make both files readeable by salt - $server.run('chgrp salt /srv/salt/*') + get_target('server').run('chgrp salt /srv/salt/*') end When(/^I uninstall the user-defined state from the server$/) do - $server.run('rm /srv/salt/{user_defined_state.sls,top.sls}') + get_target('server').run('rm /srv/salt/{user_defined_state.sls,top.sls}') end When(/^I uninstall the managed file from "([^"]*)"$/) do |host| @@ -628,12 +628,12 @@ case host when 'server' - $server.run("configure-tftpsync.sh #{ENV['PROXY']}") + get_target('server').run("configure-tftpsync.sh #{ENV['PROXY']}") when 'proxy' cmd = "configure-tftpsync.sh --non-interactive --tftpbootdir=/srv/tftpboot \ --server-fqdn=#{ENV['SERVER']} \ --proxy-fqdn='proxy.example.org'" - $proxy.run(cmd) + get_target('proxy').run(cmd) else log "Host #{host} not supported" end @@ -656,7 +656,7 @@ end When(/^I clean the search index on the server$/) do - output, _code = $server.run('/usr/sbin/rhn-search cleanindex', check_errors: false) + output, _code = get_target('server').run('/usr/sbin/rhn-search cleanindex', check_errors: false) log 'Search reindex finished.' if output.include?('Index files have been deleted and database has been cleaned up, ready to reindex') raise 'The output includes an error log' if output.include?('ERROR') step %(I wait until rhn-search is responding) @@ -666,10 +666,10 @@ step %(I wait until "rhn-search" service is active on "server") repeat_until_timeout(timeout: 60, message: 'rhn-search is not responding properly.') do begin - log "Search by hostname: #{$minion.hostname}" - result = $api_test.system.search.hostname($minion.hostname) + log "Search by hostname: #{get_target('sle_minion').hostname}" + result = $api_test.system.search.hostname(get_target('sle_minion').hostname) log result - break if $minion.full_hostname.include? result.first['hostname'] + break if get_target('sle_minion').full_hostname.include? result.first['hostname'] rescue StandardError => e log "rhn-search still not responding.\nError message: #{e.message}" sleep 3 @@ -681,7 +681,7 @@ # mgr-sync refresh is a slow operation, we don't use the default timeout cmd = "spacecmd -u admin -p admin api sync.content.listProducts" repeat_until_timeout(timeout: 1800, message: "'mgr-sync refresh' did not finish") do - result, code = $server.run(cmd, check_errors: false) + result, code = get_target('server').run(cmd, check_errors: false) break if result.include? "SLES" sleep 5 end @@ -758,7 +758,7 @@ When(/^I wait until file "(.*)" exists on server$/) do |file| repeat_until_timeout do - break if file_exists?($server, file) + break if file_exists?(get_target('server'), file) sleep(1) end end @@ -771,11 +771,11 @@ end When(/^I call spacewalk\-repo\-sync for channel "(.*?)" with a custom url "(.*?)"$/) do |arg1, arg2| - @command_output, _code = $server.run("spacewalk-repo-sync -c #{arg1} -u #{arg2}", check_errors: false) + @command_output, _code = get_target('server').run("spacewalk-repo-sync -c #{arg1} -u #{arg2}", check_errors: false) end When(/^I call spacewalk\-repo\-sync to sync the channel "(.*?)"$/) do |channel| - @command_output, _code = $server.run("spacewalk-repo-sync -c #{channel}", check_errors: false) + @command_output, _code = get_target('server').run("spacewalk-repo-sync -c #{channel}", check_errors: false) end When(/^I call spacewalk\-repo\-sync to sync the parent channel "(.*?)"$/) do |channel| @@ -783,13 +783,13 @@ end When(/^I get "(.*?)" file details for channel "(.*?)" via spacecmd$/) do |arg1, arg2| - @command_output, _code = $server.run("spacecmd -u admin -p admin -q -- configchannel_filedetails #{arg2} '#{arg1}'", check_errors: false) + @command_output, _code = get_target('server').run("spacecmd -u admin -p admin -q -- configchannel_filedetails #{arg2} '#{arg1}'", check_errors: false) end # Repositories and packages management When(/^I migrate the non-SUMA repositories on "([^"]*)"$/) do |host| node = get_target(host) - salt_call = $use_salt_bundle ? "venv-salt-call" : "salt-call" + salt_call = use_salt_bundle ? "venv-salt-call" : "salt-call" # use sumaform states to migrate to latest SP the system repositories: node.run("#{salt_call} --local --file-root /root/salt/ state.apply repos") # disable again the non-SUMA repositories: @@ -839,16 +839,16 @@ When(/^I enable source package syncing$/) do cmd = "echo 'server.sync_source_packages = 1' >> /etc/rhn/rhn.conf" - $server.run(cmd) + get_target('server').run(cmd) end When(/^I disable source package syncing$/) do cmd = "sed -i 's/^server.sync_source_packages = 1.*//g' /etc/rhn/rhn.conf" - $server.run(cmd) + get_target('server').run(cmd) end When(/^I install pattern "([^"]*)" on this "([^"]*)"$/) do |pattern, host| - if pattern.include?("suma") && $product == "Uyuni" + if pattern.include?("suma") && product == "Uyuni" pattern.gsub! "suma", "uyuni" end node = get_target(host) @@ -858,7 +858,7 @@ end When(/^I remove pattern "([^"]*)" from this "([^"]*)"$/) do |pattern, host| - if pattern.include?("suma") && $product == "Uyuni" + if pattern.include?("suma") && product == "Uyuni" pattern.gsub! "suma", "uyuni" end node = get_target(host) @@ -940,16 +940,16 @@ end When(/^I install package tftpboot-installation on the server$/) do - output, _code = $server.run('find /var/spacewalk/packages -name tftpboot-installation-SLE-15-SP4-x86_64-*.noarch.rpm') + output, _code = get_target('server').run('find /var/spacewalk/packages -name tftpboot-installation-SLE-15-SP4-x86_64-*.noarch.rpm') packages = output.split("\n") pattern = '/tftpboot-installation-([^/]+)*.noarch.rpm' # Reverse sort the package name to get the latest version first and install it package = packages.min { |a, b| b.match(pattern)[0] <=> a.match(pattern)[0] } - $server.run("rpm -i #{package}", check_errors: false) + get_target('server').run("rpm -i #{package}", check_errors: false) end When(/^I reset tftp defaults on the proxy$/) do - $proxy.run("echo 'TFTP_USER=\"tftp\"\nTFTP_OPTIONS=\"\"\nTFTP_DIRECTORY=\"/srv/tftpboot\"\n' > /etc/sysconfig/tftp") + get_target('proxy').run("echo 'TFTP_USER=\"tftp\"\nTFTP_OPTIONS=\"\"\nTFTP_DIRECTORY=\"/srv/tftpboot\"\n' > /etc/sysconfig/tftp") end When(/^I wait until the package "(.*?)" has been cached on this "(.*?)"$/) do |pkg_name, host| @@ -969,7 +969,7 @@ base_channel = BASE_CHANNEL_BY_CLIENT[host] channel = CHANNEL_TO_SYNC_BY_BASE_CHANNEL[base_channel] parent_channel = PARENT_CHANNEL_TO_SYNC_BY_BASE_CHANNEL[base_channel] - $server.wait_while_process_running('mgr-create-bootstrap-repo') + get_target('server').wait_while_process_running('mgr-create-bootstrap-repo') cmd = if parent_channel.nil? "mgr-create-bootstrap-repo --create #{channel} --with-custom-channels --flush" else @@ -977,47 +977,47 @@ end log 'Creating the boostrap repository on the server:' log ' ' + cmd - $server.run(cmd) + get_target('server').run(cmd) end When(/^I install "([^"]*)" product on the proxy$/) do |product| - out, = $proxy.run("zypper ref && zypper --non-interactive install --auto-agree-with-licenses --force-resolution -t product #{product}") + out, = get_target('proxy').run("zypper ref && zypper --non-interactive install --auto-agree-with-licenses --force-resolution -t product #{product}") log "Installed #{product} product: #{out}" end When(/^I install proxy pattern on the proxy$/) do - pattern = $product == 'Uyuni' ? 'uyuni_proxy' : 'suma_proxy' + pattern = product == 'Uyuni' ? 'uyuni_proxy' : 'suma_proxy' cmd = "zypper --non-interactive install -t pattern #{pattern}" - $proxy.run(cmd, timeout: 600, successcodes: [0, 100, 101, 102, 103, 106]) + get_target('proxy').run(cmd, timeout: 600, successcodes: [0, 100, 101, 102, 103, 106]) end When(/^I let squid use avahi on the proxy$/) do file = '/usr/share/rhn/proxy-template/squid.conf' key = 'dns_multicast_local' val = 'on' - $proxy.run("grep '^#{key}' #{file} && sed -i -e 's/^#{key}.*$/#{key} #{val}/' #{file} || echo '#{key} #{val}' >> #{file}") + get_target('proxy').run("grep '^#{key}' #{file} && sed -i -e 's/^#{key}.*$/#{key} #{val}/' #{file} || echo '#{key} #{val}' >> #{file}") key = 'ignore_unknown_nameservers' val = 'off' - $proxy.run("grep '^#{key}' #{file} && sed -i -e 's/^#{key}.*$/#{key} #{val}/' #{file} || echo '#{key} #{val}' >> #{file}") + get_target('proxy').run("grep '^#{key}' #{file} && sed -i -e 's/^#{key}.*$/#{key} #{val}/' #{file} || echo '#{key} #{val}' >> #{file}") end When(/^I open avahi port on the proxy$/) do - $proxy.run('firewall-offline-cmd --zone=public --add-service=mdns') + get_target('proxy').run('firewall-offline-cmd --zone=public --add-service=mdns') end When(/^I copy server\'s keys to the proxy$/) do %w[RHN-ORG-PRIVATE-SSL-KEY RHN-ORG-TRUSTED-SSL-CERT rhn-ca-openssl.cnf].each do |file| - return_code = file_extract($server, '/root/ssl-build/' + file, '/tmp/' + file) + return_code = file_extract(get_target('server'), '/root/ssl-build/' + file, '/tmp/' + file) raise 'File extraction failed' unless return_code.zero? - $proxy.run('mkdir -p /root/ssl-build') - return_code = file_inject($proxy, '/tmp/' + file, '/root/ssl-build/' + file) + get_target('proxy').run('mkdir -p /root/ssl-build') + return_code = file_inject(get_target('proxy'), '/tmp/' + file, '/root/ssl-build/' + file) raise 'File injection failed' unless return_code.zero? end end When(/^I configure the proxy$/) do # prepare the settings file - settings = "RHN_PARENT=#{$server.full_hostname}\n" \ + settings = "RHN_PARENT=#{get_target('server').full_hostname}\n" \ "HTTP_PROXY=''\n" \ "VERSION=''\n" \ "TRACEBACK_EMAIL=galaxy-noise@suse.de\n" \ @@ -1026,7 +1026,7 @@ "SSL_PASSWORD=spacewalk\n" \ "SSL_ORG=SUSE\n" \ "SSL_ORGUNIT=SUSE\n" \ - "SSL_COMMON=#{$proxy.full_hostname}\n" \ + "SSL_COMMON=#{get_target('proxy').full_hostname}\n" \ "SSL_CITY=Nuremberg\n" \ "SSL_STATE=Bayern\n" \ "SSL_COUNTRY=DE\n" \ @@ -1042,62 +1042,62 @@ filename = File.basename(path) cmd = "configure-proxy.sh --non-interactive --rhn-user=admin --rhn-password=admin --answer-file=#{filename}" proxy_timeout = 600 - $proxy.run(cmd, timeout: proxy_timeout) + get_target('proxy').run(cmd, timeout: proxy_timeout) end When(/^I allow all SSL protocols on the proxy's apache$/) do file = '/etc/apache2/ssl-global.conf' key = 'SSLProtocol' val = 'all -SSLv2 -SSLv3' - $proxy.run("grep '#{key}' #{file} && sed -i -e 's/#{key}.*$/#{key} #{val}/' #{file}") - $proxy.run("systemctl reload apache2.service") + get_target('proxy').run("grep '#{key}' #{file} && sed -i -e 's/#{key}.*$/#{key} #{val}/' #{file}") + get_target('proxy').run("systemctl reload apache2.service") end When(/^I restart squid service on the proxy$/) do # We need to restart squid when we add a CNAME to the certificate - $proxy.run("systemctl restart squid.service") + get_target('proxy').run("systemctl restart squid.service") end When(/^I create channel "([^"]*)" from spacecmd of type "([^"]*)"$/) do |name, type| command = "spacecmd -u admin -p admin -- configchannel_create -n #{name} -t #{type}" - $server.run(command) + get_target('server').run(command) end When(/^I update init.sls from spacecmd with content "([^"]*)" for channel "([^"]*)"$/) do |content, label| filepath = "/tmp/#{label}" - $server.run("echo -e \"#{content}\" > #{filepath}", timeout: 600) + get_target('server').run("echo -e \"#{content}\" > #{filepath}", timeout: 600) command = "spacecmd -u admin -p admin -- configchannel_updateinitsls -c #{label} -f #{filepath} -y" - $server.run(command) - file_delete($server, filepath) + get_target('server').run(command) + file_delete(get_target('server'), filepath) end When(/^I update init.sls from spacecmd with content "([^"]*)" for channel "([^"]*)" and revision "([^"]*)"$/) do |content, label, revision| filepath = "/tmp/#{label}" - $server.run("echo -e \"#{content}\" > #{filepath}", timeout: 600) + get_target('server').run("echo -e \"#{content}\" > #{filepath}", timeout: 600) command = "spacecmd -u admin -p admin -- configchannel_updateinitsls -c #{label} -f #{filepath} -r #{revision} -y" - $server.run(command) - file_delete($server, filepath) + get_target('server').run(command) + file_delete(get_target('server'), filepath) end When(/^I schedule apply configchannels for "([^"]*)"$/) do |host| system_name = get_system_name(host) - $server.run('spacecmd -u admin -p admin clear_caches') + get_target('server').run('spacecmd -u admin -p admin clear_caches') command = "spacecmd -y -u admin -p admin -- system_scheduleapplyconfigchannels #{system_name}" - $server.run(command) + get_target('server').run(command) end # WORKAROUND # Work around issue https://github.com/SUSE/spacewalk/issues/10360 # Remove as soon as the issue is fixed When(/^I let Kiwi build from external repositories$/) do - $server.run("sed -i 's/--ignore-repos-used-for-build//' /usr/share/susemanager/salt/images/kiwi-image-build.sls") + get_target('server').run("sed -i 's/--ignore-repos-used-for-build//' /usr/share/susemanager/salt/images/kiwi-image-build.sls") end When(/^I refresh packages list via spacecmd on "([^"]*)"$/) do |client| node = get_system_name(client) - $server.run("spacecmd -u admin -p admin clear_caches") + get_target('server').run("spacecmd -u admin -p admin clear_caches") command = "spacecmd -u admin -p admin system_schedulepackagerefresh #{node}" - $server.run(command) + get_target('server').run(command) end When(/^I refresh the packages list via package manager on "([^"]*)"$/) do |host| @@ -1114,19 +1114,19 @@ current_time = Time.now.strftime('%Y%m%d%H%M') timeout_time = (Time.now + long_wait_delay + round_minute).strftime('%Y%m%d%H%M') node = get_system_name(client) - $server.run("spacecmd -u admin -p admin clear_caches") + get_target('server').run("spacecmd -u admin -p admin clear_caches") # Gather all the ids of package refreshes existing at SUMA - refreshes, = $server.run("spacecmd -u admin -p admin schedule_list | grep 'Package List Refresh' | cut -f1 -d' '", check_errors: false) + refreshes, = get_target('server').run("spacecmd -u admin -p admin schedule_list | grep 'Package List Refresh' | cut -f1 -d' '", check_errors: false) node_refreshes = "" refreshes.split(' ').each do |refresh_id| next unless refresh_id.match('/[0-9]{1,4}/') - refresh_result, = $server.run("spacecmd -u admin -p admin schedule_details #{refresh_id}") # Filter refreshes for specific system + refresh_result, = get_target('server').run("spacecmd -u admin -p admin schedule_details #{refresh_id}") # Filter refreshes for specific system next unless refresh_result.include? node node_refreshes += "^#{refresh_id}|" end cmd = "spacecmd -u admin -p admin schedule_list #{current_time} #{timeout_time} | egrep '#{node_refreshes.delete_suffix('|')}'" repeat_until_timeout(timeout: long_wait_delay, message: "'refresh package list' did not finish") do - result, code = $server.run(cmd, check_errors: false) + result, code = get_target('server').run(cmd, check_errors: false) sleep 1 next if result.include? '0 0 1' break if result.include? '1 0 0' @@ -1136,9 +1136,9 @@ When(/^spacecmd should show packages "([^"]*)" installed on "([^"]*)"$/) do |packages, client| node = get_system_name(client) - $server.run("spacecmd -u admin -p admin clear_caches") + get_target('server').run("spacecmd -u admin -p admin clear_caches") command = "spacecmd -u admin -p admin system_listinstalledpackages #{node}" - result, _code = $server.run(command, check_errors: false) + result, _code = get_target('server').run(command, check_errors: false) packages.split(' ').each do |package| pkg = package.strip raise "package #{pkg} is not installed" unless result.include? pkg @@ -1147,10 +1147,10 @@ When(/^I wait until package "([^"]*)" is installed on "([^"]*)" via spacecmd$/) do |pkg, client| node = get_system_name(client) - $server.run("spacecmd -u admin -p admin clear_caches") + get_target('server').run("spacecmd -u admin -p admin clear_caches") command = "spacecmd -u admin -p admin system_listinstalledpackages #{node}" repeat_until_timeout(timeout: 600, message: "package #{pkg} is not installed yet") do - result, _code = $server.run(command, check_errors: false) + result, _code = get_target('server').run(command, check_errors: false) break if result.include? pkg sleep 1 end @@ -1158,10 +1158,10 @@ When(/^I wait until package "([^"]*)" is removed from "([^"]*)" via spacecmd$/) do |pkg, client| node = get_system_name(client) - $server.run("spacecmd -u admin -p admin clear_caches") + get_target('server').run("spacecmd -u admin -p admin clear_caches") command = "spacecmd -u admin -p admin system_listinstalledpackages #{node}" repeat_until_timeout(timeout: 600, message: "package #{pkg} is still present") do - result, code = $server.run(command, check_errors: false) + result, code = get_target('server').run(command, check_errors: false) sleep 1 break unless result.include? pkg end @@ -1173,7 +1173,7 @@ os_family = node.os_family repositories = 'tools_pool_repo tools_update_repo' if os_family =~ /^opensuse/ || os_family =~ /^sles/ - if $product != 'Uyuni' + if product != 'Uyuni' repositories.concat(' tools_additional_repo') # Needed because in SLES15SP3 and openSUSE 15.3 and higher, firewalld will replace this package. # But the tools_update_repo's priority doesn't allow to cope with the obsoletes option from firewalld. @@ -1187,7 +1187,7 @@ When(/^I apply "([^"]*)" local salt state on "([^"]*)"$/) do |state, host| node = get_target(host) - salt_call = $use_salt_bundle ? "venv-salt-call" : "salt-call" + salt_call = use_salt_bundle ? "venv-salt-call" : "salt-call" if host == 'server' salt_call = 'salt-call' end @@ -1200,30 +1200,30 @@ When(/^I copy unset package file on server$/) do base_dir = File.dirname(__FILE__) + "/../upload_files/unset_package/" - return_code = file_inject($server, base_dir + 'subscription-tools-1.0-0.noarch.rpm', '/root/subscription-tools-1.0-0.noarch.rpm') + return_code = file_inject(get_target('server'), base_dir + 'subscription-tools-1.0-0.noarch.rpm', '/root/subscription-tools-1.0-0.noarch.rpm') raise 'File injection failed' unless return_code.zero? end When(/^I copy vCenter configuration file on server$/) do base_dir = File.dirname(__FILE__) + "/../upload_files/virtualization/" - return_code = file_inject($server, base_dir + 'vCenter.json', '/var/tmp/vCenter.json') + return_code = file_inject(get_target('server'), base_dir + 'vCenter.json', '/var/tmp/vCenter.json') raise 'File injection failed' unless return_code.zero? end When(/^I export software channels "([^"]*)" with ISS v2 to "([^"]*)"$/) do |channel, path| - $server.run("inter-server-sync export --channels=#{channel} --outputDir=#{path}") + get_target('server').run("inter-server-sync export --channels=#{channel} --outputDir=#{path}") end When(/^I export config channels "([^"]*)" with ISS v2 to "([^"]*)"$/) do |channel, path| - $server.run("inter-server-sync export --configChannels=#{channel} --outputDir=#{path}") + get_target('server').run("inter-server-sync export --configChannels=#{channel} --outputDir=#{path}") end When(/^I import data with ISS v2 from "([^"]*)"$/) do |path| - $server.run("inter-server-sync import --importDir=#{path}") + get_target('server').run("inter-server-sync import --importDir=#{path}") end Then(/^"(.*?)" folder on server is ISS v2 export directory$/) do |folder| - raise "Folder #{folder} not found" unless file_exists?($server, folder + "/sql_statements.sql.gz") + raise "Folder #{folder} not found" unless file_exists?(get_target('server'), folder + "/sql_statements.sql.gz") end Then(/^export folder "(.*?)" shouldn't exist on "(.*?)"$/) do |folder, host| @@ -1240,12 +1240,12 @@ Given(/^I can connect to the ReportDB on the Server$/) do # connect and quit database - _result, return_code = $server.run(reportdb_server_query('\\q')) + _result, return_code = get_target('server').run(reportdb_server_query('\\q')) raise 'Couldn\'t connect to the ReportDB on the server' unless return_code.zero? end Given(/^I have a user with admin access to the ReportDB$/) do - users_and_permissions, return_code = $server.run(reportdb_server_query('\\du')) + users_and_permissions, return_code = get_target('server').run(reportdb_server_query('\\du')) raise 'Couldn\'t connect to the ReportDB on the server' unless return_code.zero? # extract only the line for the suma user suma_user_permissions = users_and_permissions[/pythia_susemanager(.*)}/] @@ -1258,13 +1258,13 @@ file = 'create_user_reportdb.exp' source = "#{File.dirname(__FILE__)}/../upload_files/#{file}" dest = "/tmp/#{file}" - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection in server failed' unless return_code.zero? - $server.run("expect -f /tmp/#{file} #{$reportdb_ro_user}") + get_target('server').run("expect -f /tmp/#{file} #{$reportdb_ro_user}") end Then(/^I should see the read-only user listed on the ReportDB user accounts$/) do - users_and_permissions, _code = $server.run(reportdb_server_query('\\du')) + users_and_permissions, _code = get_target('server').run(reportdb_server_query('\\du')) raise 'Couldn\'t find the newly created user on the ReportDB' unless users_and_permissions.include? $reportdb_ro_user end @@ -1272,19 +1272,19 @@ file = 'delete_user_reportdb.exp' source = "#{File.dirname(__FILE__)}/../upload_files/#{file}" dest = "/tmp/#{file}" - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection in server failed' unless return_code.zero? - $server.run("expect -f /tmp/#{file} #{$reportdb_ro_user}") + get_target('server').run("expect -f /tmp/#{file} #{$reportdb_ro_user}") end Then(/^I shouldn't see the read-only user listed on the ReportDB user accounts$/) do - users_and_permissions, _code = $server.run(reportdb_server_query('\\du')) + users_and_permissions, _code = get_target('server').run(reportdb_server_query('\\du')) raise 'Created read-only user on the ReportDB remains listed' if users_and_permissions.include? $reportdb_ro_user end When(/^I connect to the ReportDB with read-only user from external machine$/) do # connection from the controller to the reportdb in the server - $reportdb_ro_conn = PG.connect(host: $server.public_ip, port: 5432, dbname: 'reportdb', user: $reportdb_ro_user, password: 'linux') + $reportdb_ro_conn = PG.connect(host: get_target('server').public_ip, port: 5432, dbname: 'reportdb', user: $reportdb_ro_user, password: 'linux') end Then(/^I should be able to query the ReportDB$/) do @@ -1322,14 +1322,14 @@ Then(/^I should be able to connect to the ReportDB with the ReportDB admin user$/) do # connection from the controller to the reportdb in the server - reportdb_admin_conn = PG.connect(host: $server.public_ip, port: 5432, dbname: 'reportdb', user: $reportdb_admin_user, password: $reportdb_admin_password) + reportdb_admin_conn = PG.connect(host: get_target('server').public_ip, port: 5432, dbname: 'reportdb', user: $reportdb_admin_user, password: $reportdb_admin_password) raise 'Couldn\'t connect to ReportDB with admin from external machine' unless reportdb_admin_conn.status.zero? end Then(/^I should not be able to connect to product database with the ReportDB admin user$/) do - dbname = $product.delete(' ').downcase + dbname = product.delete(' ').downcase assert_raises PG::ConnectionBad do - PG.connect(host: $server.public_ip, port: 5432, dbname: dbname, user: $reportdb_admin_user, password: $reportdb_admin_password) + PG.connect(host: get_target('server').public_ip, port: 5432, dbname: dbname, user: $reportdb_admin_user, password: $reportdb_admin_password) end end @@ -1366,21 +1366,21 @@ When(/^I generate the configuration "([^"]*)" of Containerized Proxy on the server$/) do |file_path| # Doc: https://www.uyuni-project.org/uyuni-docs/en/uyuni/reference/spacecmd/proxy_container.html command = "echo spacewalk > cert_pass && spacecmd -u admin -p admin proxy_container_config_generate_cert" \ - " -- -o #{file_path} -p 8022 #{$proxy.full_hostname.sub('pxy', 'pod-pxy')} #{$server.full_hostname}" \ + " -- -o #{file_path} -p 8022 #{get_target('proxy').full_hostname.sub('pxy', 'pod-pxy')} #{get_target('server').full_hostname}" \ " 2048 galaxy-noise@suse.de --ca-pass cert_pass" \ " && rm cert_pass" - $server.run(command) + get_target('server').run(command) end When(/^I add avahi hosts in Containerized Proxy configuration$/) do - if $server.full_hostname.include? 'tf.local' + if get_target('server').full_hostname.include? 'tf.local' hosts_list = "" $host_by_node.each do |node, _host| hosts_list += "--add-host=#{node.full_hostname}:#{node.public_ip} " end hosts_list = escape_regex(hosts_list) regex = "s/^#?EXTRA_POD_ARGS=.*$/EXTRA_POD_ARGS=#{hosts_list}/g;" - $proxy.run("sed -i.bak -Ee '#{regex}' /etc/sysconfig/uyuni-proxy-systemd-services") + get_target('proxy').run("sed -i.bak -Ee '#{regex}' /etc/sysconfig/uyuni-proxy-systemd-services") log "Avahi hosts added: #{hosts_list}" log 'The Development team has not been working to support avahi in Containerized Proxy, yet. This is best effort.' else @@ -1400,7 +1400,7 @@ end Then(/^port "([^"]*)" should be (open|closed)$/) do |port, selection| - _output, code = $server.run("ss --listening --numeric | grep :#{port}", check_errors: false, verbose: true) + _output, code = get_target('server').run("ss --listening --numeric | grep :#{port}", check_errors: false, verbose: true) port_opened = code.zero? if selection == 'closed' raise "Port '#{port}' open although it should not be!" if port_opened @@ -1411,14 +1411,13 @@ # rebooting via SSH When(/^I reboot the server through SSH$/) do - init_string = "ssh:#{$server.public_ip}" + init_string = "ssh:#{get_target('server').public_ip}" temp_server = twopence_init(init_string) - temp_server.extend(LavandaBasic) temp_server.run('reboot > /dev/null 2> /dev/null &') default_timeout = 300 - check_shutdown($server.public_ip, default_timeout) - check_restart($server.public_ip, temp_server, default_timeout) + check_shutdown(get_target('server').public_ip, default_timeout) + check_restart(get_target('server').public_ip, temp_server, default_timeout) repeat_until_timeout(timeout: default_timeout, message: "Spacewalk didn't come up") do out, code = temp_server.run('spacewalk-service status', check_errors: false, timeout: 10) @@ -1435,7 +1434,7 @@ node.run('reboot > /dev/null 2> /dev/null &') reboot_timeout = 120 check_shutdown(node.public_ip, reboot_timeout) - check_restart($server.public_ip, node, reboot_timeout) + check_restart(get_target('server').public_ip, node, reboot_timeout) end When(/^I reboot the "([^"]*)" minion through the web UI$/) do |host| @@ -1458,21 +1457,20 @@ end When(/^I change the server's short hostname from hosts and hostname files$/) do - old_hostname = $server.hostname + old_hostname = get_target('server').hostname new_hostname = old_hostname + '2' log "New short hostname: #{new_hostname}" - $server.run("sed -i 's/#{old_hostname}/#{new_hostname}/g' /etc/hostname && - echo '#{$server.public_ip} #{$server.full_hostname} #{old_hostname}' >> /etc/hosts && - echo '#{$server.public_ip} #{new_hostname}#{$server.full_hostname.delete_prefix($server.hostname)} #{new_hostname}' >> /etc/hosts") + get_target('server').run("sed -i 's/#{old_hostname}/#{new_hostname}/g' /etc/hostname && + echo '#{get_target('server').public_ip} #{get_target('server').full_hostname} #{old_hostname}' >> /etc/hosts && + echo '#{get_target('server').public_ip} #{new_hostname}#{get_target('server').full_hostname.delete_prefix(get_target('server').hostname)} #{new_hostname}' >> /etc/hosts") end # changing hostname When(/^I run spacewalk-hostname-rename command on the server$/) do - temp_server = twopence_init("ssh:#{$server.public_ip}") - temp_server.extend(LavandaBasic) + temp_server = twopence_init("ssh:#{get_target('server').public_ip}") command = "spacecmd --nossl -q api api.getVersion -u admin -p admin; " \ - "spacewalk-hostname-rename #{$server.public_ip} " \ + "spacewalk-hostname-rename #{get_target('server').public_ip} " \ "--ssl-country=DE --ssl-state=Bayern --ssl-city=Nuremberg " \ "--ssl-org=SUSE --ssl-orgunit=SUSE --ssl-email=galaxy-noise@suse.de " \ "--ssl-ca-password=spacewalk" @@ -1493,15 +1491,14 @@ end When(/^I change back the server's hostname$/) do - init_string = "ssh:#{$server.public_ip}" + init_string = "ssh:#{get_target('server').public_ip}" temp_server = twopence_init(init_string) - temp_server.extend(LavandaBasic) - temp_server.run("echo '#{$server.full_hostname}' > /etc/hostname ") + temp_server.run("echo '#{get_target('server').full_hostname}' > /etc/hostname ") end When(/^I clean up the server's hosts file$/) do command = "sed -i '$d' /etc/hosts && sed -i '$d' /etc/hosts" - $server.run(command) + get_target('server').run(command) end When(/^I enable firewall ports for monitoring on this "([^"]*)"$/) do |host| @@ -1525,7 +1522,7 @@ When(/^I delete the system "([^"]*)" via spacecmd$/) do |minion| node = get_system_name(minion) command = "spacecmd -u admin -p admin -y system_delete #{node}" - $server.run(command, check_errors: true, verbose: true) + get_target('server').run(command, check_errors: true, verbose: true) end When(/^I execute "([^"]*)" on the "([^"]*)"$/) do |command, host| diff --git a/testsuite/features/step_definitions/common_steps.rb b/testsuite/features/step_definitions/common_steps.rb index 09a9f2678bb1..fa9536c0d05d 100644 --- a/testsuite/features/step_definitions/common_steps.rb +++ b/testsuite/features/step_definitions/common_steps.rb @@ -26,12 +26,12 @@ iso_path = url.sub(/^http:.*\/pub/, '/mirror/pub') else iso_path = "/tmp/#{name}.iso" - $server.run("wget --no-check-certificate -O #{iso_path} #{url}", timeout: 1500) + get_target('server').run("wget --no-check-certificate -O #{iso_path} #{url}", timeout: 1500) end mount_point = "/srv/www/htdocs/#{name}" - $server.run("mkdir -p #{mount_point}") - $server.run("grep #{iso_path} /etc/fstab || echo '#{iso_path} #{mount_point} iso9660 loop,ro,_netdev 0 0' >> /etc/fstab") - $server.run("umount #{iso_path}; mount #{iso_path}") + get_target('server').run("mkdir -p #{mount_point}") + get_target('server').run("grep #{iso_path} /etc/fstab || echo '#{iso_path} #{mount_point} iso9660 loop,ro,_netdev 0 0' >> /etc/fstab") + get_target('server').run("umount #{iso_path}; mount #{iso_path}") end Then(/^the hostname for "([^"]*)" should be correct$/) do |host| @@ -459,7 +459,7 @@ xml-commons-resolver xorriso xtables-plugins" - $build_host.run("zypper --non-interactive in #{packages}", timeout: 600) + get_target('build_host').run("zypper --non-interactive in #{packages}", timeout: 600) end # rubocop:enable Metrics/BlockLength @@ -504,14 +504,14 @@ end Given(/^metadata generation finished for "([^"]*)"$/) do |channel| - $server.run_until_ok("ls /var/cache/rhn/repodata/#{channel}/*updateinfo.xml.gz") + get_target('server').run_until_ok("ls /var/cache/rhn/repodata/#{channel}/*updateinfo.xml.gz") end When(/^I push package "([^"]*)" into "([^"]*)" channel$/) do |arg1, arg2| srvurl = "http://#{ENV['SERVER']}/APP" command = "rhnpush --server=#{srvurl} -u admin -p admin --nosig -c #{arg2} #{arg1} " - $server.run(command, timeout: 500) - $server.run('ls -lR /var/spacewalk/packages', timeout: 500) + get_target('server').run(command, timeout: 500) + get_target('server').run('ls -lR /var/spacewalk/packages', timeout: 500) end Then(/^I should see package "([^"]*)" in channel "([^"]*)"$/) do |pkg, channel| diff --git a/testsuite/features/step_definitions/content_lifecycle_steps.rb b/testsuite/features/step_definitions/content_lifecycle_steps.rb index f0eaecb4c6d2..662b5c8d7ab4 100644 --- a/testsuite/features/step_definitions/content_lifecycle_steps.rb +++ b/testsuite/features/step_definitions/content_lifecycle_steps.rb @@ -94,10 +94,10 @@ When(/^I add "([^\"]*)" calendar file as url$/) do |file| source = File.dirname(__FILE__) + '/../upload_files/' + file dest = "/srv/www/htdocs/pub/" + file - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? - $server.run("chmod 644 #{dest}") - url = "https://#{$server.full_hostname}/pub/" + file + get_target('server').run("chmod 644 #{dest}") + url = "https://#{get_target('server').full_hostname}/pub/" + file log "URL: #{url}" step %(I enter "#{url}" as "calendar-data-text") end diff --git a/testsuite/features/step_definitions/docker_steps.rb b/testsuite/features/step_definitions/docker_steps.rb index 845717ad656e..188676c3e4aa 100644 --- a/testsuite/features/step_definitions/docker_steps.rb +++ b/testsuite/features/step_definitions/docker_steps.rb @@ -12,9 +12,9 @@ def retrieve_build_host_id systems = $api_test.system.list_systems refute_nil(systems) build_host_id = systems - .select { |s| s['name'] == $build_host.full_hostname } + .select { |s| s['name'] == get_target('build_host').full_hostname } .map { |s| s['id'] }.first - refute_nil(build_host_id, "Build host #{$build_host.full_hostname} is not yet registered?") + refute_nil(build_host_id, "Build host #{get_target('build_host').full_hostname} is not yet registered?") build_host_id end diff --git a/testsuite/features/step_definitions/file_management_steps.rb b/testsuite/features/step_definitions/file_management_steps.rb index 8766a7110ea7..26dbac3217b5 100644 --- a/testsuite/features/step_definitions/file_management_steps.rb +++ b/testsuite/features/step_definitions/file_management_steps.rb @@ -6,7 +6,7 @@ # generic file management steps When(/^I destroy "([^"]*)" directory on server$/) do |directory| - $server.run("rm -rf #{directory}") + get_target('server').run("rm -rf #{directory}") end When(/^I destroy "([^"]*)" directory on "([^"]*)"$/) do |directory, host| @@ -20,7 +20,7 @@ end Then(/^file "([^"]*)" should exist on server$/) do |filename| - $server.run("test -f #{filename}") + get_target('server').run("test -f #{filename}") end Then(/^file "([^"]*)" should exist on "([^"]*)"$/) do |filename, host| @@ -34,7 +34,7 @@ end Then(/^file "([^"]*)" should not exist on server$/) do |filename| - $server.run("test ! -f #{filename}") + get_target('server').run("test ! -f #{filename}") end Then(/^file "([^"]*)" should not exist on "([^"]*)"$/) do |filename, host| @@ -49,14 +49,14 @@ When(/^I bootstrap "([^"]*)" using bootstrap script with activation key "([^"]*)" from the (server|proxy)$/) do |host, key, target_type| # Use server if proxy is not defined as proxy is not mandatory - target = $proxy - if target_type.include? 'server' or $proxy.nil? + target = get_target('proxy') + if target_type.include? 'server' or get_target('proxy').nil? log 'WARN: Bootstrapping to server, because proxy is not defined.' unless target_type.include? 'server' - target = $server + target = get_target('server') end # Prepare bootstrap script for different types of clients - force_bundle = $use_salt_bundle ? '--force-bundle' : '' + force_bundle = use_salt_bundle ? '--force-bundle' : '' node = get_target(host) gpg_keys = get_gpg_keys(node, target) @@ -94,5 +94,5 @@ Then(/^I remove server hostname from hosts file on "([^"]*)"$/) do |host| node = get_target(host) - node.run("sed -i \'s/#{$server.full_hostname}//\' /etc/hosts") + node.run("sed -i \'s/#{get_target('server').full_hostname}//\' /etc/hosts") end diff --git a/testsuite/features/step_definitions/navigation_steps.rb b/testsuite/features/step_definitions/navigation_steps.rb index 36758fc55337..c54027c376a2 100644 --- a/testsuite/features/step_definitions/navigation_steps.rb +++ b/testsuite/features/step_definitions/navigation_steps.rb @@ -1058,7 +1058,7 @@ end When(/^I enter the server hostname as the redfish server address$/) do - step %(I enter "#{$server.full_hostname}:8443" as "powerAddress") + step %(I enter "#{get_target('server').full_hostname}:8443" as "powerAddress") end When(/^I clear browser cookies$/) do diff --git a/testsuite/features/step_definitions/retail_steps.rb b/testsuite/features/step_definitions/retail_steps.rb index 2ef7db9b89e8..78253134ae8f 100644 --- a/testsuite/features/step_definitions/retail_steps.rb +++ b/testsuite/features/step_definitions/retail_steps.rb @@ -46,7 +46,7 @@ def compute_kiwi_profile_filename(host) case image when 'sles15sp3', 'sles15sp3o', 'sles15sp4', 'sles15sp4o' # 'Kiwi/POS_Image-JeOS7_42' for 4.2 branch - $product == 'Uyuni' ? 'Kiwi/POS_Image-JeOS7_uyuni' : 'Kiwi/POS_Image-JeOS7_head' + product == 'Uyuni' ? 'Kiwi/POS_Image-JeOS7_uyuni' : 'Kiwi/POS_Image-JeOS7_head' when 'sles15sp2', 'sles15sp2o' 'Kiwi/POS_Image-JeOS7_41' when 'sles15sp1', 'sles15sp1o' @@ -64,7 +64,7 @@ def compute_kiwi_profile_name(host) case image when 'sles15sp3', 'sles15sp3o', 'sles15sp4', 'sles15sp4o' # 'POS_Image_JeOS7_42' for 4.2 branch - $product == 'Uyuni' ? 'POS_Image_JeOS7_uyuni' : 'POS_Image_JeOS7_head' + product == 'Uyuni' ? 'POS_Image_JeOS7_uyuni' : 'POS_Image_JeOS7_head' when 'sles15sp2', 'sles15sp2o' 'POS_Image_JeOS7_41' when 'sles15sp1', 'sles15sp1o' @@ -92,12 +92,12 @@ def compute_kiwi_profile_version(host) end When(/^I (enable|disable) repositories (before|after) installing branch server$/) do |action, _when| - os_version = $proxy.os_version - os_family = $proxy.os_family + os_version = get_target('proxy').os_version + os_family = get_target('proxy').os_family # Distribution repos = 'os_pool_repo os_update_repo testing_overlay_devel_repo' - log $proxy.run("zypper mr --#{action} #{repos}") + log get_target('proxy').run("zypper mr --#{action} #{repos}") # Server Applications, proxy product and modules, proxy devel if os_family =~ /^sles/ && os_version =~ /^15/ @@ -109,11 +109,11 @@ def compute_kiwi_profile_version(host) elsif os_family =~ /^opensuse/ repos = 'proxy_pool_repo' end - log $proxy.run("zypper mr --#{action} #{repos}") + log get_target('proxy').run("zypper mr --#{action} #{repos}") end When(/^I start tftp on the proxy$/) do - case $product + case product # TODO: Should we handle this in Sumaform? when 'Uyuni' step %(I enable repositories before installing branch server) @@ -121,22 +121,22 @@ def compute_kiwi_profile_version(host) 'zypper --non-interactive install tftp && ' \ 'systemctl enable tftp.service && ' \ 'systemctl start tftp.service' - $proxy.run(cmd) + get_target('proxy').run(cmd) step %(I disable repositories after installing branch server) else cmd = 'systemctl enable tftp.service && systemctl start tftp.service' - $proxy.run(cmd) + get_target('proxy').run(cmd) end end When(/^I stop tftp on the proxy$/) do - $proxy.run('systemctl stop tftp.service') + get_target('proxy').run('systemctl stop tftp.service') end When(/^I set up the private network on the terminals$/) do proxy = net_prefix + ADDRESSES['proxy'] # /etc/sysconfig/network/ifcfg-eth1 and /etc/resolv.conf - nodes = [$minion] + nodes = [get_target('sle_minion')] conf = "STARTMODE='auto'\\nBOOTPROTO='dhcp'" file = '/etc/sysconfig/network/ifcfg-eth1' script2 = "-e '/^#/d' -e 's/^search /search example.org /' -e '$anameserver #{proxy}' -e '/^nameserver /d'" @@ -212,11 +212,11 @@ def compute_kiwi_profile_version(host) file = 'restart-network-pxeboot.exp' source = File.dirname(__FILE__) + '/../upload_files/' + file dest = '/tmp/' + file - return_code = file_inject($proxy, source, dest) + return_code = file_inject(get_target('proxy'), source, dest) raise 'File injection failed' unless return_code.zero? # We have no direct access to the PXE boot minion # so we run the command from the proxy - $proxy.run("expect -f /tmp/#{file} #{ipv6}") + get_target('proxy').run("expect -f /tmp/#{file} #{ipv6}") end When(/^I reboot the (Retail|Cobbler) terminal "([^"]*)"$/) do |context, host| @@ -236,19 +236,19 @@ def compute_kiwi_profile_version(host) file = 'reboot-pxeboot.exp' source = File.dirname(__FILE__) + '/../upload_files/' + file dest = '/tmp/' + file - return_code = file_inject($proxy, source, dest) + return_code = file_inject(get_target('proxy'), source, dest) raise 'File injection failed' unless return_code.zero? - $proxy.run("expect -f /tmp/#{file} #{ipv6} #{context}") + get_target('proxy').run("expect -f /tmp/#{file} #{ipv6} #{context}") end When(/^I create bootstrap script for "([^"]+)" hostname and set the activation key "([^"]*)" in the bootstrap script on the proxy$/) do |host, key| # WORKAROUND: Revert once pxeboot autoinstallation contains venv-salt-minion - # force_bundle = $use_salt_bundle ? '--force-bundle' : '' - # $proxy.run("mgr-bootstrap #{force_bundle}") - $proxy.run("mgr-bootstrap --hostname=#{host}") + # force_bundle = use_salt_bundle ? '--force-bundle' : '' + # get_target('proxy').run("mgr-bootstrap #{force_bundle}") + get_target('proxy').run("mgr-bootstrap --hostname=#{host}") - $proxy.run("sed -i '/^ACTIVATION_KEYS=/c\\ACTIVATION_KEYS=#{key}' /srv/www/htdocs/pub/bootstrap/bootstrap.sh") - output, _code = $proxy.run('cat /srv/www/htdocs/pub/bootstrap/bootstrap.sh') + get_target('proxy').run("sed -i '/^ACTIVATION_KEYS=/c\\ACTIVATION_KEYS=#{key}' /srv/www/htdocs/pub/bootstrap/bootstrap.sh") + output, _code = get_target('proxy').run('cat /srv/www/htdocs/pub/bootstrap/bootstrap.sh') raise "Key: #{key} not included" unless output.include? key raise "Hostname: #{host} not included" unless output.include? host end @@ -257,44 +257,44 @@ def compute_kiwi_profile_version(host) file = 'bootstrap-pxeboot.exp' source = File.dirname(__FILE__) + '/../upload_files/' + file dest = '/tmp/' + file - return_code = file_inject($proxy, source, dest) + return_code = file_inject(get_target('proxy'), source, dest) raise 'File injection failed' unless return_code.zero? ipv4 = net_prefix + ADDRESSES['pxeboot_minion'] - $proxy.run("expect -f /tmp/#{file} #{ipv4}", verbose: true) + get_target('proxy').run("expect -f /tmp/#{file} #{ipv4}", verbose: true) end When(/^I accept key of pxeboot minion in the Salt master$/) do - $server.run('salt-key -y --accept=pxeboot.example.org') + get_target('server').run('salt-key -y --accept=pxeboot.example.org') end When(/^I install the GPG key of the test packages repository on the PXE boot minion$/) do file = 'uyuni.key' source = File.dirname(__FILE__) + '/../upload_files/' + file dest = '/tmp/' + file - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? system_name = get_system_name('pxeboot_minion') - $server.run("salt-cp #{system_name} #{dest} #{dest}") - $server.run("salt #{system_name} cmd.run 'rpmkeys --import #{dest}'") + get_target('server').run("salt-cp #{system_name} #{dest} #{dest}") + get_target('server').run("salt #{system_name} cmd.run 'rpmkeys --import #{dest}'") end When(/^I wait until Salt client is inactive on the PXE boot minion$/) do file = 'wait-end-of-cleanup-pxeboot.exp' source = File.dirname(__FILE__) + '/../upload_files/' + file dest = '/tmp/' + file - return_code = file_inject($proxy, source, dest) + return_code = file_inject(get_target('proxy'), source, dest) raise 'File injection failed' unless return_code.zero? ipv4 = net_prefix + ADDRESSES['pxeboot_minion'] - $proxy.run("expect -f /tmp/#{file} #{ipv4}") + get_target('proxy').run("expect -f /tmp/#{file} #{ipv4}") end When(/^I prepare the retail configuration file on server$/) do source = File.dirname(__FILE__) + '/../upload_files/massive-import-terminals.yml' dest = '/tmp/massive-import-terminals.yml' - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise "File #{file} couldn't be copied to server" unless return_code.zero? - sed_values = "s//#{$proxy.full_hostname}/; " + sed_values = "s//#{get_target('proxy').full_hostname}/; " sed_values << "s//#{net_prefix}/; " sed_values << "s//#{ADDRESSES['proxy']}/; " sed_values << "s//#{ADDRESSES['range begin']}/; " @@ -304,12 +304,12 @@ def compute_kiwi_profile_version(host) sed_values << "s//#{ADDRESSES['sle_minion']}/; " sed_values << "s//#{get_mac_address('sle_minion')}/; " sed_values << "s//#{compute_kiwi_profile_name('pxeboot_minion')}/" - $server.run("sed -i '#{sed_values}' #{dest}") + get_target('server').run("sed -i '#{sed_values}' #{dest}") end When(/^I import the retail configuration using retail_yaml command$/) do filepath = '/tmp/massive-import-terminals.yml' - $server.run("retail_yaml --api-user admin --api-pass admin --from-yaml #{filepath}") + get_target('server').run("retail_yaml --api-user admin --api-pass admin --from-yaml #{filepath}") end # Click on the terminal @@ -563,7 +563,7 @@ def compute_kiwi_profile_version(host) When(/^I am on the image store of the Kiwi image for organization "([^"]*)"$/) do |org| # There is no navigation step to access this URL, so we must use a visit call (https://github.com/SUSE/spacewalk/issues/15256) - visit("https://#{$server.full_hostname}/os-images/#{org}/") + visit("https://#{get_target('server').full_hostname}/os-images/#{org}/") end Then(/^I should see the name of the image for "([^"]*)"$/) do |host| @@ -573,6 +573,6 @@ def compute_kiwi_profile_version(host) Then(/^the image for "([^"]*)" should exist on the branch server$/) do |host| image = compute_kiwi_profile_name(host) - images, _code = $proxy.run('ls /srv/saltboot/image/') + images, _code = get_target('proxy').run('ls /srv/saltboot/image/') raise "Image #{image} for #{host} does not exist" unless images.include? image end diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index 3faa8726354b..3218da49fbae 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -14,7 +14,7 @@ # 300 is the default 1st keepalive interval for the minion # where it realizes the connection is stuck repeat_until_timeout(timeout: 300, retries: 3, message: "Master can not communicate with #{minion}", report_result: true) do - out, _code = $server.run("salt #{system_name} test.ping") + out, _code = get_target('server').run("salt #{system_name} test.ping") if out.include?(system_name) && out.include?('True') finished = Time.now log "Took #{finished.to_i - start.to_i} seconds to contact the minion" @@ -26,12 +26,12 @@ end When(/^I get the contents of the remote file "(.*?)"$/) do |filename| - $output, _code = $server.run("cat #{filename}") + $output, _code = get_target('server').run("cat #{filename}") end When(/^I stop salt-minion on "(.*?)"$/) do |minion| node = get_target(minion) - pkgname = $use_salt_bundle ? "venv-salt-minion" : "salt-minion" + pkgname = use_salt_bundle ? "venv-salt-minion" : "salt-minion" os_version = node.os_version os_family = node.os_family if os_family =~ /^sles/ && os_version =~ /^11/ @@ -43,7 +43,7 @@ When(/^I start salt-minion on "(.*?)"$/) do |minion| node = get_target(minion) - pkgname = $use_salt_bundle ? "venv-salt-minion" : "salt-minion" + pkgname = use_salt_bundle ? "venv-salt-minion" : "salt-minion" os_version = node.os_version os_family = node.os_family if os_family =~ /^sles/ && os_version =~ /^11/ @@ -55,7 +55,7 @@ When(/^I restart salt-minion on "(.*?)"$/) do |minion| node = get_target(minion) - pkgname = $use_salt_bundle ? "venv-salt-minion" : "salt-minion" + pkgname = use_salt_bundle ? "venv-salt-minion" : "salt-minion" os_version = node.os_version os_family = node.os_family if os_family =~ /^sles/ && os_version =~ /^11/ @@ -67,7 +67,7 @@ When(/^I refresh salt-minion grains on "(.*?)"$/) do |minion| node = get_target(minion) - salt_call = $use_salt_bundle ? "venv-salt-call" : "salt-call" + salt_call = use_salt_bundle ? "venv-salt-call" : "salt-call" node.run("#{salt_call} saltutil.refresh_grains") end @@ -76,7 +76,7 @@ repeat_until_timeout(timeout: key_timeout.to_i, message: "Minion '#{minion}' is not listed among #{key_type} keys on Salt master") do system_name = get_system_name(minion) unless system_name.empty? - output, return_code = $server.run(cmd, check_errors: false) + output, return_code = get_target('server').run(cmd, check_errors: false) break if return_code.zero? && output.include?(system_name) end sleep 1 @@ -84,7 +84,7 @@ end When(/^I wait until Salt client is inactive on "([^"]*)"$/) do |minion| - salt_minion = $use_salt_bundle ? "venv-salt-minion" : "salt-minion" + salt_minion = use_salt_bundle ? "venv-salt-minion" : "salt-minion" step %(I wait until "#{salt_minion}" service is inactive on "#{minion}") end @@ -100,21 +100,21 @@ When(/^I delete "([^"]*)" key in the Salt master$/) do |host| system_name = get_system_name(host) - $output, _code = $server.run("salt-key -y -d #{system_name}", check_errors: false) + $output, _code = get_target('server').run("salt-key -y -d #{system_name}", check_errors: false) end When(/^I accept "([^"]*)" key in the Salt master$/) do |host| system_name = get_system_name(host) - $server.run("salt-key -y --accept=#{system_name}*") + get_target('server').run("salt-key -y --accept=#{system_name}*") end When(/^I list all Salt keys shown on the Salt master$/) do - $server.run("salt-key --list-all", check_errors: false, verbose: true) + get_target('server').run("salt-key --list-all", check_errors: false, verbose: true) end When(/^I get OS information of "([^"]*)" from the Master$/) do |host| system_name = get_system_name(host) - $output, _code = $server.run("salt #{system_name} grains.get osfullname") + $output, _code = get_target('server').run("salt #{system_name} grains.get osfullname") end Then(/^it should contain a "([^"]*?)" text$/) do |content| @@ -130,16 +130,16 @@ When(/^I apply state "([^"]*)" to "([^"]*)"$/) do |state, host| system_name = get_system_name(host) - $server.run("salt #{system_name} state.apply #{state}", verbose: true) + get_target('server').run("salt #{system_name} state.apply #{state}", verbose: true) end Then(/^salt\-api should be listening on local port (\d+)$/) do |port| - $output, _code = $server.run("ss -ntl | grep #{port}") + $output, _code = get_target('server').run("ss -ntl | grep #{port}") assert_match(/127.0.0.1:#{port}/, $output) end Then(/^salt\-master should be listening on public port (\d+)$/) do |port| - $output, _code = $server.run("ss -ntl | grep #{port}") + $output, _code = get_target('server').run("ss -ntl | grep #{port}") assert_match(/(0.0.0.0|\*|\[::\]):#{port}/, $output) end @@ -159,7 +159,7 @@ Then(/^"(.*?)" should have been reformatted$/) do |host| system_name = get_system_name(host) - output, _code = $server.run("salt #{system_name} file.file_exists /intact") + output, _code = get_target('server').run("salt #{system_name} file.file_exists /intact") raise "Minion #{host} is intact" unless output.include? 'False' end @@ -199,38 +199,38 @@ # Salt formulas When(/^I manually install the "([^"]*)" formula on the server$/) do |package| - $server.run("zypper --non-interactive refresh") - $server.run("zypper --non-interactive install --force #{package}-formula") + get_target('server').run("zypper --non-interactive refresh") + get_target('server').run("zypper --non-interactive install --force #{package}-formula") end When(/^I manually uninstall the "([^"]*)" formula from the server$/) do |package| - $server.run("zypper --non-interactive remove #{package}-formula") + get_target('server').run("zypper --non-interactive remove #{package}-formula") # Remove automatically installed dependency if needed if package == 'uyuni-config' - $server.run("zypper --non-interactive remove #{package}-modules") + get_target('server').run("zypper --non-interactive remove #{package}-modules") end end When(/^I synchronize all Salt dynamic modules on "([^"]*)"$/) do |host| system_name = get_system_name(host) - $server.run("salt #{system_name} saltutil.sync_all") + get_target('server').run("salt #{system_name} saltutil.sync_all") end When(/^I remove "([^"]*)" from salt cache on "([^"]*)"$/) do |filename, host| node = get_target(host) - salt_cache = $use_salt_bundle ? "/var/cache/venv-salt-minion/" : "/var/cache/salt/" + salt_cache = use_salt_bundle ? "/var/cache/venv-salt-minion/" : "/var/cache/salt/" file_delete(node, "#{salt_cache}#{filename}") end When(/^I remove "([^"]*)" from salt minion config directory on "([^"]*)"$/) do |filename, host| node = get_target(host) - salt_config = $use_salt_bundle ? "/etc/venv-salt-minion/minion.d/" : "/etc/salt/minion.d/" + salt_config = use_salt_bundle ? "/etc/venv-salt-minion/minion.d/" : "/etc/salt/minion.d/" file_delete(node, "#{salt_config}#{filename}") end When(/^I configure salt minion on "([^"]*)"$/) do |host| content = %( -master: #{$server.full_hostname} +master: #{get_target('server').full_hostname} server_id_use_crc: adler32 enable_legacy_startup_events: False enable_fqdns_grains: False @@ -242,7 +242,7 @@ end When(/^I store "([^"]*)" into file "([^"]*)" in salt minion config directory on "([^"]*)"$/) do |content, filename, host| - salt_config = $use_salt_bundle ? "/etc/venv-salt-minion/minion.d/" : "/etc/salt/minion.d/" + salt_config = use_salt_bundle ? "/etc/venv-salt-minion/minion.d/" : "/etc/salt/minion.d/" step %(I store "#{content}" into file "#{salt_config}#{filename}" on "#{host}") end @@ -301,12 +301,12 @@ end When(/^I refresh the pillar data$/) do - $server.run("salt '#{$minion.full_hostname}' saltutil.refresh_pillar wait=True") + get_target('server').run("salt '#{get_target('sle_minion').full_hostname}' saltutil.refresh_pillar wait=True") end When(/^I wait until there is no pillar refresh salt job active$/) do repeat_until_timeout(message: "pillar refresh job still active") do - output, = $server.run("salt-run jobs.active") + output, = get_target('server').run("salt-run jobs.active") break unless output.include?("saltutil.refresh_pillar") sleep 1 end @@ -327,7 +327,7 @@ def pillar_get(key, minion) else raise 'Invalid target' end - $server.run("#{cmd} #{system_name} pillar.get #{key}") + get_target('server').run("#{cmd} #{system_name} pillar.get #{key}") end Then(/^the pillar data for "([^"]*)" should be "([^"]*)" on "([^"]*)"$/) do |key, value, minion| @@ -360,7 +360,7 @@ def pillar_get(key, minion) end Given(/^I try to download "([^"]*)" from channel "([^"]*)"$/) do |rpm, channel| - url = "https://#{$server.full_hostname}/rhn/manager/download/#{channel}/getPackage/#{rpm}" + url = "https://#{get_target('server').full_hostname}/rhn/manager/download/#{channel}/getPackage/#{rpm}" url = "#{url}?#{@token}" if @token @download_path = nil @download_error = nil @@ -400,7 +400,7 @@ def pillar_get(key, minion) When(/^I see "([^"]*)" fingerprint$/) do |host| node = get_target(host) - salt_call = $use_salt_bundle ? "venv-salt-call" : "salt-call" + salt_call = use_salt_bundle ? "venv-salt-call" : "salt-call" output, _code = node.run("#{salt_call} --local key.finger") fing = output.split("\n")[1].strip! raise "Text: #{fing} not found" unless has_content?(fing) @@ -457,10 +457,10 @@ def pillar_get(key, minion) file = 'salt_event_parser.py' source = "#{File.dirname(__FILE__)}/../upload_files/#{file}" dest = "/tmp/#{file}" - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? # print failures from salt event log - output, _code = $server.run("python3 /tmp/#{file}") + output, _code = get_target('server').run("python3 /tmp/#{file}") count_failures = output.to_s.scan(/false/).length output = output.join.to_s if output.respond_to?(:join) # Ignore the error if there is only the expected failure from min_salt_lock_packages.feature @@ -472,13 +472,13 @@ def pillar_get(key, minion) # salt-ssh steps When(/^I install Salt packages from "(.*?)"$/) do |host| target = get_target(host) - pkgs = $use_salt_bundle ? "venv-salt-minion" : "salt salt-minion" + pkgs = use_salt_bundle ? "venv-salt-minion" : "salt salt-minion" if suse_host?(host) target.run("test -e /usr/bin/zypper && zypper --non-interactive install -y #{pkgs}", check_errors: false) elsif rh_host?(host) target.run("test -e /usr/bin/yum && yum -y install #{pkgs}", check_errors: false) elsif deb_host?(host) - pkgs = "salt-common salt-minion" if $product != 'Uyuni' + pkgs = "salt-common salt-minion" if product != 'Uyuni' target.run("test -e /usr/bin/apt && apt -y install #{pkgs}", check_errors: false) end end @@ -494,8 +494,8 @@ def pillar_get(key, minion) # minion bootstrap steps Then(/^I run spacecmd listevents for "([^"]*)"$/) do |host| system_name = get_system_name(host) - $server.run('spacecmd -u admin -p admin clear_caches') - $server.run("spacecmd -u admin -p admin system_listevents #{system_name}") + get_target('server').run('spacecmd -u admin -p admin clear_caches') + get_target('server').run("spacecmd -u admin -p admin system_listevents #{system_name}") end When(/^I enter KVM Server password$/) do @@ -504,7 +504,7 @@ def pillar_get(key, minion) When(/^I perform a full salt minion cleanup on "([^"]*)"$/) do |host| node = get_target(host) - if $use_salt_bundle + if use_salt_bundle if rh_host?(host) node.run("yum -y remove --setopt=clean_requirements_on_remove=1 venv-salt-minion", check_errors: false) elsif deb_host?(host) @@ -544,12 +544,12 @@ def pillar_get(key, minion) content = "pkg_download_point_protocol: #{uri.scheme}\n"\ "pkg_download_point_host: #{uri.host}\n"\ "pkg_download_point_port: #{uri.port}" - $server.run("echo -e \"#{content}\" > #{filepath}") + get_target('server').run("echo -e \"#{content}\" > #{filepath}") end When(/^I delete the package download endpoint pillar file from the server$/) do filepath = '/srv/pillar/pkg_endpoint.sls' - return_code = file_delete($server, filepath) + return_code = file_delete(get_target('server'), filepath) raise 'File deletion failed' unless return_code.zero? end @@ -557,22 +557,22 @@ def pillar_get(key, minion) source = File.dirname(__FILE__) + '/../upload_files/' + file dest = "/srv/formula_metadata/" + formula + '/' + file - $server.run("mkdir -p /srv/formula_metadata/" + formula) - return_code = file_inject($server, source, dest) + get_target('server').run("mkdir -p /srv/formula_metadata/" + formula) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? - $server.run("chmod 644 " + dest) + get_target('server').run("chmod 644 " + dest) end When(/^I migrate "([^"]*)" from salt-minion to venv-salt-minion$/) do |host| node = get_target(host) system_name = node.full_hostname migrate = "salt #{system_name} state.apply util.mgr_switch_to_venv_minion" - $server.run(migrate, check_errors: true, verbose: true) + get_target('server').run(migrate, check_errors: true, verbose: true) end When(/^I purge salt-minion on "([^"]*)" after a migration$/) do |host| node = get_target(host) system_name = node.full_hostname cleanup = %(salt #{system_name} state.apply util.mgr_switch_to_venv_minion pillar='{"mgr_purge_non_venv_salt_files": True, "mgr_purge_non_venv_salt": True}') - $server.run(cleanup, check_errors: true, verbose: true) + get_target('server').run(cleanup, check_errors: true, verbose: true) end diff --git a/testsuite/features/step_definitions/setup_steps.rb b/testsuite/features/step_definitions/setup_steps.rb index 6aec20e3b247..6943dd6fdd79 100644 --- a/testsuite/features/step_definitions/setup_steps.rb +++ b/testsuite/features/step_definitions/setup_steps.rb @@ -153,7 +153,7 @@ end Then(/^the SLE15 (SP3|SP4) product should be added$/) do |sp_version| - output, _code = $server.run('echo -e "admin\nadmin\n" | mgr-sync list channels', check_errors: false, buffer_size: 1_000_000) + output, _code = get_target('server').run('echo -e "admin\nadmin\n" | mgr-sync list channels', check_errors: false, buffer_size: 1_000_000) STDOUT.puts "Products list:\n#{output}" match = "[I] SLE-Product-SLES15-#{sp_version}-Pool for x86_64 SUSE Linux Enterprise Server 15 #{sp_version} x86_64 [sle-product-sles15-#{sp_version.downcase}-pool-x86_64]" raise "Not included:\n #{match}" unless output.include? match @@ -212,8 +212,8 @@ command = "spacecmd -u admin -p admin system_list" system_name = get_system_name(host) repeat_until_timeout(message: "system #{system_name} is not in the list yet") do - $server.run("spacecmd -u admin -p admin clear_caches") - result, _code = $server.run(command, check_errors: false, verbose: true) + get_target('server').run("spacecmd -u admin -p admin clear_caches") + result, _code = get_target('server').run(command, check_errors: false, verbose: true) break if result.include? system_name sleep 1 end @@ -258,7 +258,7 @@ def token(secret, claims = {}) end def server_secret - rhnconf, _code = $server.run('cat /etc/rhn/rhn.conf', check_errors: false) + rhnconf, _code = get_target('server').run('cat /etc/rhn/rhn.conf', check_errors: false) data = /server.secret_key\s*=\s*(\h+)$/.match(rhnconf) data[1].strip end diff --git a/testsuite/features/step_definitions/smdba_steps.rb b/testsuite/features/step_definitions/smdba_steps.rb index a7c489c05870..05d45ef6fe5c 100644 --- a/testsuite/features/step_definitions/smdba_steps.rb +++ b/testsuite/features/step_definitions/smdba_steps.rb @@ -5,35 +5,35 @@ ### and access to the database. Given(/^a postgresql database is running$/) do - $output, _code = $server.run('file /var/lib/pgsql/data/postgresql.conf', check_errors: false) + $output, _code = get_target('server').run('file /var/lib/pgsql/data/postgresql.conf', check_errors: false) unless $output.include? 'ASCII text' log 'Tests require Postgresql database, skipping...' pending end - smdba_db_status, _code = $server.run('smdba db-status', check_errors: false) + smdba_db_status, _code = get_target('server').run('smdba db-status', check_errors: false) if smdba_db_status.include? 'online' log 'Database is running' else - $server.run('smdba db-start') - smdba_db_status, _code = $server.run('smdba db-status', check_errors: false) + get_target('server').run('smdba db-start') + smdba_db_status, _code = get_target('server').run('smdba db-status', check_errors: false) assert_includes(smdba_db_status, 'online') end end Given(/^there is no such "(.*?)" directory$/) do |bkp_dir| - $server.run("test -d #{bkp_dir} && rm -rf #{bkp_dir}", check_errors: false) + get_target('server').run("test -d #{bkp_dir} && rm -rf #{bkp_dir}", check_errors: false) end When(/^I start database with the command "(.*?)"$/) do |start_command| - $output, _code = $server.run(start_command) + $output, _code = get_target('server').run(start_command) end When(/^I stop the database with the command "(.*?)"$/) do |stop_command| - $output, _code = $server.run(stop_command) + $output, _code = get_target('server').run(stop_command) end When(/^I check the database status with the command "(.*?)"$/) do |check_command| - $output, _code = $server.run(check_command) + $output, _code = get_target('server').run(check_command) end When(/^I see that the database is "(.*?)" or "(.*?)" as it might already running$/) do |scs_status, fl_status| @@ -49,14 +49,14 @@ end When(/^I configure "(.*?)" parameter "(.*?)" to "(.*?)"$/) do |config_file, param, value| - $server.run("sed -i '/wal_level/d' #{config_file}", check_errors: false) - $server.run("echo \"#{param} = #{value}\" >> #{config_file}", check_errors: false) - local_output, _code = $server.run("cat #{config_file} | grep #{param}", check_errors: false) + get_target('server').run("sed -i '/wal_level/d' #{config_file}", check_errors: false) + get_target('server').run("echo \"#{param} = #{value}\" >> #{config_file}", check_errors: false) + local_output, _code = get_target('server').run("cat #{config_file} | grep #{param}", check_errors: false) assert_includes(local_output, value) end Then(/^I check internally configuration for "(.*?)" option$/) do |_config_key| - $current_checked_config_value, _code = $server.run("cd /;sudo -u postgres psql -c 'show wal_level;'", check_errors: false) + $current_checked_config_value, _code = get_target('server').run("cd /;sudo -u postgres psql -c 'show wal_level;'", check_errors: false) end Then(/^the configuration should be set to "(.*?)"$/) do |value| @@ -68,7 +68,7 @@ end Then(/^I issue command "(.*?)"$/) do |command| - $output, _code = $server.run(command, check_errors: false) + $output, _code = get_target('server').run(command, check_errors: false) end Then(/^tablespace "([^"]*)" should be listed$/) do |ts| @@ -88,16 +88,16 @@ # Given(/^database "(.*?)" has no table "(.*?)"$/) do |dbname, tbl| $db = dbname - out, err, _code = $server.run("sudo -u postgres psql -d #{$db} -c 'drop table dummy'", separated_results: true, check_errors: false) + out, err, _code = get_target('server').run("sudo -u postgres psql -d #{$db} -c 'drop table dummy'", separated_results: true, check_errors: false) refute_includes(out, 'DROP TABLE') assert_includes(err, "table \"#{tbl}\" does not exist") end When(/^I create backup directory "(.*?)" with UID "(.*?)" and GID "(.*?)"$/) do |bkp_dir, uid, gid| - $server.run("mkdir /#{bkp_dir};chown #{uid}:#{gid} /#{bkp_dir}") + get_target('server').run("mkdir /#{bkp_dir};chown #{uid}:#{gid} /#{bkp_dir}") bkp_dir.sub!('/', '') log 'Backup directory:' - log $server.run("ls -la / | /usr/bin/grep #{bkp_dir}", check_errors: false)[0] + log get_target('server').run("ls -la / | /usr/bin/grep #{bkp_dir}", check_errors: false)[0] end Then(/^I should see error message that asks "(.*?)" belong to the same UID\/GID as "(.*?)" directory$/) do |bkp_dir, data_dir| @@ -111,14 +111,14 @@ end Then(/^I remove backup directory "(.*?)"$/) do |bkp_dir| - $server.run("test -d #{bkp_dir} && rm -rf #{bkp_dir}") + get_target('server').run("test -d #{bkp_dir} && rm -rf #{bkp_dir}") end When(/^I change Access Control List on "(.*?)" directory to "(.*?)"$/) do |bkp_dir, acl_octal| bkp_dir.sub!('/', '') - $server.run("test -d /#{bkp_dir} && chmod #{acl_octal} /#{bkp_dir}") + get_target('server').run("test -d /#{bkp_dir} && chmod #{acl_octal} /#{bkp_dir}") log "Backup directory, ACL to \"#{acl_octal}\":" - log $server.run("ls -la / | /usr/bin/grep #{bkp_dir}", check_errors: false)[0] + log get_target('server').run("ls -la / | /usr/bin/grep #{bkp_dir}", check_errors: false)[0] log "\n*** Taking backup, this might take a while ***\n" end @@ -128,17 +128,17 @@ Then(/^in "(.*?)" directory there is "(.*?)" file and at least one backup checkpoint file$/) do |bkp_dir, archive_file| refute_includes( - $server.run("test -f #{bkp_dir}/#{archive_file} && echo \"exists\" || echo \"missing\"", check_errors: false), + get_target('server').run("test -f #{bkp_dir}/#{archive_file} && echo \"exists\" || echo \"missing\"", check_errors: false), 'missing' ) refute_includes( - $server.run("ls #{bkp_dir}/*.backup 1>/dev/null 2>/dev/null && echo \"exists\" || echo \"missing\"", check_errors: false), + get_target('server').run("ls #{bkp_dir}/*.backup 1>/dev/null 2>/dev/null && echo \"exists\" || echo \"missing\"", check_errors: false), 'missing' ) end Then(/^parameter "(.*?)" in the configuration file "(.*?)" is "(.*?)"$/) do |param, cfg_file, fuzzy_value| - $output, _code = $server.run("cat #{cfg_file} | grep #{param}") + $output, _code = get_target('server').run("cat #{cfg_file} | grep #{param}") assert_includes($output, fuzzy_value) end @@ -147,17 +147,17 @@ end When(/^I set a checkpoint$/) do - $server.run("sudo -u postgres psql -d #{$db} -c 'checkpoint' 2>/dev/null", check_errors: false) + get_target('server').run("sudo -u postgres psql -d #{$db} -c 'checkpoint' 2>/dev/null", check_errors: false) end When(/^in the database I create dummy table "(.*?)" with column "(.*?)" and value "(.*?)"$/) do |tbl, clm, val| fn = '/tmp/smdba-data-test.sql' - $server.run("echo \"create table #{tbl} (#{clm} varchar);insert into #{tbl} (#{clm}) values (\'#{val}\');\" > #{fn}", check_errors: false) - $server.run("sudo -u postgres psql -d #{$db} -c 'drop table dummy' 2>/dev/null", check_errors: false) - $server.run("sudo -u postgres psql -d #{$db} -af #{fn}", check_errors: false) - $server.run("file -f #{fn} && rm #{fn}") + get_target('server').run("echo \"create table #{tbl} (#{clm} varchar);insert into #{tbl} (#{clm}) values (\'#{val}\');\" > #{fn}", check_errors: false) + get_target('server').run("sudo -u postgres psql -d #{$db} -c 'drop table dummy' 2>/dev/null", check_errors: false) + get_target('server').run("sudo -u postgres psql -d #{$db} -af #{fn}", check_errors: false) + get_target('server').run("file -f #{fn} && rm #{fn}") assert_includes( - $server.run("sudo -u postgres psql -d #{$db} -c 'select * from dummy' 2>/dev/null", check_errors: false)[0], + get_target('server').run("sudo -u postgres psql -d #{$db} -c 'select * from dummy' 2>/dev/null", check_errors: false)[0], val ) log "Table \"#{tbl}\" has been created with some dummy data inside" @@ -165,13 +165,13 @@ When(/^I restore database from the backup$/) do log "\n*** Restoring database from the backup. This will may take a while. ***\n\n" - output, code = $server.run('smdba backup-restore') + output, code = get_target('server').run('smdba backup-restore') log "#{output}\n\n" raise 'Restore Failed' unless code.zero? end Then(/^I disable backup in the directory "(.*?)"$/) do |_arg1| assert_includes( - $server.run('smdba backup-hot --enable=off', check_errors: false)[0], 'Finished' + get_target('server').run('smdba backup-hot --enable=off', check_errors: false)[0], 'Finished' ) end diff --git a/testsuite/features/support/code_coverage.rb b/testsuite/features/support/code_coverage.rb index 2165e9d9dae5..1021e28643ed 100644 --- a/testsuite/features/support/code_coverage.rb +++ b/testsuite/features/support/code_coverage.rb @@ -69,8 +69,8 @@ def jacoco_dump(feature_name, html = false, xml = true, source = false) sourcefiles = source ? '--sourcefiles /tmp/uyuni-master/java/code/src' : '' classfiles = '--classfiles /srv/tomcat/webapps/rhn/WEB-INF/lib/rhn.jar' dump_path = "/tmp/jacoco-#{feature_name}.exec" - $server.run("#{cli} dump --address localhost --destfile #{dump_path} --port 6300 --reset") - $server.run("#{cli} report #{dump_path} #{html_report} #{xml_report} #{sourcefiles} #{classfiles}") - file_extract($server, "/srv/www/htdocs/pub/jacoco-#{feature_name}.xml", "/tmp/jacoco-#{feature_name}.xml") + get_target('server').run("#{cli} dump --address localhost --destfile #{dump_path} --port 6300 --reset") + get_target('server').run("#{cli} report #{dump_path} #{html_report} #{xml_report} #{sourcefiles} #{classfiles}") + file_extract(get_target('server'), "/srv/www/htdocs/pub/jacoco-#{feature_name}.xml", "/tmp/jacoco-#{feature_name}.xml") end end diff --git a/testsuite/features/support/commonlib.rb b/testsuite/features/support/commonlib.rb index e469351bdc37..9d80cb3436d7 100644 --- a/testsuite/features/support/commonlib.rb +++ b/testsuite/features/support/commonlib.rb @@ -36,7 +36,7 @@ def compute_channels_to_leave_running else CHANNEL_TO_SYNCH_BY_OS_VERSION['default'] end - [$minion, $build_host, $ssh_minion, $rhlike_minion].each do |node| + [get_target('sle_minion'), get_target('build_host'), get_target('ssh_minion'), get_target('rhlike_minion')].each do |node| next unless node os_version = node.os_version os_family = node.os_family @@ -56,18 +56,18 @@ def count_table_items end def product - _product_raw, code = $server.run('rpm -q patterns-uyuni_server', check_errors: false) + _product_raw, code = get_target('server').run('rpm -q patterns-uyuni_server', check_errors: false) return 'Uyuni' if code.zero? - _product_raw, code = $server.run('rpm -q patterns-suma_server', check_errors: false) + _product_raw, code = get_target('server').run('rpm -q patterns-suma_server', check_errors: false) return 'SUSE Manager' if code.zero? raise 'Could not determine product' end def product_version - product_raw, code = $server.run('rpm -q patterns-uyuni_server', check_errors: false) + product_raw, code = get_target('server').run('rpm -q patterns-uyuni_server', check_errors: false) m = product_raw.match(/patterns-uyuni_server-(.*)-.*/) return m[1] if code.zero? && !m.nil? - product_raw, code = $server.run('rpm -q patterns-suma_server', check_errors: false) + product_raw, code = get_target('server').run('rpm -q patterns-suma_server', check_errors: false) m = product_raw.match(/patterns-suma_server-(.*)-.*/) return m[1] if code.zero? && !m.nil? raise 'Could not determine product version' @@ -75,16 +75,16 @@ def product_version def use_salt_bundle # Use venv-salt-minion in Uyuni, or SUMA Head, 4.2 and 4.3 - $product == 'Uyuni' || %w[head 4.3 4.2].include?($product_version) + product == 'Uyuni' || %w[head 4.3 4.2].include?(product_version) end # create salt pillar file in the default pillar_roots location def inject_salt_pillar_file(source, file) dest = '/srv/pillar/' + file - return_code = file_inject($server, source, dest) + return_code = file_inject(get_target('server'), source, dest) raise 'File injection failed' unless return_code.zero? # make file readable by salt - $server.run("chgrp salt #{dest}") + get_target('server').run("chgrp salt #{dest}") return_code end @@ -305,7 +305,7 @@ def get_os_version(node) [os_version, os_family] end -def get_gpg_keys(node, target = $server) +def get_gpg_keys(node, target = get_target('server')) os_version, os_family = get_os_version(node) if os_family =~ /^sles/ # HACK: SLE 15 uses SLE 12 GPG key @@ -333,3 +333,100 @@ def add_context(key, value) $context[$feature_scope] = {} unless $context.key?($feature_scope) $context[$feature_scope].merge!({ key => value }) end + +# This function gets the system name, as displayed in systems list +# * for the usual clients, it is the full hostname, e.g. suma-41-min-sle15.tf.local +# * for the PXE booted clients, it is derived from the branch name, the hardware type, +# and a fingerprint, e.g. example.Intel-Genuine-None-d6df84cca6f478cdafe824e35bbb6e3b +def get_system_name(host) + case host + # The PXE boot minion and the terminals are not directly accessible on the network, + # therefore they are not represented by a twopence node + when 'pxeboot_minion' + output, _code = get_target('server').run('salt-key') + system_name = + output.split.find do |word| + word =~ /example.Intel-Genuine-None-/ || word =~ /example.pxeboot-/ || word =~ /example.Intel/ || word =~ /pxeboot-/ + end + system_name = 'pxeboot.example.org' if system_name.nil? + when 'sle12sp5_terminal' + output, _code = get_target('server').run('salt-key') + system_name = + output.split.find do |word| + word =~ /example.sle12sp5terminal-/ + end + system_name = 'sle12sp5terminal.example.org' if system_name.nil? + when 'sle15sp4_terminal' + output, _code = get_target('server').run('salt-key') + system_name = + output.split.find do |word| + word =~ /example.sle15sp4terminal-/ + end + system_name = 'sle15sp4terminal.example.org' if system_name.nil? + when 'containerized_proxy' + system_name = get_target('proxy').full_hostname.sub('pxy', 'pod-pxy') + else + begin + node = get_target(host) + system_name = node.full_hostname + rescue RuntimeError + # If the node for that host is not defined, just return the host parameter as system_name + system_name = host + end + end + system_name +end + +# Get MAC address of system +def get_mac_address(host) + if host == 'pxeboot_minion' + mac = ENV['PXEBOOT_MAC'] + else + node = get_target(host) + output, _code = node.run('ip link show dev eth1') + mac = output.split("\n")[1].split[1] + end + mac +end + +# This function returns the net prefix, caching it +def net_prefix + $net_prefix = $private_net.sub(%r{\.0+/24$}, '.') if $net_prefix.nil? && !$private_net.nil? + $net_prefix +end + +# This function tests whether a file exists on a node +def file_exists?(node, file) + _out, local, _remote, code = node.test_and_store_results_together("test -f #{file}", 'root', 500) + code.zero? && local.zero? +end + +# This function tests whether a folder exists on a node +def folder_exists?(node, file) + _out, local, _remote, code = node.test_and_store_results_together("test -d #{file}", 'root', 500) + code.zero? && local.zero? +end + +# This function deletes a file from a node +def file_delete(node, file) + _out, _local, _remote, code = node.test_and_store_results_together("rm #{file}", 'root', 500) + code +end + +# This function deletes a file from a node +def folder_delete(node, folder) + _out, _local, _remote, code = node.test_and_store_results_together("rm -rf #{folder}", 'root', 500) + code +end + +# This function extracts a file from a node +def file_extract(node, remote_file, local_file) + code, _remote = node.extract_file(remote_file, local_file, 'root', false) + code +end + +# This function injects a file into a node +def file_inject(node, local_file, remote_file) + code, _remote = node.inject_file(local_file, remote_file, 'root', false) + code +end diff --git a/testsuite/features/support/constants.rb b/testsuite/features/support/constants.rb index 7df9ec17d57c..6158f678ceff 100644 --- a/testsuite/features/support/constants.rb +++ b/testsuite/features/support/constants.rb @@ -1,6 +1,71 @@ # Copyright (c) 2019-2023 SUSE LLC # Licensed under the terms of the MIT license. +ENV_VAR_BY_HOST = { 'localhost' => 'HOSTNAME', + 'proxy' => 'PROXY', + 'server' => 'SERVER', + 'kvm_server' => 'VIRTHOST_KVM_URL', + 'sle_minion' => 'MINION', + 'ssh_minion' => 'SSH_MINION', + 'rhlike_minion' => 'RHLIKE_MINION', + 'deblike_minion' => 'DEBLIKE_MINION', + 'build_host' => 'BUILD_HOST', + 'salt_migration_minion' => 'MIN_NESTED', + # Build Validation environment + 'sle12sp4_minion' => 'SLE12SP4_MINION', + 'sle12sp4_ssh_minion' => 'SLE12SP4_SSHMINION', + 'sle12sp5_minion' => 'SLE12SP5_MINION', + 'sle12sp5_ssh_minion' => 'SLE12SP5_SSHMINION', + 'sle15sp1_minion' => 'SLE15SP1_MINION', + 'sle15sp1_ssh_minion' => 'SLE15SP1_SSHMINION', + 'sle15sp2_minion' => 'SLE15SP2_MINION', + 'sle15sp2_ssh_minion' => 'SLE15SP2_SSHMINION', + 'sle15sp3_minion' => 'SLE15SP3_MINION', + 'sle15sp3_ssh_minion' => 'SLE15SP3_SSHMINION', + 'sle15sp4_minion' => 'SLE15SP4_MINION', + 'sle15sp4_ssh_minion' => 'SLE15SP4_SSHMINION', + 'sle15sp5_minion' => 'SLE15SP5_MINION', + 'sle15sp5_ssh_minion' => 'SLE15SP5_SSHMINION', + 'slemicro51_minion' => 'SLEMICRO51_MINION', + 'slemicro51_ssh_minion' => 'SLEMICRO51_SSHMINION', + 'slemicro52_minion' => 'SLEMICRO52_MINION', + 'slemicro52_ssh_minion' => 'SLEMICRO52_SSHMINION', + 'slemicro53_minion' => 'SLEMICRO53_MINION', + 'slemicro53_ssh_minion' => 'SLEMICRO53_SSHMINION', + 'slemicro54_minion' => 'SLEMICRO54_MINION', + 'slemicro54_ssh_minion' => 'SLEMICRO54_SSHMINION', + 'alma9_minion' => 'ALMA9_MINION', + 'alma9_ssh_minion' => 'ALMA9_SSHMINION', + 'centos7_minion' => 'CENTOS7_MINION', + 'centos7_ssh_minion' => 'CENTOS7_SSHMINION', + 'liberty9_minion' => 'LIBERTY9_MINION', + 'liberty9_ssh_minion' => 'LIBERTY9_SSHMINION', + 'oracle9_minion' => 'ORACLE9_MINION', + 'oracle9_ssh_minion' => 'ORACLE9_SSHMINION', + 'rhel9_minion' => 'RHEL9_MINION', + 'rhel9_ssh_minion' => 'RHEL9_SSHMINION', + 'rocky8_minion' => 'ROCKY8_MINION', + 'rocky8_ssh_minion' => 'ROCKY8_SSHMINION', + 'rocky9_minion' => 'ROCKY9_MINION', + 'rocky9_ssh_minion' => 'ROCKY9_SSHMINION', + 'ubuntu1804_minion' => 'UBUNTU1804_MINION', + 'ubuntu1804_ssh_minion' => 'UBUNTU1804_SSHMINION', + 'ubuntu2004_minion' => 'UBUNTU2004_MINION', + 'ubuntu2004_ssh_minion' => 'UBUNTU2004_SSHMINION', + 'ubuntu2204_minion' => 'UBUNTU2204_MINION', + 'ubuntu2204_ssh_minion' => 'UBUNTU2204_SSHMINION', + 'debian10_minion' => 'DEBIAN10_MINION', + 'debian10_ssh_minion' => 'DEBIAN10_SSHMINION', + 'debian11_minion' => 'DEBIAN11_MINION', + 'debian11_ssh_minion' => 'DEBIAN11_SSHMINION', + 'opensuse154arm_minion' => 'OPENSUSE154ARM_MINION', + 'opensuse154arm_ssh_minion' => 'OPENSUSE154ARM_SSHMINION', + 'opensuse155arm_minion' => 'OPENSUSE155ARM_MINION', + 'opensuse155arm_ssh_minion' => 'OPENSUSE155ARM_SSHMINION', + 'sle12sp5_buildhost' => 'SLE12SP5_BUILDHOST', + 'sle15sp4_buildhost' => 'SLE15SP4_BUILDHOST', + 'monitoring_server' => 'MONITORING_SERVER' }.freeze + ADDRESSES = { 'network' => '0', 'sle_minion' => '3', 'pxeboot_minion' => '4', diff --git a/testsuite/features/support/env.rb b/testsuite/features/support/env.rb index 929392cf67a1..448e496fa047 100644 --- a/testsuite/features/support/env.rb +++ b/testsuite/features/support/env.rb @@ -15,6 +15,7 @@ require 'multi_test' require 'set' require_relative 'code_coverage' +require_relative 'twopence_env' ## code coverage analysis # SimpleCov.start @@ -35,6 +36,18 @@ # Context per feature $context = {} +# Other global variables +$pxeboot_mac = ENV['PXEBOOT_MAC'] +$pxeboot_image = ENV['PXEBOOT_IMAGE'] || 'sles15sp3o' +$sle12sp5_terminal_mac = ENV['SLE12SP5_TERMINAL_MAC'] +$sle15sp4_terminal_mac = ENV['SLE15SP4_TERMINAL_MAC'] +$private_net = ENV['PRIVATENET'] if ENV['PRIVATENET'] +$mirror = ENV['MIRROR'] +$server_http_proxy = ENV['SERVER_HTTP_PROXY'] if ENV['SERVER_HTTP_PROXY'] +$custom_download_endpoint = ENV['CUSTOM_DOWNLOAD_ENDPOINT'] if ENV['CUSTOM_DOWNLOAD_ENDPOINT'] +$no_auth_registry = ENV['NO_AUTH_REGISTRY'] if ENV['NO_AUTH_REGISTRY'] +$auth_registry = ENV['AUTH_REGISTRY'] if ENV['AUTH_REGISTRY'] + # maximal wait before giving up # the tests return much before that delay in case of success STDOUT.sync = true @@ -43,7 +56,7 @@ DEFAULT_TIMEOUT = ENV['DEFAULT_TIMEOUT'] ? ENV['DEFAULT_TIMEOUT'].to_i : 250 $is_cloud_provider = ENV["PROVIDER"].include? 'aws' $is_container_provider = ENV["PROVIDER"].include? 'podman' -$is_container_server = ['k3s', 'podman'].include? ENV.fetch("CONTAINER_RUNTIME", '') +$is_container_server = %w[k3s podman].include? ENV.fetch("CONTAINER_RUNTIME", '') $is_using_build_image = ENV.fetch('IS_USING_BUILD_IMAGE') { false } $is_using_scc_repositories = (ENV.fetch('IS_USING_SCC_REPOSITORIES', 'False') != 'False') @@ -55,11 +68,6 @@ $build_validation = true end -def enable_assertions - # include assertion globally - World(MiniTest::Assertions) -end - # Fix a problem with minitest and cucumber options passed through rake MultiTest.disable_autorun @@ -105,7 +113,7 @@ def enable_assertions STDOUT.puts "Capybara APP Host: #{Capybara.app_host}:#{Capybara.server_port}" # enable minitest assertions in steps -enable_assertions +World(MiniTest::Assertions) # Init CodeCoverage Handler $code_coverage = CodeCoverage.new(ENV['REDIS_HOST'], ENV['REDIS_PORT'], ENV['REDIS_USERNAME'], ENV['REDIS_PASSWORD']) if $code_coverage_mode @@ -131,7 +139,7 @@ def enable_assertions rescue StandardError => e warn e.message ensure - debug_server_on_realtime_failure + print_server_logs previous_url = current_url step %(I am authorized for the "Admin" section) visit previous_url @@ -169,7 +177,7 @@ def process_code_coverage After('@scope_cobbler') do |scenario| if scenario.failed? STDOUT.puts '=> /var/log/cobbler/cobbler.log' - out, _code = $server.run("tail -n20 /var/log/cobbler/cobbler.log") + out, _code = get_target('server').run("tail -n20 /var/log/cobbler/cobbler.log") out.each_line do |line| STDOUT.puts line.to_s end @@ -192,19 +200,19 @@ def process_code_coverage # do some tests only if the corresponding node exists Before('@proxy') do - skip_this_scenario unless $proxy + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['proxy'] end Before('@sle_minion') do - skip_this_scenario unless $minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle_minion'] end Before('@rhlike_minion') do - skip_this_scenario unless $rhlike_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['rhlike_minion'] end Before('@deblike_minion') do - skip_this_scenario unless $deblike_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['deblike_minion'] end Before('@pxeboot_minion') do @@ -212,183 +220,183 @@ def process_code_coverage end Before('@ssh_minion') do - skip_this_scenario unless $ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['ssh_minion'] end Before('@buildhost') do - skip_this_scenario unless $build_host + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['build_host'] end Before('@virthost_kvm') do - skip_this_scenario unless $kvm_server + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['kvm_server'] end Before('@alma9_minion') do - skip_this_scenario unless $alma9_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['alma9_minion'] end Before('@alma9_ssh_minion') do - skip_this_scenario unless $alma9_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['alma9_ssh_minion'] end Before('@centos7_minion') do - skip_this_scenario unless $centos7_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['centos7_minion'] end Before('@centos7_ssh_minion') do - skip_this_scenario unless $centos7_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['centos7_ssh_minion'] end Before('@liberty9_minion') do - skip_this_scenario unless $liberty9_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['liberty9_minion'] end Before('@liberty9_ssh_minion') do - skip_this_scenario unless $liberty9_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['liberty9_ssh_minion'] end Before('@oracle9_minion') do - skip_this_scenario unless $oracle9_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['oracle9_minion'] end Before('@oracle9_ssh_minion') do - skip_this_scenario unless $oracle9_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['oracle9_ssh_minion'] end Before('@rhel9_minion') do - skip_this_scenario unless $rhel9_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['rhel9_minion'] end Before('@rhel9_ssh_minion') do - skip_this_scenario unless $rhel9_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['rhel9_ssh_minion'] end Before('@rocky8_minion') do - skip_this_scenario unless $rocky8_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['rocky8_minion'] end Before('@rocky8_ssh_minion') do - skip_this_scenario unless $rocky8_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['rocky8_ssh_minion'] end Before('@rocky9_minion') do - skip_this_scenario unless $rocky9_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['rocky9_minion'] end Before('@rocky9_ssh_minion') do - skip_this_scenario unless $rocky9_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['rocky9_ssh_minion'] end Before('@ubuntu1804_minion') do - skip_this_scenario unless $ubuntu1804_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['ubuntu1804_minion'] end Before('@ubuntu1804_ssh_minion') do - skip_this_scenario unless $ubuntu1804_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['ubuntu1804_ssh_minion'] end Before('@ubuntu2004_minion') do - skip_this_scenario unless $ubuntu2004_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['ubuntu2004_minion'] end Before('@ubuntu2004_ssh_minion') do - skip_this_scenario unless $ubuntu2004_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['ubuntu2004_ssh_minion'] end Before('@ubuntu2204_minion') do - skip_this_scenario unless $ubuntu2204_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['ubuntu2204_minion'] end Before('@ubuntu2204_ssh_minion') do - skip_this_scenario unless $ubuntu2204_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['ubuntu2204_ssh_minion'] end Before('@debian10_minion') do - skip_this_scenario unless $debian10_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['debian10_minion'] end Before('@debian10_ssh_minion') do - skip_this_scenario unless $debian10_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['debian10_ssh_minion'] end Before('@debian11_minion') do - skip_this_scenario unless $debian11_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['debian11_minion'] end Before('@debian11_ssh_minion') do - skip_this_scenario unless $debian11_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['debian11_ssh_minion'] end Before('@sle12sp4_minion') do - skip_this_scenario unless $sle12sp4_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle12sp4_minion'] end Before('@sle12sp4_ssh_minion') do - skip_this_scenario unless $sle12sp4_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle12sp4_ssh_minion'] end Before('@sle12sp5_minion') do - skip_this_scenario unless $sle12sp5_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle12sp5_minion'] end Before('@sle12sp5_ssh_minion') do - skip_this_scenario unless $sle12sp5_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle12sp5_ssh_minion'] end Before('@sle15sp1_minion') do - skip_this_scenario unless $sle15sp1_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp1_minion'] end Before('@sle15sp1_ssh_minion') do - skip_this_scenario unless $sle15sp1_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp1_ssh_minion'] end Before('@sle15sp2_minion') do - skip_this_scenario unless $sle15sp2_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp2_minion'] end Before('@sle15sp2_ssh_minion') do - skip_this_scenario unless $sle15sp2_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp2_ssh_minion'] end Before('@sle15sp3_minion') do - skip_this_scenario unless $sle15sp3_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp3_minion'] end Before('@sle15sp3_ssh_minion') do - skip_this_scenario unless $sle15sp3_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp3_ssh_minion'] end Before('@sle15sp4_minion') do - skip_this_scenario unless $sle15sp4_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp4_minion'] end Before('@sle15sp4_ssh_minion') do - skip_this_scenario unless $sle15sp4_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp4_ssh_minion'] end Before('@sle15sp5_minion') do - skip_this_scenario unless $sle15sp5_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp5_minion'] end Before('@sle15sp5_ssh_minion') do - skip_this_scenario unless $sle15sp5_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp5_ssh_minion'] end Before('@opensuse154arm_minion') do - skip_this_scenario unless $opensuse154arm_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['opensuse154arm_minion'] end Before('@opensuse154arm_ssh_minion') do - skip_this_scenario unless $opensuse154arm_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['opensuse154arm_ssh_minion'] end Before('@opensuse155arm_minion') do - skip_this_scenario unless $opensuse155arm_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['opensuse155arm_minion'] end Before('@opensuse155arm_ssh_minion') do - skip_this_scenario unless $opensuse155arm_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['opensuse155arm_ssh_minion'] end Before('@slemicro') do |scenario| @@ -396,39 +404,39 @@ def process_code_coverage end Before('@slemicro51_minion') do - skip_this_scenario unless $slemicro51_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro51_minion'] end Before('@slemicro51_ssh_minion') do - skip_this_scenario unless $slemicro51_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro51_ssh_minion'] end Before('@slemicro52_minion') do - skip_this_scenario unless $slemicro52_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro52_minion'] end Before('@slemicro52_ssh_minion') do - skip_this_scenario unless $slemicro52_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro52_ssh_minion'] end Before('@slemicro53_minion') do - skip_this_scenario unless $slemicro53_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro53_minion'] end Before('@slemicro53_ssh_minion') do - skip_this_scenario unless $slemicro53_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro53_ssh_minion'] end Before('@slemicro54_minion') do - skip_this_scenario unless $slemicro54_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro54_minion'] end Before('@slemicro54_ssh_minion') do - skip_this_scenario unless $slemicro54_ssh_minion + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['slemicro54_ssh_minion'] end Before('@sle12sp5_buildhost') do - skip_this_scenario unless $sle12sp5_buildhost + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle12sp5_buildhost'] end Before('@sle12sp5_terminal') do @@ -436,11 +444,11 @@ def process_code_coverage end Before('@sle15sp4_buildhost') do - skip_this_scenario unless $sle15sp4_buildhost + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['sle15sp4_buildhost'] end Before('@monitoring_server') do - skip_this_scenario unless $monitoring_server + skip_this_scenario unless ENV.key? ENV_VAR_BY_HOST['monitoring_server'] end Before('@sle15sp4_terminal') do @@ -464,11 +472,11 @@ def process_code_coverage # TODO: remove these 2 "skip" tags when Rocky and Alma have patches available. Before('@skip_for_alma9') do - skip_this_scenario if $alma9_minion || $alma9_ssh_minion + skip_this_scenario if ENV.key?(ENV_VAR_BY_HOST['alma9_minion']) || ENV.key?(ENV_VAR_BY_HOST['alma9_ssh_minion']) end Before('@skip_for_rocky9') do - skip_this_scenario if $rocky9_minion || $rocky_ssh_minion + skip_this_scenario if ENV.key?(ENV_VAR_BY_HOST['rocky9_minion']) || ENV.key?(ENV_VAR_BY_HOST['rocky_ssh_minion']) end Before('@skip_for_sle_micro') do |scenario| @@ -492,22 +500,22 @@ def process_code_coverage # do some tests only if the server is using SUSE Manager Before('@susemanager') do - skip_this_scenario unless $product == 'SUSE Manager' + skip_this_scenario unless product == 'SUSE Manager' end # do some tests only if the server is using Uyuni Before('@uyuni') do - skip_this_scenario unless $product == 'Uyuni' + skip_this_scenario unless product == 'Uyuni' end # do some tests only if we are using salt bundle Before('@salt_bundle') do - skip_this_scenario unless $use_salt_bundle + skip_this_scenario unless use_salt_bundle end # do some tests only if we are using salt bundle Before('@skip_if_salt_bundle') do - skip_this_scenario if $use_salt_bundle + skip_this_scenario if use_salt_bundle end # do test only if HTTP proxy for Uyuni is defined @@ -546,15 +554,15 @@ def process_code_coverage end # have more infos about the errors -def debug_server_on_realtime_failure +def print_server_logs STDOUT.puts '=> /var/log/rhn/rhn_web_ui.log' - out, _code = $server.run("tail -n20 /var/log/rhn/rhn_web_ui.log | awk -v limit=\"$(date --date='5 minutes ago' '+%Y-%m-%d %H:%M:%S')\" ' $0 > limit'") + out, _code = get_target('server').run("tail -n20 /var/log/rhn/rhn_web_ui.log | awk -v limit=\"$(date --date='5 minutes ago' '+%Y-%m-%d %H:%M:%S')\" ' $0 > limit'") out.each_line do |line| STDOUT.puts line.to_s end STDOUT.puts STDOUT.puts '=> /var/log/rhn/rhn_web_api.log' - out, _code = $server.run("tail -n20 /var/log/rhn/rhn_web_api.log | awk -v limit=\"$(date --date='5 minutes ago' '+%Y-%m-%d %H:%M:%S')\" ' $0 > limit'") + out, _code = get_target('server').run("tail -n20 /var/log/rhn/rhn_web_api.log | awk -v limit=\"$(date --date='5 minutes ago' '+%Y-%m-%d %H:%M:%S')\" ' $0 > limit'") out.each_line do |line| STDOUT.puts line.to_s end diff --git a/testsuite/features/support/lavanda.rb b/testsuite/features/support/lavanda.rb index 732e2347b19c..64ca455ab277 100644 --- a/testsuite/features/support/lavanda.rb +++ b/testsuite/features/support/lavanda.rb @@ -5,8 +5,8 @@ require 'timeout' # Extend the objects node VMs with useful methods needed for testsuite. -# All function added here will be available like $server.run -# or $minion.run_until_ok etc. +# All function added here will be available like get_target('server').run +# or get_target('sle_minion').run_until_ok etc. module LavandaBasic # init the hostnames, only one time def init_hostname(hostname) diff --git a/testsuite/features/support/namespaces/system.rb b/testsuite/features/support/namespaces/system.rb index 039fe17165ca..9fc541e9703f 100644 --- a/testsuite/features/support/namespaces/system.rb +++ b/testsuite/features/support/namespaces/system.rb @@ -72,10 +72,10 @@ def list_latest_upgradable_packages(server) # activation_key: The activation key to use for the system. # salt_ssh: Boolean value determining if the system is SSH managed or not. def bootstrap_system(host, activation_key, salt_ssh) - if $proxy.nil? + if get_target('proxy').nil? @test.call('system.bootstrap', sessionKey: @test.token, host: host, sshPort: 22, sshUser: 'root', sshPassword: 'linux', activationKey: activation_key, saltSSH: salt_ssh) else - proxy = @test.call('system.searchByName', sessionKey: @test.token, regexp: $proxy.full_hostname) + proxy = @test.call('system.searchByName', sessionKey: @test.token, regexp: get_target('proxy').full_hostname) proxy_id = proxy.map { |s| s['id'] }.first @test.call('system.bootstrap', sessionKey: @test.token, host: host, sshPort: 22, sshUser: 'root', sshPassword: 'linux', activationKey: activation_key, proxyId: proxy_id, saltSSH: salt_ssh) end diff --git a/testsuite/features/support/twopence_env.rb b/testsuite/features/support/twopence_env.rb new file mode 100644 index 000000000000..aeb417e4f3a0 --- /dev/null +++ b/testsuite/features/support/twopence_env.rb @@ -0,0 +1,43 @@ +# Copyright (c) 2016-2023 SUSE LLC. +# Licensed under the terms of the MIT license. + +require 'require_all' +require 'twopence' +require_all 'features/support' + +# Raise a warning if any of these environment variables is missing +raise 'Server IP address or domain name variable empty' if ENV['SERVER'].nil? + +warn 'Proxy IP address or domain name variable empty' if ENV['PROXY'].nil? +unless $build_validation + warn 'Minion IP address or domain name variable empty' if ENV['MINION'].nil? + warn 'Buildhost IP address or domain name variable empty' if ENV['BUILD_HOST'].nil? + warn 'Red Hat-like minion IP address or domain name variable empty' if ENV['RHLIKE_MINION'].nil? + warn 'Debian-like minion IP address or domain name variable empty' if ENV['DEBLIKE_MINION'].nil? + warn 'SSH minion IP address or domain name variable empty' if ENV['SSH_MINION'].nil? + warn 'PXE boot MAC address variable empty' if ENV['PXEBOOT_MAC'].nil? + warn 'KVM server minion IP address or domain name variable empty' if ENV['VIRTHOST_KVM_URL'].nil? + warn 'Nested VM hostname empty' if ENV['MIN_NESTED'].nil? + warn 'Nested VM MAC address empty' if ENV['MAC_MIN_NESTED'].nil? +end + +# Dictionaries to obtain host or node from the Twopence objects +$nodes = [] +$node_by_host = {} +$host_by_node = {} + +# Preserve FQDN before initialization +$named_nodes = {} + +# Define SCC credentials through the environment variable +if ENV['SCC_CREDENTIALS'] + scc_username, scc_password = ENV['SCC_CREDENTIALS'].split('|') + $scc_credentials = !scc_username.to_s.empty? && !scc_password.to_s.empty? +end + +# Get the Twopence node passing the host (includes lazy initialization) +def get_target(host) + node = $node_by_host[host] + node = twopence_init(host) if node.nil? + node +end diff --git a/testsuite/features/support/twopence_init.rb b/testsuite/features/support/twopence_init.rb index 611eb0b6c9d0..006bc8e9a888 100644 --- a/testsuite/features/support/twopence_init.rb +++ b/testsuite/features/support/twopence_init.rb @@ -1,366 +1,19 @@ # Copyright (c) 2016-2023 SUSE LLC. # Licensed under the terms of the MIT license. -require 'require_all' require 'twopence' -require_all 'features/support' -# Initialize SSH targets from environment variables -raise 'Server IP address or domain name variable empty' if ENV['SERVER'].nil? -warn 'Proxy IP address or domain name variable empty' if ENV['PROXY'].nil? -unless $build_validation - warn 'Minion IP address or domain name variable empty' if ENV['MINION'].nil? - warn 'Buildhost IP address or domain name variable empty' if ENV['BUILD_HOST'].nil? - warn 'Red Hat-like minion IP address or domain name variable empty' if ENV['RHLIKE_MINION'].nil? - warn 'Debian-like minion IP address or domain name variable empty' if ENV['DEBLIKE_MINION'].nil? - warn 'SSH minion IP address or domain name variable empty' if ENV['SSH_MINION'].nil? - warn 'PXE boot MAC address variable empty' if ENV['PXEBOOT_MAC'].nil? - warn 'KVM server minion IP address or domain name variable empty' if ENV['VIRTHOST_KVM_URL'].nil? - warn 'Nested VM hostname empty' if ENV['MIN_NESTED'].nil? - warn 'Nested VM MAC address empty' if ENV['MAC_MIN_NESTED'].nil? -end - -# Preserve FQDN before initialization -$named_nodes = {} - -def twopence_init(target) - init_target = Twopence.init(target) - $named_nodes[init_target.hash] = target.split(':')[1] - init_target -end - -# Define common twopence objects -$localhost = twopence_init("ssh:#{ENV['HOSTNAME']}") unless $debug_mode -$proxy = twopence_init("ssh:#{ENV['PROXY']}") if ENV['PROXY'] -$server = twopence_init("ssh:#{ENV['SERVER']}") -$kvm_server = twopence_init("ssh:#{ENV['VIRTHOST_KVM_URL']}") if ENV['VIRTHOST_KVM_URL'] && ENV['VIRTHOST_KVM_PASSWORD'] - -$nodes = [$localhost, $server, $proxy, $kvm_server] - -if $build_validation - # Define twopence objects for Build Validation environment - $sle12sp4_minion = twopence_init("ssh:#{ENV['SLE12SP4_MINION']}") if ENV['SLE12SP4_MINION'] - $sle12sp4_ssh_minion = twopence_init("ssh:#{ENV['SLE12SP4_SSHMINION']}") if ENV['SLE12SP4_SSHMINION'] - $sle12sp5_minion = twopence_init("ssh:#{ENV['SLE12SP5_MINION']}") if ENV['SLE12SP5_MINION'] - $sle12sp5_ssh_minion = twopence_init("ssh:#{ENV['SLE12SP5_SSHMINION']}") if ENV['SLE12SP5_SSHMINION'] - $sle15sp1_minion = twopence_init("ssh:#{ENV['SLE15SP1_MINION']}") if ENV['SLE15SP1_MINION'] - $sle15sp1_ssh_minion = twopence_init("ssh:#{ENV['SLE15SP1_SSHMINION']}") if ENV['SLE15SP1_SSHMINION'] - $sle15sp2_minion = twopence_init("ssh:#{ENV['SLE15SP2_MINION']}") if ENV['SLE15SP2_MINION'] - $sle15sp2_ssh_minion = twopence_init("ssh:#{ENV['SLE15SP2_SSHMINION']}") if ENV['SLE15SP2_SSHMINION'] - $sle15sp3_minion = twopence_init("ssh:#{ENV['SLE15SP3_MINION']}") if ENV['SLE15SP3_MINION'] - $sle15sp3_ssh_minion = twopence_init("ssh:#{ENV['SLE15SP3_SSHMINION']}") if ENV['SLE15SP3_SSHMINION'] - $sle15sp4_minion = twopence_init("ssh:#{ENV['SLE15SP4_MINION']}") if ENV['SLE15SP4_MINION'] - $sle15sp4_ssh_minion = twopence_init("ssh:#{ENV['SLE15SP4_SSHMINION']}") if ENV['SLE15SP4_SSHMINION'] - $sle15sp5_minion = twopence_init("ssh:#{ENV['SLE15SP5_MINION']}") if ENV['SLE15SP5_MINION'] - $sle15sp5_ssh_minion = twopence_init("ssh:#{ENV['SLE15SP5_SSHMINION']}") if ENV['SLE15SP5_SSHMINION'] - $slemicro51_minion = twopence_init("ssh:#{ENV['SLEMICRO51_MINION']}") if ENV['SLEMICRO51_MINION'] - $slemicro51_ssh_minion = twopence_init("ssh:#{ENV['SLEMICRO51_SSHMINION']}") if ENV['SLEMICRO51_SSHMINION'] - $slemicro52_minion = twopence_init("ssh:#{ENV['SLEMICRO52_MINION']}") if ENV['SLEMICRO52_MINION'] - $slemicro52_ssh_minion = twopence_init("ssh:#{ENV['SLEMICRO52_SSHMINION']}") if ENV['SLEMICRO52_SSHMINION'] - $slemicro53_minion = twopence_init("ssh:#{ENV['SLEMICRO53_MINION']}") if ENV['SLEMICRO53_MINION'] - $slemicro53_ssh_minion = twopence_init("ssh:#{ENV['SLEMICRO53_SSHMINION']}") if ENV['SLEMICRO53_SSHMINION'] - $slemicro54_minion = twopence_init("ssh:#{ENV['SLEMICRO54_MINION']}") if ENV['SLEMICRO54_MINION'] - $slemicro54_ssh_minion = twopence_init("ssh:#{ENV['SLEMICRO54_SSHMINION']}") if ENV['SLEMICRO54_SSHMINION'] - $alma9_minion = twopence_init("ssh:#{ENV['ALMA9_MINION']}") if ENV['ALMA9_MINION'] - $alma9_ssh_minion = twopence_init("ssh:#{ENV['ALMA9_SSHMINION']}") if ENV['ALMA9_SSHMINION'] - $centos7_minion = twopence_init("ssh:#{ENV['CENTOS7_MINION']}") if ENV['CENTOS7_MINION'] - $centos7_ssh_minion = twopence_init("ssh:#{ENV['CENTOS7_SSHMINION']}") if ENV['CENTOS7_SSHMINION'] - $liberty9_minion = twopence_init("ssh:#{ENV['LIBERTY9_MINION']}") if ENV['LIBERTY9_MINION'] - $liberty9_ssh_minion = twopence_init("ssh:#{ENV['LIBERTY9_SSHMINION']}") if ENV['LIBERTY9_SSHMINION'] - $oracle9_minion = twopence_init("ssh:#{ENV['ORACLE9_MINION']}") if ENV['ORACLE9_MINION'] - $oracle9_ssh_minion = twopence_init("ssh:#{ENV['ORACLE9_SSHMINION']}") if ENV['ORACLE9_SSHMINION'] - $rhel9_minion = twopence_init("ssh:#{ENV['RHEL9_MINION']}") if ENV['RHEL9_MINION'] - $rhel9_ssh_minion = twopence_init("ssh:#{ENV['RHEL9_SSHMINION']}") if ENV['RHEL9_SSHMINION'] - $rocky8_minion = twopence_init("ssh:#{ENV['ROCKY8_MINION']}") if ENV['ROCKY8_MINION'] - $rocky8_ssh_minion = twopence_init("ssh:#{ENV['ROCKY8_SSHMINION']}") if ENV['ROCKY8_SSHMINION'] - $rocky9_minion = twopence_init("ssh:#{ENV['ROCKY9_MINION']}") if ENV['ROCKY9_MINION'] - $rocky9_ssh_minion = twopence_init("ssh:#{ENV['ROCKY9_SSHMINION']}") if ENV['ROCKY9_SSHMINION'] - $ubuntu1804_minion = twopence_init("ssh:#{ENV['UBUNTU1804_MINION']}") if ENV['UBUNTU1804_MINION'] - $ubuntu1804_ssh_minion = twopence_init("ssh:#{ENV['UBUNTU1804_SSHMINION']}") if ENV['UBUNTU1804_SSHMINION'] - $ubuntu2004_minion = twopence_init("ssh:#{ENV['UBUNTU2004_MINION']}") if ENV['UBUNTU2004_MINION'] - $ubuntu2004_ssh_minion = twopence_init("ssh:#{ENV['UBUNTU2004_SSHMINION']}") if ENV['UBUNTU2004_SSHMINION'] - $ubuntu2204_minion = twopence_init("ssh:#{ENV['UBUNTU2204_MINION']}") if ENV['UBUNTU2204_MINION'] - $ubuntu2204_ssh_minion = twopence_init("ssh:#{ENV['UBUNTU2204_SSHMINION']}") if ENV['UBUNTU2204_SSHMINION'] - $debian10_minion = twopence_init("ssh:#{ENV['DEBIAN10_MINION']}") if ENV['DEBIAN10_MINION'] - $debian10_ssh_minion = twopence_init("ssh:#{ENV['DEBIAN10_SSHMINION']}") if ENV['DEBIAN10_SSHMINION'] - $debian11_minion = twopence_init("ssh:#{ENV['DEBIAN11_MINION']}") if ENV['DEBIAN11_MINION'] - $debian11_ssh_minion = twopence_init("ssh:#{ENV['DEBIAN11_SSHMINION']}") if ENV['DEBIAN11_SSHMINION'] - $opensuse154arm_minion = twopence_init("ssh:#{ENV['OPENSUSE154ARM_MINION']}") if ENV['OPENSUSE154ARM_MINION'] - $opensuse154arm_ssh_minion = twopence_init("ssh:#{ENV['OPENSUSE154ARM_SSHMINION']}") if ENV['OPENSUSE154ARM_SSHMINION'] - $opensuse155arm_minion = twopence_init("ssh:#{ENV['OPENSUSE155ARM_MINION']}") if ENV['OPENSUSE155ARM_MINION'] - $opensuse155arm_ssh_minion = twopence_init("ssh:#{ENV['OPENSUSE155ARM_SSHMINION']}") if ENV['OPENSUSE155ARM_SSHMINION'] - $sle12sp5_buildhost = twopence_init("ssh:#{ENV['SLE12SP5_BUILDHOST']}") if ENV['SLE12SP5_BUILDHOST'] - $sle15sp4_buildhost = twopence_init("ssh:#{ENV['SLE15SP4_BUILDHOST']}") if ENV['SLE15SP4_BUILDHOST'] - $monitoring_server = twopence_init("ssh:#{ENV['MONITORING_SERVER']}") if ENV['MONITORING_SERVER'] - $nodes += [$sle12sp4_minion, $sle12sp4_ssh_minion, - $sle12sp5_minion, $sle12sp5_ssh_minion, - $sle15sp1_minion, $sle15sp1_ssh_minion, - $sle15sp2_minion, $sle15sp2_ssh_minion, - $sle15sp3_minion, $sle15sp3_ssh_minion, - $sle15sp4_minion, $sle15sp4_ssh_minion, - $sle15sp5_minion, $sle15sp5_ssh_minion, - $slemicro51_minion, $slemicro51_ssh_minion, - $slemicro52_minion, $slemicro52_ssh_minion, - $slemicro53_minion, $slemicro53_ssh_minion, - $slemicro54_minion, $slemicro54_ssh_minion, - $alma9_minion, $alma9_ssh_minion, - $centos7_minion, $centos7_ssh_minion, - $liberty9_minion, $liberty9_ssh_minion, - $oracle9_minion, $oracle9_ssh_minion, - $rhel9_minion, $rhel9_ssh_minion, - $rocky8_minion, $rocky8_ssh_minion, - $rocky9_minion, $rocky9_ssh_minion, - $ubuntu1804_minion, $ubuntu1804_ssh_minion, - $ubuntu2004_minion, $ubuntu2004_ssh_minion, - $ubuntu2204_minion, $ubuntu2204_ssh_minion, - $debian10_minion, $debian10_ssh_minion, - $debian11_minion, $debian11_ssh_minion, - $opensuse154arm_minion, $opensuse154arm_ssh_minion, - $opensuse155arm_minion, $opensuse155arm_ssh_minion, - $sle12sp5_buildhost, - $sle15sp4_buildhost, - $monitoring_server] -else - # Define twopence objects for QA environment - $minion = twopence_init("ssh:#{ENV['MINION']}") if ENV['MINION'] - $ssh_minion = twopence_init("ssh:#{ENV['SSH_MINION']}") if ENV['SSH_MINION'] - $rhlike_minion = twopence_init("ssh:#{ENV['RHLIKE_MINION']}") if ENV['RHLIKE_MINION'] - $deblike_minion = twopence_init("ssh:#{ENV['DEBLIKE_MINION']}") if ENV['DEBLIKE_MINION'] - $build_host = twopence_init("ssh:#{ENV['BUILD_HOST']}") if ENV['BUILD_HOST'] - $salt_migration_minion = twopence_init("ssh:#{ENV['MIN_NESTED']}") if ENV['MIN_NESTED'] - $nodes += [$minion, $ssh_minion, $rhlike_minion, $deblike_minion, $build_host, $salt_migration_minion] -end - -# Lavanda library module extension -# Look at support/lavanda.rb for more details -$nodes.each do |node| - next if node.nil? - - node.extend(LavandaBasic) -end - -# Initialize hostname -$nodes.each do |node| - next if node.nil? - - hostname, local, remote, code = node.test_and_store_results_together('hostname', 'root', 500) - # special handling for nested VMs since they will only be crated later in the test suite - # we to a late hostname initialization in a special step for those - next if hostname.empty? || node == $salt_migration_minion - - raise "Cannot connect to get hostname for '#{$named_nodes[node.hash]}'. Response code: #{code}, local: #{local}, remote: #{remote}" if code.nonzero? || remote.nonzero? || local.nonzero? - raise "No hostname for '#{$named_nodes[node.hash]}'. Response code: #{code}" if hostname.empty? - node.init_hostname(hostname) - - fqdn, local, remote, code = node.test_and_store_results_together('hostname -f', 'root', 500) - raise "Cannot connect to get FQDN for '#{$named_nodes[node.hash]}'. Response code: #{code}, local: #{local}, remote: #{remote}" if code.nonzero? || remote.nonzero? || local.nonzero? - raise "No FQDN for '#{$named_nodes[node.hash]}'. Response code: #{code}" if fqdn.empty? - node.init_full_hostname(fqdn) - - STDOUT.puts "Host '#{$named_nodes[node.hash]}' is alive with determined hostname #{hostname.strip} and FQDN #{fqdn.strip}" unless $build_validation +# Retrieve and set OS Family and Version of a node +def process_os_family_and_version(host, fqdn, hostname, node) + STDOUT.puts "Host '#{host}' is alive with determined hostname #{hostname.strip} and FQDN #{fqdn.strip}" unless $build_validation os_version, os_family = get_os_version(node) node.init_os_family(os_family) node.init_os_version(os_version) -end - -# This function is used to get one of the nodes based on its type -def get_target(host) - node = $node_by_host[host] - raise 'Invalid target' if node.nil? node end -# This function gets the system name, as displayed in systems list -# * for the usual clients, it is the full hostname, e.g. suma-41-min-sle15.tf.local -# * for the PXE booted clients, it is derived from the branch name, the hardware type, -# and a fingerprint, e.g. example.Intel-Genuine-None-d6df84cca6f478cdafe824e35bbb6e3b -def get_system_name(host) - case host - # The PXE boot minion and the terminals are not directly accessible on the network, - # therefore they are not represented by a twopence node - when 'pxeboot_minion' - output, _code = $server.run('salt-key') - system_name = output.split.find do |word| - word =~ /example.Intel-Genuine-None-/ || word =~ /example.pxeboot-/ || word =~ /example.Intel/ || word =~ /pxeboot-/ - end - system_name = 'pxeboot.example.org' if system_name.nil? - when 'sle12sp5_terminal' - output, _code = $server.run('salt-key') - system_name = output.split.find do |word| - word =~ /example.sle12sp5terminal-/ - end - system_name = 'sle12sp5terminal.example.org' if system_name.nil? - when 'sle15sp4_terminal' - output, _code = $server.run('salt-key') - system_name = output.split.find do |word| - word =~ /example.sle15sp4terminal-/ - end - system_name = 'sle15sp4terminal.example.org' if system_name.nil? - when 'containerized_proxy' - system_name = $proxy.full_hostname.sub('pxy', 'pod-pxy') - else - begin - node = get_target(host) - system_name = node.full_hostname - rescue RuntimeError - # If the node for that host is not defined, just return the host parameter as system_name - system_name = host - end - end - system_name -end - -# Get MAC address of system -def get_mac_address(host) - if host == 'pxeboot_minion' - mac = ENV['PXEBOOT_MAC'] - else - node = get_target(host) - output, _code = node.run('ip link show dev eth1') - mac = output.split("\n")[1].split[1] - end - mac -end - -# This function returns the net prefix, caching it -def net_prefix - $net_prefix = $private_net.sub(%r{\.0+/24$}, '.') if $net_prefix.nil? && !$private_net.nil? - $net_prefix -end - -# This function tests whether a file exists on a node -def file_exists?(node, file) - _out, local, _remote, code = node.test_and_store_results_together("test -f #{file}", 'root', 500) - code.zero? && local.zero? -end - -# This function tests whether a folder exists on a node -def folder_exists?(node, file) - _out, local, _remote, code = node.test_and_store_results_together("test -d #{file}", 'root', 500) - code.zero? && local.zero? -end - -# This function deletes a file from a node -def file_delete(node, file) - _out, _local, _remote, code = node.test_and_store_results_together("rm #{file}", 'root', 500) - code -end - -# This function deletes a file from a node -def folder_delete(node, folder) - _out, _local, _remote, code = node.test_and_store_results_together("rm -rf #{folder}", 'root', 500) - code -end - -# This function extracts a file from a node -def file_extract(node, remote_file, local_file) - code, _remote = node.extract_file(remote_file, local_file, 'root', false) - code -end - -# This function injects a file into a node -def file_inject(node, local_file, remote_file) - code, _remote = node.inject_file(local_file, remote_file, 'root', false) - code -end - -# Other global variables -$product = product -$product_version = product_version -$use_salt_bundle = use_salt_bundle -$pxeboot_mac = ENV['PXEBOOT_MAC'] -$pxeboot_image = ENV['PXEBOOT_IMAGE'] || 'sles15sp3o' -$sle12sp5_terminal_mac = ENV['SLE12SP5_TERMINAL_MAC'] -$sle15sp4_terminal_mac = ENV['SLE15SP4_TERMINAL_MAC'] -$private_net = ENV['PRIVATENET'] if ENV['PRIVATENET'] -$mirror = ENV['MIRROR'] -$server_http_proxy = ENV['SERVER_HTTP_PROXY'] if ENV['SERVER_HTTP_PROXY'] -$custom_download_endpoint = ENV['CUSTOM_DOWNLOAD_ENDPOINT'] if ENV['CUSTOM_DOWNLOAD_ENDPOINT'] -$no_auth_registry = ENV['NO_AUTH_REGISTRY'] if ENV['NO_AUTH_REGISTRY'] -$auth_registry = ENV['AUTH_REGISTRY'] if ENV['AUTH_REGISTRY'] -if ENV['SCC_CREDENTIALS'] - scc_username, scc_password = ENV['SCC_CREDENTIALS'].split('|') - $scc_credentials = !scc_username.to_s.empty? && !scc_password.to_s.empty? -end -$node_by_host = { 'localhost' => $localhost, - 'server' => $server, - 'proxy' => $proxy, - 'containerized_proxy' => $proxy, - 'sle_minion' => $minion, - 'ssh_minion' => $ssh_minion, - 'rhlike_minion' => $rhlike_minion, - 'deblike_minion' => $deblike_minion, - 'build_host' => $build_host, - 'kvm_server' => $kvm_server, - 'sle12sp4_minion' => $sle12sp4_minion, - 'sle12sp4_ssh_minion' => $sle12sp4_ssh_minion, - 'sle12sp5_minion' => $sle12sp5_minion, - 'sle12sp5_ssh_minion' => $sle12sp5_ssh_minion, - 'sle15sp1_minion' => $sle15sp1_minion, - 'sle15sp1_ssh_minion' => $sle15sp1_ssh_minion, - 'sle15sp2_minion' => $sle15sp2_minion, - 'sle15sp2_ssh_minion' => $sle15sp2_ssh_minion, - 'sle15sp3_minion' => $sle15sp3_minion, - 'sle15sp3_ssh_minion' => $sle15sp3_ssh_minion, - 'sle15sp4_minion' => $sle15sp4_minion, - 'sle15sp4_ssh_minion' => $sle15sp4_ssh_minion, - 'sle15sp5_minion' => $sle15sp5_minion, - 'sle15sp5_ssh_minion' => $sle15sp5_ssh_minion, - 'slemicro51_minion' => $slemicro51_minion, - 'slemicro51_ssh_minion' => $slemicro51_ssh_minion, - 'slemicro52_minion' => $slemicro52_minion, - 'slemicro52_ssh_minion' => $slemicro52_ssh_minion, - 'slemicro53_minion' => $slemicro53_minion, - 'slemicro53_ssh_minion' => $slemicro53_ssh_minion, - 'slemicro54_minion' => $slemicro54_minion, - 'slemicro54_ssh_minion' => $slemicro54_ssh_minion, - 'alma9_minion' => $alma9_minion, - 'alma9_ssh_minion' => $alma9_ssh_minion, - 'centos7_minion' => $centos7_minion, - 'centos7_ssh_minion' => $centos7_ssh_minion, - 'liberty9_minion' => $liberty9_minion, - 'liberty9_ssh_minion' => $liberty9_ssh_minion, - 'oracle9_minion' => $oracle9_minion, - 'oracle9_ssh_minion' => $oracle9_ssh_minion, - 'rhel9_minion' => $rhel9_minion, - 'rhel9_ssh_minion' => $rhel9_ssh_minion, - 'rocky8_minion' => $rocky8_minion, - 'rocky8_ssh_minion' => $rocky8_ssh_minion, - 'rocky9_minion' => $rocky9_minion, - 'rocky9_ssh_minion' => $rocky9_ssh_minion, - 'ubuntu1804_minion' => $ubuntu1804_minion, - 'ubuntu1804_ssh_minion' => $ubuntu1804_ssh_minion, - 'ubuntu2004_minion' => $ubuntu2004_minion, - 'ubuntu2004_ssh_minion' => $ubuntu2004_ssh_minion, - 'ubuntu2204_minion' => $ubuntu2204_minion, - 'ubuntu2204_ssh_minion' => $ubuntu2204_ssh_minion, - 'debian10_minion' => $debian10_minion, - 'debian10_ssh_minion' => $debian10_ssh_minion, - 'debian11_minion' => $debian11_minion, - 'debian11_ssh_minion' => $debian11_ssh_minion, - 'opensuse154arm_minion' => $opensuse154arm_minion, - 'opensuse154arm_ssh_minion' => $opensuse154arm_ssh_minion, - 'opensuse155arm_minion' => $opensuse155arm_minion, - 'opensuse155arm_ssh_minion' => $opensuse155arm_ssh_minion, - 'sle12sp5_buildhost' => $sle12sp5_buildhost, - 'sle15sp4_buildhost' => $sle15sp4_buildhost, - 'monitoring_server' => $monitoring_server, - 'salt_migration_minion' => $salt_migration_minion } - -# This is the inverse of `node_by_host`. -$host_by_node = {} -$node_by_host.each do |host, node| - next if node.nil? - - [host, node].each do |it| - raise ">>> Either host '#{host}' of node '#{node}' is empty. Please check" if it == '' - end - - $host_by_node[node] = host -end - -def client_public_ip(host) - node = $node_by_host[host] +# Obtain the Public IP for a node +def client_public_ip(node) raise "Cannot resolve node for host '#{host}'" if node.nil? %w[br0 eth0 eth1 ens0 ens1 ens2 ens3 ens4 ens5 ens6].each do |dev| @@ -369,25 +22,58 @@ def client_public_ip(host) node.init_public_interface(dev) return '' if output.empty? + return output.split[1].split('/')[0] end raise "Cannot resolve public ip of #{host}" end -# Initialize IP address or domain name -$nodes.each do |node| - next if node.nil? - next if node.is_a?(String) && node.empty? - - host = $host_by_node[node] - raise "Cannot resolve host for node: '#{node.hostname}'" if host.nil? || host == '' - +# Retrieve and set private and public IPs of a node +def process_private_and_public_ip(host, node) if (ADDRESSES.key? host) && !$private_net.nil? node.init_private_ip(net_prefix + ADDRESSES[host]) node.init_private_interface('eth1') end - ip = client_public_ip host - next if ip.empty? - node.init_public_ip ip + ip = client_public_ip node + node.init_public_ip(ip) unless ip.empty? + node +end + +# Initialize a Twopence node through its host (additionally it will setup some handy maps) +def twopence_init(host) + puts "Initializing a twopence node for '#{host}'." + target = "ssh:#{ENV[ENV_VAR_BY_HOST[host]]}" + node = Twopence.init(target) + raise "Twopence node #{host} initialization has failed." if node.nil? + + $named_nodes[node.hash] = target.split(':')[1] + + # Lavanda library module extension + # Look at support/lavanda.rb for more details + node.extend(LavandaBasic) + + # Initialize hostname + hostname, local, remote, code = node.test_and_store_results_together('hostname', 'root', 500) + + # special handling for nested VMs since they will only be created later in the test suite + # we to a late hostname initialization in a special step for those + unless hostname.empty? || host == 'salt_migration_minion' + raise "Cannot connect to get hostname for '#{$named_nodes[node.hash]}'. Response code: #{code}, local: #{local}, remote: #{remote}" if code.nonzero? || remote.nonzero? || local.nonzero? + raise "No hostname for '#{$named_nodes[node.hash]}'. Response code: #{code}" if hostname.empty? + node.init_hostname(hostname) + + fqdn, local, remote, code = node.test_and_store_results_together('hostname -f', 'root', 500) + raise "Cannot connect to get FQDN for '#{$named_nodes[node.hash]}'. Response code: #{code}, local: #{local}, remote: #{remote}" if code.nonzero? || remote.nonzero? || local.nonzero? + raise "No FQDN for '#{$named_nodes[node.hash]}'. Response code: #{code}" if fqdn.empty? + node.init_full_hostname(fqdn) + + node = process_os_family_and_version(host, fqdn, hostname, node) + node = process_private_and_public_ip(host, node) + end + + $nodes << node + $node_by_host[host] = node + $host_by_node[node] = host + node end