From ce04003d148f3a57070d65b0432780ee6170873c Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Tue, 19 Mar 2024 14:38:10 +0100 Subject: [PATCH 1/3] Fix omitting credentials when CLI has already been instantiated --- robottelo/hosts.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 7596411fa56..432430f04e8 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1848,8 +1848,30 @@ def cli(self): @contextmanager def omit_credentials(self): self.omitting_credentials = True + # if CLI is already created + if self._cli._configured: + for file in Path('robottelo/cli/').iterdir(): + if file.suffix == '.py' and not file.name.startswith('_'): + cli_module = importlib.import_module(f'robottelo.cli.{file.stem}') + for name, obj in cli_module.__dict__.items(): + try: + if Base in obj.mro(): + getattr(self._cli, name).omitting_credentials = True + except AttributeError: + # not everything has an mro method, we don't care about them + pass yield self.omitting_credentials = False + for file in Path('robottelo/cli/').iterdir(): + if file.suffix == '.py' and not file.name.startswith('_'): + cli_module = importlib.import_module(f'robottelo.cli.{file.stem}') + for name, obj in cli_module.__dict__.items(): + try: + if Base in obj.mro(): + getattr(self._cli, name).omitting_credentials = False + except AttributeError: + # not everything has an mro method, we don't care about them + pass @contextmanager def ui_session(self, testname=None, user=None, password=None, url=None, login=True): From 0bd5010988e6b5590eaf1f2a93ea69f24bbd66ff Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Mon, 15 Apr 2024 17:30:25 +0200 Subject: [PATCH 2/3] Rework based on comments --- robottelo/hosts.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 432430f04e8..f721a64d482 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1847,31 +1847,27 @@ def cli(self): @contextmanager def omit_credentials(self): - self.omitting_credentials = True - # if CLI is already created - if self._cli._configured: - for file in Path('robottelo/cli/').iterdir(): - if file.suffix == '.py' and not file.name.startswith('_'): - cli_module = importlib.import_module(f'robottelo.cli.{file.stem}') - for name, obj in cli_module.__dict__.items(): - try: - if Base in obj.mro(): - getattr(self._cli, name).omitting_credentials = True - except AttributeError: - # not everything has an mro method, we don't care about them - pass + change = not self.omitting_credentials # if not already set to omit + if change: + self.omitting_credentials = True + # if CLI is already created + if self._cli._configured: + for name, obj in self._cli.__dict__.items(): + with contextlib.suppress( + AttributeError + ): # not everything has an mro method, we don't care about them + if Base in obj.mro(): + getattr(self._cli, name).omitting_credentials = True yield - self.omitting_credentials = False - for file in Path('robottelo/cli/').iterdir(): - if file.suffix == '.py' and not file.name.startswith('_'): - cli_module = importlib.import_module(f'robottelo.cli.{file.stem}') - for name, obj in cli_module.__dict__.items(): - try: + if change: + self.omitting_credentials = False + if self._cli._configured: + for name, obj in self._cli.__dict__.items(): + with contextlib.suppress( + AttributeError + ): # not everything has an mro method, we don't care about them if Base in obj.mro(): - getattr(self._cli, name).omitting_credentials = False - except AttributeError: - # not everything has an mro method, we don't care about them - pass + getattr(self._cli, name).omitting_credentials = True @contextmanager def ui_session(self, testname=None, user=None, password=None, url=None, login=True): From b1959d033345c9d42fa3c0ef7274e95fa2122ad8 Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Tue, 23 Apr 2024 10:56:23 +0200 Subject: [PATCH 3/3] Set to False after yield --- robottelo/hosts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index f721a64d482..484d40cd2ca 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1867,7 +1867,7 @@ def omit_credentials(self): AttributeError ): # not everything has an mro method, we don't care about them if Base in obj.mro(): - getattr(self._cli, name).omitting_credentials = True + getattr(self._cli, name).omitting_credentials = False @contextmanager def ui_session(self, testname=None, user=None, password=None, url=None, login=True):