Skip to content

Commit

Permalink
Mail Results - Disable Plugin
Browse files Browse the repository at this point in the history
Plugin was attemtping SMTP connections regardless
of if the plugin config was using defaults.
Now checks on pre/post checks to stop attempted
SMTP connections before the plugin was disabled.

Signed-off-by:  <[email protected]>
  • Loading branch information
harvey0100 committed Aug 14, 2024
1 parent 4c590e2 commit cff205c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions optional_plugins/mail/avocado_result_mail/result_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(self):
settings.register_option(
section="plugins.mail",
key="recipient",
default="[email protected]",
default=None,
help_msg=help_msg,
)

Expand All @@ -38,31 +38,31 @@ def initialize(self):
settings.register_option(
section="plugins.mail",
key="sender",
default="[email protected]",
default=None,
help_msg=help_msg,
)

help_msg = "Mail server."
settings.register_option(
section="plugins.mail",
key="server",
default="localhost",
default=None,
help_msg=help_msg,
)

help_msg = "Mail server port."
settings.register_option(
section="plugins.mail",
key="port",
default=587,
default=None,
help_msg=help_msg,
)

help_msg = "Mail server Application Password."
settings.register_option(
section="plugins.mail",
key="password",
default="",
default=None,
help_msg=help_msg,
)

Expand Down Expand Up @@ -160,6 +160,10 @@ def _send_email(smtp, sender, rcpt, msg):

@staticmethod
def _smtp_login_and_send(job, msg):
if not job.config.get("plugins.mail.server"):
job_log.error("SMTP server not configured. Plugin Disabled.")
return False

server, port, sender, password = Mail._get_smtp_config(job)
smtp = Mail._create_smtp_connection(server, port)
if smtp:
Expand Down Expand Up @@ -257,6 +261,7 @@ def _get_test_summary(job):

def pre(self, job):
if not self.enabled:
job_log.info("Email plugin disabled, skipping start notification.")
return

phase = "Start"
Expand All @@ -268,6 +273,9 @@ def pre(self, job):

def post(self, job):
if not self.enabled or not self.start_email_sent:
job_log.info(
"Email plugin disabled or start email not sent, skipping end notification."
)
return

phase = "Post"
Expand All @@ -285,14 +293,10 @@ def post(self, job):
def _validate_email_config(self, job):
required_keys = ["recipient", "sender", "server", "port"]
for key in required_keys:
if not job.config.get(f"plugins.mail.{key}"):
if job.config.get(f"plugins.mail.{key}") is None:
job_log.error(
f"Email configuration {key} is missing. Disabling Plugin."
f"Email configuration {key} is missing or set to None. Disabling Plugin."
)
return False

if job.config.get("plugins.mail.sender") == "[email protected]":
job_log.error("Email sender is still set to default. Disabling Plugin.")
return False

return True

0 comments on commit cff205c

Please sign in to comment.