aboutsummaryrefslogtreecommitdiff
path: root/tests/acceptance/avocado_qemu
diff options
context:
space:
mode:
authorCaio Carrara <ccarrara@redhat.com>2019-02-12 17:38:54 -0200
committerCleber Rosa <crosa@redhat.com>2019-02-22 14:07:01 -0500
commitb7287d428325705ddf9d9b26d3a7dc2d4ffe837f (patch)
tree5d0f0fa45898afea810da5ae5642cc7ff2169cf9 /tests/acceptance/avocado_qemu
parent10314fb060f2bd42c3fb0f5523edb8dbb0247d00 (diff)
tests.acceptance: adds multi vm capability for acceptance tests
This change adds the possibility to write acceptance tests with multi virtual machine support. It's done keeping the virtual machines objects stored in a test attribute (dictionary). This dictionary shouldn't be accessed directly but through the new method added `get_vm`. This new method accept a list of args (that will be added as virtual machine arguments) and an optional name argument. The name is the key that identify a single virtual machine along the test machines available. If a name without a machine is informed a new machine will be instantiated. The current usage of vm in tests will not be broken by this change since it keeps a property called vm in the base test class. This property only calls the new method `get_vm` with default parameters (no args and 'default' as machine name). Signed-off-by: Caio Carrara <ccarrara@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Message-Id: <20190212193855.13223-2-ccarrara@redhat.com> Signed-off-by: Cleber Rosa <crosa@redhat.com>
Diffstat (limited to 'tests/acceptance/avocado_qemu')
-rw-r--r--tests/acceptance/avocado_qemu/__init__.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 28bfb8e9d3..a66ec72daa 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -10,6 +10,7 @@
import os
import sys
+import uuid
import avocado
@@ -41,13 +42,29 @@ def pick_default_qemu_bin():
class Test(avocado.Test):
def setUp(self):
- self.vm = None
+ self._vms = {}
self.qemu_bin = self.params.get('qemu_bin',
default=pick_default_qemu_bin())
if self.qemu_bin is None:
self.cancel("No QEMU binary defined or found in the source tree")
- self.vm = QEMUMachine(self.qemu_bin)
+
+ def _new_vm(self, *args):
+ vm = QEMUMachine(self.qemu_bin)
+ if args:
+ vm.add_args(*args)
+ return vm
+
+ @property
+ def vm(self):
+ return self.get_vm(name='default')
+
+ def get_vm(self, *args, name=None):
+ if not name:
+ name = str(uuid.uuid4())
+ if self._vms.get(name) is None:
+ self._vms[name] = self._new_vm(*args)
+ return self._vms[name]
def tearDown(self):
- if self.vm is not None:
- self.vm.shutdown()
+ for vm in self._vms.values():
+ vm.shutdown()