Skip to content

Commit

Permalink
QE: Lazy initialization of Twopence nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
srbarrios committed Aug 1, 2023
1 parent 3d5d964 commit 47ef6bc
Show file tree
Hide file tree
Showing 20 changed files with 715 additions and 820 deletions.
10 changes: 5 additions & 5 deletions testsuite/features/step_definitions/api_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
94 changes: 47 additions & 47 deletions testsuite/features/step_definitions/cobbler_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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')
Expand All @@ -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"
Expand All @@ -109,39 +109,39 @@

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]
isolinux_profiles = []
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
Expand All @@ -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
Expand All @@ -174,72 +174,72 @@
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

When(/^I cleanup Cobbler files and restart apache and cobblerd services$/) do
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")
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Loading

0 comments on commit 47ef6bc

Please sign in to comment.