Skip to content

Commit

Permalink
Merge pull request #338 from mykaul/prep_for_v4_ovirt_api
Browse files Browse the repository at this point in the history
Prep for oVirt v4 API
  • Loading branch information
lago-bot authored Oct 10, 2016
2 parents 640247d + c5dfc9c commit f070ef8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 22 deletions.
18 changes: 16 additions & 2 deletions ovirtlago/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ def wrapper(prefix, *args, **kwargs):
return wrapper


def with_ovirt_api4(func):
@functools.wraps(func)
@with_ovirt_prefix
def wrapper(prefix, *args, **kwargs):
return func(
prefix.virt_env.engine_vm().get_api(api_ver=4),
*args,
**kwargs
)

return wrapper


def continue_on_failure(func):
func.continue_on_failure = True
return func
Expand Down Expand Up @@ -132,8 +145,9 @@ def wrapped_test():
failure_occured[0] = True
raise

wrapped_test.description = test.__name__
yield wrapped_test
if test is not None:
wrapped_test.description = test.__name__
yield wrapped_test


class LogCollectorPlugin(nose.plugins.Plugin):
Expand Down
76 changes: 56 additions & 20 deletions ovirtlago/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
import lago.vm
import ovirtsdk.api
from ovirtsdk.infrastructure.errors import (RequestError, ConnectionError)
try:
import ovirtsdk4 as sdk4
API_V4 = True
except ImportError:
API_V4 = False

from . import (constants, testlib, )

Expand Down Expand Up @@ -118,34 +123,51 @@ def wait_for_ssh(self):
class EngineVM(lago.vm.DefaultVM):
def __init__(self, *args, **kwargs):
super(EngineVM, self).__init__(*args, **kwargs)
self._api = None
self._api_v3 = None
self._api_v4 = None

def stop(self):
super(EngineVM, self).stop()
self._api = None
self._api_v3 = None

def _artifact_paths(self):
inherited_artifacts = super(EngineVM, self)._artifact_paths()
return set(inherited_artifacts + ['/var/log/ovirt-engine', ])

def _create_api(self):
def _create_api(self, api_ver):
url = 'https://%s/ovirt-engine/api' % self.ip()
return ovirtsdk.api.API(
url=url,
username=constants.ENGINE_USER,
password=str(self.metadata['ovirt-engine-password']),
validate_cert_chain=False,
insecure=True,
)
if api_ver == 3:
return ovirtsdk.api.API(
url=url,
username=constants.ENGINE_USER,
password=str(self.metadata['ovirt-engine-password']),
validate_cert_chain=False,
insecure=True,
)
if api_ver == 4:
if not API_V4:
raise RuntimeError('oVirt Python SDK v4 not found.')
return sdk4.Connection(
url=url,
username=constants.ENGINE_USER,
password=str(self.metadata['ovirt-engine-password']),
insecure=True,
debug=True,
)
raise RuntimeError('Unknown API requested: %s' % api_ver)

def _get_api(self):
def _get_api(self, api_ver):
try:
api = []
api_v3 = []
api_v4 = []

def get():
instance = self._create_api()
instance = self._create_api(api_ver)
if instance:
api.append(instance)
if api_ver == 3:
api_v3.append(instance)
else:
api_v4.append(instance)
return True
return False

Expand All @@ -156,12 +178,26 @@ def get():
except AssertionError:
raise RuntimeError('Failed to connect to the engine')

return api.pop()

def get_api(self):
if self._api is None or not self._api.test():
self._api = self._get_api()
return self._api
if api_ver == 3:
return api_v3.pop()
else:
return api_v4.pop()

def get_api(self, api_ver=3):
if api_ver == 3:
return self.get_api_v3()
if api_ver == 4:
return self.get_api_v4()

def get_api_v3(self):
if self._api_v3 is None or not self._api_v3.test():
self._api_v3 = self._get_api(api_ver=3)
return self._api_v3

def get_api_v4(self):
if self._api_v4 is None or not self._api_v4.test():
self._api_v4 = self._get_api(api_ver=4)
return self._api_v4

def add_iso(self, path):
iso_name = os.path.basename(path)
Expand Down

0 comments on commit f070ef8

Please sign in to comment.