Commit 877ea405 authored by Jérome Perrin's avatar Jérome Perrin

software/grafana: fix smtp_verify_ssl option handling

This software uses xml for parameters serialisation, so we can not use
boolean type. As a result, smtp_verify_ssl was always "true" and disabling ssl
verification was not working.

When accessing the smtp server from localhost, grafana attempt STARTLS and
verifies certificate, so scenarios of using localhost:25 as smtp server usually
needed smtp_verify_ssl="false".
parent 3501098b
...@@ -27,7 +27,7 @@ md5sum = a1a9c22c2a7829c66a49fc2504604d21 ...@@ -27,7 +27,7 @@ md5sum = a1a9c22c2a7829c66a49fc2504604d21
[grafana-config-file] [grafana-config-file]
filename = grafana-config-file.cfg.in filename = grafana-config-file.cfg.in
md5sum = 8244d430905b968795c7946049bed9e3 md5sum = e255dcca466f5de51698d24cbd114577
[grafana-provisioning-config-file] [grafana-provisioning-config-file]
filename = grafana-provisioning-config-file.cfg.in filename = grafana-provisioning-config-file.cfg.in
......
...@@ -346,7 +346,7 @@ password = {{ slapparameter_dict.get('smtp-password', '') and '"""%s"""' % slapp ...@@ -346,7 +346,7 @@ password = {{ slapparameter_dict.get('smtp-password', '') and '"""%s"""' % slapp
cert_file = cert_file =
key_file = key_file =
#skip_verify = false #skip_verify = false
skip_verify = {{ slapparameter_dict.get('smtp-verify-ssl', True) and 'false' or 'true' }} skip_verify = {{ slapparameter_dict.get('smtp-verify-ssl', 'true').lower() == 'true' and 'false' or 'true' }}
#from_address = admin@grafana.localhost #from_address = admin@grafana.localhost
from_address = {{ slapparameter_dict.get('email-from-address', '') }} from_address = {{ slapparameter_dict.get('email-from-address', '') }}
#from_name = Grafana #from_name = Grafana
......
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
}, },
"smtp-verify-ssl": { "smtp-verify-ssl": {
"description": "Verify SSL certificate of SMTP server", "description": "Verify SSL certificate of SMTP server",
"type": "boolean", "type": "string",
"default": true "enum": [
"true",
"false"
]
}, },
"email-from-address": { "email-from-address": {
"description": "Email address used in From: header of emails", "description": "Email address used in From: header of emails",
......
{ {
"name": "Grafana", "name": "Grafana",
"description": "Grafana, Telegraf and Influxdb", "description": "Grafana, Telegraf and Influxdb",
"serialisation": "json-in-xml", "serialisation": "xml",
"software-type": { "software-type": {
"default": { "default": {
"title": "Default", "title": "Default",
......
...@@ -45,6 +45,7 @@ setup( ...@@ -45,6 +45,7 @@ setup(
'slapos.libnetworkcache', 'slapos.libnetworkcache',
'erp5.util', 'erp5.util',
'requests', 'requests',
'six',
'supervisor', 'supervisor',
'psutil', 'psutil',
], ],
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
# #
############################################################################## ##############################################################################
from __future__ import unicode_literals
import io
import logging import logging
import os import os
import tempfile import tempfile
...@@ -33,6 +35,7 @@ import time ...@@ -33,6 +35,7 @@ import time
import psutil import psutil
import requests import requests
from six.moves import configparser
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
...@@ -93,6 +96,52 @@ class TestGrafana(GrafanaTestCase): ...@@ -93,6 +96,52 @@ class TestGrafana(GrafanaTestCase):
sorted(['influxdb', 'loki']), sorted(['influxdb', 'loki']),
sorted([ds['type'] for ds in resp.json()])) sorted([ds['type'] for ds in resp.json()]))
def test_email_disabled(self):
config = configparser.ConfigParser()
# grafana config file is like an ini file with an implicit default section
with open(
os.path.join(self.computer_partition_root_path, 'etc',
'grafana-config-file.cfg')) as f:
config.readfp(io.StringIO('[default]\n' + f.read()))
self.assertEqual(config.get('smtp', 'enabled'), 'false')
class TestGrafanaEmailEnabled(GrafanaTestCase):
__partition_reference__ = 'mail'
smtp_verify_ssl = "true"
smtp_skip_verify = "false"
@classmethod
def getInstanceParameterDict(cls):
return {
"smtp-server": "smtp.example.com:25",
"smtp-username": "smtp_username",
"smtp-password": "smtp_password",
'smtp-verify-ssl': cls.smtp_verify_ssl,
"email-from-address": "grafana@example.com",
"email-from-name": "Grafana From Name",
}
def test_email_enabled(self):
config = configparser.ConfigParser()
with open(
os.path.join(self.computer_partition_root_path, 'etc',
'grafana-config-file.cfg')) as f:
config.readfp(io.StringIO('[default]\n' + f.read()))
self.assertEqual(config.get('smtp', 'enabled'), 'true')
self.assertEqual(config.get('smtp', 'host'), 'smtp.example.com:25')
self.assertEqual(config.get('smtp', 'user'), 'smtp_username')
self.assertEqual(config.get('smtp', 'password'), '"""smtp_password"""')
self.assertEqual(config.get('smtp', 'skip_verify'), self.smtp_skip_verify)
self.assertEqual(config.get('smtp', 'from_address'), 'grafana@example.com')
self.assertEqual(config.get('smtp', 'from_name'), 'Grafana From Name')
class TestGrafanaEmailEnabledSkipVerify(TestGrafanaEmailEnabled):
smtp_verify_ssl = "false"
smtp_skip_verify = "true"
class TestInfluxDb(GrafanaTestCase): class TestInfluxDb(GrafanaTestCase):
def setUp(self): def setUp(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment