From 1e9484bf05704c1afff57e9a083dc206692a3595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Mon, 24 Aug 2020 03:32:59 +0200 Subject: [PATCH] caddy-frontend/test: use getPromisePluginParameterDict from slapos.testing --- software/caddy-frontend/test/test.py | 53 ++++------------------------ 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/software/caddy-frontend/test/test.py b/software/caddy-frontend/test/test.py index 7390b38c9..b554df2ce 100644 --- a/software/caddy-frontend/test/test.py +++ b/software/caddy-frontend/test/test.py @@ -66,6 +66,7 @@ from cryptography.x509.oid import NameOID from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.utils import findFreeTCPPort +from slapos.testing.utils import getPromisePluginParameterDict setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass( os.path.abspath( os.path.join(os.path.dirname(__file__), '..', 'software.cfg'))) @@ -243,44 +244,6 @@ def isHTTP2(domain, ip): 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): def getTrimmedProcessInfo(self): return '\n'.join(sorted([ @@ -3569,7 +3532,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): 'check-_monitor-ipv6-test-ipv6-packet-list-test.py'))[0] # get promise module and check that parameters are ok self.assertEqual( - getPluginParameterDict(self.software_path, monitor_file), + getPromisePluginParameterDict(monitor_file), { 'frequency': '720', 'address': 'monitor-ipv6-test' @@ -3606,7 +3569,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): 'check-_monitor-ipv4-test-ipv4-packet-list-test.py'))[0] # get promise module and check that parameters are ok self.assertEqual( - getPluginParameterDict(self.software_path, monitor_file), + getPromisePluginParameterDict(monitor_file), { 'frequency': '720', 'ipv4': 'true', @@ -4702,8 +4665,7 @@ class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase, re6st_connectivity_promise_file = re6st_connectivity_promise_list[0] self.assertEqual( - getPluginParameterDict( - self.software_path, re6st_connectivity_promise_file), + getPromisePluginParameterDict(re6st_connectivity_promise_file), { 'url': 'http://[2001:67c:1254:4::1]/index.html', } @@ -4757,8 +4719,7 @@ class TestRe6stVerificationUrlSlave(SlaveHttpFrontendTestCase, re6st_connectivity_promise_file = re6st_connectivity_promise_list[0] self.assertEqual( - getPluginParameterDict( - self.software_path, re6st_connectivity_promise_file), + getPromisePluginParameterDict(re6st_connectivity_promise_file), { 'url': 'some-re6st-verification-url', } @@ -6462,7 +6423,7 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase): # get promise module and check that parameters are ok self.assertEqual( - getPluginParameterDict(self.software_path, monitor_file), + getPromisePluginParameterDict(monitor_file), { 'frequency': '720', 'ipv4': 'true', @@ -6506,7 +6467,7 @@ class TestSlaveRejectReportUnsafeDamaged(SlaveHttpFrontendTestCase): 'check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test.py'))[0] # get promise module and check that parameters are ok self.assertEqual( - getPluginParameterDict(self.software_path, monitor_file), + getPromisePluginParameterDict(monitor_file), { 'frequency': '720', 'address': '${section:option}\nafternewline ipv6' -- 2.30.9