From e56b64e21d0e42ba4da33249af569268361330d2 Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 26 Apr 2023 20:15:36 +0530 Subject: [PATCH 1/5] module done version added is left to update --- salt/modules/virt.py | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/salt/modules/virt.py b/salt/modules/virt.py index 1e671621c25f..7c089507310b 100644 --- a/salt/modules/virt.py +++ b/salt/modules/virt.py @@ -947,6 +947,9 @@ def _gen_xml( consoles=None, stop_on_reboot=False, host_devices=None, + stop_on_crash=False, + stop_on_poweroff=False, + stop_on_lockfailure=False, **kwargs ): """ @@ -958,6 +961,9 @@ def _gen_xml( "hypervisor_features": hypervisor_features or {}, "clock": clock or {}, "on_reboot": "destroy" if stop_on_reboot else "restart", + "on_crash": "destroy" if stop_on_crash else "restart", + "on_poweroff": "destroy" if stop_on_poweroff else "restart", + "on_lockfailure": "destroy" if stop_on_lockfailure else "restart", } context["to_kib"] = lambda v: int(_handle_unit(v) / 1024) @@ -2006,6 +2012,9 @@ def init( consoles=None, stop_on_reboot=False, host_devices=None, + stop_on_crash=False, + stop_on_poweroff=False, + stop_on_lockfailure=False, **kwargs ): """ @@ -2217,6 +2226,30 @@ def init( .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + :param boot: Specifies kernel, initial ramdisk and kernel command line parameters for the virtual machine. This is an optional parameter, all of the keys are optional within the dictionary. The structure of @@ -2912,6 +2945,9 @@ def seeder(path): consoles, stop_on_reboot, host_devices, + stop_on_crash, + stop_on_poweroff, + stop_on_lockfailure, **kwargs ) log.debug("New virtual machine definition: %s", vm_xml) @@ -3499,6 +3535,9 @@ def update( stop_on_reboot=False, host_devices=None, autostart=False, + stop_on_crash=False, + stop_on_poweroff=False, + stop_on_lockfailure=False, **kwargs ): """ @@ -3619,6 +3658,30 @@ def update( .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + :param test: run in dry-run mode if set to True .. versionadded:: 3001 @@ -3761,6 +3824,9 @@ def update( consoles=consoles, stop_on_reboot=stop_on_reboot, host_devices=host_devices, + stop_on_crash=stop_on_crash, + stop_on_poweroff=stop_on_poweroff, + stop_on_lockfailure=stop_on_lockfailure, **kwargs ) ) @@ -3886,6 +3952,21 @@ def _set_cpuset(node, value): "xpath": "on_reboot", "convert": lambda v: "destroy" if v else "restart", }, + { + "path": "stop_on_crash", + "xpath": "on_crash", + "convert": lambda v: "destroy" if v else "restart", + }, + { + "path": "stop_on_poweroff", + "xpath": "on_poweroff", + "convert": lambda v: "destroy" if v else "restart", + }, + { + "path": "stop_on_poweroff", + "xpath": "on_poweroff", + "convert": lambda v: "destroy" if v else "restart", + }, {"path": "boot:kernel", "xpath": "os/kernel"}, {"path": "boot:initrd", "xpath": "os/initrd"}, {"path": "boot:cmdline", "xpath": "os/cmdline"}, From 1d0ddb328cd73754fd9a8d1f16ef0db344965c47 Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 26 Apr 2023 20:21:34 +0530 Subject: [PATCH 2/5] updated --- salt/modules/virt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/modules/virt.py b/salt/modules/virt.py index 7c089507310b..ae2d0fe5dff9 100644 --- a/salt/modules/virt.py +++ b/salt/modules/virt.py @@ -3963,8 +3963,8 @@ def _set_cpuset(node, value): "convert": lambda v: "destroy" if v else "restart", }, { - "path": "stop_on_poweroff", - "xpath": "on_poweroff", + "path": "stop_on_lockfailure", + "xpath": "on_lockfailure", "convert": lambda v: "destroy" if v else "restart", }, {"path": "boot:kernel", "xpath": "os/kernel"}, From 2b3e6c13bf4ee409e7a1f5a8357d0dc16535ca3f Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 26 Apr 2023 20:30:28 +0530 Subject: [PATCH 3/5] states done --- salt/states/virt.py | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/salt/states/virt.py b/salt/states/virt.py index 3b958e32d60a..9b9138c6f7d5 100644 --- a/salt/states/virt.py +++ b/salt/states/virt.py @@ -297,6 +297,9 @@ def defined( live=True, host_devices=None, autostart=False, + stop_on_crash=False, + stop_on_poweroff=False, + stop_on_lockfailure=False, ): """ Starts an existing guest, or defines and starts a new VM with specified arguments. @@ -586,6 +589,30 @@ def defined( .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + :param live: If set to ``False`` the changes will not be applied live to the running instance, but will only apply at the next start. Note that reboot will not take those changes. @@ -673,6 +700,9 @@ def defined( stop_on_reboot=stop_on_reboot, host_devices=host_devices, autostart=autostart, + stop_on_crash=stop_on_crash, + stop_on_poweroff=stop_on_poweroff, + stop_on_lockfailure=stop_on_lockfailure, ) ret["changes"][name] = status if not status.get("definition"): @@ -716,6 +746,9 @@ def defined( clock=clock, stop_on_reboot=stop_on_reboot, host_devices=host_devices, + stop_on_crash=stop_on_crash, + stop_on_poweroff=stop_on_poweroff, + stop_on_lockfailure=stop_on_lockfailure, ) ret["changes"][name] = {"definition": True} ret["comment"] = "Domain {} defined".format(name) @@ -756,6 +789,9 @@ def running( stop_on_reboot=False, host_devices=None, autostart=False, + stop_on_crash=False, + stop_on_poweroff=False, + stop_on_lockfailure=False, ): """ Starts an existing guest, or defines and starts a new VM with specified arguments. @@ -907,6 +943,30 @@ def running( .. versionadded:: 3003 + :param stop_on_crash: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_poweroff: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + + :param stop_on_lockfailure: + If set to ``True`` the guest will stop instead of rebooting. + This is specially useful when creating a virtual machine with an installation cdrom or + an autoinstallation needing a special first boot configuration. + Defaults to ``False`` + + .. versionadded:: ? + :param hypervisor_features: Enable or disable hypervisor-specific features on the virtual machine. @@ -1035,6 +1095,9 @@ def running( consoles=consoles, host_devices=host_devices, autostart=autostart, + stop_on_crash=stop_on_crash, + stop_on_poweroff=stop_on_poweroff, + stop_on_lockfailure=stop_on_lockfailure, ) result = True if not __opts__["test"] else None From bd7a2cbada35b1d22548a15dbe440aaaa11c68c9 Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 26 Apr 2023 20:36:06 +0530 Subject: [PATCH 4/5] test virt --- tests/unit/modules/test_virt.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/modules/test_virt.py b/tests/unit/modules/test_virt.py index 7e72d07b8e77..51b94161e00f 100644 --- a/tests/unit/modules/test_virt.py +++ b/tests/unit/modules/test_virt.py @@ -2635,6 +2635,9 @@ def test_update_existing_numatune_params(self): hvm restart + restart + restart + restart """ domain_mock = self.set_mock_vm("vm_with_numatune_param", xml_numatune) @@ -3662,6 +3665,9 @@ def test_update_exist_memorybacking_params(self): hvm restart + restart + restart + restart """ domain_mock = self.set_mock_vm("vm_with_memback_param", xml_with_memback_params) From 32737a44411718bf6012e026529d99f8417fd0dd Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 27 Apr 2023 21:06:13 +0530 Subject: [PATCH 5/5] resolved fixes --- salt/modules/virt.py | 44 ++++++++++++++++++++++---------------------- salt/states/virt.py | 44 ++++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/salt/modules/virt.py b/salt/modules/virt.py index ae2d0fe5dff9..a912885373af 100644 --- a/salt/modules/virt.py +++ b/salt/modules/virt.py @@ -2220,35 +2220,35 @@ def init( :param stop_on_reboot: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 :param stop_on_crash: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_poweroff: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_lockfailure: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param boot: Specifies kernel, initial ramdisk and kernel command line parameters for the virtual machine. @@ -3652,35 +3652,35 @@ def update( :param stop_on_reboot: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 :param stop_on_crash: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_poweroff: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_lockfailure: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param test: run in dry-run mode if set to True diff --git a/salt/states/virt.py b/salt/states/virt.py index 9b9138c6f7d5..5fbafac1e3b1 100644 --- a/salt/states/virt.py +++ b/salt/states/virt.py @@ -583,35 +583,35 @@ def defined( :param stop_on_reboot: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 :param stop_on_crash: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_poweroff: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_lockfailure: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param live: If set to ``False`` the changes will not be applied live to the running instance, but will @@ -937,35 +937,35 @@ def running( :param stop_on_reboot: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` .. versionadded:: 3003 :param stop_on_crash: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_poweroff: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param stop_on_lockfailure: If set to ``True`` the guest will stop instead of rebooting. - This is specially useful when creating a virtual machine with an installation cdrom or - an autoinstallation needing a special first boot configuration. + This is especially useful when creating a virtual machine with an installation cdrom or + an auto-installation needing a special first boot configuration. Defaults to ``False`` - .. versionadded:: ? + .. versionadded:: 3007 :param hypervisor_features: Enable or disable hypervisor-specific features on the virtual machine.