summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorentin LABBE <clabbe@baylibre.com>2018-07-18 14:41:12 +0200
committerCorentin LABBE <clabbe@baylibre.com>2019-09-19 14:24:00 +0200
commitb8462ce7dd6e91f3c64761bca2322b35e3aa0ee7 (patch)
tree690b1ffa7009266f467f88754360d79ceaa12f94
parentb2cb84589ca69f14155ae695678c63a7733b55ef (diff)
Permit to custom SMTP server
This patch permits to specify a SMTP server which LAVA will use for report.
-rw-r--r--README.md8
-rwxr-xr-xlavalab-gen.py66
2 files changed, 71 insertions, 3 deletions
diff --git a/README.md b/README.md
index d7c4651..6776c84 100644
--- a/README.md
+++ b/README.md
@@ -247,6 +247,14 @@ masters:
- username: The LAVA user owning the token below. (This user should be created via users:)
token: The token for this callback
description: The description of this token. This string could be used with LAVA-CI.
+ smtp: WARNING: Usage of an SMTP server makes it mandatory for each user to have an email address
+ email_host: The host to use for sending email
+ email_host_user: Username to use for the SMTP server
+ email_host_password: Password to use for the SMTP server
+ email_port: Port to use for the SMTP server (default: 25)
+ email_use_tls: Whether to use a TLS (secure) connection when talking to the SMTP server
+ email_use_ssl: Whether to use an implicit TLS (secure) connection when talking to the SMTP server
+ email_backend: The backend to use for sending emails (default: 'django.core.mail.backends.smtp.EmailBackend')
slaveenv: A list of environment to pass to slave
- name: slavename The name of slave (mandatory)
env:
diff --git a/lavalab-gen.py b/lavalab-gen.py
index bf4fd2e..539d80c 100755
--- a/lavalab-gen.py
+++ b/lavalab-gen.py
@@ -64,7 +64,15 @@ template_settings_conf = string.Template("""
"ALLOWED_HOSTS": [ $allowed_hosts ],
"CSRF_TRUSTED_ORIGINS": ["$lava_http_fqdn"],
"CSRF_COOKIE_SECURE": $cookie_secure,
- "SESSION_COOKIE_SECURE": $session_cookie_secure
+ "SESSION_COOKIE_SECURE": $session_cookie_secure,
+ "SERVER_EMAIL": "$server_email",
+ "EMAIL_HOST": "$email_host",
+ "EMAIL_HOST_USER": "$email_host_user",
+ "EMAIL_HOST_PASSWORD": "$email_host_password",
+ "EMAIL_PORT": $email_port,
+ "EMAIL_USE_TLS": $email_use_tls,
+ "EMAIL_USE_SSL": $email_use_ssl,
+ "EMAIL_BACKEND": "$email_backend"
}
""")
@@ -105,7 +113,7 @@ def main():
else:
masters = workers["masters"]
for master in masters:
- keywords_master = [ "name", "type", "host", "users", "groups", "tokens", "webadmin_https", "persistent_db", "zmq_auth", "zmq_auth_key", "zmq_auth_key_secret", "http_fqdn", "slave_keys", "slaveenv", "loglevel", "allowed_hosts", "lava-coordinator", "healthcheck_url" ]
+ keywords_master = [ "name", "type", "host", "users", "groups", "tokens", "webadmin_https", "persistent_db", "zmq_auth", "zmq_auth_key", "zmq_auth_key_secret", "http_fqdn", "slave_keys", "slaveenv", "loglevel", "allowed_hosts", "lava-coordinator", "healthcheck_url", "smtp" ]
for keyword in master:
if not keyword in keywords_master:
print("WARNING: unknown keyword %s" % keyword)
@@ -185,8 +193,60 @@ def main():
f_fqdn = open("%s/lava_http_fqdn" % workerdir, 'w')
f_fqdn.write(lava_http_fqdn)
f_fqdn.close()
+ # DJANGO defaults
+ email_host = "localhost"
+ email_host_user = ""
+ email_host_password = ""
+ email_port = 25
+ email_use_tls = 'false'
+ email_use_ssl = 'false'
+ email_backend = 'django.core.mail.backends.smtp.EmailBackend'
+ server_email = "root@localhost"
+ if "smtp" in worker:
+ if "server_email" in worker["smtp"]:
+ server_email = worker["smtp"]["server_email"]
+ if "email_host" in worker["smtp"]:
+ email_host = worker["smtp"]["email_host"]
+ if "email_host_user" in worker["smtp"]:
+ email_host_user = worker["smtp"]["email_host_user"]
+ if "email_host_password" in worker["smtp"]:
+ email_host_password = worker["smtp"]["email_host_password"]
+ if "email_port" in worker["smtp"]:
+ email_port = worker["smtp"]["email_port"]
+ # django does not like True or False but want true/false (no upper case)
+ if "email_use_tls" in worker["smtp"]:
+ email_use_tls = worker["smtp"]["email_use_tls"]
+ if isinstance(email_use_tls, bool):
+ if email_use_tls:
+ email_use_tls = 'true'
+ else:
+ email_use_tls = 'false'
+ if "email_use_ssl" in worker["smtp"]:
+ email_use_ssl = worker["smtp"]["email_use_ssl"]
+ if isinstance(email_use_ssl, bool):
+ if email_use_ssl:
+ email_use_ssl = 'true'
+ else:
+ email_use_ssl = 'false'
+ if "email_backend" in worker["smtp"]:
+ email_backend = worker["smtp"]["email_backend"]
fsettings = open("%s/settings.conf" % workerdir, 'w')
- fsettings.write(template_settings_conf.substitute(cookie_secure=cookie_secure, session_cookie_secure=session_cookie_secure, lava_http_fqdn=lava_http_fqdn, allowed_hosts=allowed_hosts))
+ fsettings.write(
+ template_settings_conf.substitute(
+ cookie_secure=cookie_secure,
+ session_cookie_secure=session_cookie_secure,
+ lava_http_fqdn=lava_http_fqdn,
+ allowed_hosts=allowed_hosts,
+ email_host = email_host,
+ email_host_user = email_host_user,
+ email_host_password = email_host_password,
+ email_port = email_port,
+ email_use_tls = email_use_tls,
+ email_use_ssl = email_use_ssl,
+ email_backend = email_backend,
+ server_email = server_email
+ )
+ )
fsettings.close()
master_use_zmq_auth = False
if "zmq_auth" in worker: