From cabd4bdee1b27b8d62196f3c0ff633427d7be63a Mon Sep 17 00:00:00 2001 From: Stephen Mwangi Date: Thu, 7 Mar 2024 12:31:34 +0300 Subject: [PATCH] fix(setup): Display correct landscape-config command on snap --- landscape/client/configuration.py | 8 ++- landscape/client/tests/test_configuration.py | 59 ++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/landscape/client/configuration.py b/landscape/client/configuration.py index 759b45f75..f3ba91a55 100644 --- a/landscape/client/configuration.py +++ b/landscape/client/configuration.py @@ -14,6 +14,7 @@ from urllib.parse import urlparse from landscape.client import GROUP +from landscape.client import IS_SNAP from landscape.client import USER from landscape.client.broker.amp import RemoteBrokerConnector from landscape.client.broker.config import BrokerConfiguration @@ -507,7 +508,10 @@ def show_summary(self): "https_proxy", "http_proxy", ) - cmd = ["sudo", "landscape-config"] + cmd = [ + "sudo", + "landscape-client.config" if IS_SNAP else "landscape-config", + ] for param in params: value = self.config.get(param) if value: @@ -520,7 +524,7 @@ def show_summary(self): else: cmd.append(shlex.quote(value)) show_help( - "The landscape-config parameters to repeat this registration" + "The landscape config parameters to repeat this registration" " on another machine are:", ) show_help(" ".join(cmd)) diff --git a/landscape/client/tests/test_configuration.py b/landscape/client/tests/test_configuration.py index f026a842b..c15d06f0f 100644 --- a/landscape/client/tests/test_configuration.py +++ b/landscape/client/tests/test_configuration.py @@ -839,6 +839,65 @@ def side_effect_getpass(prompt): self.assertEqual(config.https_proxy, "https://new.proxy") self.assertEqual(config.include_manager_plugins, "") + @mock.patch("landscape.client.configuration.IS_SNAP", "1") + @mock.patch("landscape.client.configuration.print_text") + @mock.patch("landscape.client.configuration.getpass.getpass") + @mock.patch("landscape.client.configuration.input") + @mock.patch("landscape.client.configuration.show_help") + def test_setup_on_the_snap_version( + self, + mock_help, + mock_input, + mock_getpass, + mock_print_text, + ): + filename = self.makeFile( + "[client]\n" + "computer_title = Old Title\n" + "account_name = Old Name\n" + "registration_key = Old Password\n" + "http_proxy = http://old.proxy\n" + "https_proxy = https://old.proxy\n" + "url = http://url\n", + ) + + def side_effect_input(prompt): + fixtures = { + "[Old Title]": "New Title", + "[Old Name]": "New Name", + "[http://old.proxy]": "http://new.proxy", + "[https://old.proxy]": "https://new.proxy", + "Will you be using your own " + "Self-Hosted Landscape installation? [y/N]": "n", + } + for key, value in iteritems(fixtures): + if key in prompt: + return value + + def side_effect_getpass(prompt): + fixtures = { + "(Optional) Registration Key:": "New Password", + "Please confirm:": "New Password", + } + for key, value in iteritems(fixtures): + if key in prompt: + return value + + mock_input.side_effect = side_effect_input + mock_getpass.side_effect = side_effect_getpass + + config = self.get_config(["--no-start", "--config", filename]) + setup(config) + + self.assertEqual( + "sudo landscape-client.config " + "--account-name 'New Name' " + "--registration-key HIDDEN " + "--https-proxy https://new.proxy " + "--http-proxy http://new.proxy", + mock_help.mock_calls[-1].args[0], + ) + @mock.patch("landscape.client.configuration.ServiceConfig") def test_silent_setup(self, mock_serviceconfig): """