From 413ad5470e82af3837793bac0bc3c835b32fcdc4 Mon Sep 17 00:00:00 2001 From: omkarkhatavkar Date: Wed, 8 Nov 2023 09:39:02 +0530 Subject: [PATCH] recording ui-session-id for report portal logging --- pytest_fixtures/component/maintain.py | 6 ++++-- pytest_fixtures/core/broker.py | 21 +++++++++++-------- pytest_fixtures/core/sat_cap_factory.py | 17 ++++++++------- pytest_fixtures/core/ui.py | 3 ++- robottelo/hosts.py | 28 ++++++++++++++++++------- 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/pytest_fixtures/component/maintain.py b/pytest_fixtures/component/maintain.py index 844f522de66..a0aefd7e400 100644 --- a/pytest_fixtures/component/maintain.py +++ b/pytest_fixtures/component/maintain.py @@ -22,9 +22,11 @@ def module_stash(request): @pytest.fixture(scope='module') -def sat_maintain(request, module_target_sat, module_capsule_configured): +def sat_maintain(request, module_target_sat, module_capsule_configured, record_property): if settings.remotedb.server: - yield Satellite(settings.remotedb.server) + sat = Satellite(settings.remotedb.server) + sat.record_property = record_property + yield sat else: module_target_sat.register_to_cdn(pool_ids=settings.subscription.fm_rhn_poolid.split()) hosts = {'satellite': module_target_sat, 'capsule': module_capsule_configured} diff --git a/pytest_fixtures/core/broker.py b/pytest_fixtures/core/broker.py index 9d207fcd9d7..124167ba62c 100644 --- a/pytest_fixtures/core/broker.py +++ b/pytest_fixtures/core/broker.py @@ -19,42 +19,45 @@ def _default_sat(align_to_satellite): @contextmanager -def _target_sat_imp(request, _default_sat, satellite_factory): +def _target_sat_imp(request, _default_sat, satellite_factory, record_property): """This is the actual working part of the following target_sat fixtures""" if request.node.get_closest_marker(name='destructive'): new_sat = satellite_factory() + new_sat.record_property = record_property yield new_sat new_sat.teardown() Broker(hosts=[new_sat]).checkin() elif 'sanity' in request.config.option.markexpr: installer_sat = lru_sat_ready_rhel(settings.server.version.rhel_version) settings.set('server.hostname', installer_sat.hostname) + installer_sat.record_property = record_property yield installer_sat else: + _default_sat.record_property = record_property yield _default_sat @pytest.fixture -def target_sat(request, _default_sat, satellite_factory): - with _target_sat_imp(request, _default_sat, satellite_factory) as sat: +def target_sat(request, _default_sat, satellite_factory, record_property): + with _target_sat_imp(request, _default_sat, satellite_factory, record_property) as sat: yield sat @pytest.fixture(scope='module') -def module_target_sat(request, _default_sat, satellite_factory): - with _target_sat_imp(request, _default_sat, satellite_factory) as sat: +def module_target_sat(request, _default_sat, satellite_factory, record_property): + with _target_sat_imp(request, _default_sat, satellite_factory, record_property) as sat: yield sat @pytest.fixture(scope='session') -def session_target_sat(request, _default_sat, satellite_factory): - with _target_sat_imp(request, _default_sat, satellite_factory) as sat: +def session_target_sat(request, _default_sat, satellite_factory, record_property): + with _target_sat_imp(request, _default_sat, satellite_factory, record_property) as sat: yield sat @pytest.fixture(scope='class') -def class_target_sat(request, _default_sat, satellite_factory): - with _target_sat_imp(request, _default_sat, satellite_factory) as sat: +def class_target_sat(request, _default_sat, satellite_factory, record_property): + with _target_sat_imp(request, _default_sat, satellite_factory, record_property) as sat: yield sat diff --git a/pytest_fixtures/core/sat_cap_factory.py b/pytest_fixtures/core/sat_cap_factory.py index 2fbb8cec7b6..5fcee6ffe33 100644 --- a/pytest_fixtures/core/sat_cap_factory.py +++ b/pytest_fixtures/core/sat_cap_factory.py @@ -26,7 +26,7 @@ def resolve_deploy_args(args_dict): @contextmanager -def _target_satellite_host(request, satellite_factory): +def _target_satellite_host(request, satellite_factory, record_property): if 'sanity' not in request.config.option.markexpr: new_sat = satellite_factory() yield new_sat @@ -105,23 +105,23 @@ def factory(retry_limit=3, delay=300, workflow=None, **broker_args): @pytest.fixture -def satellite_host(request, satellite_factory): +def satellite_host(request, satellite_factory, record_property): """A fixture that provides a Satellite based on config settings""" - with _target_satellite_host(request, satellite_factory) as sat: + with _target_satellite_host(request, satellite_factory, record_property) as sat: yield sat @pytest.fixture(scope='module') -def module_satellite_host(request, satellite_factory): +def module_satellite_host(request, satellite_factory, record_property): """A fixture that provides a Satellite based on config settings""" - with _target_satellite_host(request, satellite_factory) as sat: + with _target_satellite_host(request, satellite_factory, record_property) as sat: yield sat @pytest.fixture(scope='session') -def session_satellite_host(request, satellite_factory): +def session_satellite_host(request, satellite_factory, record_property): """A fixture that provides a Satellite based on config settings""" - with _target_satellite_host(request, satellite_factory) as sat: + with _target_satellite_host(request, satellite_factory, record_property) as sat: yield sat @@ -285,7 +285,7 @@ def cap_ready_rhel(): @pytest.fixture(scope='session') -def installer_satellite(request): +def installer_satellite(request, record_property): """A fixture to freshly install the satellite using installer on RHEL machine This is a pure / virgin / nontemplate based satellite @@ -322,6 +322,7 @@ def installer_satellite(request): if 'sanity' in request.config.option.markexpr: configure_nailgun() configure_airgun() + sat.record_property = record_property yield sat if 'sanity' not in request.config.option.markexpr: sanity_sat = Satellite(sat.hostname) diff --git a/pytest_fixtures/core/ui.py b/pytest_fixtures/core/ui.py index 7edbd39b731..f87f4cec0ad 100644 --- a/pytest_fixtures/core/ui.py +++ b/pytest_fixtures/core/ui.py @@ -49,7 +49,8 @@ def test_foo(session): session.architecture.create({'name': 'bar'}) """ - return target_sat.ui_session(test_name, ui_user.login, ui_user.password) + with target_sat.ui_session(test_name, ui_user.login, ui_user.password) as session: + yield session @pytest.fixture diff --git a/robottelo/hosts.py b/robottelo/hosts.py index d8838a9606b..4cf51640a0c 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1726,6 +1726,7 @@ def __init__(self, hostname=None, **kwargs): # create dummy classes for later population self._api = type('api', (), {'_configured': False}) self._cli = type('cli', (), {'_configured': False}) + self.record_property = None @property def api(self): @@ -1802,6 +1803,7 @@ def omit_credentials(self): yield self.omitting_credentials = False + @contextmanager def ui_session(self, testname=None, user=None, password=None, url=None, login=True): """Initialize an airgun Session object and store it as self.ui_session""" @@ -1814,14 +1816,24 @@ def get_caller(): if frame.function.startswith('test_'): return frame.function - return Session( - session_name=testname or get_caller(), - user=user or settings.server.admin_username, - password=password or settings.server.admin_password, - url=url, - hostname=self.hostname, - login=login, - ) + try: + ui_session = Session( + session_name=testname or get_caller(), + user=user or settings.server.admin_username, + password=password or settings.server.admin_password, + url=url, + hostname=self.hostname, + login=login, + ) + yield ui_session + except Exception: + raise + finally: + video_url = settings.ui.grid_url.replace( + ':4444', f'/videos/{ui_session.ui_session_id}.mp4' + ) + self.record_property('video_url', video_url) + self.record_property('session_id', ui_session.ui_session_id) @property def satellite(self):