Guide interactive installation through a terminal wizard
This commit is contained in:
1 parent
f18470090b
commit
aa3b776809
8 files changed
+1124
-274
No files matched your search
@@ -3,7 +3,7 @@ import shlex
|
||||
import stat
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import redirect_stdout
|
||||
from contextlib import redirect_stderr, redirect_stdout
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
@@ -11,7 +11,9 @@ from unittest.mock import Mock, patch
|
||||
|
||||
from deploy.panel_installer.cli import (
|
||||
export_parameters,
|
||||
install,
|
||||
interactive_plan,
|
||||
main,
|
||||
save_interactive_plan,
|
||||
)
|
||||
from deploy.panel_installer.config import (
|
||||
@@ -143,15 +145,15 @@ class InstallerParametersTests(unittest.TestCase):
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path = Path(folder) / "panel.toml"
|
||||
with patch(
|
||||
"deploy.panel_installer.cli.prompt", return_value=str(path)
|
||||
):
|
||||
with patch("builtins.input", return_value=str(path)):
|
||||
save_interactive_plan(plan, None)
|
||||
self.assertEqual(stat.S_IMODE(path.stat().st_mode), 0o600)
|
||||
self.assertEqual(parse_plan(read_plan(path)), plan)
|
||||
|
||||
def test_interactive_hosting_hints_explain_dns_and_keep_defaults(self):
|
||||
replies = [
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"panel.example.net",
|
||||
"",
|
||||
@@ -159,11 +161,10 @@ class InstallerParametersTests(unittest.TestCase):
|
||||
"ops@example.net",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"192.0.2.21",
|
||||
"ns1.example.net",
|
||||
"",
|
||||
"install",
|
||||
]
|
||||
output = StringIO()
|
||||
with (
|
||||
@@ -183,6 +184,163 @@ class InstallerParametersTests(unittest.TestCase):
|
||||
)
|
||||
self.assertIn("SPF and managed mail DNS", output.getvalue())
|
||||
|
||||
def test_distributed_wizard_corrects_inputs_and_retries_preflight(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
host_key = Path(folder) / "ssh_host_ed25519_key.pub"
|
||||
host_key.write_text("ssh-ed25519 fixture-key\n")
|
||||
responses = (
|
||||
"distributed",
|
||||
"local",
|
||||
"",
|
||||
"panel.example.net",
|
||||
"",
|
||||
"",
|
||||
"ops",
|
||||
"ops@example.net",
|
||||
"coulobre-mail",
|
||||
"192.0.2.33",
|
||||
"70000",
|
||||
"",
|
||||
str(host_key.with_name("missing.pub")),
|
||||
str(host_key),
|
||||
"root",
|
||||
"/root/ssh-admin",
|
||||
"mail.example.net",
|
||||
"",
|
||||
"192.0.2.22",
|
||||
"ns1.example.net",
|
||||
"192.168.1.33",
|
||||
"93.184.215.14",
|
||||
"install",
|
||||
"edit",
|
||||
"192.0.2.34",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"install",
|
||||
)
|
||||
output, errors = StringIO(), StringIO()
|
||||
with (
|
||||
patch("builtins.input", side_effect=responses),
|
||||
patch("deploy.panel_installer.interactive.root_file"),
|
||||
patch("deploy.panel_installer.interactive.run"),
|
||||
patch(
|
||||
"deploy.panel_installer.remote.ssh_bootstrap",
|
||||
side_effect=[InstallError("Connection failed."), None],
|
||||
) as preflight,
|
||||
redirect_stdout(output),
|
||||
redirect_stderr(errors),
|
||||
):
|
||||
plan = interactive_plan()
|
||||
|
||||
self.assertEqual(plan.hostname, "panel.example.net")
|
||||
self.assertEqual(plan.dns.mode, "local")
|
||||
self.assertEqual(plan.mail.host, "192.0.2.34")
|
||||
self.assertEqual(plan.mail.mail_hostname, "mail.example.net")
|
||||
self.assertEqual(plan.mail.tls, "acme")
|
||||
self.assertEqual(plan.hosting.public_addresses, ("192.0.2.22",))
|
||||
self.assertEqual(
|
||||
plan.hosting.mail_sending_addresses, ("93.184.215.14",)
|
||||
)
|
||||
self.assertEqual(preflight.call_count, 2)
|
||||
self.assertTrue(
|
||||
all(call.kwargs["check"] for call in preflight.mock_calls)
|
||||
)
|
||||
self.assertIn("fully qualified SSH hostname", errors.getvalue())
|
||||
self.assertIn("port from 1 to 65535", errors.getvalue())
|
||||
self.assertIn("verified mail server host key", errors.getvalue())
|
||||
self.assertIn("administrator email address", errors.getvalue())
|
||||
self.assertIn(
|
||||
"public IP addresses for outgoing mail", errors.getvalue()
|
||||
)
|
||||
self.assertLess(
|
||||
output.getvalue().index("=== Deployment topology ==="),
|
||||
output.getvalue().index("=== Email service ==="),
|
||||
)
|
||||
self.assertNotIn("/root/ssh-admin", output.getvalue())
|
||||
|
||||
def test_cancel_from_review_does_not_start_installation(self):
|
||||
replies = (
|
||||
"custom",
|
||||
"",
|
||||
"",
|
||||
"panel.example.net",
|
||||
"",
|
||||
"",
|
||||
"ops@example.net",
|
||||
"",
|
||||
"cancel",
|
||||
)
|
||||
with (
|
||||
patch("builtins.input", side_effect=replies),
|
||||
patch("deploy.panel_installer.cli.platform_settings"),
|
||||
patch("deploy.panel_installer.cli.os.geteuid", return_value=0),
|
||||
patch("deploy.panel_installer.cli.Installer") as installer,
|
||||
patch("deploy.panel_installer.cli.get_password") as password,
|
||||
redirect_stdout(StringIO()),
|
||||
):
|
||||
self.assertEqual(main(["--interactive"]), 0)
|
||||
installer.assert_not_called()
|
||||
password.assert_not_called()
|
||||
|
||||
def test_review_can_edit_only_the_panel_section(self):
|
||||
replies = (
|
||||
"custom",
|
||||
"",
|
||||
"",
|
||||
"first.example.net",
|
||||
"",
|
||||
"ops",
|
||||
"ops@example.net",
|
||||
"192.0.2.23",
|
||||
"edit",
|
||||
"panel",
|
||||
"second.example.net",
|
||||
"",
|
||||
"install",
|
||||
)
|
||||
with (
|
||||
patch("builtins.input", side_effect=replies),
|
||||
redirect_stdout(StringIO()),
|
||||
):
|
||||
plan = interactive_plan()
|
||||
|
||||
self.assertEqual(plan.hostname, "second.example.net")
|
||||
self.assertEqual(plan.admin_username, "ops")
|
||||
self.assertEqual(plan.hosting.public_addresses, ("192.0.2.23",))
|
||||
|
||||
def test_retry_resumes_with_the_same_plan_and_password(self):
|
||||
plan = parse_plan({"panel": PROXY, "admin": ADMIN})
|
||||
with (
|
||||
patch(
|
||||
"deploy.panel_installer.cli.Installer",
|
||||
side_effect=[
|
||||
Mock(
|
||||
install=Mock(
|
||||
side_effect=InstallError("Database failed.")
|
||||
)
|
||||
),
|
||||
Mock(),
|
||||
],
|
||||
) as installer,
|
||||
patch("builtins.input", return_value="retry"),
|
||||
redirect_stdout(StringIO()),
|
||||
redirect_stderr(StringIO()),
|
||||
):
|
||||
self.assertEqual(
|
||||
install(plan, "fixture-password", interactive=True), 0
|
||||
)
|
||||
self.assertEqual(
|
||||
[call.args[:2] for call in installer.call_args_list],
|
||||
[(plan, "fixture-password"), (plan, "fixture-password")],
|
||||
)
|
||||
|
||||
def test_browser_and_parameter_file_share_the_same_plan(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
params = Path(folder) / "panel.toml"
|
||||
@@ -253,21 +411,23 @@ class InstallerParametersTests(unittest.TestCase):
|
||||
)
|
||||
inputs = (
|
||||
"custom",
|
||||
"off",
|
||||
"remote",
|
||||
"panel.example.net",
|
||||
"acme",
|
||||
ADMIN["username"],
|
||||
ADMIN["email"],
|
||||
"off",
|
||||
"remote",
|
||||
"192.0.2.41",
|
||||
"",
|
||||
str(path),
|
||||
"mail.example.net",
|
||||
"",
|
||||
"93.184.215.14",
|
||||
"install",
|
||||
)
|
||||
with (
|
||||
patch("builtins.input", side_effect=inputs),
|
||||
patch("deploy.panel_installer.interactive.run"),
|
||||
redirect_stdout(StringIO()),
|
||||
):
|
||||
cli = interactive_plan()
|
||||
|
||||
Reference in new issue
Block a user