Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mechanism to swap nailgun versions on demand #12840

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,14 +1752,26 @@ def __init__(self, hostname=None, **kwargs):
self._api = type('api', (), {'_configured': False})
self._cli = type('cli', (), {'_configured': False})

def _swap_nailgun(self, new_version):
jyejare marked this conversation as resolved.
Show resolved Hide resolved
"""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]
Comment on lines +1764 to +1765
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this clearance should be done after uninstalling the previous Nailgun version and before installing new nailgun version ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation would likely cleanup the bits of newly installed nailgun as well hence above comment, correct me if I am wrong .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the order here is less important than you might think. the current modules are live in memory, so this only really helps for new imports (like what we do when recreating the Satellite.api attributes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting how popping out the nailgun specific modules from sys.modules would still make nailgun module available.

Do you mean the newly installed nailgun isnt the part of sys.modules and only unistalled is ?


@property
def api(self):
"""Import all nailgun entities and wrap them under self.api"""
if not self._api:
self._api = type('api', (), {'_configured': False})
if self._api._configured:
return self._api

from nailgun import entities as _entities # use a private import
jyejare marked this conversation as resolved.
Show resolved Hide resolved
from nailgun.config import ServerConfig
from nailgun.entity_mixins import Entity

Expand All @@ -1779,7 +1791,7 @@ class DecClass(cls):
verify=False,
)
# 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__
Expand Down
Loading