Skip to content

Commit

Permalink
[6.14.z] recording ui-session-id for report portal logging (#13182)
Browse files Browse the repository at this point in the history
recording ui-session-id for report portal logging (#13055)

* recording ui-session-id for report portal logging

* moving the fixture to common location and adding fspath check

(cherry picked from commit 3e4abae)

Co-authored-by: Omkar Khatavkar <[email protected]>
  • Loading branch information
Satellite-QE and omkarkhatavkar authored Nov 24, 2023
1 parent 7e73dc8 commit ed72662
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pytest_fixtures/core/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,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

def _swap_nailgun(self, new_version):
"""Install a different version of nailgun from GitHub and invalidate the module cache."""
Expand Down Expand Up @@ -1828,6 +1829,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"""

Expand All @@ -1840,14 +1842,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):
Expand Down
25 changes: 25 additions & 0 deletions tests/foreman/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Configurations for py.test runner"""

import pytest

from robottelo.hosts import Satellite
from robottelo.logging import collection_logger


Expand Down Expand Up @@ -40,3 +42,26 @@ def pytest_collection_modifyitems(session, items, config):

config.hook.pytest_deselected(items=deselected_items)
items[:] = [item for item in items if item not in deselected_items]


@pytest.fixture(autouse=True)
def ui_session_record_property(request, record_property):
"""
Autouse fixture to set the record_property attribute for Satellite instances in the test.
This fixture iterates over all fixtures in the current test node
(excluding the current fixture) and sets the record_property attribute
for instances of the Satellite class.
Args:
request: The pytest request object.
record_property: The value to set for the record_property attribute.
"""
test_directories = ['tests/foreman/destructive', 'tests/foreman/ui']
test_file_path = request.node.fspath.strpath
if any(directory in test_file_path for directory in test_directories):
for fixture in request.node.fixturenames:
if request.fixturename != fixture:
if isinstance(request.getfixturevalue(fixture), Satellite):
sat = request.getfixturevalue(fixture)
sat.record_property = record_property
3 changes: 2 additions & 1 deletion tests/foreman/destructive/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ def test_foo(session):
session.architecture.create({'name': 'bar'})
"""
return module_target_sat.ui_session(test_name, ui_user.login, ui_user.password)
with module_target_sat.ui_session(test_name, ui_user.login, ui_user.password) as session:
yield session

0 comments on commit ed72662

Please sign in to comment.