diff --git a/.github/workflows/test-and-deploy-ipv4only.yaml b/.github/workflows/test-and-deploy-ipv4only.yaml index ecc79def..158bab98 100644 --- a/.github/workflows/test-and-deploy-ipv4only.yaml +++ b/.github/workflows/test-and-deploy-ipv4only.yaml @@ -71,25 +71,35 @@ jobs: - name: run deploy-chatmail offline tests run: pytest --pyargs cmdeploy - - run: | - cmdeploy init staging-ipv4.testrun.org - sed -i 's#disable_ipv6 = False#disable_ipv6 = True#' chatmail.ini - sed -i 's/#\s*mtail_address/mtail_address/' chatmail.ini - cmdeploy run --verbose --skip-dns-check + - name: setup dependencies + run: | + ssh root@staging-ipv4.testrun.org apt update + ssh root@staging-ipv4.testrun.org apt install -y git python3.11-venv python3-dev gcc + ssh root@staging-ipv4.testrun.org git clone https://github.com/chatmail/relay + ssh root@staging-ipv4.testrun.org "cd relay && git checkout " ${{ github.head_ref }} + ssh root@staging-ipv4.testrun.org "cd relay && scripts/initenv.sh" + + - name: initialize config + run: | + ssh root@staging-ipv4.testrun.org "cd relay && scripts/cmdeploy init staging-ipv4.testrun.org" + ssh root@staging-ipv4.testrun.org "sed -i 's#disable_ipv6 = False#disable_ipv6 = True#' relay/chatmail.ini" + ssh root@staging-ipv4.testrun.org "sed -i 's/#\s*mtail_address/mtail_address/' relay/chatmail.ini" + + - run: ssh root@staging-ipv4.testrun.org "cd relay && scripts/cmdeploy run --verbose --skip-dns-check --ssh-host localhost" - name: set DNS entries run: | - ssh -o StrictHostKeyChecking=accept-new -v root@staging-ipv4.testrun.org chown opendkim:opendkim -R /etc/dkimkeys - cmdeploy dns --zonefile staging-generated.zone - cat staging-generated.zone >> .github/workflows/staging-ipv4.testrun.org-default.zone + ssh root@staging-ipv4.testrun.org chown opendkim:opendkim -R /etc/dkimkeys + ssh root@staging-ipv4.testrun.org "cd relay && scripts/cmdeploy dns --zonefile staging-generated.zone --ssh-host localhost" + ssh root@staging-ipv4.testrun.org cat relay/staging-generated.zone >> .github/workflows/staging-ipv4.testrun.org-default.zone cat .github/workflows/staging-ipv4.testrun.org-default.zone scp .github/workflows/staging-ipv4.testrun.org-default.zone root@ns.testrun.org:/etc/nsd/staging-ipv4.testrun.org.zone ssh root@ns.testrun.org nsd-checkzone staging-ipv4.testrun.org /etc/nsd/staging-ipv4.testrun.org.zone ssh root@ns.testrun.org systemctl reload nsd - name: cmdeploy test - run: CHATMAIL_DOMAIN2=ci-chatmail.testrun.org cmdeploy test --slow + run: ssh root@staging-ipv4.testrun.org "cd relay && CHATMAIL_DOMAIN2=ci-chatmail.testrun.org scripts/cmdeploy test --slow --ssh-host localhost" - name: cmdeploy dns - run: cmdeploy dns -v + run: ssh root@staging-ipv4.testrun.org "cd relay && scripts/cmdeploy dns -v --ssh-host localhost" diff --git a/cmdeploy/src/cmdeploy/cmdeploy.py b/cmdeploy/src/cmdeploy/cmdeploy.py index 9fd9763f..260ef561 100644 --- a/cmdeploy/src/cmdeploy/cmdeploy.py +++ b/cmdeploy/src/cmdeploy/cmdeploy.py @@ -207,6 +207,7 @@ def test_cmd_options(parser): action="store_true", help="also run slow tests", ) + add_ssh_host_option(parser) def test_cmd(args, out): @@ -218,6 +219,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 = [ @@ -231,7 +235,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/service/chatmail-metadata.service.f b/cmdeploy/src/cmdeploy/service/chatmail-metadata.service.f index 968b4885..d9bdebe0 100644 --- a/cmdeploy/src/cmdeploy/service/chatmail-metadata.service.f +++ b/cmdeploy/src/cmdeploy/service/chatmail-metadata.service.f @@ -4,7 +4,7 @@ Description=Chatmail dict proxy for IMAP METADATA [Service] ExecStart={execpath} /run/chatmail-metadata/metadata.socket {config_path} Restart=always -RestartSec=30 +RestartSec=5 User=vmail RuntimeDirectory=chatmail-metadata UMask=0077 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 af57816e..50ca14b6 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 a87081fd..b1644794 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 @@ -91,7 +91,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 6bef2e7e..60d27efc 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -361,8 +361,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: