Skip to content

Commit

Permalink
Add support for multiple engine
Browse files Browse the repository at this point in the history
Signed-off-by: Galit <[email protected]>
  • Loading branch information
galitf authored and Galit committed Nov 5, 2018
1 parent 073353b commit 5280615
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
10 changes: 8 additions & 2 deletions ovirtlago/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ def prepare_repo(
sub_repo_name='default'
):
# Detect distros from template metadata
engine_dists = [self.virt_env.engine_vm().distro()] \
if self.virt_env.engine_vm() else []
if isinstance(self.virt_env.engine_vm(), list):
engine_dists = list(
set([host.distro() for host in self.virt_env.engine_vm()])
)
else:
engine_dists = [self.virt_env.engine_vm().distro()] \
if self.virt_env.engine_vm() else []

vdsm_dists = list(
set([host.distro() for host in self.virt_env.host_vms()])
)
Expand Down
4 changes: 2 additions & 2 deletions ovirtlago/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ def get_vm_caps(vm):
return caps.issubset(existing_caps)


def engine_capability(caps):
def engine_capability(caps, idx=0):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
prefix = get_test_prefix()
if not _vms_capable([prefix.virt_env.engine_vm()], caps):
if not _vms_capable([prefix.virt_env.engine_vm()[idx]], caps):
raise SkipTest()
return func()

Expand Down
45 changes: 32 additions & 13 deletions ovirtlago/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

class OvirtVirtEnv(lago.virt.VirtEnv):
def __init__(self, prefix, vm_specs, net_spec):
self._engine_vm = None
self._engine_vm = []
self._host_vms = []
super(OvirtVirtEnv, self).__init__(prefix, vm_specs, net_spec)

Expand All @@ -71,12 +71,11 @@ def _create_vm(self, vm_spec):
)

if provider_name == 'ovirt-engine':
if self._engine_vm is not None:
raise RuntimeError('Engine VM already exists')

vm_spec['vm-type'] = provider_name
self._engine_vm = super(OvirtVirtEnv, self)._create_vm(vm_spec)
return self._engine_vm
self._engine_vm.append(
super(OvirtVirtEnv, self)._create_vm(vm_spec)
)
return self._engine_vm[-1]

elif provider_name in ('ovirt-host', 'ovirt-node'):
vm_spec['vm-type'] = provider_name
Expand All @@ -89,7 +88,13 @@ def _create_vm(self, vm_spec):
return super(OvirtVirtEnv, self)._create_vm(vm_spec)

def engine_vm(self):
return self._engine_vm
if len(self._engine_vm) == 1:
return self._engine_vm[0]
else:
return self._engine_vm[:]

def engine_vms(self):
return self._engine_vm[:]

def host_vms(self):
return self._host_vms[:]
Expand Down Expand Up @@ -121,7 +126,7 @@ def get_ovirt_cpu_family(self, host=None):
except IndexError:
pass
if not host:
host = self.engine_vm()
host = self.engine_vms()[-1]
if host is None:
raise RuntimeError('No Engine or Host VMs found')

Expand Down Expand Up @@ -154,9 +159,12 @@ def get_ovirt_cpu_family(self, host=None):
return cpu_map[host.cpu_vendor][host.cpu_model]

@require_sdk(version='4')
def update_clusters_cpu(self, timeout=2 * 60):
def update_clusters_cpu(self, timeout=2 * 60, idx=0):
cpu_family = self.get_ovirt_cpu_family()
api = self.engine_vm().get_api_v4(check=True)
if idx == 0:
api = self.engine_vm().get_api_v4(check=True)
else:
api = self.engine_vm()[idx].get_api_v4(check=True)
clusters_service = api.system_service().clusters_service()
clusters = clusters_service.list()

Expand Down Expand Up @@ -229,7 +237,7 @@ def _vdsm_up(host):
),
)

def assert_engine_alive(self, timeout=2 * 60):
def assert_engine_alive(self, timeout=2 * 60, idx=0):
"""
Assert service 'ovirt-engine' reports running on the engine VM
Expand All @@ -243,14 +251,18 @@ def assert_engine_alive(self, timeout=2 * 60):
AssertionError: if ovirt-engine is not reported running after the
given timeout, or ssh is unreachable.
"""
if idx == 0:
engine_host = self.engine_vm()
else:
engine_host = self.engine_vm()[idx]

def _ovirt_engine_up(host):
status = host.service('ovirt-engine').alive()
LOGGER.debug('ovirt-engine status: %s', status)
return status

testlib.assert_true_within(
partial(_ovirt_engine_up, self.engine_vm()),
partial(_ovirt_engine_up, engine_host),
timeout=timeout,
allowed_exceptions=self._get_check_running_allowed_exceptions(),
)
Expand Down Expand Up @@ -378,7 +390,14 @@ def add_iso(self, path):
if ret:
raise RuntimeError('Failed to remove uploaded image')

def engine_setup(self, config=None):
@require_sdk(version='4')
def engine_setup(self, timeout=8 * 60):
api = self.get_api_v4(check=True)
vms_service = api.system_service().vms_service()
ids = self._search_vms(vms_service, query='name=HostedEngine')
[vms_service.vm_service(id).engine_setup_one() for id in ids]

def engine_setup_one(self, config=None):
self.wait_for_ssh()

if config:
Expand Down

0 comments on commit 5280615

Please sign in to comment.