Skip to content

Commit

Permalink
fix(setup): Display correct landscape-config command on snap (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw committed Mar 7, 2024
1 parent 5f0bdd7 commit 2614270
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
8 changes: 6 additions & 2 deletions landscape/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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))
Expand Down
59 changes: 59 additions & 0 deletions landscape/client/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 2614270

Please sign in to comment.