mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Added conditional to only collect qmpstatus on qemu VMs (#4816)
* Added conditional to only collect qmpstatus on qemu VMs * Processed feedback, added changelog * Initial change to unit tests * Made Sanity tests happy again * Missed a function call, removed superfluous function * Derp, no need to mock get_vm_status anymore * Added detail checks whether hosts are mapped to the paused/prelaunch groups * Fix sanity check * Processed feedback * Processed feedback - noqa
This commit is contained in:
parent
dd24c98fe5
commit
71745b8024
3 changed files with 105 additions and 7 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- proxmox inventory plugin - fixed extended status detection for qemu (https://github.com/ansible-collections/community.general/pull/4816).
|
|
@ -443,7 +443,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
def _get_vm_status(self, properties, node, vmid, vmtype, name):
|
def _get_vm_status(self, properties, node, vmid, vmtype, name):
|
||||||
ret = self._get_json("%s/api2/json/nodes/%s/%s/%s/status/current" % (self.proxmox_url, node, vmtype, vmid))
|
ret = self._get_json("%s/api2/json/nodes/%s/%s/%s/status/current" % (self.proxmox_url, node, vmtype, vmid))
|
||||||
properties[self._fact('status')] = ret['status']
|
properties[self._fact('status')] = ret['status']
|
||||||
properties[self._fact('qmpstatus')] = ret['qmpstatus']
|
if vmtype == 'qemu':
|
||||||
|
properties[self._fact('qmpstatus')] = ret['qmpstatus']
|
||||||
|
|
||||||
def _get_vm_snapshots(self, properties, node, vmid, vmtype, name):
|
def _get_vm_snapshots(self, properties, node, vmid, vmtype, name):
|
||||||
ret = self._get_json("%s/api2/json/nodes/%s/%s/%s/snapshot" % (self.proxmox_url, node, vmtype, vmid))
|
ret = self._get_json("%s/api2/json/nodes/%s/%s/%s/snapshot" % (self.proxmox_url, node, vmtype, vmid))
|
||||||
|
|
|
@ -520,6 +520,99 @@ def get_json(url):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
elif url == "https://localhost:8006/api2/json/nodes/testnode/lxc/100/status/current":
|
||||||
|
# _get_vm_status (lxc)
|
||||||
|
return {
|
||||||
|
"swap": 0,
|
||||||
|
"name": "test-lxc",
|
||||||
|
"diskread": 0,
|
||||||
|
"vmid": 100,
|
||||||
|
"diskwrite": 0,
|
||||||
|
"pid": 9000,
|
||||||
|
"mem": 89980928,
|
||||||
|
"netin": 1950776396424,
|
||||||
|
"disk": 4998168576,
|
||||||
|
"cpu": 0.00163430613110039,
|
||||||
|
"type": "lxc",
|
||||||
|
"uptime": 6793736,
|
||||||
|
"maxmem": 1073741824,
|
||||||
|
"status": "running",
|
||||||
|
"cpus": "1",
|
||||||
|
"ha": {
|
||||||
|
"group": 'null',
|
||||||
|
"state": "started",
|
||||||
|
"managed": 1
|
||||||
|
},
|
||||||
|
"maxdisk": 3348329267200,
|
||||||
|
"netout": 1947793356037,
|
||||||
|
"maxswap": 1073741824
|
||||||
|
}
|
||||||
|
elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu/101/status/current":
|
||||||
|
# _get_vm_status (qemu)
|
||||||
|
return {
|
||||||
|
"status": "stopped",
|
||||||
|
"uptime": 0,
|
||||||
|
"maxmem": 5364514816,
|
||||||
|
"maxdisk": 34359738368,
|
||||||
|
"netout": 0,
|
||||||
|
"cpus": 2,
|
||||||
|
"ha": {
|
||||||
|
"managed": 0
|
||||||
|
},
|
||||||
|
"diskread": 0,
|
||||||
|
"vmid": 101,
|
||||||
|
"diskwrite": 0,
|
||||||
|
"name": "test-qemu",
|
||||||
|
"cpu": 0,
|
||||||
|
"disk": 0,
|
||||||
|
"netin": 0,
|
||||||
|
"mem": 0,
|
||||||
|
"qmpstatus": "stopped"
|
||||||
|
}
|
||||||
|
elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu/102/status/current":
|
||||||
|
# _get_vm_status (qemu)
|
||||||
|
return {
|
||||||
|
"status": "stopped",
|
||||||
|
"uptime": 0,
|
||||||
|
"maxmem": 5364514816,
|
||||||
|
"maxdisk": 34359738368,
|
||||||
|
"netout": 0,
|
||||||
|
"cpus": 2,
|
||||||
|
"ha": {
|
||||||
|
"managed": 0
|
||||||
|
},
|
||||||
|
"diskread": 0,
|
||||||
|
"vmid": 102,
|
||||||
|
"diskwrite": 0,
|
||||||
|
"name": "test-qemu-windows",
|
||||||
|
"cpu": 0,
|
||||||
|
"disk": 0,
|
||||||
|
"netin": 0,
|
||||||
|
"mem": 0,
|
||||||
|
"qmpstatus": "prelaunch"
|
||||||
|
}
|
||||||
|
elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu/103/status/current":
|
||||||
|
# _get_vm_status (qemu)
|
||||||
|
return {
|
||||||
|
"status": "stopped",
|
||||||
|
"uptime": 0,
|
||||||
|
"maxmem": 5364514816,
|
||||||
|
"maxdisk": 34359738368,
|
||||||
|
"netout": 0,
|
||||||
|
"cpus": 2,
|
||||||
|
"ha": {
|
||||||
|
"managed": 0
|
||||||
|
},
|
||||||
|
"diskread": 0,
|
||||||
|
"vmid": 103,
|
||||||
|
"diskwrite": 0,
|
||||||
|
"name": "test-qemu-multi-nic",
|
||||||
|
"cpu": 0,
|
||||||
|
"disk": 0,
|
||||||
|
"netin": 0,
|
||||||
|
"mem": 0,
|
||||||
|
"qmpstatus": "paused"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_vm_snapshots(node, properties, vmtype, vmid, name):
|
def get_vm_snapshots(node, properties, vmtype, vmid, name):
|
||||||
|
@ -537,10 +630,6 @@ def get_vm_snapshots(node, properties, vmtype, vmid, name):
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
def get_vm_status(properties, node, vmtype, vmid, name):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def get_option(opts):
|
def get_option(opts):
|
||||||
def fn(option):
|
def fn(option):
|
||||||
default = opts.get('default', False)
|
default = opts.get('default', False)
|
||||||
|
@ -568,7 +657,6 @@ def test_populate(inventory, mocker):
|
||||||
# bypass authentication and API fetch calls
|
# bypass authentication and API fetch calls
|
||||||
inventory._get_auth = mocker.MagicMock(side_effect=get_auth)
|
inventory._get_auth = mocker.MagicMock(side_effect=get_auth)
|
||||||
inventory._get_json = mocker.MagicMock(side_effect=get_json)
|
inventory._get_json = mocker.MagicMock(side_effect=get_json)
|
||||||
inventory._get_vm_status = mocker.MagicMock(side_effect=get_vm_status)
|
|
||||||
inventory._get_vm_snapshots = mocker.MagicMock(side_effect=get_vm_snapshots)
|
inventory._get_vm_snapshots = mocker.MagicMock(side_effect=get_vm_snapshots)
|
||||||
inventory.get_option = mocker.MagicMock(side_effect=get_option(opts))
|
inventory.get_option = mocker.MagicMock(side_effect=get_option(opts))
|
||||||
inventory._can_add_host = mocker.MagicMock(return_value=True)
|
inventory._can_add_host = mocker.MagicMock(return_value=True)
|
||||||
|
@ -617,6 +705,14 @@ def test_populate(inventory, mocker):
|
||||||
for group in ['paused', 'prelaunch']:
|
for group in ['paused', 'prelaunch']:
|
||||||
assert ('%sall_%s' % (inventory.group_prefix, group)) in inventory.inventory.groups
|
assert ('%sall_%s' % (inventory.group_prefix, group)) in inventory.inventory.groups
|
||||||
|
|
||||||
|
# check if qemu-windows is in the prelaunch group
|
||||||
|
group_prelaunch = inventory.inventory.groups['proxmox_all_prelaunch']
|
||||||
|
assert group_prelaunch.hosts == [host_qemu_windows]
|
||||||
|
|
||||||
|
# check if qemu-multi-nic is in the paused group
|
||||||
|
group_paused = inventory.inventory.groups['proxmox_all_paused']
|
||||||
|
assert group_paused.hosts == [host_qemu_multi_nic]
|
||||||
|
|
||||||
|
|
||||||
def test_populate_missing_qemu_extended_groups(inventory, mocker):
|
def test_populate_missing_qemu_extended_groups(inventory, mocker):
|
||||||
# module settings
|
# module settings
|
||||||
|
@ -638,7 +734,6 @@ def test_populate_missing_qemu_extended_groups(inventory, mocker):
|
||||||
# bypass authentication and API fetch calls
|
# bypass authentication and API fetch calls
|
||||||
inventory._get_auth = mocker.MagicMock(side_effect=get_auth)
|
inventory._get_auth = mocker.MagicMock(side_effect=get_auth)
|
||||||
inventory._get_json = mocker.MagicMock(side_effect=get_json)
|
inventory._get_json = mocker.MagicMock(side_effect=get_json)
|
||||||
inventory._get_vm_status = mocker.MagicMock(side_effect=get_vm_status)
|
|
||||||
inventory._get_vm_snapshots = mocker.MagicMock(side_effect=get_vm_snapshots)
|
inventory._get_vm_snapshots = mocker.MagicMock(side_effect=get_vm_snapshots)
|
||||||
inventory.get_option = mocker.MagicMock(side_effect=get_option(opts))
|
inventory.get_option = mocker.MagicMock(side_effect=get_option(opts))
|
||||||
inventory._can_add_host = mocker.MagicMock(return_value=True)
|
inventory._can_add_host = mocker.MagicMock(return_value=True)
|
||||||
|
|
Loading…
Reference in a new issue