From f10676ef421b3dbc69e18b86e0a2850e95f28c62 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Wed, 27 Sep 2023 16:01:47 -0400 Subject: [PATCH] Add a mechanism to swap nailgun versions on demand Satellite._swap_nailgun("x.y.z") can be used to change out the operating version of nailgun. --- robottelo/hosts.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index d8838a9606b..42edd4c446e 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1727,6 +1727,18 @@ def __init__(self, hostname=None, **kwargs): self._api = type('api', (), {'_configured': False}) self._cli = type('cli', (), {'_configured': False}) + def _swap_nailgun(self, new_version): + """Install a different version of nailgun from GitHub and invalidate the module cache.""" + import sys + + from pip._internal import main as pip_main + + pip_main(['uninstall', '-y', 'nailgun']) + pip_main(['install', f'https://github.com/SatelliteQE/nailgun/archive/{new_version}.zip']) + self._api = type('api', (), {'_configured': False}) + to_clear = [k for k in sys.modules.keys() if 'nailgun' in k] + [sys.modules.pop(k) for k in to_clear] + @property def api(self): """Import all nailgun entities and wrap them under self.api""" @@ -1734,7 +1746,7 @@ def api(self): self._api = type('api', (), {'_configured': False}) if self._api._configured: return self._api - + from nailgun import entities as _entities # use a private import from nailgun.config import ServerConfig from nailgun.entity_mixins import Entity @@ -1754,7 +1766,7 @@ class DecClass(cls): verify=settings.server.verify_ca, ) # add each nailgun entity to self.api, injecting our server config - for name, obj in entities.__dict__.items(): + for name, obj in _entities.__dict__.items(): try: if Entity in obj.mro(): # create a copy of the class and inject our server config into the __init__