mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #50448 from cbosdo/fluorine-backport
Fix virtual disk creation in update
This commit is contained in:
commit
c51f3643c2
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user