diff --git a/swh/vault/backend.py b/swh/vault/backend.py --- a/swh/vault/backend.py +++ b/swh/vault/backend.py @@ -75,7 +75,6 @@ self.cache = VaultCache(**config["cache"]) self.scheduler = get_scheduler(**config["scheduler"]) self.storage = get_storage(**config["storage"]) - self.smtp_server = smtplib.SMTP(**config.get("smtp", {})) if "db" not in self.config: raise ValueError( @@ -488,15 +487,17 @@ def _smtp_send(self, msg: MIMEText): # Reconnect if needed + smtp_server = smtplib.SMTP(**self.config.get("smtp", {})) try: - status = self.smtp_server.noop()[0] + status = smtp_server.noop()[0] except smtplib.SMTPException: status = -1 if status != 250: - self.smtp_server.connect("localhost", 25) + # XXX this is doomed + smtp_server.connect("localhost", 25) # Send the message - self.smtp_server.send_message(msg) + smtp_server.send_message(msg) @db_transaction() def _cache_expire(self, cond, *args, db=None, cur=None) -> None: diff --git a/swh/vault/tests/test_backend.py b/swh/vault/tests/test_backend.py --- a/swh/vault/tests/test_backend.py +++ b/swh/vault/tests/test_backend.py @@ -212,10 +212,10 @@ swh_vault.set_status(TEST_TYPE, TEST_SWHID, "done") - with patch.object(swh_vault, "smtp_server") as m: + with patch.object(swh_vault, "_smtp_send") as m: swh_vault.send_notif(TEST_TYPE, TEST_SWHID) - sent_emails = {k[0][0] for k in m.send_message.call_args_list} + sent_emails = {k[0][0] for k in m.call_args_list} assert {k["To"] for k in sent_emails} == set(emails) for e in sent_emails: @@ -327,10 +327,10 @@ swh_vault.set_status(TEST_TYPE, TEST_SWHID, "failed") swh_vault.set_progress(TEST_TYPE, TEST_SWHID, "test error") - with patch.object(swh_vault, "smtp_server") as m: + with patch.object(swh_vault, "_smtp_send") as m: swh_vault.send_notif(TEST_TYPE, TEST_SWHID) - e = [k[0][0] for k in m.send_message.call_args_list][0] + e = [k[0][0] for k in m.call_args_list][0] assert e["To"] == "a@example.com" assert "bot@softwareheritage.org" in e["From"]