Commit 07c5d803 authored by Łukasz Nowak's avatar Łukasz Nowak

caddy-frontend: Test monitoring configuration

Only TestSlave class is tested, as this is that one which uses enough
complex scenario: master partition, kedifa partition and frontend partition.
parent 3e6eca2e
Pipeline #8148 failed with stage
in 0 seconds
......@@ -47,6 +47,7 @@ import gzip
import base64
import re
from slapos.recipe.librecipe import generateHashFromFiles
import xml.etree.ElementTree as ET
try:
......@@ -1367,6 +1368,102 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
}
}
monitor_setup_url_key = 'monitor-setup-url'
def test_monitor_setup(self):
IP = self._ipv6_address
self.monitor_configuration_list = [
{
'htmlUrl': 'https://[%s]:8401/public/feed' % (IP,),
'text': 'testing partition 0',
'title': 'testing partition 0',
'type': 'rss',
'url': 'https://[%s]:8401/share/private/' % (IP,),
'version': 'RSS',
'xmlUrl': 'https://[%s]:8401/public/feed' % (IP,),
},
{
'htmlUrl': 'https://[%s]:8402/public/feed' % (IP,),
'text': 'kedifa',
'title': 'kedifa',
'type': 'rss',
'url': 'https://[%s]:8402/share/private/' % (IP,),
'version': 'RSS',
'xmlUrl': 'https://[%s]:8402/public/feed' % (IP,),
},
{
'htmlUrl': 'https://[%s]:8411/public/feed' % (IP,),
'text': 'caddy-frontend-1',
'title': 'caddy-frontend-1',
'type': 'rss',
'url': 'https://[%s]:8411/share/private/' % (IP,),
'version': 'RSS',
'xmlUrl': 'https://[%s]:8411/public/feed' % (IP,),
},
]
connection_parameter_dict = self\
.computer_partition.getConnectionParameterDict()
self.assertTrue(
self.monitor_setup_url_key in connection_parameter_dict,
'%s not in %s' % (self.monitor_setup_url_key, connection_parameter_dict))
monitor_setup_url_value = connection_parameter_dict[
self.monitor_setup_url_key]
monitor_url_match = re.match(r'.*url=(.*)', monitor_setup_url_value)
self.assertNotEqual(
None, monitor_url_match, '%s not parsable' % (monitor_setup_url_value,))
self.assertEqual(1, len(monitor_url_match.groups()))
monitor_url = monitor_url_match.groups()[0]
monitor_url_split = monitor_url.split('&')
self.assertEqual(
3, len(monitor_url_split), '%s not splitabble' % (monitor_url,))
self.monitor_url = monitor_url_split[0]
monitor_username = monitor_url_split[1].split('=')
self.assertEqual(
2, len(monitor_username), '%s not splittable' % (monitor_username))
monitor_password = monitor_url_split[2].split('=')
self.assertEqual(
2, len(monitor_password), '%s not splittable' % (monitor_password))
self.monitor_username = monitor_username[1]
self.monitor_password = monitor_password[1]
opml_text = requests.get(self.monitor_url, verify=False).text
opml = ET.fromstring(opml_text)
body = opml[1]
self.assertEqual('body', body.tag)
outline_list = body[0].findall('outline')
self.assertEqual(
self.monitor_configuration_list,
[q.attrib for q in outline_list]
)
expected_status_code_list = []
got_status_code_list = []
for monitor_configuration in self.monitor_configuration_list:
status_code = requests.get(
monitor_configuration['url'],
verify=False,
auth=(self.monitor_username, self.monitor_password)
).status_code
expected_status_code_list.append(
{
'url': monitor_configuration['url'],
'status_code': 200
}
)
got_status_code_list.append(
{
'url': monitor_configuration['url'],
'status_code': status_code
}
)
self.assertEqual(
expected_status_code_list,
got_status_code_list
)
def getMasterPartitionPath(self):
# partition w/o etc/trafficserver, but with buildout.cfg
return [
......
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