From a83504cb34cf1debff60a14601784fe3981bfcfd Mon Sep 17 00:00:00 2001 From: pjcreath Date: Tue, 23 Aug 2022 18:23:41 +0000 Subject: [PATCH] Include the "pool" parameter when cloning a VM with the proxmox salt-cloud driver Fixes #62521 --- changelog/62521.fixed | 1 + salt/cloud/clouds/proxmox.py | 2 ++ tests/unit/cloud/clouds/test_proxmox.py | 26 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 changelog/62521.fixed diff --git a/changelog/62521.fixed b/changelog/62521.fixed new file mode 100644 index 00000000000..35e58e90298 --- /dev/null +++ b/changelog/62521.fixed @@ -0,0 +1 @@ +Fixed the omitted "pool" parameter when cloning a VM with the proxmox salt-cloud driver diff --git a/salt/cloud/clouds/proxmox.py b/salt/cloud/clouds/proxmox.py index ccbd5133bf1..af025a789fb 100644 --- a/salt/cloud/clouds/proxmox.py +++ b/salt/cloud/clouds/proxmox.py @@ -1034,6 +1034,8 @@ def create_node(vm_, newid): if "clone" in vm_ and vm_["clone"] is True and vm_["technology"] == "qemu": postParams = {} postParams["newid"] = newnode["vmid"] + if "pool" in vm_: + postParams["pool"] = vm_["pool"] for prop in "description", "format", "full", "name": if ( diff --git a/tests/unit/cloud/clouds/test_proxmox.py b/tests/unit/cloud/clouds/test_proxmox.py index 8bb4eaefcaa..7944bfeefe6 100644 --- a/tests/unit/cloud/clouds/test_proxmox.py +++ b/tests/unit/cloud/clouds/test_proxmox.py @@ -6,6 +6,7 @@ import io import textwrap import requests + from salt import config from salt.cloud.clouds import proxmox from tests.support.helpers import TstSuiteLoggingHandler @@ -162,6 +163,31 @@ class ProxmoxTest(TestCase, LoaderModuleMockMixin): ) assert result == {} + def test_clone_pool(self): + """ + Test that cloning a VM passes the pool parameter if present + """ + mock_query = MagicMock(return_value="") + with patch( + "salt.cloud.clouds.proxmox._get_properties", MagicMock(return_value=[]) + ), patch("salt.cloud.clouds.proxmox.query", mock_query): + vm_ = { + "technology": "qemu", + "name": "new2", + "host": "myhost", + "clone": True, + "clone_from": 123, + "pool": "mypool", + } + + result = proxmox.create_node(vm_, ANY) + mock_query.assert_called_once_with( + "post", + "nodes/myhost/qemu/123/clone", + {"newid": ANY, "pool": "mypool"}, + ) + assert result == {} + def test_find_agent_ips(self): """ Test find_agent_ip will return an IP