Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(setup): display correct landscape config command on snap #227

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gentle reminder that mock.patch.multiple exists.

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
Loading