don't use env vars but explicit pytest options to pass ssh info around.

This commit is contained in:
holger krekel
2026-03-06 10:24:15 +01:00
parent 861fdf7a50
commit 49705863d3
6 changed files with 39 additions and 33 deletions

View File

@@ -249,10 +249,6 @@ def test_cmd(args, out):
env = os.environ.copy() env = os.environ.copy()
env["CHATMAIL_INI"] = str(args.inipath.resolve()) env["CHATMAIL_INI"] = str(args.inipath.resolve())
if args.ssh_host:
env["CHATMAIL_SSH"] = args.ssh_host
if args.ssh_config:
env["CHATMAIL_SSH_CONFIG"] = str(Path(args.ssh_config).resolve())
pytest_path = shutil.which("pytest") pytest_path = shutil.which("pytest")
pytest_args = [ pytest_args = [
@@ -266,6 +262,10 @@ def test_cmd(args, out):
] ]
if args.slow: if args.slow:
pytest_args.append("--slow") pytest_args.append("--slow")
if args.ssh_host:
pytest_args.extend(["--ssh-host", args.ssh_host])
if args.ssh_config:
pytest_args.extend(["--ssh-config", str(Path(args.ssh_config).resolve())])
ret = out.run_ret(pytest_args, env=env) ret = out.run_ret(pytest_args, env=env)
return ret return ret

View File

@@ -1,5 +1,4 @@
import datetime import datetime
import os
import smtplib import smtplib
import socket import socket
import subprocess import subprocess
@@ -13,8 +12,8 @@ from cmdeploy.cmdeploy import get_sshexec
class TestSSHExecutor: class TestSSHExecutor:
@pytest.fixture(scope="class") @pytest.fixture(scope="class")
def sshexec(self, sshdomain): def sshexec(self, sshdomain, pytestconfig):
ssh_config = os.environ.get("CHATMAIL_SSH_CONFIG") ssh_config = pytestconfig.getoption("ssh_config")
return get_sshexec(sshdomain, ssh_config=ssh_config) return get_sshexec(sshdomain, ssh_config=ssh_config)
def test_ls(self, sshexec): def test_ls(self, sshexec):

View File

@@ -1,5 +1,4 @@
import ipaddress import ipaddress
import os
import re import re
import time import time
@@ -68,7 +67,7 @@ class TestEndToEndDeltaChat:
assert msg2.get_snapshot().text == "message0" assert msg2.get_snapshot().text == "message0"
def test_exceed_quota( def test_exceed_quota(
self, cmfactory, lp, tmpdir, remote, chatmail_config, sshdomain self, cmfactory, lp, tmpdir, remote, chatmail_config, sshdomain, pytestconfig
): ):
"""This is a very slow test as it needs to upload >100MB of mail data """This is a very slow test as it needs to upload >100MB of mail data
before quota is exceeded, and thus depends on the speed of the upload. before quota is exceeded, and thus depends on the speed of the upload.
@@ -94,7 +93,7 @@ class TestEndToEndDeltaChat:
fn = f"7743102289.M843172P2484002.c20,S={quota},W=2398:2," fn = f"7743102289.M843172P2484002.c20,S={quota},W=2398:2,"
path = chatmail_config.mailboxes_dir.joinpath(user, "cur", fn) path = chatmail_config.mailboxes_dir.joinpath(user, "cur", fn)
sshexec = get_sshexec( sshexec = get_sshexec(
sshdomain, ssh_config=os.environ.get("CHATMAIL_SSH_CONFIG") sshdomain, ssh_config=pytestconfig.getoption("ssh_config")
) )
sshexec(call=rshell.write_numbytes, kwargs=dict(path=str(path), num=120)) sshexec(call=rshell.write_numbytes, kwargs=dict(path=str(path), num=120))
res = sshexec(call=rshell.dovecot_recalc_quota, kwargs=dict(user=user)) res = sshexec(call=rshell.dovecot_recalc_quota, kwargs=dict(user=user))

View File

