GRM-17: fix grm list still showing unknown status for active runners

- run_ad_hoc() now accepts ask_become_pass and check parameters
- list_runners() passes ask_become_pass=True so --ask-become-pass is
  added when running in a TTY, matching playbook behavior
- list_runners() passes check=False so systemctl is-active non-zero
  exit codes (inactive=3, unknown=4) don't raise exceptions; the
  actual status string is parsed from stdout instead
- TTY guard prevents --ask-become-pass from hanging in non-interactive
  environments (CI, scripts)
- 123 tests, 100% coverage, pyright clean, ruff clean
This commit is contained in:
Emil Simeonov
2026-06-19 02:24:03 +02:00
parent ebb1088a8c
commit 51f204f90a
4 changed files with 70 additions and 3 deletions
+48
View File
@@ -207,6 +207,54 @@ class TestAnsibleExecutorAdHoc:
cmd = mock_run.call_args.args[0]
assert "--become" in cmd
def test_run_ad_hoc_with_ask_become_pass(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:
with patch("sys.stdin.isatty", return_value=True):
result = executor.run_ad_hoc(
"10.0.0.1", "ubuntu", None, "shell", "cmd", become=True, ask_become_pass=True
)
assert result == "ok"
cmd = mock_run.call_args.args[0]
assert "--become" in cmd
assert "--ask-become-pass" in cmd
def test_run_ad_hoc_ask_become_pass_no_tty(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:
with patch("sys.stdin.isatty", return_value=False):
result = executor.run_ad_hoc(
"10.0.0.1", "ubuntu", None, "shell", "cmd", become=True, ask_become_pass=True
)
assert result == "ok"
cmd = mock_run.call_args.args[0]
assert "--become" in cmd
assert "--ask-become-pass" not in cmd
def test_run_ad_hoc_check_false(self, tmp_path: Path) -> None:
executor = AnsibleExecutor(log_dir=tmp_path)
result_mock = MagicMock()
result_mock.stdout = "inactive\n"
result_mock.returncode = 3
result_mock.stderr = ""
with patch("subprocess.run", return_value=result_mock):
result = executor.run_ad_hoc("10.0.0.1", "ubuntu", None, "shell", "systemctl is-active svc", check=False)
assert result == "inactive"
def test_run_ad_hoc_failure_raises(self, tmp_path: Path) -> None:
executor = AnsibleExecutor(log_dir=tmp_path)
result_mock = MagicMock()