summaryrefslogtreecommitdiffstats
path: root/vnfs
diff options
context:
space:
mode:
Diffstat (limited to 'vnfs')
-rw-r--r--vnfs/qemu/qemu.py43
1 files changed, 22 insertions, 21 deletions
diff --git a/vnfs/qemu/qemu.py b/vnfs/qemu/qemu.py
index 87126da8..51553277 100644
--- a/vnfs/qemu/qemu.py
+++ b/vnfs/qemu/qemu.py
@@ -151,27 +151,28 @@ class IVnfQemu(IVnf):
"""
Stops VNF instance gracefully first.
"""
- try:
- # exit testpmd if needed
- if self._guest_loopback == 'testpmd':
- self.execute_and_wait('stop', 120, "Done")
- self.execute_and_wait('quit', 120, "[bB]ye")
-
- # turn off VM
- self.execute_and_wait('poweroff', 120, "Power down")
-
- except pexpect.TIMEOUT:
- self.kill()
-
- # wait until qemu shutdowns
- self._logger.debug('Wait for QEMU to terminate')
- for dummy in range(30):
- time.sleep(1)
- if not self.is_running():
- break
-
- # just for case that graceful shutdown failed
- super(IVnfQemu, self).stop()
+ if self.is_running():
+ try:
+ # exit testpmd if needed
+ if self._guest_loopback == 'testpmd':
+ self.execute_and_wait('stop', 120, "Done")
+ self.execute_and_wait('quit', 120, "[bB]ye")
+
+ # turn off VM
+ self.execute_and_wait('poweroff', 120, "Power down")
+
+ except pexpect.TIMEOUT:
+ self.kill()
+
+ # wait until qemu shutdowns
+ self._logger.debug('Wait for QEMU to terminate')
+ for dummy in range(30):
+ time.sleep(1)
+ if not self.is_running():
+ break
+
+ # just for case that graceful shutdown failed
+ super(IVnfQemu, self).stop()
# helper functions