Commit 1e9484bf authored by Jérome Perrin's avatar Jérome Perrin

caddy-frontend/test: use getPromisePluginParameterDict from slapos.testing

parent ec7222b5
...@@ -66,6 +66,7 @@ from cryptography.x509.oid import NameOID ...@@ -66,6 +66,7 @@ from cryptography.x509.oid import NameOID
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
from slapos.testing.utils import findFreeTCPPort from slapos.testing.utils import findFreeTCPPort
from slapos.testing.utils import getPromisePluginParameterDict
setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass( setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath( os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg'))) os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
...@@ -243,44 +244,6 @@ def isHTTP2(domain, ip): ...@@ -243,44 +244,6 @@ def isHTTP2(domain, ip):
return 'Using HTTP2, server supports multi-use' in err return 'Using HTTP2, server supports multi-use' in err
def getPluginParameterDict(software_path, filepath):
"""Load the slapos monitor plugin and returns the configuration used by this plugin.
This allow to check that monitoring plugin are using a proper config.
"""
# This is implemented by creating a wrapper script that loads the plugin wrapper
# script and returns its `extra_config_dict`. This might have to be adjusted if
# internals of slapos promise plugins change.
bin_file = os.path.join(software_path, 'bin', 'test-plugin-promise')
monitor_python_with_eggs = os.path.join(software_path, 'bin', 'monitor-pythonwitheggs')
if not os.path.exists(monitor_python_with_eggs):
raise ValueError("Monitoring stack's python does not exist at %s" % monitor_python_with_eggs)
with open(bin_file, 'w') as f:
f.write("""#!%s
import os
import importlib
import sys
import json
filepath = sys.argv[1]
sys.path[0:0] = [os.path.dirname(filepath)]
filename = os.path.basename(filepath)
module = importlib.import_module(os.path.splitext(filename)[0])
print json.dumps(module.extra_config_dict)
""" % monitor_python_with_eggs)
os.chmod(bin_file, 0o755)
result = subprocess_output([bin_file, filepath]).strip()
try:
return json.loads(result)
except ValueError, e:
raise ValueError("%s\nResult was: %s" % (e, result))
class TestDataMixin(object): class TestDataMixin(object):
def getTrimmedProcessInfo(self): def getTrimmedProcessInfo(self):
return '\n'.join(sorted([ return '\n'.join(sorted([
...@@ -3569,7 +3532,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): ...@@ -3569,7 +3532,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'check-_monitor-ipv6-test-ipv6-packet-list-test.py'))[0] 'check-_monitor-ipv6-test-ipv6-packet-list-test.py'))[0]
# get promise module and check that parameters are ok # get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
getPluginParameterDict(self.software_path, monitor_file), getPromisePluginParameterDict(monitor_file),
{ {
'frequency': '720', 'frequency': '720',
'address': 'monitor-ipv6-test' 'address': 'monitor-ipv6-test'
...@@ -3606,7 +3569,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): ...@@ -3606,7 +3569,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'check-_monitor-ipv4-test-ipv4-packet-list-test.py'))[0] 'check-_monitor-ipv4-test-ipv4-packet-list-test.py'))[0]
# get promise module and check that parameters are ok # get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
getPluginParameterDict(self.software_path, monitor_file), getPromisePluginParameterDict(monitor_file),
{ {
'frequency': '720', 'frequency': '720',
'ipv4': 'true', 'ipv4': 'true',
...@@ -4702,8 +4665,7 @@ class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase, ...@@ -4702,8 +4665,7 @@ class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase,
re6st_connectivity_promise_file = re6st_connectivity_promise_list[0] re6st_connectivity_promise_file = re6st_connectivity_promise_list[0]
self.assertEqual( self.assertEqual(
getPluginParameterDict( getPromisePluginParameterDict(re6st_connectivity_promise_file),
self.software_path, re6st_connectivity_promise_file),
{ {
'url': 'http://[2001:67c:1254:4::1]/index.html', 'url': 'http://[2001:67c:1254:4::1]/index.html',
} }
...@@ -4757,8 +4719,7 @@ class TestRe6stVerificationUrlSlave(SlaveHttpFrontendTestCase, ...@@ -4757,8 +4719,7 @@ class TestRe6stVerificationUrlSlave(SlaveHttpFrontendTestCase,
re6st_connectivity_promise_file = re6st_connectivity_promise_list[0] re6st_connectivity_promise_file = re6st_connectivity_promise_list[0]
self.assertEqual( self.assertEqual(
getPluginParameterDict( getPromisePluginParameterDict(re6st_connectivity_promise_file),
self.software_path, re6st_connectivity_promise_file),
{ {
'url': 'some-re6st-verification-url', 'url': 'some-re6st-verification-url',
} }
...@@ -6462,7 +6423,7 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase): ...@@ -6462,7 +6423,7 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase):
# get promise module and check that parameters are ok # get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
getPluginParameterDict(self.software_path, monitor_file), getPromisePluginParameterDict(monitor_file),
{ {
'frequency': '720', 'frequency': '720',
'ipv4': 'true', 'ipv4': 'true',
...@@ -6506,7 +6467,7 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase): ...@@ -6506,7 +6467,7 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase):
'check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test.py'))[0] 'check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test.py'))[0]
# get promise module and check that parameters are ok # get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
getPluginParameterDict(self.software_path, monitor_file), getPromisePluginParameterDict(monitor_file),
{ {
'frequency': '720', 'frequency': '720',
'address': '${section:option}\nafternewline ipv6' 'address': '${section:option}\nafternewline ipv6'
......
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