introduce remotelog fixture for capturing systemd-unit logs

This commit is contained in:
holger krekel
2023-10-16 18:13:14 +02:00
parent ea5eccf377
commit c2692c7e92
4 changed files with 25 additions and 16 deletions

View File

@@ -30,11 +30,8 @@ def maildomain():
@pytest.fixture
def chatmail_ssh(maildomain):
domain = os.environ.get("CHATMAIL_SSH")
if not domain:
domain = maildomain
return domain
def sshdomain(maildomain):
return os.environ.get("CHATMAIL_SSH", maildomain)
def pytest_report_header():
@@ -51,6 +48,7 @@ def imap(maildomain):
class ImapConn:
AuthError = imaplib.IMAP4.error
logunit = "dovecot"
def __init__(self, host):
self.host = host
@@ -71,6 +69,7 @@ def smtp(maildomain):
class SmtpConn:
AuthError = smtplib.SMTPAuthenticationError
logunit = "postfix"
def __init__(self, host):
self.host = host
@@ -158,13 +157,20 @@ def cmfactory(request, maildomain, gencreds, tmpdir, data):
@pytest.fixture
def dovelogreader(chatmail_ssh):
def remote_reader():
popen = subprocess.Popen(
["ssh", f"root@{chatmail_ssh}", "journalctl -f -u dovecot"],
def remotelog(sshdomain):
return RemoteLog(sshdomain)
class RemoteLog:
def __init__(self, sshdomain):
self.sshdomain = sshdomain
def iter(self, unit=""):
getjournal = f"journalctl -f -u {unit}" if unit else "journalctl -f"
self.popen = subprocess.Popen(
["ssh", f"root@{self.sshdomain}", getjournal],
stdout=subprocess.PIPE,
)
while 1:
yield popen.stdout.readline()
return remote_reader
line = self.popen.stdout.readline()
yield line.decode().strip().lower()

View File

@@ -0,0 +1,4 @@
def test_remotelog(remotelog, imap_or_smtp):
lineproducer = remotelog.iter(imap_or_smtp.logunit)
imap_or_smtp.connect()
assert imap_or_smtp.logunit in next(lineproducer)

View File

@@ -17,7 +17,7 @@ def test_login_basic_functioning(imap_or_smtp, gencreds, lp):
imap_or_smtp.connect()
lp.sec("success")
lp.sec("reconnect and verify wrong password fails {user} ")
lp.sec(f"reconnect and verify wrong password fails {user} ")
imap_or_smtp.connect()
with pytest.raises(imap_or_smtp.AuthError):
imap_or_smtp.login(user, password + "wrong")

View File

@@ -19,7 +19,7 @@ class TestEndToEndDeltaChat:
assert msg2.text == "message0"
@pytest.mark.slow
def test_exceed_quota(self, cmfactory, lp, tmpdir, dovelogreader):
def test_exceed_quota(self, cmfactory, lp, tmpdir, remotelog):
"""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.
"""
@@ -48,8 +48,7 @@ class TestEndToEndDeltaChat:
addr = ac2.get_config("addr").lower()
saved_ok = 0
for line in dovelogreader():
line = line.decode().lower().strip()
for line in remotelog.iter("dovecot"):
if addr not in line:
# print(line)
continue