Merge pull request #50448 from cbosdo/fluorine-backport

Fix virtual disk creation in update
This commit is contained in:
Nicole Thomas 2018-11-09 10:00:04 -05:00 committed by GitHub
commit c51f3643c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -1807,7 +1807,8 @@ def update(name,
# Create missing disks if needed
if changes['disk']:
for idx, item in enumerate(changes['disk']['sorted']):
if item in new and not os.path.isfile(all_disks[idx]['source_file']):
source_file = all_disks[idx]['source_file']
if item in changes['disk']['new'] and source_file and not os.path.isfile(source_file):
_qemu_image_create(all_disks[idx])
try:

View File

@ -1127,20 +1127,23 @@ class VirtTestCase(TestCase, LoaderModuleMockMixin):
mock_run = MagicMock()
with patch.dict(os.__dict__, {'chmod': mock_chmod}): # pylint: disable=no-member
with patch.dict(virt.__salt__, {'cmd.run': mock_run}): # pylint: disable=no-member
ret = virt.update('myvm', disk_profile='default', disks=[{'name': 'added', 'size': 2048}])
ret = virt.update('myvm', disk_profile='default', disks=[
{'name': 'cddrive', 'device': 'cdrom', 'source_file': None, 'model': 'ide'},
{'name': 'added', 'size': 2048}])
added_disk_path = os.path.join(
virt.__salt__['config.get']('virt:images'), 'myvm_added.qcow2') # pylint: disable=no-member
self.assertEqual(mock_run.call_args[0][0],
'qemu-img create -f qcow2 {0} 2048M'.format(added_disk_path))
self.assertEqual(mock_chmod.call_args[0][0], added_disk_path)
self.assertListEqual(
[os.path.join(root_dir, 'myvm_added.qcow2')],
[ET.fromstring(disk).find('source').get('file') for disk in ret['disk']['attached']])
[None, os.path.join(root_dir, 'myvm_added.qcow2')],
[ET.fromstring(disk).find('source').get('file') if str(disk).find('<source') > -1 else None
for disk in ret['disk']['attached']])
self.assertListEqual(
[os.path.join(root_dir, 'myvm_data.qcow2')],
[ET.fromstring(disk).find('source').get('file') for disk in ret['disk']['detached']])
devattach_mock.assert_called_once()
self.assertEqual(devattach_mock.call_count, 2)
devdetach_mock.assert_called_once()
# Update nics case