From 040bf4a39cd840cc1cc9d1603f1833d2ec92b221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Wed, 7 Nov 2018 17:55:56 +0100 Subject: [PATCH] Fix virt.pool_info usage in virt.update pool_info was changed to return a dict of pool infos even for a single pool search. Adapt calls of it in the virt module. --- salt/modules/virt.py | 3 ++- tests/unit/modules/test_virt.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/salt/modules/virt.py b/salt/modules/virt.py index b0a74c71e7..19f7e8b94b 100644 --- a/salt/modules/virt.py +++ b/salt/modules/virt.py @@ -928,7 +928,8 @@ def _fill_disk_filename(vm_name, disk, hypervisor, **kwargs): else: if not base_dir.startswith('/'): # The pool seems not to be a path, lookup for pool infos - pool = pool_info(base_dir, **kwargs) + infos = pool_info(base_dir, **kwargs) + pool = infos[base_dir] if base_dir in infos else None if not pool or not pool['target_path'] or pool['target_path'].startswith('/dev'): raise CommandExecutionError( 'Unable to create new disk {0}, specified pool {1} does not exist ' diff --git a/tests/unit/modules/test_virt.py b/tests/unit/modules/test_virt.py index bbcd69d4fe..ffafdbcfa4 100644 --- a/tests/unit/modules/test_virt.py +++ b/tests/unit/modules/test_virt.py @@ -636,32 +636,32 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin): self.assertTrue(len(root.findall('.//interface')) == 2) @patch('salt.modules.virt.pool_info', - return_value={'target_path': os.path.join(salt.syspaths.ROOT_DIR, - 'pools', - 'default')}) + return_value={'mypool': {'target_path': os.path.join(salt.syspaths.ROOT_DIR, 'pools', 'mypool')}}) def test_disk_profile_kvm_disk_pool(self, mock_poolinfo): ''' Test virt._gen_xml(), KVM case with pools defined. ''' disks = { 'noeffect': [ - {'first': {'size': 8192, 'pool': 'default'}}, + {'first': {'size': 8192, 'pool': 'mypool'}}, {'second': {'size': 4096}} ] } + + # pylint: disable=no-member with patch.dict(virt.__salt__, {'config.get': MagicMock(side_effect=[ disks, os.path.join(salt.syspaths.ROOT_DIR, 'default', 'path')])}): + diskp = virt._disk_profile('noeffect', 'kvm', [], 'hello') - pools_path = os.path.join( - salt.syspaths.ROOT_DIR, 'pools', 'default') + os.sep - default_path = os.path.join( - salt.syspaths.ROOT_DIR, 'default', 'path') + os.sep + pools_path = os.path.join(salt.syspaths.ROOT_DIR, 'pools', 'mypool') + os.sep + default_path = os.path.join(salt.syspaths.ROOT_DIR, 'default', 'path') + os.sep self.assertEqual(len(diskp), 2) self.assertTrue(diskp[0]['source_file'].startswith(pools_path)) self.assertTrue(diskp[1]['source_file'].startswith(default_path)) + # pylint: enable=no-member def test_disk_profile_kvm_disk_external_image(self): '''