diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index eddbc89b..497d6bb7 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -203,6 +203,7 @@ def test_cmd_options(parser): action="store_true", help="also run slow tests", ) + add_ssh_host_option(parser) def test_cmd(args, out): @@ -214,6 +215,9 @@ def test_cmd(args, out): x = importlib.util.find_spec("deltachat") if x is None: out.check_call(f"{sys.executable} -m pip install deltachat") + env = os.environ.copy() + if args.ssh_host: + env["CHATMAIL_SSH"] = args.ssh_host pytest_path = shutil.which("pytest") pytest_args = [ @@ -227,7 +231,7 @@ def test_cmd(args, out): ] if args.slow: pytest_args.append("--slow") - ret = out.run_ret(pytest_args) + ret = out.run_ret(pytest_args, env=env) return ret diff --git a/cmdeploy/src/cmdeploy/sshexec.py b/cmdeploy/src/cmdeploy/sshexec.py index c8dd2c79..7470d927 100644 --- a/cmdeploy/src/cmdeploy/sshexec.py +++ b/cmdeploy/src/cmdeploy/sshexec.py @@ -85,16 +85,31 @@ class SSHExec: class LocalExec: + FuncError = FuncError + def __init__(self, verbose=False, docker=False): self.verbose = verbose self.docker = docker + def __call__(self, call, kwargs=None, log_callback=None): + if kwargs is None: + kwargs = {} + return call(**kwargs) + def logged(self, call, kwargs: dict): + title = call.__doc__ + if not title: + title = call.__name__ where = "locally" if self.docker: if call == remote.rdns.perform_initial_checks: kwargs["pre_command"] = "docker exec chatmail " where = "in docker" if self.verbose: - print(f"Running {where}: {call.__name__}(**{kwargs})") - return call(**kwargs) + print_stderr(f"Running {where}: {title}(**{kwargs})") + return self(call, kwargs, log_callback=print_stderr) + else: + print_stderr(title, end="") + res = self(call, kwargs, log_callback=remote.rshell.log_progress) + print_stderr() + return res diff --git a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py index c8525125..61f34381 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py @@ -7,13 +7,13 @@ import time import pytest from cmdeploy import remote -from cmdeploy.sshexec import SSHExec +from cmdeploy.cmdeploy import get_sshexec class TestSSHExecutor: @pytest.fixture(scope="class") def sshexec(self, sshdomain): - return SSHExec(sshdomain) + return get_sshexec(sshdomain) def test_ls(self, sshexec): out = sshexec(call=remote.rdns.shell, kwargs=dict(command="ls")) @@ -27,6 +27,7 @@ class TestSSHExecutor: assert res["A"] or res["AAAA"] def test_logged(self, sshexec, maildomain, capsys): + sshexec.verbose = False sshexec.logged( remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=maildomain) ) @@ -52,6 +53,8 @@ class TestSSHExecutor: remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=None), ) + except AssertionError: + pass except sshexec.FuncError as e: assert "rdns.py" in str(e) assert "AssertionError" in str(e) diff --git a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py index c0cb85e6..2a0527c6 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py @@ -7,7 +7,7 @@ import pytest import requests from cmdeploy.remote import rshell -from cmdeploy.sshexec import SSHExec +from cmdeploy.cmdeploy import get_sshexec @pytest.fixture @@ -90,7 +90,7 @@ class TestEndToEndDeltaChat: lp.sec(f"filling remote inbox for {user}") fn = f"7743102289.M843172P2484002.c20,S={quota},W=2398:2," path = chatmail_config.mailboxes_dir.joinpath(user, "cur", fn) - sshexec = SSHExec(sshdomain) + sshexec = get_sshexec(sshdomain) sshexec(call=rshell.write_numbytes, kwargs=dict(path=str(path), num=120)) res = sshexec(call=rshell.dovecot_recalc_quota, kwargs=dict(user=user)) assert res["percent"] >= 100 diff --git a/cmdeploy/src/cmdeploy/tests/online/test_3_status.py b/cmdeploy/src/cmdeploy/tests/online/test_3_status.py index 1783c32e..d505faf7 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_3_status.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_3_status.py @@ -5,7 +5,11 @@ from cmdeploy.cmdeploy import main def test_status_cmd(chatmail_config, capsys, request): os.chdir(request.config.invocation_params.dir) - assert main(["status"]) == 0 + command = ["status"] + if os.getenv("CHATMAIL_SSH"): + command.append("--ssh-host") + command.append(os.getenv("CHATMAIL_SSH")) + assert main(command) == 0 status_out = capsys.readouterr() print(status_out.out) diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index 6037518b..67d07ccf 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -337,8 +337,14 @@ class Remote: def iter_output(self, logcmd=""): getjournal = "journalctl -f" if not logcmd else logcmd + print(self.sshdomain) + match self.sshdomain: + case "@local": command = [] + case "localhost": command = [] + case _: command = ["ssh", f"root@{self.sshdomain}"] + [command.append(arg) for arg in getjournal.split()] self.popen = subprocess.Popen( - ["ssh", f"root@{self.sshdomain}", getjournal], + command, stdout=subprocess.PIPE, ) while 1: