From 55fd4ccd2345f3c20170d0b9ab74ddb2a5a512f1 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 2 Sep 2020 15:38:03 -0400 Subject: [PATCH] uitests: Add connection login console lookup testing Signed-off-by: Cole Robinson --- tests/uitests/test_connection.py | 5 +++++ virtManager/connection.py | 10 ++++++++-- virtManager/lib/testmock.py | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/uitests/test_connection.py b/tests/uitests/test_connection.py index 5f9faf071..984e53055 100644 --- a/tests/uitests/test_connection.py +++ b/tests/uitests/test_connection.py @@ -105,3 +105,8 @@ class UITestConnection(uiutils.UITestCase): uiutils.check(lambda: not dialog.showing) self._click_alert_button("Unable to connect", "Close") manager.find("test testdriver.xml - Not Connected", "table cell") + + def testConnectionSessionError(self): + self.app.open( + extra_opts=["--test-options=fake-session-error"]) + self._click_alert_button("Could not detect a local session", "Close") diff --git a/virtManager/connection.py b/virtManager/connection.py index 97148ad04..8aefc6738 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -915,6 +915,11 @@ class vmmConnection(vmmGObject): data = self if self.config.CLITestOptions.fake_openauth: testmock.fake_openauth(self, cb, data) + if self.config.CLITestOptions.fake_session_error: + lerr = libvirt.libvirtError("fake session error") + lerr.err = [libvirt.VIR_ERR_AUTH_FAILED, None, + "fake session error not authorized"] + raise lerr self._backend.open(cb, data) return True, None except Exception as e: @@ -935,8 +940,9 @@ class vmmConnection(vmmGObject): log.debug("Looks like we might have failed policykit " "auth. Checking to see if we have a valid " "console session") - if (not self.is_remote() and - not connectauth.do_we_have_session()): + if not self.is_remote(): + warnconsole = bool(not connectauth.do_we_have_session()) + if self.config.CLITestOptions.fake_session_error: warnconsole = True ConnectError = connectauth.connect_error( diff --git a/virtManager/lib/testmock.py b/virtManager/lib/testmock.py index d3d51a1c1..0780601e3 100644 --- a/virtManager/lib/testmock.py +++ b/virtManager/lib/testmock.py @@ -165,6 +165,8 @@ class CLITestOptionsClass: * fake-nodedev-event: Fake nodedev API events * fake-openauth: Fake user+pass response from libvirt openauth, for testing the TCP URI auth dialog + * fake-session-error: Fake a connection open error that + triggers logind session lookup """ def __init__(self, test_options_str): optset = set() @@ -208,6 +210,7 @@ class CLITestOptionsClass: self.fake_agent_event = _get_value("fake-agent-event") self.fake_nodedev_event = _get_value("fake-nodedev-event") self.fake_openauth = _get("fake-openauth") + self.fake_session_error = _get("fake-session-error") if optset: # pragma: no cover raise RuntimeError("Unknown --test-options keys: %s" % optset)