提交 177cc460 编写于 作者: L Lukáš Doktor 提交者: Cleber Rosa

avocado.core.remote: Improve VMTestRunner tear_down method

The tear_down method can be currently called even before the `self.vm`
is initialized, producing an ugly traceback. This patch only cleanups
the vm when it's initialized and undefines it afterwards, so multiple
runs won't restore the snapshot multiple times.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 bd749276
......@@ -318,7 +318,9 @@ class VMTestRunner(RemoteTestRunner):
def tear_down(self):
super(VMTestRunner, self).tear_down()
if self.job.args.vm_cleanup is True:
if (self.job.args.vm_cleanup is True and
isinstance(getattr(self, 'vm', None), virt.VM)):
self.vm.stop()
if self.vm.snapshot is not None:
self.vm.restore_snapshot()
self.vm = None
......@@ -16,13 +16,23 @@ JSON_RESULTS = ('Something other than json\n'
'1}\nAdditional stuff other than json')
class _FakeVM(virt.VM):
"""
Fake VM-inherited object (it's better to inherit it, than to flexmock the
isinstance)
"""
def __init__(self): # don't call virt.VM.__init__ pylint: disable=W0231
self.snapshot = True
self.domain = flexmock(isActive=lambda: True)
class VMTestRunnerSetup(unittest.TestCase):
""" Tests the VMTestRunner setup() method """
def setUp(self):
mock_vm = flexmock(snapshot=True,
domain=flexmock(isActive=lambda: True))
mock_vm = flexmock(_FakeVM())
flexmock(virt).should_receive('vm_connect').and_return(mock_vm).once().ordered()
mock_vm.should_receive('start').and_return(True).once().ordered()
mock_vm.should_receive('create_snapshot').once().ordered()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册