GRM-9: feat: add runner registry for simplified CLI UX
This commit is contained in:
@@ -155,3 +155,45 @@ class TestAnsibleExecutorTranslation:
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "[GRM] Running Ansible playbook" in captured.out # English fallback
|
||||
|
||||
|
||||
class TestAnsibleExecutorAdHoc:
|
||||
def test_run_ad_hoc_success(self, tmp_path: Path) -> None:
|
||||
executor = AnsibleExecutor(log_dir=tmp_path)
|
||||
result_mock = MagicMock()
|
||||
result_mock.stdout = "active\n"
|
||||
result_mock.returncode = 0
|
||||
result_mock.stderr = ""
|
||||
|
||||
with patch("subprocess.run", return_value=result_mock):
|
||||
result = executor.run_ad_hoc("10.0.0.1", "ubuntu", "/key", "shell", "systemctl is-active svc")
|
||||
|
||||
assert result == "active"
|
||||
|
||||
def test_run_ad_hoc_without_key(self, tmp_path: Path) -> None:
|
||||
executor = AnsibleExecutor(log_dir=tmp_path)
|
||||
result_mock = MagicMock()
|
||||
result_mock.stdout = "inactive\n"
|
||||
result_mock.returncode = 0
|
||||
result_mock.stderr = ""
|
||||
|
||||
with patch("subprocess.run", return_value=result_mock) as mock_run:
|
||||
result = executor.run_ad_hoc("10.0.0.1", "ubuntu", None, "shell", "cmd")
|
||||
|
||||
assert result == "inactive"
|
||||
cmd = mock_run.call_args.args[0]
|
||||
assert "--private-key" not in cmd
|
||||
|
||||
def test_run_ad_hoc_with_become(self, tmp_path: Path) -> None:
|
||||
executor = AnsibleExecutor(log_dir=tmp_path)
|
||||
result_mock = MagicMock()
|
||||
result_mock.stdout = "ok\n"
|
||||
result_mock.returncode = 0
|
||||
result_mock.stderr = ""
|
||||
|
||||
with patch("subprocess.run", return_value=result_mock) as mock_run:
|
||||
result = executor.run_ad_hoc("10.0.0.1", "ubuntu", None, "shell", "cmd", become=True)
|
||||
|
||||
assert result == "ok"
|
||||
cmd = mock_run.call_args.args[0]
|
||||
assert "--become" in cmd
|
||||
|
||||
Reference in New Issue
Block a user