Skip to content

Commit

Permalink
QE: Add Cobbler profile tests
Browse files Browse the repository at this point in the history
This will add specific Cobbler profile tests and extends our test suite
to be able to use more Cobbler and SUMA XML-RPC API calls.

See SUSE/spacewalk#20409

Signed-off-by: Dominik Gedon <dominik.gedon@suse.com>
  • Loading branch information
nodeg committed Mar 8, 2023
1 parent 7a6df19 commit ce3f1d3
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 3 deletions.
102 changes: 102 additions & 0 deletions testsuite/features/secondary/srv_cobbler_profile_ise.feature
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions testsuite/features/step_definitions/api_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
16 changes: 14 additions & 2 deletions testsuite/features/step_definitions/cobbler_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
# -------------------------------
Expand Down Expand Up @@ -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
Expand Down
169 changes: 169 additions & 0 deletions testsuite/features/support/cobbler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions testsuite/features/support/namespaces/kickstart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ce3f1d3

Please sign in to comment.