diff --git a/testsuite/features/secondary/srv_cobbler_profile_ise.feature b/testsuite/features/secondary/srv_cobbler_profile_ise.feature new file mode 100644 index 000000000000..55baf23c2f3f --- /dev/null +++ b/testsuite/features/secondary/srv_cobbler_profile_ise.feature @@ -0,0 +1,102 @@ +# Copyright (c) 2023 SUSE LLC. +# Licensed under the terms of the MIT license. + +@scope_cobbler +Feature: Cobbler editing profiles results in ISE + Tests for occuring Cobbler issue (bsc#1207532) + This feature is split up into 2 section + The first section uses the webUI + The second one uses the XML-RPC API + + Background: The Cobbler service should be running + Given cobblerd is running + + Scenario: Copy cobbler profiles on the server + When I copy autoinstall mocked files on server + + Scenario: Log in as testing user + Given I am authorized as "testing" with password "testing" + + ## UI tests + Scenario: Create a Cobbler distribution via the UI + When I follow the left menu "Systems > Autoinstallation > Distributions" + And I follow "Create Distribution" + When I enter "isedistro_ui" as "label" + And I enter "/var/autoinstall/Fedora_12_i386/" as "basepath" + And I select "Fedora" from "installtype" + And I click on "Create Autoinstallable Distribution" + Then I should see a "Autoinstallable Distributions" text + And I should see a "isedistro_ui" link + + Scenario: Create a Cobbler profile via the UI + When I follow the left menu "Systems > Autoinstallation > Profiles" + And I follow "Create Kickstart Profile" + When I enter "iseprofile_ui" as "kickstartLabel" + And I click on "Next" + And I click on "Next" + And I enter "linux" as "rootPassword" + And I enter "linux" as "rootPasswordConfirm" + And I click on "Finish" + Then I should see a "Autoinstallation: iseprofile_ui" text + And I should see a "Autoinstallation Details" link + + Scenario: Check Cobbler created distro and profile via the UI + When I follow the left menu "Systems > Autoinstallation > Profiles" + Then I should see a "iseprofile_ui" text + And I should see a "isedistro_ui" text + + Scenario: Change profile variables using the UI + When I follow the left menu "Systems > Autoinstallation > Profiles" + And I follow "iseprofile_ui" + And I follow "Variables" + And I enter "ise_ui_test=ISE_UI_TEST" as "variables" + And I click on "Update Variables" + And I refresh the page + Then I should see a "ISE_UI_TEST" text + + ## XML-RPC API tests + Scenario: Create a Cobbler distribution via the UI in the XML-RPC context + When I follow the left menu "Systems > Autoinstallation > Distributions" + And I follow "Create Distribution" + When I enter "isedistro_api" as "label" + And I enter "/var/autoinstall/Fedora_12_i386/" as "basepath" + And I select "Fedora" from "installtype" + And I click on "Create Autoinstallable Distribution" + Then I should see a "Autoinstallable Distributions" text + And I should see a "isedistro_api" link + + Scenario: Create a Cobbler profile via the UI in the XML-RPC context + When I follow the left menu "Systems > Autoinstallation > Profiles" + And I follow "Create Kickstart Profile" + When I enter "iseprofile_api" as "kickstartLabel" + And I click on "Next" + And I click on "Next" + And I enter "linux" as "rootPassword" + And I enter "linux" as "rootPasswordConfirm" + And I click on "Finish" + Then I should see a "Autoinstallation: iseprofile_api" text + And I should see a "Autoinstallation Details" link + + Scenario: Check Cobbler created distro and profile via the UI in the XML-RPC context + When I follow the left menu "Systems > Autoinstallation > Profiles" + Then I should see a "iseprofile_api" text + And I should see a "isedistro_api" text + + Scenario: Create a Cobbler system via the XML-RPC API + And I create a system record with name "isesystem_api" and kickstart label "iseprofile_api" + + Scenario: Create and modify a System profile using the XML-RPC API + # XML-RPC should return an error here + And I create and modify the kickstart system "isesystem_api" with hostname "ise-system.test" via XML-RPC + | inst.repo | http://ise.cobbler.test | + | self_update | http://ise.cobbler.test | + + Scenario: Cleanup: delete test distros and profiles + When I remove kickstart profiles and distros + And I follow the left menu "Systems > System List" + And I wait until I see the "isesystem_api" system, refreshing the page + And I follow "isesystem_api" + And I follow "Delete System" + Then I should see a "Confirm System Profile Deletion" text + When I click on "Delete Profile" + And I wait until I see "has been deleted" text diff --git a/testsuite/features/step_definitions/api_common.rb b/testsuite/features/step_definitions/api_common.rb index c16bf3905cc1..50586b623656 100644 --- a/testsuite/features/step_definitions/api_common.rb +++ b/testsuite/features/step_definitions/api_common.rb @@ -67,6 +67,11 @@ $api_test.system.create_system_record('testserver', 'fedora_kickstart_profile_upload', '', 'my test server', [dev]) end +When(/^I create a system record with name "([^"]*)" and kickstart label "([^"]*)"$/) do |name, label| + dev = { 'name' => 'eth0', 'ip' => '1.1.1.2', 'mac' => '00:22:22:77:EE:DD', 'dnsname' => 'testserver.example.com' } + $api_test.system.create_system_record(name, label, '', 'my test server', [dev]) +end + When(/^I wait for the OpenSCAP audit to finish$/) do @sle_id = $api_test.system.retrieve_server_id($minion.full_hostname) begin @@ -570,3 +575,11 @@ def wait_action_complete(actionid, timeout: DEFAULT_TIMEOUT) Then(/^"([^"]*)" should be present in the result$/) do |profile_name| assert($output.select { |p| p['name'] == profile_name }.count == 1) end + +When(/^I create and modify the kickstart system "([^"]*)" with hostname "([^"]*)" via XML-RPC$/) do |name, hostname, values| + system_id = $api_test.system.create_system_profile(name, 'hostname' => hostname) + STDOUT.puts "system_id: #{system_id}" + # this works only with a 2 column table where the key is in the left column + variables = values.rows_hash + _command = $api_test.system.set_variables(system_id, variables) +end diff --git a/testsuite/features/step_definitions/cobbler_steps.rb b/testsuite/features/step_definitions/cobbler_steps.rb index 8e371f1c4dad..da957e0b82ac 100644 --- a/testsuite/features/step_definitions/cobbler_steps.rb +++ b/testsuite/features/step_definitions/cobbler_steps.rb @@ -54,6 +54,18 @@ ct.system_remove(system) end +When(/^I remove profile "([^"]*)" as user "([^"]*)" with password "([^"]*)"$/) do |system, user, pwd| + ct = ::CobblerTest.new + ct.login(user, pwd) + ct.profile_remove(system) +end + +When(/^I remove distro "([^"]*)" as user "([^"]*)" with password "([^"]*)"$/) do |system, user, pwd| + ct = ::CobblerTest.new + ct.login(user, pwd) + ct.distro_remove(system) +end + When(/^I remove kickstart profiles and distros$/) do host = $server.full_hostname # ------------------------------- @@ -232,8 +244,8 @@ When(/^I run Cobbler sync (with|without) error checking$/) do |checking| if checking == 'with' - out, _code = $server.run('cobbler sync') - raise 'cobbler sync failed' if out.include? 'Push failed' + out, _code = $server.run('cobbler sync') + raise 'cobbler sync failed' if out.include? 'Push failed' else _out, _code = $server.run('cobbler sync') end diff --git a/testsuite/features/support/cobbler_test.rb b/testsuite/features/support/cobbler_test.rb index a6baa86bd6bb..9f289ba64c3e 100644 --- a/testsuite/features/support/cobbler_test.rb +++ b/testsuite/features/support/cobbler_test.rb @@ -237,4 +237,173 @@ def get(what, name, key) end result end + + ## + # Modifies a profile and saves it afterwards. + # + # For more information, see https://cobbler.readthedocs.io/en/latest/cobbler.html#cobbler-profile + # Args: + # name: The name of the profile + # attribute: The attribute you want to modify + # value: The new value you want to set for attribute + def profile_modify(name, attribute, value) + begin + # TODO: Starting with Cobbler 3.4.0 the handle will be the UID: profile.uid + profile = @server.call('get_profile_handle', name, @token) + rescue ::StandardError + raise(::StandardError, "Profile with name #{name} not found. #{$ERROR_INFO}") + end + begin + @server.call('modify_profile', profile, attribute, value, @token) + rescue ::StandardError + raise(::StandardError, "Modifying profile failed. #{$ERROR_INFO}") + end + begin + @server.call('save_profile', profile, @token) + rescue ::StandardError + raise(::StandardError, "Saving profile failed. #{$ERROR_INFO}") + end + profile + end + + ## + # Modifies a distribution and saves it afterwards. + # + # For more information, see https://cobbler.readthedocs.io/en/latest/cobbler.html#cobbler-distro + # Args: + # name: The name of the distribution + # attribute: The attribute you want to modify + # value: The new value you want to set for attribute + def distro_modify(name, attribute, value) + begin + # TODO: Starting with Cobbler 3.4.0 the handle will be the UID: distro.uid + distro = @server.call('get_distro_handle', name, @token) + rescue ::StandardError + raise(::StandardError, "Distribution with name #{name} not found. #{$ERROR_INFO}") + end + begin + @server.call('modify_distro', distro, attribute, value, @token) + rescue ::StandardError + raise(::StandardError, "Modifying distribution failed. #{$ERROR_INFO}") + end + begin + @server.call('save_distro', distro, @token) + rescue ::StandardError + raise(::StandardError, "Saving distribution failed. #{$ERROR_INFO}") + end + distro + end + + ## + # Modifies a system and saves it afterwards. + # + # For more information, see https://cobbler.readthedocs.io/en/latest/cobbler.html#cobbler-system + # Args: + # name: The name of the system + # attribute: The attribute you want to modify + # value: The new value you want to set for attribute + def system_modify(name, attribute, value) + begin + # TODO: Starting with Cobbler 3.4.0 the handle will be the UID: system.uid + system = @server.call('get_system_handle', name, @token) + rescue ::StandardError + raise(::StandardError, "System with name #{name} not found. #{$ERROR_INFO}") + end + begin + @server.call('modify_system', system, attribute, value, @token) + rescue ::StandardError + raise(::StandardError, "Modifying system failed. #{$ERROR_INFO}") + end + begin + @server.call('save_system', system, @token) + rescue ::StandardError + raise(::StandardError, "Saving system failed. #{$ERROR_INFO}") + end + system + end + + ## + # Removes a distribution from the Spacewalk server. + # + # The first thing this function does is check to see if the distribution exists. If it doesn't, it raises an error. + # If it does, it calls the remove_distro function on the Spacewalk server. If that fails, it raises an error. + # + # Args: + # name: The name of the distribution to be removed. + def distro_remove(name) + raise(::IndexError, "Distribution cannot be found. #{$ERROR_INFO}") unless distro_exists(name) + begin + @server.call('remove_distro', name, @token) + rescue ::StandardError + raise(::StandardError, "Deleting distribution failed. #{$ERROR_INFO}") + end + end + + ## + # Removes a profile from the Spacewalk server. + # + # The first thing this function does is check to see if the profile exists. If it doesn't, it raises an error. If it + # does, it calls the remove_profile function on the Spacewalk server. If that fails, it raises an error. + # + # Args: + # name: The name of the profile to be removed. + def profile_remove(name) + raise(::IndexError, "Profile cannot be found. #{$ERROR_INFO}") unless profile_exists(name) + begin + @server.call('remove_profile', name, @token) + rescue ::StandardError + raise(::StandardError, "Deleting profile failed. #{$ERROR_INFO}") + end + end + + ## + # Get a handle for a system. + # + # Get a handle for a system which allows you to use the functions modify_* or save_* to manipulate it. + # + # Args: + # name: The name of the system to get the ID of + def get_system_handle(name) + begin + # TODO: Starting with Cobbler 3.4.0 the handle will be the UID: system.uid + system = @server.call('get_system_handle', name, @token) + rescue ::StandardError + raise(::StandardError, "System with name #{name} not found. #{$ERROR_INFO}") + end + system + end + + ## + # Get a handle for a profile. + # + # Get a handle for a profile which allows you to use the functions modify_* or save_* to manipulate it. + # + # Args: + # name: The name of the profile to get the ID of + def get_profile_handle(name) + begin + # TODO: Starting with Cobbler 3.4.0 the handle will be the UID: profile.uid + system = @server.call('get_profile_handle', name, @token) + rescue ::StandardError + raise(::StandardError, "Profile with name #{name} not found. #{$ERROR_INFO}") + end + system + end + + ## + # Get a handle for a distribution. + # + # Get a handle for a distribution which allows you to use the functions modify_* or save_* to manipulate it. + # + # Args: + # name: The name of the distribution to get the ID of + def get_distro_handle(name) + begin + # TODO: Starting with Cobbler 3.4.0 the handle will be the UID: distro.uid + system = @server.call('get_distro_handle', name, @token) + rescue ::StandardError + raise(::StandardError, "Distribution with name #{name} not found. #{$ERROR_INFO}") + end + system + end end diff --git a/testsuite/features/support/namespaces/kickstart.rb b/testsuite/features/support/namespaces/kickstart.rb index 5488c8594466..7f9a18462813 100644 --- a/testsuite/features/support/namespaces/kickstart.rb +++ b/testsuite/features/support/namespaces/kickstart.rb @@ -11,9 +11,48 @@ class NamespaceKickstart def initialize(api_test) @test = api_test @tree = NamespaceKickstartTree.new(api_test) + @profile = NamespaceKickstartProfile.new(api_test) end attr_reader :tree + attr_reader :profile + + ## + # Create a new kickstart profile using the default download URL for the kickstartable tree and kickstart host + # specified. + # + # Args: + # name: The name of the new kickstart profile + # vmType: Virtualization type, or none + # kstreelabel: The Label of a kickstartable tree + # kshost: The Kickstart hostname (of a server or proxy) used to construct the default download URL + # rootPassword: The root password + # updateType: Set the automatic ks tree update strategy for the profile. Valid choices are "none" or "all". + def create_profile(name, kstreelabel, kshost) + @test.call('kickstart.profile.createProfile', sessionKey: @test.token, profileLabel: name, vmType: 'none', kickstartableTreeLabel: kstreelabel, kickstartHost: kshost, rootPassword: 'linux', updateType: 'all') + end +end + +# Kickstart.profile namespace +class NamespaceKickstartProfile + ## + # It initializes the function. + # + # Args: + # api_test: This is the test object that is passed to the initialize method. + def initialize(api_test) + @test = api_test + end + + ## + # Associates list of kickstart variables with the specified kickstart profile + # + # Args: + # profile: The name of the kickstart profile + # variables: A list of variables to set + def set_variables(profile, variables) + @test.call('kickstart.profile.setVariables', sessionKey: @test.token, ksLabel: profile, variables: variables) + end end # "kickstart.tree" namespace diff --git a/testsuite/features/support/namespaces/system.rb b/testsuite/features/support/namespaces/system.rb index 941da1fbd2aa..c35254ac944b 100644 --- a/testsuite/features/support/namespaces/system.rb +++ b/testsuite/features/support/namespaces/system.rb @@ -128,7 +128,7 @@ def schedule_script_run(server, uid, gid, timeout, script, date) end ## - # Creates a system record in the Satellite 6 server. + # Creates a system record on the Spacewalk server. # # Args: # name: The name of the system record. @@ -166,6 +166,17 @@ def list_empty_system_profiles def obtain_reactivation_key(server) @test.call('system.obtainReactivationKey', sessionKey: @test.token, sid: server) end + + ## + # Sets a list of kickstart variables in the Cobbler system record for the specified server. + # + # Args: + # server: The server ID of the server you want to reactivate + # netboot: Enabled by default here + # variables: A list of system kickstart variables to set + def set_variables(server, variables) + @test.call('system.setVariables', sessionKey: @test.token, sid: server, netboot: true, variables: variables) + end end # System Configuration namespace diff --git a/testsuite/run_sets/secondary.yml b/testsuite/run_sets/secondary.yml index ed1f055d61e3..7afa7b948196 100644 --- a/testsuite/run_sets/secondary.yml +++ b/testsuite/run_sets/secondary.yml @@ -57,4 +57,5 @@ - features/secondary/srv_rename_hostname.feature - features/secondary/proxy_as_pod_basic_tests.feature - features/secondary/srv_logfile.feature +- features/secondary/srv_cobbler_profile_ise.feature ## Secondary features END ##