virt: add boot_dev parameter to virt.running state

virt.init knows how to set the boot device order for a while, but this
feature never came to virt.running. This commit is fixing this omission
and adds it for both virt.running and virt.defined states.
This commit is contained in:
Cédric Bosdonnat 2020-06-04 15:42:22 +02:00 committed by Daniel Wozniak
parent f643cf6104
commit 4de137d209
3 changed files with 38 additions and 1 deletions

1
changelog/57544.added Normal file
View file

@ -0,0 +1 @@
Allow setting VM boot devices order in virt.running and virt.defined states

View file

@ -287,6 +287,7 @@ def defined(
arch=None,
boot=None,
update=True,
boot_dev=None,
):
"""
Starts an existing guest, or defines and starts a new VM with specified arguments.
@ -347,6 +348,14 @@ def defined(
.. deprecated:: 3001
:param boot_dev:
Space separated list of devices to boot from sorted by decreasing priority.
Values can be ``hd``, ``fd``, ``cdrom`` or ``network``.
By default, the value will ``"hd"``.
.. versionadded:: Magnesium
.. rubric:: Example States
Make sure a virtual machine called ``domain_name`` is defined:
@ -357,6 +366,7 @@ def defined(
virt.defined:
- cpu: 2
- mem: 2048
- boot_dev: network hd
- disk_profile: prod
- disks:
- name: system
@ -409,6 +419,7 @@ def defined(
password=password,
boot=boot,
test=__opts__["test"],
boot_dev=boot_dev,
)
ret["changes"][name] = status
if not status.get("definition"):
@ -443,6 +454,7 @@ def defined(
password=password,
boot=boot,
start=False,
boot_dev=boot_dev,
)
ret["changes"][name] = {"definition": True}
ret["comment"] = "Domain {} defined".format(name)
@ -475,6 +487,7 @@ def running(
os_type=None,
arch=None,
boot=None,
boot_dev=None,
):
"""
Starts an existing guest, or defines and starts a new VM with specified arguments.
@ -569,6 +582,14 @@ def running(
.. versionadded:: 3000
:param boot_dev:
Space separated list of devices to boot from sorted by decreasing priority.
Values can be ``hd``, ``fd``, ``cdrom`` or ``network``.
By default, the value will ``"hd"``.
.. versionadded:: Magnesium
.. rubric:: Example States
Make sure an already-defined virtual machine called ``domain_name`` is running:
@ -587,6 +608,7 @@ def running(
- cpu: 2
- mem: 2048
- disk_profile: prod
- boot_dev: network hd
- disks:
- name: system
size: 8192
@ -635,6 +657,7 @@ def running(
arch=arch,
boot=boot,
update=update,
boot_dev=boot_dev,
connection=connection,
username=username,
password=password,

View file

@ -338,6 +338,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
"myvm",
cpu=2,
mem=2048,
boot_dev="cdrom hd",
os_type="linux",
arch="i686",
vm_type="qemu",
@ -360,6 +361,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
"myvm",
cpu=2,
mem=2048,
boot_dev="cdrom hd",
os_type="linux",
arch="i686",
disk="prod",
@ -468,10 +470,13 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
"comment": "Domain myvm updated with live update(s) failures",
}
)
self.assertDictEqual(virt.defined("myvm", cpu=2), ret)
self.assertDictEqual(
virt.defined("myvm", cpu=2, boot_dev="cdrom hd"), ret
)
update_mock.assert_called_with(
"myvm",
cpu=2,
boot_dev="cdrom hd",
mem=None,
disk_profile=None,
disks=None,
@ -595,6 +600,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
password=None,
boot=None,
test=True,
boot_dev=None,
)
# No changes case
@ -629,6 +635,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
password=None,
boot=None,
test=True,
boot_dev=None,
)
def test_running(self):
@ -705,6 +712,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
install=True,
pub_key=None,
priv_key=None,
boot_dev=None,
connection=None,
username=None,
password=None,
@ -766,6 +774,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
install=False,
pub_key="/path/to/key.pub",
priv_key="/path/to/key",
boot_dev="network hd",
connection="someconnection",
username="libvirtuser",
password="supersecret",
@ -790,6 +799,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
start=False,
pub_key="/path/to/key.pub",
priv_key="/path/to/key",
boot_dev="network hd",
connection="someconnection",
username="libvirtuser",
password="supersecret",
@ -934,6 +944,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
password=None,
boot=None,
test=False,
boot_dev=None,
)
# Failed definition update case
@ -1052,6 +1063,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
password=None,
boot=None,
test=True,
boot_dev=None,
)
start_mock.assert_not_called()
@ -1088,6 +1100,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
password=None,
boot=None,
test=True,
boot_dev=None,
)
def test_stopped(self):