add and update tests

This commit is contained in:
MKLeb 2022-10-05 13:24:32 -04:00 committed by Megan Wilhite
parent 79bd783cff
commit 2f2df11287
3 changed files with 16 additions and 50 deletions

View file

@ -1271,6 +1271,15 @@ def test_update_cpu_simple(make_mock_vm):
assert domain_mock.setVcpusFlags.call_args[0][0] == 2
def test_update_autostart(make_mock_vm):
"""
Test virt.update(), simple autostart update
"""
domain_mock = make_mock_vm()
virt.update("my_vm", autostart=True)
domain_mock.setAutostart.assert_called_with(1)
def test_update_add_cpu_topology(make_mock_vm):
"""
Test virt.update(), add cpu topology settings

View file

@ -69,6 +69,7 @@ def domain_update_call(
live=True,
host_devices=None,
test=False,
autostart=False,
):
"""
Create a call object with the missing default parameters from virt.update()
@ -96,4 +97,5 @@ def domain_update_call(
clock=clock,
stop_on_reboot=stop_on_reboot,
host_devices=host_devices,
autostart=autostart,
)

View file

@ -2,10 +2,9 @@ import pytest
import salt.states.virt as virt
from salt.exceptions import CommandExecutionError
from tests.pytests.unit.states.virt.helpers import domain_update_call
from tests.support.mock import MagicMock, patch
from .helpers import domain_update_call
@pytest.fixture
def configure_loader_modules(libvirt_mock):
@ -208,30 +207,9 @@ def test_defined_update_error(test):
"comment": "Domain myvm updated with live update(s) failures",
}
init_mock.assert_not_called()
update_mock.assert_called_with(
"myvm",
cpu=2,
boot_dev="cdrom hd",
mem=None,
disk_profile=None,
disks=None,
nic_profile=None,
interfaces=None,
graphics=None,
live=True,
connection=None,
username=None,
password=None,
boot=None,
numatune=None,
test=test,
hypervisor_features=None,
clock=None,
serials=None,
consoles=None,
stop_on_reboot=False,
host_devices=None,
)
assert update_mock.call_args_list == [
domain_update_call("myvm", cpu=2, test=test, boot_dev="cdrom hd")
]
def test_defined_update_definition_error(test):
@ -509,30 +487,7 @@ def test_running_update_error():
"result": True,
"comment": "Domain myvm updated with live update(s) failures",
}
update_mock.assert_called_with(
"myvm",
cpu=2,
mem=None,
disk_profile=None,
disks=None,
nic_profile=None,
interfaces=None,
graphics=None,
live=True,
connection=None,
username=None,
password=None,
boot=None,
numatune=None,
test=False,
boot_dev=None,
hypervisor_features=None,
clock=None,
serials=None,
consoles=None,
stop_on_reboot=False,
host_devices=None,
)
assert update_mock.call_args_list == [domain_update_call("myvm", cpu=2)]
@pytest.mark.parametrize("running", ["running", "shutdown"])