From f6e7f86c8a7894b93a6dd27050083b333a328582 Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:22:34 -0400 Subject: [PATCH] [6.15.z] Fix omitting credentials when CLI has already been instantiated (#14880) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix omitting credentials when CLI has already been instantiated (#14449) * Fix omitting credentials when CLI has already been instantiated * Rework based on comments * Set to False after yield (cherry picked from commit 845ef03f9e55d75bd751f2f3646c66b2c33b9e00) Co-authored-by: Lukáš Hellebrandt --- robottelo/hosts.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index d06eb127547..8dd1e48f139 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1851,9 +1851,27 @@ def cli(self): @contextmanager def omit_credentials(self): - self.omitting_credentials = True + 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 + 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 @contextmanager def ui_session(self, testname=None, user=None, password=None, url=None, login=True):