Skip to content

Commit

Permalink
Merge pull request #2963 from cobbler/tests/xmlrpc-to-python-switch
Browse files Browse the repository at this point in the history
Tests: XML-RPC to Python switch
  • Loading branch information
SchoolGuy committed Mar 7, 2022
2 parents 72d8927 + a93ee70 commit 2cb7dc9
Show file tree
Hide file tree
Showing 36 changed files with 777 additions and 975 deletions.
3 changes: 3 additions & 0 deletions cobbler/utils.py
Expand Up @@ -255,11 +255,14 @@ def service_restart(service_name: str):
if is_supervisord():
with ServerProxy('http://localhost:9001/RPC2') as server:
try:
process_state = -1 # Not redundant because we could run otherwise in an UnboundLocalError
process_state = server.supervisor.getProcessInfo(service_name).get("state")
if process_state in (10, 20):
server.supervisor.stopProcess(service_name)
if server.supervisor.startProcess(service_name): # returns a boolean
return 0
logger.error('Restarting service "%s" failed', service_name)
return 1
except xmlrpc.client.Fault as clientFault:
logger.error(
'Restarting service "%s" failed (supervisord process state was "%s")',
Expand Down
88 changes: 44 additions & 44 deletions templates/etc/dhcp.template
Expand Up @@ -91,50 +91,50 @@ subnet 192.168.1.0 netmask 255.255.255.0 {
## or really any valid dhcpd.conf construct ... if you only use the
## default dhcp tag in cobbler, the group block can be deleted for a
## flat configuration
# group for Cobbler DHCP tag: $dhcp_tag
group {
#for mac in $dhcp_tags[$dhcp_tag].keys():
#set iface = $dhcp_tags[$dhcp_tag][$mac]
host $iface.name {
#if $iface.interface_type == "infiniband":
option dhcp-client-identifier = $mac;
#else
hardware ethernet $mac;
#end if
#if $iface.ip_address:
fixed-address $iface.ip_address;
#end if
#if $iface.dns_name:
option host-name "$iface.dns_name";
#else if $iface.hostname:
option host-name "$iface.hostname";
#end if
#if $iface.netmask:
option subnet-mask $iface.netmask;
#end if
#if $iface.if_gateway:
option routers $iface.if_gateway;
#else if $iface.gateway:
option routers $iface.gateway;
#end if
#if $iface.enable_ipxe:
if exists user-class and option user-class = "iPXE" {
filename "http://$cobbler_server/cblr/svc/op/ipxe/system/$iface.owner";
} else {
filename "undionly.kpxe";
}
#end if
#if $iface.next_server_v4:
next-server $iface.next_server_v4;
#end if
#if $iface.filename:
filename "$iface.filename";
#end if
#if $iface.name_servers:
#set $mynameservers = ','.join($iface.name_servers)
option domain-name-servers $mynameservers;
#end if
}
# group for Cobbler DHCP tag: $dhcp_tag
group {
#for mac in $dhcp_tags[$dhcp_tag].keys():
#set iface = $dhcp_tags[$dhcp_tag][$mac]
host $iface.name {
#if $iface.interface_type == "infiniband":
option dhcp-client-identifier = $mac;
#else
hardware ethernet $mac;
#end if
#if $iface.ip_address:
fixed-address $iface.ip_address;
#end if
#if $iface.dns_name:
option host-name "$iface.dns_name";
#else if $iface.hostname:
option host-name "$iface.hostname";
#end if
#if $iface.netmask:
option subnet-mask $iface.netmask;
#end if
#if $iface.if_gateway:
option routers $iface.if_gateway;
#else if $iface.gateway:
option routers $iface.gateway;
#end if
#if $iface.enable_ipxe:
if exists user-class and option user-class = "iPXE" {
filename "http://$cobbler_server/cblr/svc/op/ipxe/system/$iface.owner";
} else {
filename "undionly.kpxe";
}
#end if
#if $iface.next_server_v4:
next-server $iface.next_server_v4;
#end if
#if $iface.filename:
filename "$iface.filename";
#end if
#if $iface.name_servers:
#set $mynameservers = ','.join($iface.name_servers)
option domain-name-servers $mynameservers;
#end if
}
#end for
}
#end for
Expand Down
56 changes: 28 additions & 28 deletions templates/etc/dhcp6.template
Expand Up @@ -58,34 +58,34 @@ subnet6 2001:db8:0:1::/64 {
group {
#for mac in $dhcp_tags[$dhcp_tag].keys():
#set iface = $dhcp_tags[$dhcp_tag][$mac]
host $iface.name {
##
## dhcp-client-identifier
#if $iface.interface_type == "infiniband":
option dhcp-client-identifier = $mac;
#else
hardware ethernet $mac;
#end if
##
## fixed-address6
fixed-address6 $iface.ipv6_address;
##
## host-name
#if $iface.hostname:
option host-name "$iface.hostname";
#else if $iface.dns_name:
option host-name "$iface.dns_name";
#end if
##
## dhcp6.bootfile-url
## Do we have a host specific next_server or filename
## In DHCPv6 that means: Do we point to a host specific boot loader
#set host_filename = $iface.get("filename", None)
#set host_next_server_v6 = $iface.get("next_server_v6", $next_server_v6)
#if $host_next_server_v6 != $next_server_v6 or $host_filename:
option dhcp6.bootfile-url "tftp://[$host_next_server_v6]/$host_filename";
#end if
}
host $iface.name {
##
## dhcp-client-identifier
#if $iface.interface_type == "infiniband":
option dhcp-client-identifier = $mac;
#else
hardware ethernet $mac;
#end if
##
## fixed-address6
fixed-address6 $iface.ipv6_address;
##
## host-name
#if $iface.hostname:
option host-name "$iface.hostname";
#else if $iface.dns_name:
option host-name "$iface.dns_name";
#end if
##
## dhcp6.bootfile-url
## Do we have a host specific next_server or filename
## In DHCPv6 that means: Do we point to a host specific boot loader
#set host_filename = $iface.get("filename", None)
#set host_next_server_v6 = $iface.get("next_server_v6", $next_server_v6)
#if $host_next_server_v6 != $next_server_v6 or $host_filename:
option dhcp6.bootfile-url "tftp://[$host_next_server_v6]/$host_filename";
#end if
}
#end for
}
#end for
14 changes: 4 additions & 10 deletions tests/actions/mkloaders_test.py
Expand Up @@ -5,26 +5,20 @@

import cobbler.actions.mkloaders
from cobbler.actions import mkloaders
from cobbler.api import CobblerAPI


@pytest.fixture()
def api():
return CobblerAPI()


def test_grubimage_object(api):
def test_grubimage_object(cobbler_api):
# Arrange & Act
test_image_creator = mkloaders.MkLoaders(api)
test_image_creator = mkloaders.MkLoaders(cobbler_api)

# Assert
assert isinstance(test_image_creator, mkloaders.MkLoaders)
assert str(test_image_creator.syslinux_folder) == "/usr/share/syslinux"


def test_grubimage_run(api, mocker):
def test_grubimage_run(cobbler_api, mocker):
# Arrange
test_image_creator = mkloaders.MkLoaders(api)
test_image_creator = mkloaders.MkLoaders(cobbler_api)
mocker.patch("cobbler.actions.mkloaders.symlink", spec=cobbler.actions.mkloaders.symlink)
mocker.patch("cobbler.actions.mkloaders.mkimage", spec=cobbler.actions.mkloaders.mkimage)

Expand Down
22 changes: 9 additions & 13 deletions tests/api/find_test.py
@@ -1,16 +1,12 @@
import pytest

from cobbler.api import CobblerAPI
from tests.conftest import does_not_raise

# TODO: Extend the fillup and add more testcases


@pytest.fixture
def find_fillup():
test_api = CobblerAPI()

return test_api
def find_fillup(cobbler_api):
# TODO: Extend the fillup and add more testcases
return cobbler_api


@pytest.mark.parametrize("what,criteria,name,return_list,no_errors,expected_exception,expected_result", [
Expand Down Expand Up @@ -97,7 +93,7 @@ def test_find_system(find_fillup, name, return_list, no_errors, criteria, expect
])
def test_find_repo(find_fillup, name, return_list, no_errors, criteria, expected_exception, expected_result):
# Arrange
test_api = CobblerAPI()
test_api = find_fillup

# Act
with expected_exception:
Expand All @@ -116,7 +112,7 @@ def test_find_repo(find_fillup, name, return_list, no_errors, criteria, expected
])
def test_find_image(find_fillup, name, return_list, no_errors, criteria, expected_exception, expected_result):
# Arrange
test_api = CobblerAPI()
test_api = find_fillup

# Act
with expected_exception:
Expand All @@ -135,7 +131,7 @@ def test_find_image(find_fillup, name, return_list, no_errors, criteria, expecte
])
def test_find_mgmtclass(find_fillup, name, return_list, no_errors, criteria, expected_exception, expected_result):
# Arrange
test_api = CobblerAPI()
test_api = find_fillup

# Act
with expected_exception:
Expand All @@ -154,7 +150,7 @@ def test_find_mgmtclass(find_fillup, name, return_list, no_errors, criteria, exp
])
def test_find_package(find_fillup, name, return_list, no_errors, criteria, expected_exception, expected_result):
# Arrange
test_api = CobblerAPI()
test_api = find_fillup

# Act
with expected_exception:
Expand All @@ -173,7 +169,7 @@ def test_find_package(find_fillup, name, return_list, no_errors, criteria, expec
])
def test_find_file(find_fillup, name, return_list, no_errors, criteria, expected_exception, expected_result):
# Arrange
test_api = CobblerAPI()
test_api = find_fillup

# Act
with expected_exception:
Expand All @@ -194,7 +190,7 @@ def test_find_file(find_fillup, name, return_list, no_errors, criteria, expected
])
def test_find_menu(find_fillup, name, return_list, no_errors, criteria, expected_exception, expected_result):
# Arrange
test_api = CobblerAPI()
test_api = find_fillup

# Act
with expected_exception:
Expand Down
3 changes: 1 addition & 2 deletions tests/api/miscellaneous_test.py
Expand Up @@ -35,13 +35,12 @@ def test_settings_migration(caplog, mocker, input_automigration, result_migrate_
assert spy_validate.call_count == result_validate_count


def test_buildiso(mocker):
def test_buildiso(mocker, cobbler_api):
# Arrange
netboot_stub = create_autospec(spec=NetbootBuildiso)
standalone_stub = create_autospec(spec=StandaloneBuildiso)
mocker.patch("cobbler.api.StandaloneBuildiso", return_value=standalone_stub)
mocker.patch("cobbler.api.NetbootBuildiso", return_value=netboot_stub)
cobbler_api = CobblerAPI()

# Act
cobbler_api.build_iso()
Expand Down

0 comments on commit 2cb7dc9

Please sign in to comment.