Skip to content

Commit

Permalink
virt: add boot_dev parameter to virt.running state
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbosdo authored and dwoz committed Jul 31, 2020
1 parent f643cf6 commit 4de137d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/57544.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow setting VM boot devices order in virt.running and virt.defined states
23 changes: 23 additions & 0 deletions salt/states/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -357,6 +366,7 @@ def defined(
virt.defined:
- cpu: 2
- mem: 2048
- boot_dev: network hd
- disk_profile: prod
- disks:
- name: system
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -587,6 +608,7 @@ def running(
- cpu: 2
- mem: 2048
- disk_profile: prod
- boot_dev: network hd
- disks:
- name: system
size: 8192
Expand Down Expand Up @@ -635,6 +657,7 @@ def running(
arch=arch,
boot=boot,
update=update,
boot_dev=boot_dev,
connection=connection,
username=username,
password=password,
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/states/test_virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def test_defined(self):
"myvm",
cpu=2,
mem=2048,
boot_dev="cdrom hd",
os_type="linux",
arch="i686",
vm_type="qemu",
Expand All @@ -360,6 +361,7 @@ def test_defined(self):
"myvm",
cpu=2,
mem=2048,
boot_dev="cdrom hd",
os_type="linux",
arch="i686",
disk="prod",
Expand Down Expand Up @@ -468,10 +470,13 @@ def test_defined(self):
"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,
Expand Down Expand Up @@ -595,6 +600,7 @@ def test_defined(self):
password=None,
boot=None,
test=True,
boot_dev=None,
)

# No changes case
Expand Down Expand Up @@ -629,6 +635,7 @@ def test_defined(self):
password=None,
boot=None,
test=True,
boot_dev=None,
)

def test_running(self):
Expand Down Expand Up @@ -705,6 +712,7 @@ def test_running(self):
install=True,
pub_key=None,
priv_key=None,
boot_dev=None,
connection=None,
username=None,
password=None,
Expand Down Expand Up @@ -766,6 +774,7 @@ def test_running(self):
install=False,
pub_key="/path/to/key.pub",
priv_key="/path/to/key",
boot_dev="network hd",
connection="someconnection",
username="libvirtuser",
password="supersecret",
Expand All @@ -790,6 +799,7 @@ def test_running(self):
start=False,
pub_key="/path/to/key.pub",
priv_key="/path/to/key",
boot_dev="network hd",
connection="someconnection",
username="libvirtuser",
password="supersecret",
Expand Down Expand Up @@ -934,6 +944,7 @@ def test_running(self):
password=None,
boot=None,
test=False,
boot_dev=None,
)

# Failed definition update case
Expand Down Expand Up @@ -1052,6 +1063,7 @@ def test_running(self):
password=None,
boot=None,
test=True,
boot_dev=None,
)
start_mock.assert_not_called()

Expand Down Expand Up @@ -1088,6 +1100,7 @@ def test_running(self):
password=None,
boot=None,
test=True,
boot_dev=None,
)

def test_stopped(self):
Expand Down

0 comments on commit 4de137d

Please sign in to comment.