@@ -3,15 +3,15 @@ import os
from cmdeploy.cmdeploy import main from cmdeploy.cmdeploy import main
def test_status_cmd(chatmail_config, capsys, request): def test_status_cmd(chatmail_config, capsys, request, pytestconfig):
os.chdir(request.config.invocation_params.dir) os.chdir(request.config.invocation_params.dir)
command = ["status"] command = ["status"]
if os.getenv("CHATMAIL_SSH"): ssh_host = pytestconfig.getoption("ssh_host")
command.append("--ssh-host") if ssh_host:
command.append(os.getenv("CHATMAIL_SSH")) command.extend(["--ssh-host", ssh_host])
if os.getenv("CHATMAIL_SSH_CONFIG"): ssh_config = pytestconfig.getoption("ssh_config")
command.append("--ssh-config") if ssh_config:
command.append(os.getenv("CHATMAIL_SSH_CONFIG")) command.extend(["--ssh-config", ssh_config])
assert main(command) == 0 assert main(command) == 0
status_out = capsys.readouterr() status_out = capsys.readouterr()
print(status_out.out) print(status_out.out)

View File

@@ -20,6 +20,18 @@ def pytest_addoption(parser):
parser.addoption( parser.addoption(
"--slow", action="store_true", default=False, help="also run slow tests" "--slow", action="store_true", default=False, help="also run slow tests"
) )
parser.addoption(
"--ssh-host",
dest="ssh_host",
default=None,
help="SSH host (overrides mail_domain for SSH operations).",
)
parser.addoption(
"--ssh-config",
dest="ssh_config",
default=None,
help="Path to an SSH config file (e.g. lxconfigs/ssh-config).",
)
def _parse_ssh_config_hosts(path): def _parse_ssh_config_hosts(path):
@@ -57,9 +69,9 @@ def _make_patched_getaddrinfo(host_map):
@pytest.fixture(autouse=True, scope="session") @pytest.fixture(autouse=True, scope="session")
def _setup_localchat_dns(): def _setup_localchat_dns(pytestconfig):
"""Monkey-patch socket.getaddrinfo to resolve .localchat via ssh-config.""" """Monkey-patch socket.getaddrinfo to resolve .localchat via ssh-config."""
ssh_config = os.environ.get("CHATMAIL_SSH_CONFIG") ssh_config = pytestconfig.getoption("ssh_config")
if not ssh_config or not Path(ssh_config).exists(): if not ssh_config or not Path(ssh_config).exists():
yield {} yield {}
return return
@@ -126,8 +138,8 @@ def maildomain(chatmail_config):
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def sshdomain(maildomain): def sshdomain(maildomain, pytestconfig):
return os.environ.get("CHATMAIL_SSH", maildomain) return pytestconfig.getoption("ssh_host") or maildomain
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@@ -471,14 +483,14 @@ def cmfactory(
@pytest.fixture @pytest.fixture
def remote(sshdomain): def remote(sshdomain, pytestconfig):
return Remote(sshdomain) return Remote(sshdomain, ssh_config=pytestconfig.getoption("ssh_config"))
class Remote: class Remote:
def __init__(self, sshdomain): def __init__(self, sshdomain, ssh_config=None):
self.sshdomain = sshdomain self.sshdomain = sshdomain
self.ssh_config = os.environ.get("CHATMAIL_SSH_CONFIG") self.ssh_config = ssh_config
def iter_output(self, logcmd="", ready=None): def iter_output(self, logcmd="", ready=None):
getjournal = "journalctl -f" if not logcmd else logcmd getjournal = "journalctl -f" if not logcmd else logcmd

View File

@@ -96,18 +96,14 @@ CLI reference
``lxc-stop [--destroy] [--destroy-all] [NAME ...]`` ``lxc-stop [--destroy] [--destroy-all] [NAME ...]``
Stop relay containers. Stop relay containers.
Without arguments, stops ``test0-localchat`` Without arguments, stops ``test0-localchat`` and ``test1-localchat``.
and ``test1-localchat``.
Pass ``NAME`` to stop specific containers. Pass ``NAME`` to stop specific containers.
Use ``--destroy`` to also delete the containers Use ``--destroy`` to also delete the containers and their config files.
and their config files.
Use ``--destroy-all`` to additionally destroy Use ``--destroy-all`` to additionally destroy
the ``ns-localchat`` DNS container **and** remove the ``ns-localchat`` DNS container **and** remove
the cached ``localchat-base`` and ``localchat-relay`` the cached ``localchat-base`` and ``localchat-relay``
images, giving a fully clean slate images, giving a fully clean slate for the next ``lxc-test``.
for the next ``lxc-test``. User containers are **never** destroyed unless named explicitly.
User containers are **never** destroyed
unless named explicitly.
``lxc-test [--one]`` ``lxc-test [--one]``
Idempotent full pipeline: Idempotent full pipeline: