Skip to content

Commit

Permalink
Fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cbosdo committed Sep 1, 2023
1 parent dcdb41c commit 9748a6d
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 49 deletions.
3 changes: 3 additions & 0 deletions testsuite/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ Metrics/CyclomaticComplexity:
Metrics/ClassLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Style/MissingElse:
Enabled: false
3 changes: 3 additions & 0 deletions testsuite/features/init_clients/proxy_branch_network.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions testsuite/features/step_definitions/command_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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}`
Expand Down
2 changes: 0 additions & 2 deletions testsuite/features/step_definitions/salt_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testsuite/features/support/commonlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
57 changes: 47 additions & 10 deletions testsuite/features/support/lavanda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand All @@ -240,26 +245,40 @@ 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?
code, _remote = extract_file(tmp_file, local_file, user, dots)
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)
Expand All @@ -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)
Expand All @@ -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}'")
Expand All @@ -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}'")
Expand Down
63 changes: 35 additions & 28 deletions testsuite/features/support/twopence_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}'."
Expand All @@ -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
Expand Down

0 comments on commit 9748a6d

Please sign in to comment.