mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Updating running domains in virt.running
So far virt.running does nothing if the corresponding domain is already
defined. Use the new virt.update function to change the domain
configuration.
(cherry picked from commit 2a5f6ae5d6
)
This commit is contained in:
parent
13d7819c7f
commit
1c65d25eb4
1 changed files with 42 additions and 1 deletions
|
@ -232,7 +232,7 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'comment': 'myvm is running'}
|
||||
with patch.dict(virt.__salt__, { # pylint: disable=no-member
|
||||
'virt.vm_state': MagicMock(return_value='stopped'),
|
||||
'virt.start': MagicMock(return_value=0)
|
||||
'virt.start': MagicMock(return_value=0),
|
||||
}):
|
||||
ret.update({'changes': {'myvm': 'Domain started'},
|
||||
'comment': 'Domain myvm started'})
|
||||
|
@ -324,6 +324,47 @@ class LibvirtTestCase(TestCase, LoaderModuleMockMixin):
|
|||
ret.update({'changes': {}, 'result': False, 'comment': 'libvirt error msg'})
|
||||
self.assertDictEqual(virt.running('myvm'), ret)
|
||||
|
||||
# Working update case when running
|
||||
with patch.dict(virt.__salt__, { # pylint: disable=no-member
|
||||
'virt.vm_state': MagicMock(return_value='running'),
|
||||
'virt.update': MagicMock(return_value={'definition': True, 'cpu': True})
|
||||
}):
|
||||
ret.update({'changes': {'myvm': {'definition': True, 'cpu': True}},
|
||||
'result': True,
|
||||
'comment': 'Domain myvm updated, restart to fully apply the changes'})
|
||||
self.assertDictEqual(virt.running('myvm', update=True, cpu=2), ret)
|
||||
|
||||
# Working update case when stopped
|
||||
with patch.dict(virt.__salt__, { # pylint: disable=no-member
|
||||
'virt.vm_state': MagicMock(return_value='stopped'),
|
||||
'virt.start': MagicMock(return_value=0),
|
||||
'virt.update': MagicMock(return_value={'definition': True})
|
||||
}):
|
||||
ret.update({'changes': {'myvm': 'Domain updated and started'},
|
||||
'result': True,
|
||||
'comment': 'Domain myvm updated and started'})
|
||||
self.assertDictEqual(virt.running('myvm', update=True, cpu=2), ret)
|
||||
|
||||
# Failed live update case
|
||||
with patch.dict(virt.__salt__, { # pylint: disable=no-member
|
||||
'virt.vm_state': MagicMock(return_value='running'),
|
||||
'virt.update': MagicMock(return_value={'definition': True, 'cpu': False, 'errors': ['some error']})
|
||||
}):
|
||||
ret.update({'changes': {'myvm': {'definition': True, 'cpu': False, 'errors': ['some error']}},
|
||||
'result': True,
|
||||
'comment': 'Domain myvm updated, but some live update(s) failed'})
|
||||
self.assertDictEqual(virt.running('myvm', update=True, cpu=2), ret)
|
||||
|
||||
# Failed definition update case
|
||||
with patch.dict(virt.__salt__, { # pylint: disable=no-member
|
||||
'virt.vm_state': MagicMock(return_value='running'),
|
||||
'virt.update': MagicMock(side_effect=[self.mock_libvirt.libvirtError('error message')])
|
||||
}):
|
||||
ret.update({'changes': {},
|
||||
'result': False,
|
||||
'comment': 'error message'})
|
||||
self.assertDictEqual(virt.running('myvm', update=True, cpu=2), ret)
|
||||
|
||||
def test_stopped(self):
|
||||
'''
|
||||
stopped state test cases.
|
||||
|
|
Loading…
Add table
Reference in a new issue