Make cluster setup easier to navigate and verify
This commit is contained in:
1 parent
185be0fa62
commit
8c33cb07af
11 files changed
+615
-72
No files matched your search
@@ -7,12 +7,16 @@ from io import StringIO
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from deploy.panel_installer import cluster
|
||||
from deploy.panel_installer import cluster, remote, ssh_keys
|
||||
from deploy.panel_installer.cli import (
|
||||
interactive_configuration,
|
||||
main,
|
||||
write_interactive_plan,
|
||||
)
|
||||
from deploy.panel_installer.cluster_wizard import (
|
||||
collect_cluster,
|
||||
panel_defaults,
|
||||
)
|
||||
from deploy.panel_installer.config import InstallError, parse_plan
|
||||
from deploy.panel_installer.terminal import PlainTerminal
|
||||
|
||||
@@ -203,6 +207,97 @@ class ClusterInstallerTests(unittest.TestCase):
|
||||
with self.assertRaises(InstallError):
|
||||
parse_plan(self.config)
|
||||
|
||||
def test_new_panels_inherit_only_reusable_defaults(self):
|
||||
draft = self.config["cluster"]
|
||||
previous = draft["panels"][1]
|
||||
previous["dns"] = "local"
|
||||
previous["hosting"] = {
|
||||
"nameservers": ["ns.example.net"],
|
||||
"public_addresses": ["192.0.2.22"],
|
||||
}
|
||||
defaults = panel_defaults(draft, 2)
|
||||
self.assertEqual(defaults["panel"], {"access": "acme"})
|
||||
self.assertEqual(defaults["admin"], {"email": "ops@example.net"})
|
||||
self.assertEqual(defaults["dns"], "local")
|
||||
self.assertEqual(
|
||||
defaults["hosting"], {"nameservers": ["ns.example.net"]}
|
||||
)
|
||||
self.assertEqual(
|
||||
defaults["ssh"],
|
||||
{
|
||||
"ssh_user": "root",
|
||||
"ssh_identity": "/root/cluster-admin",
|
||||
},
|
||||
)
|
||||
self.assertNotIn("domains", defaults)
|
||||
|
||||
def test_review_retries_a_failed_preflight_before_offering_install(self):
|
||||
terminal = Mock(spec=PlainTerminal)
|
||||
terminal.choose.side_effect = ("check connections", "retry", "install")
|
||||
with (
|
||||
patch(
|
||||
"deploy.panel_installer.cluster_wizard.collect_inventory",
|
||||
return_value=self.config["cluster"],
|
||||
),
|
||||
patch(
|
||||
"deploy.panel_installer.cluster_wizard.ClusterInstaller"
|
||||
) as installer,
|
||||
):
|
||||
installer.return_value.check.side_effect = (
|
||||
InstallError("Check sudo."),
|
||||
None,
|
||||
)
|
||||
self.assertIsNotNone(collect_cluster(terminal))
|
||||
self.assertEqual(installer.return_value.check.call_count, 2)
|
||||
installer.return_value.install.assert_not_called()
|
||||
choices = [call.args[1] for call in terminal.choose.call_args_list]
|
||||
self.assertNotIn("install", choices[0])
|
||||
self.assertIn("install", choices[-1])
|
||||
terminal.error.assert_called_once()
|
||||
|
||||
def test_known_hosts_only_offers_trusted_unrevoked_keys(self):
|
||||
entries = (
|
||||
"# Host [192.0.2.22]:2222 found: line 1\n"
|
||||
"|1|hash ssh-ed25519 revoked\n"
|
||||
"@revoked [192.0.2.22]:2222 ssh-ed25519 revoked\n"
|
||||
"@cert-authority [192.0.2.22]:2222 ssh-ed25519 ca\n"
|
||||
"|1|hash ssh-ed25519 accepted\n"
|
||||
)
|
||||
with (
|
||||
patch.object(ssh_keys, "root_controlled", return_value=True),
|
||||
patch.object(
|
||||
ssh_keys.engine, "run", return_value=entries
|
||||
) as command,
|
||||
patch.object(
|
||||
ssh_keys,
|
||||
"fingerprint",
|
||||
side_effect=("SHA256:revoked", "SHA256:valid"),
|
||||
),
|
||||
):
|
||||
keys = ssh_keys.trusted_keys("192.0.2.22", 2222)
|
||||
self.assertEqual(
|
||||
keys, {"ssh-ed25519 SHA256:valid": "ssh-ed25519 accepted"}
|
||||
)
|
||||
self.assertIn("[192.0.2.22]:2222", command.call_args.args)
|
||||
|
||||
def test_preflight_distinguishes_ssh_authentication_and_sudo_failures(
|
||||
self,
|
||||
):
|
||||
self.assertIn(
|
||||
"authorize the matching public key",
|
||||
remote.ssh_failure(
|
||||
255, b"root@host: Permission denied (publickey)."
|
||||
),
|
||||
)
|
||||
self.assertIn(
|
||||
"noninteractive sudo",
|
||||
remote.ssh_failure(1, b"sudo: a password is required"),
|
||||
)
|
||||
self.assertIn(
|
||||
"host key did not match",
|
||||
remote.ssh_failure(255, b"Host key verification failed."),
|
||||
)
|
||||
|
||||
def test_cluster_is_a_topology_in_the_interactive_entry_point(self):
|
||||
inputs = [
|
||||
"cluster",
|
||||
|
||||
@@ -215,7 +215,7 @@ class InstallerParametersTests(unittest.TestCase):
|
||||
"edit",
|
||||
"192.0.2.34",
|
||||
"",
|
||||
"",
|
||||
str(host_key),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
|
||||
Reference in new issue
Block a user