feat: bootstrap ssh-monitor updater when missing on host (0.20.2)
SAC now clones the ssh-monitor repo and installs update_ssh_monitor.sh before running the update when the remote updater script is absent.
This commit is contained in:
@@ -152,21 +152,70 @@ def test_run_ssh_command_auth_failure(monkeypatch):
|
||||
client.close.assert_called_once()
|
||||
|
||||
|
||||
def test_run_ssh_monitor_update_missing_script(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
ssh_connect,
|
||||
"run_ssh_command",
|
||||
lambda **kwargs: ssh_connect.SshCommandResult(
|
||||
def test_run_ssh_monitor_update_missing_script_bootstraps(monkeypatch):
|
||||
calls = 0
|
||||
|
||||
def fake_run(**kwargs):
|
||||
nonlocal calls
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
return ssh_connect.SshCommandResult(
|
||||
ok=True,
|
||||
message="ok",
|
||||
target="h",
|
||||
stdout="missing\n",
|
||||
)
|
||||
if calls == 2:
|
||||
cmd = kwargs["remote_cmd"]
|
||||
assert "git clone" in cmd
|
||||
assert "update_ssh_monitor.sh" in cmd
|
||||
assert kwargs.get("need_root") is True
|
||||
return ssh_connect.SshCommandResult(
|
||||
ok=True,
|
||||
message="SSH OK",
|
||||
target="185.87.149.9",
|
||||
stdout="SUMMARY updated 2.1.0-SAC\n",
|
||||
exit_code=0,
|
||||
)
|
||||
return ssh_connect.SshCommandResult(
|
||||
ok=True,
|
||||
message="ok",
|
||||
target="185.87.149.9",
|
||||
stdout="2.1.0-SAC\n",
|
||||
exit_code=0,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(ssh_connect, "run_ssh_command", fake_run)
|
||||
|
||||
result = run_ssh_monitor_update(target="185.87.149.9", user="root", password="pw")
|
||||
assert result.ok is True
|
||||
assert result.agent_version == "2.1.0-SAC"
|
||||
assert "Bootstrap" in result.message
|
||||
assert calls == 3
|
||||
|
||||
|
||||
def test_run_ssh_monitor_update_missing_script(monkeypatch):
|
||||
def fake_run(**kwargs):
|
||||
if kwargs["remote_cmd"].startswith("test -x"):
|
||||
return ssh_connect.SshCommandResult(
|
||||
ok=True,
|
||||
message="ok",
|
||||
target="h",
|
||||
stdout="missing\n",
|
||||
)
|
||||
return ssh_connect.SshCommandResult(
|
||||
ok=False,
|
||||
message="git clone failed",
|
||||
target="h",
|
||||
stdout="missing\n",
|
||||
),
|
||||
)
|
||||
stderr="fatal: could not read",
|
||||
exit_code=128,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(ssh_connect, "run_ssh_command", fake_run)
|
||||
|
||||
result = run_ssh_monitor_update(target="ubabuba", user="root", password="pw")
|
||||
assert result.ok is False
|
||||
assert "not found" in result.message.lower()
|
||||
assert "bootstrap failed" in result.message.lower()
|
||||
|
||||
|
||||
def test_run_ssh_monitor_update_runs_script(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user