diff --git a/testsuite/.rubocop.yml b/testsuite/.rubocop.yml index 0143161b2d44..e7c0b75b4235 100644 --- a/testsuite/.rubocop.yml +++ b/testsuite/.rubocop.yml @@ -9,5 +9,8 @@ Metrics/CyclomaticComplexity: Metrics/ClassLength: Enabled: false +Metrics/ModuleLength: + Enabled: false + Style/MissingElse: Enabled: false diff --git a/testsuite/features/init_clients/proxy_branch_network.feature b/testsuite/features/init_clients/proxy_branch_network.feature index e49a45b5cb50..d2ecf6e08a54 100644 --- a/testsuite/features/init_clients/proxy_branch_network.feature +++ b/testsuite/features/init_clients/proxy_branch_network.feature @@ -21,6 +21,7 @@ Feature: Setup Uyuni for Retail branch network @proxy @private_net +@skip_if_container_server Scenario: Install or update branch network formulas on the server When I manually install the "branch-network" formula on the server And I manually install the "dhcpd" formula on the server @@ -29,6 +30,7 @@ Feature: Setup Uyuni for Retail branch network @proxy @private_net @susemanager +@skip_if_container_server Scenario: Install the Retail pattern on the SUSE Manager server When I refresh the metadata for "server" When I install pattern "suma_retail" on this "server" @@ -38,6 +40,7 @@ Feature: Setup Uyuni for Retail branch network @proxy @private_net @uyuni +@skip_if_container_server Scenario: Install the Retail pattern on the Uyuni server When I refresh the metadata for "server" When I install pattern "uyuni_retail" on this "server" diff --git a/testsuite/features/secondary/srv_user_configuration_salt_states.feature b/testsuite/features/secondary/srv_user_configuration_salt_states.feature index f01fb5b63deb..f55d283d2896 100644 --- a/testsuite/features/secondary/srv_user_configuration_salt_states.feature +++ b/testsuite/features/secondary/srv_user_configuration_salt_states.feature @@ -6,9 +6,12 @@ @scope_salt Feature: Create organizations, users, groups, and activation keys using Salt states - Scenario: Apply configuration salt state to server +@skip_if_container_server + Scenario: Install uyunu-config formula When I manually install the "uyuni-config" formula on the server - And I apply "setup_users_configuration" local salt state on "server" + + Scenario: Apply configuration salt state to server + When I apply "setup_users_configuration" local salt state on "server" Scenario: Organization my_org was correctly created Given I am authorized as "my_org_user" with password "my_org_user" @@ -66,7 +69,10 @@ Feature: Create organizations, users, groups, and activation keys using Salt sta Scenario: Cleanup: apply configuration teardown salt state to server When I apply "teardown_users_configuration" local salt state on "server" - And I manually uninstall the "uyuni-config" formula from the server + +@skip_if_container_server + Scenario: Cleanup: uninstall uyuni-config formula + When I manually uninstall the "uyuni-config" formula from the server Scenario: Cleanup: all organizations were successfully removed When I follow the left menu "Admin > Organizations" diff --git a/testsuite/features/step_definitions/command_steps.rb b/testsuite/features/step_definitions/command_steps.rb index 75a164905166..259a177df255 100644 --- a/testsuite/features/step_definitions/command_steps.rb +++ b/testsuite/features/step_definitions/command_steps.rb @@ -1073,13 +1073,13 @@ "POPULATE_CONFIG_CHANNEL=y\n" \ "RHN_USER=admin\n" \ "ACTIVATE_SLP=y\n" - if code.zero? - settings += "USE_EXISTING_CERTS=y\n" \ + settings += if code.zero? + "USE_EXISTING_CERTS=y\n" \ "CA_CERT=/tmp/ca.crt\n" \ "SERVER_KEY=/tmp/proxy.key\n" \ "SERVER_CERT=/tmp/proxy.crt\n" - else - settings += "USE_EXISTING_CERTS=n\n" \ + else + "USE_EXISTING_CERTS=n\n" \ "INSTALL_MONITORING=n\n" \ "SSL_PASSWORD=spacewalk\n" \ "SSL_ORG=SUSE\n" \ @@ -1090,7 +1090,7 @@ "SSL_COUNTRY=DE\n" \ "SSL_EMAIL=galaxy-noise@suse.de\n" \ "SSL_CNAME_ASK=proxy.example.org\n" - end + end path = generate_temp_file('config-answers.txt', settings) step 'I copy "' + path + '" to "proxy"' `rm #{path}` diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index e2f9929fb209..cb860d331c8b 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -199,13 +199,11 @@ # Salt formulas -@skip_if_container_server When(/^I manually install the "([^"]*)" formula on the server$/) do |package| get_target('server').run('zypper --non-interactive refresh') get_target('server').run("zypper --non-interactive install --force #{package}-formula") end -@skip_if_container_server When(/^I manually uninstall the "([^"]*)" formula from the server$/) do |package| get_target('server').run("zypper --non-interactive remove #{package}-formula") # Remove automatically installed dependency if needed diff --git a/testsuite/features/support/commonlib.rb b/testsuite/features/support/commonlib.rb index 0d8d420dc3e6..cc404d83b328 100644 --- a/testsuite/features/support/commonlib.rb +++ b/testsuite/features/support/commonlib.rb @@ -417,5 +417,5 @@ def file_extract(node, remote_file, local_file) # This function injects a file into a node def file_inject(node, local_file, remote_file) - node.inject(local_file, remote_file, 'root', false) + node.inject(local_file, remote_file, 'root', false) end diff --git a/testsuite/features/support/lavanda.rb b/testsuite/features/support/lavanda.rb index d2ecf627e78c..0076825f9345 100644 --- a/testsuite/features/support/lavanda.rb +++ b/testsuite/features/support/lavanda.rb @@ -151,10 +151,7 @@ def os_version # buffer_size: The maximum buffer size in bytes. Defaults to 65536. # verbose: Whether to log the output of the command in case of success. Defaults to false. def run(cmd, separated_results: false, check_errors: true, timeout: DEFAULT_TIMEOUT, user: 'root', successcodes: [0], buffer_size: 65536, verbose: false) - cmd_prefixed = cmd - if @in_has_uyunictl - cmd_prefixed = "uyunictl exec -i '#{cmd.gsub(/'/, '\'"\'"\'')}'" - end + cmd_prefixed = @in_has_uyunictl ? "uyunictl exec -i '#{cmd.gsub(/'/, '\'"\'"\'')}'" : cmd run_local(cmd_prefixed, separated_results: separated_results, check_errors: check_errors, timeout: timeout, user: user, successcodes: successcodes, buffer_size: buffer_size, verbose: verbose) end @@ -229,9 +226,17 @@ def wait_while_process_running(process) end end - def inject(local_file, remote_file, user = "root", dots = true) + ## + # Copy a local file to a remote node. + # Handles copying to the server container if possible + # + # Args: + # local_file: The path to the file to copy + # remote_file: The path in the destination + # user: The owner of the file + def inject(local_file, remote_file, user = 'root', dots = true) if @in_has_uyunictl - tmp_folder, _code = run_local("mktemp -d") + tmp_folder, _code = run_local('mktemp -d') tmp_file = File.join(tmp_folder.strip, File.basename(local_file)) code, _remote = inject_file(local_file, tmp_file, user, dots) if code.zero? @@ -240,14 +245,22 @@ def inject(local_file, remote_file, user = "root", dots = true) end run_local("rm -r #{tmp_folder}") else - code, _remote = inject_file(local_file, remote_file, user, dots) + code, _remote = inject_file(local_file, remote_file, user, dots) end code end - def extract(remote_file, local_file, user = "root", dots = true) + ## + # Copy a remote file to a local one + # Handles copying from the server container if possible + # + # Args: + # remote_file: The path in the destination + # local_file: The path to the file to copy + # user: The owner of the file + def extract(remote_file, local_file, user = 'root', dots = true) if @in_has_uyunictl - tmp_folder, _code = run_local("mktemp -d") + tmp_folder, _code = run_local('mktemp -d') tmp_file = File.join(tmp_folder.strip, File.basename(remote_file)) _out, code = run_local("uyunictl cp --user #{user} server:#{remote_file} #{tmp_file}") raise "Failed to extract #{remote_file} from container" unless code.zero? @@ -255,11 +268,17 @@ def extract(remote_file, local_file, user = "root", dots = true) raise "Failed to extract #{tmp_file} from host" unless code.zero? run_local("rm -r #{tmp_folder}") else - code, _local = extract_file(remote_file, local_file, user, dots) + code, _local = extract_file(remote_file, local_file, user, dots) end code end + ## + # Check if a file exists on a node. + # Handles checking in server container if possible. + # + # Args: + # file: The path to check on the node. def file_exists(file) if @in_has_uyunictl _out, code = run_local("uyunictl exec -- 'test -f #{file}'", check_errors: false) @@ -271,6 +290,12 @@ def file_exists(file) exists end + ## + # Check if a folder exists on a node. + # Handles checking in server container if possible. + # + # Args: + # file: The path to check on the node. def folder_exists(file) if @in_has_uyunictl _out, code = run_local("uyunictl exec -- 'test -d #{file}'", check_errors: false) @@ -282,6 +307,12 @@ def folder_exists(file) exists end + ## + # Delete a file on a node. + # Handles checking in server container if possible. + # + # Args: + # file: The path of the file to delete on the node. def file_delete(file) if @in_has_uyunictl _out, code = run_local("uyunictl exec -- 'rm #{file}'") @@ -291,6 +322,12 @@ def file_delete(file) code end + ## + # Delete a folder on a node. + # Handles checking in server container if possible. + # + # Args: + # folder: The path of the folder to delete on the node. def folder_delete(folder) if @in_has_uyunictl _out, code = run_local("uyunictl exec -- 'rm -rf #{folder}'") diff --git a/testsuite/features/support/twopence_init.rb b/testsuite/features/support/twopence_init.rb index 051470a3161b..68bf9e6fef34 100644 --- a/testsuite/features/support/twopence_init.rb +++ b/testsuite/features/support/twopence_init.rb @@ -41,6 +41,24 @@ def process_private_and_public_ip(host, node) node end +def initialize_server(host, node) + _out, code = node.run('which uyunictl', check_errors: false) + node.init_has_uyunictl if code.zero? + + fqdn, code = node.run('sed -n \'s/^java.hostname *= *\(.\+\)$/\1/p\' /etc/rhn/rhn.conf') + raise "Cannot connect to get FQDN for '#{$named_nodes[node.hash]}'. Response code: #{code}, local: #{local}, remote: #{remote}" if code.nonzero? + raise "No FQDN for '#{$named_nodes[node.hash]}'. Response code: #{code}" if fqdn.empty? + node.init_full_hostname(fqdn) + node.init_hostname(fqdn.split('.')[0]) + + node = process_os_family_and_version(host, fqdn, node.hostname, node) + node = process_private_and_public_ip(host, node) + + $node_by_host[host] = node + $host_by_node[node] = host + 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}'." @@ -62,39 +80,28 @@ def twopence_init(host) node.extend(LavandaBasic) if host == 'server' - _out, code = node.run('which uyunictl', check_errors: false) - if code.zero? - node.init_has_uyunictl - end + node = initialize_server(host, node) + return + end + + # 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 crated 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, code = node.run('sed -n \'s/^java.hostname *= *\(.\+\)$/\1/p\' /etc/rhn/rhn.conf') - raise "Cannot connect to get FQDN for '#{$named_nodes[node.hash]}'. Response code: #{code}, local: #{local}, remote: #{remote}" if code.nonzero? + 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.init_hostname(fqdn.split('.')[0]) - node = process_os_family_and_version(host, fqdn, node.hostname, node) + node = process_os_family_and_version(host, fqdn, hostname, node) node = process_private_and_public_ip(host, node) - else - # 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 crated 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 end $node_by_host[host] = node