51d9b78cf8
OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=156
93 lines
3.7 KiB
Diff
93 lines
3.7 KiB
Diff
From 2635b6c87a74e6c274d41a1f526166f6d347ae0a Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= <cbosdonnat@suse.com>
|
|
Date: Thu, 4 Apr 2019 16:18:58 +0200
|
|
Subject: [PATCH] virt.volume_infos fix for single VM
|
|
|
|
_get_domain returns a domain object when only one VM has been found.
|
|
virt.volume_infos needs to take care of it or it will fail to list the
|
|
volumes informations if the host in such a case.
|
|
---
|
|
salt/modules/virt.py | 4 +++-
|
|
tests/unit/modules/test_virt.py | 46 +++++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 49 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/salt/modules/virt.py b/salt/modules/virt.py
|
|
index 9bb3636bd1..d160f0905f 100644
|
|
--- a/salt/modules/virt.py
|
|
+++ b/salt/modules/virt.py
|
|
@@ -5050,10 +5050,12 @@ def volume_infos(pool=None, volume=None, **kwargs):
|
|
conn = __get_conn(**kwargs)
|
|
try:
|
|
backing_stores = _get_all_volumes_paths(conn)
|
|
+ domains = _get_domain(conn)
|
|
+ domains_list = domains if isinstance(domains, list) else [domains]
|
|
disks = {domain.name():
|
|
{node.get('file') for node
|
|
in ElementTree.fromstring(domain.XMLDesc(0)).findall('.//disk/source/[@file]')}
|
|
- for domain in _get_domain(conn)}
|
|
+ for domain in domains_list}
|
|
|
|
def _volume_extract_infos(vol):
|
|
'''
|
|
diff --git a/tests/unit/modules/test_virt.py b/tests/unit/modules/test_virt.py
|
|
index 6f9eea241a..cc62b67918 100644
|
|
--- a/tests/unit/modules/test_virt.py
|
|
+++ b/tests/unit/modules/test_virt.py
|
|
@@ -2864,6 +2864,52 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
|
|
}
|
|
})
|
|
|
|
+ # Single VM test
|
|
+ with patch('salt.modules.virt._get_domain', MagicMock(return_value=mock_vms[0])):
|
|
+ actual = virt.volume_infos('pool0', 'vol0')
|
|
+ self.assertEqual(1, len(actual.keys()))
|
|
+ self.assertEqual(1, len(actual['pool0'].keys()))
|
|
+ self.assertEqual(['vm0'], sorted(actual['pool0']['vol0']['used_by']))
|
|
+ self.assertEqual('/path/to/vol0.qcow2', actual['pool0']['vol0']['path'])
|
|
+ self.assertEqual('file', actual['pool0']['vol0']['type'])
|
|
+ self.assertEqual('/key/of/vol0', actual['pool0']['vol0']['key'])
|
|
+ self.assertEqual(123456789, actual['pool0']['vol0']['capacity'])
|
|
+ self.assertEqual(123456, actual['pool0']['vol0']['allocation'])
|
|
+
|
|
+ self.assertEqual(virt.volume_infos('pool1', None), {
|
|
+ 'pool1': {
|
|
+ 'vol1': {
|
|
+ 'type': 'file',
|
|
+ 'key': '/key/of/vol1',
|
|
+ 'path': '/path/to/vol1.qcow2',
|
|
+ 'capacity': 12345,
|
|
+ 'allocation': 1234,
|
|
+ 'used_by': [],
|
|
+ },
|
|
+ 'vol2': {
|
|
+ 'type': 'file',
|
|
+ 'key': '/key/of/vol2',
|
|
+ 'path': '/path/to/vol2.qcow2',
|
|
+ 'capacity': 12345,
|
|
+ 'allocation': 1234,
|
|
+ 'used_by': [],
|
|
+ }
|
|
+ }
|
|
+ })
|
|
+
|
|
+ self.assertEqual(virt.volume_infos(None, 'vol2'), {
|
|
+ 'pool1': {
|
|
+ 'vol2': {
|
|
+ 'type': 'file',
|
|
+ 'key': '/key/of/vol2',
|
|
+ 'path': '/path/to/vol2.qcow2',
|
|
+ 'capacity': 12345,
|
|
+ 'allocation': 1234,
|
|
+ 'used_by': [],
|
|
+ }
|
|
+ }
|
|
+ })
|
|
+
|
|
def test_volume_delete(self):
|
|
'''
|
|
Test virt.volume_delete
|
|
--
|
|
2.16.4
|
|
|
|
|