Commit 3c5e9e9d authored by Alain Takoudjou's avatar Alain Takoudjou

caddy-frontend: fix tests for plugin promises

parent c106130b
...@@ -42,6 +42,7 @@ from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter ...@@ -42,6 +42,7 @@ from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter
import time import time
import tempfile import tempfile
import ipaddress import ipaddress
import importlib
from utils import SlapOSInstanceTestCase from utils import SlapOSInstanceTestCase
from utils import findFreeTCPPort from utils import findFreeTCPPort
...@@ -223,6 +224,29 @@ def getQUIC(url, ip, port): ...@@ -223,6 +224,29 @@ def getQUIC(url, ip, port):
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
return False, e.output return False, e.output
def getPluginParameterDict(software_path, filepath):
bin_file = os.path.join(software_path, 'bin', 'test-plugin-promise')
with open(bin_file, 'w') as f:
f.write("""#!%s/bin/pythonwitheggs
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)
""" % software_path)
os.chmod(bin_file, 0755)
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):
@staticmethod @staticmethod
...@@ -1030,8 +1054,6 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1030,8 +1054,6 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
self.assertEqual( self.assertEqual(
set([ set([
'monitor-http-frontend',
'monitor-httpd-listening-on-tcp',
'promise-monitor-httpd-is-process-older-than-dependency-set', 'promise-monitor-httpd-is-process-older-than-dependency-set',
]), ]),
set(os.listdir(os.path.join(partition_path, 'etc', 'promise')))) set(os.listdir(os.path.join(partition_path, 'etc', 'promise'))))
...@@ -1040,6 +1062,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1040,6 +1062,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
set([ set([
'monitor-bootstrap-status.py', 'monitor-bootstrap-status.py',
'check-free-disk-space.py', 'check-free-disk-space.py',
'monitor-http-frontend.py',
'monitor-httpd-listening-on-tcp.py',
'buildout-%s-0-status.py' % (type(self).__name__,), 'buildout-%s-0-status.py' % (type(self).__name__,),
'__init__.py', '__init__.py',
]), ]),
...@@ -1056,15 +1080,23 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1056,15 +1080,23 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
partition_path, 'etc', 'httpd-cors.cfg'), 'r').read().strip()) partition_path, 'etc', 'httpd-cors.cfg'), 'r').read().strip())
def test_promise_monitor_httpd_listening_on_tcp(self): def test_promise_monitor_httpd_listening_on_tcp(self):
result = set([
subprocess.call(q) for q in glob.glob( runpromise_bin = os.path.join(self.software_path, 'bin',
'monitor.runpromise')
result = set([
subprocess.call([runpromise_bin, '-c',
os.path.join(os.path.dirname(q),
'../monitor.conf'),
'--run-only',
'monitor-httpd-listening-on-tcp.py']
) for q in glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'monitor-httpd-listening-on-tcp'))]) 'monitor-httpd-listening-on-tcp.py'))])
self.assertEqual( self.assertEqual(
set([0]), set([0]),
result result
) )
def test_slave_partition_state(self): def test_slave_partition_state(self):
partition_path = self.getSlavePartitionPath() partition_path = self.getSlavePartitionPath()
...@@ -2410,18 +2442,17 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2410,18 +2442,17 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code) self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, 'bin', 'is-icmp-packet-lost'), 'w'
).write('echo "$@"')
# call the monitor for this partition
monitor_file = glob.glob( monitor_file = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'check-_monitor-ipv6-test-ipv6-packet-list-test'))[0] 'check-_monitor-ipv6-test-ipv6-packet-list-test.py'))[0]
# get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
'-a monitor-ipv6-test', getPluginParameterDict(self.software_path, monitor_file),
subprocess_output(monitor_file).strip() {
'frequency': '720',
'address': 'monitor-ipv6-test'
}
) )
def test_monitor_ipv4_test(self): def test_monitor_ipv4_test(self):
...@@ -2452,18 +2483,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2452,18 +2483,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code) self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, 'bin', 'is-icmp-packet-lost'), 'w'
).write('echo "$@"')
# call the monitor for this partition
monitor_file = glob.glob( monitor_file = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'check-_monitor-ipv4-test-ipv4-packet-list-test'))[0] 'check-_monitor-ipv4-test-ipv4-packet-list-test.py'))[0]
# get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
'-4 -a monitor-ipv4-test', getPluginParameterDict(self.software_path, monitor_file),
subprocess_output(monitor_file).strip() {
'frequency': '720',
'ipv4': 'true',
'address': 'monitor-ipv4-test',
}
) )
def test_re6st_optimal_test(self): def test_re6st_optimal_test(self):
...@@ -2494,19 +2525,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -2494,19 +2525,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code) self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(
self.software_path, 'bin', 'check-re6st-optimal-status'), 'w'
).write('echo "$@"')
# call the monitor for this partition
monitor_file = glob.glob( monitor_file = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'check-_re6st-optimal-test-re6st-optimal-test'))[0] 'check-_re6st-optimal-test-re6st-optimal-test.py'))[0]
# get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
'-4 ipv4 -6 ipv6', getPluginParameterDict(self.software_path, monitor_file),
subprocess_output(monitor_file).strip() {
'frequency': '720',
'ipv4': 'ipv4',
'ipv6': 'ipv6'
}
) )
def test_enable_cache(self): def test_enable_cache(self):
...@@ -3370,14 +3400,17 @@ class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase, ...@@ -3370,14 +3400,17 @@ class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase,
re6st_connectivity_promise_list = glob.glob( re6st_connectivity_promise_list = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
're6st-connectivity')) 're6st-connectivity.py'))
self.assertEqual(1, len(re6st_connectivity_promise_list)) self.assertEqual(1, len(re6st_connectivity_promise_list))
re6st_connectivity_promise_file = re6st_connectivity_promise_list[0]
self.assertTrue( self.assertEqual(
'URL="http://[2001:67c:1254:4::1]/index.html"' in getPluginParameterDict(self.software_path, re6st_connectivity_promise_file),
open(re6st_connectivity_promise_list[0]).read() {
'url': 'http://[2001:67c:1254:4::1]/index.html',
}
) )
...@@ -3419,14 +3452,17 @@ class TestRe6stVerificationUrlSlave(SlaveHttpFrontendTestCase, ...@@ -3419,14 +3452,17 @@ class TestRe6stVerificationUrlSlave(SlaveHttpFrontendTestCase,
re6st_connectivity_promise_list = glob.glob( re6st_connectivity_promise_list = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
're6st-connectivity')) 're6st-connectivity.py'))
self.assertEqual(1, len(re6st_connectivity_promise_list)) self.assertEqual(1, len(re6st_connectivity_promise_list))
re6st_connectivity_promise_file = re6st_connectivity_promise_list[0]
self.assertTrue( self.assertEqual(
'URL="some-re6st-verification-url"' in getPluginParameterDict(self.software_path, re6st_connectivity_promise_file),
open(re6st_connectivity_promise_list[0]).read() {
'url': 'some-re6st-verification-url',
}
) )
...@@ -3835,23 +3871,21 @@ https://www.google.com {}""", ...@@ -3835,23 +3871,21 @@ https://www.google.com {}""",
self.assertEqual(httplib.NOT_FOUND, result.status_code) self.assertEqual(httplib.NOT_FOUND, result.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(
self.software_path, 'bin', 'check-re6st-optimal-status'), 'w'
).write('echo "$@"')
# call the monitor for this partition
monitor_file = glob.glob( monitor_file = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'check-_re6st-optimal-test-unsafe-re6st-optimal-test'))[0] 'check-_re6st-optimal-test-unsafe-re6st-optimal-test.py'))[0]
# Note: The result is a bit differnt from the request (newlines stripped), # Note: The result is a bit differnt from the request (newlines stripped),
# but good enough to prove, that ${esection:eoption} has been # but good enough to prove, that ${esection:eoption} has been
# correctly passed to the script. # correctly passed to the script.
self.assertEqual( self.assertEqual(
'-4 newline [s${esection:eoption} -6 new line;rm -fr ~;', getPluginParameterDict(self.software_path, monitor_file),
subprocess_output(monitor_file).strip() {
'frequency': '720',
'ipv4': 'new\\line\n[s${esection:eoption}',
'ipv6': 'new\nline;rm -fr ~;',
}
) )
def test_re6st_optimal_test_nocomma(self): def test_re6st_optimal_test_nocomma(self):
...@@ -3881,8 +3915,8 @@ https://www.google.com {}""", ...@@ -3881,8 +3915,8 @@ https://www.google.com {}""",
# assert that there is no nocomma file # assert that there is no nocomma file
monitor_file_list = glob.glob( monitor_file_list = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'check-_re6st-optimal-test-nocomma-re6st-optimal-test')) 'check-_re6st-optimal-test-nocomma-re6st-optimal-test.py'))
self.assertEqual( self.assertEqual(
[], [],
monitor_file_list monitor_file_list
...@@ -4029,18 +4063,19 @@ https://www.google.com {}""", ...@@ -4029,18 +4063,19 @@ https://www.google.com {}""",
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code) self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, 'bin', 'is-icmp-packet-lost'), 'w'
).write('echo "$@"')
# call the monitor for this partition
monitor_file = glob.glob( monitor_file = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'check-_monitor-ipv4-test-unsafe-ipv4-packet-list-test'))[0] 'check-_monitor-ipv4-test-unsafe-ipv4-packet-list-test.py'))[0]
# get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
'-4 -a ${section:option} afternewline ipv4', getPluginParameterDict(self.software_path, monitor_file),
subprocess_output(monitor_file).strip() {
'frequency': '720',
'ipv4': 'true',
'address': '${section:option}\nafternewline ipv4',
}
) )
def test_monitor_ipv6_test_unsafe(self): def test_monitor_ipv6_test_unsafe(self):
...@@ -4071,18 +4106,17 @@ https://www.google.com {}""", ...@@ -4071,18 +4106,17 @@ https://www.google.com {}""",
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path') parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code) self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, 'bin', 'is-icmp-packet-lost'), 'w'
).write('echo "$@"')
# call the monitor for this partition
monitor_file = glob.glob( monitor_file = glob.glob(
os.path.join( os.path.join(
self.instance_path, '*', 'etc', 'promise', self.instance_path, '*', 'etc', 'plugin',
'check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test'))[0] 'check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test.py'))[0]
# get promise module and check that parameters are ok
self.assertEqual( self.assertEqual(
'-a ${section:option} afternewline ipv6', getPluginParameterDict(self.software_path, monitor_file),
subprocess_output(monitor_file).strip() {
'frequency': '720',
'address': '${section:option}\nafternewline ipv6'
}
) )
def test_ssl_key_ssl_crt_unsafe(self): def test_ssl_key_ssl_crt_unsafe(self):
......
...@@ -7,12 +7,40 @@ TestSlaveBadParameters-0/etc/plugin/monitor-httpd-listening-on-tcp.py ...@@ -7,12 +7,40 @@ TestSlaveBadParameters-0/etc/plugin/monitor-httpd-listening-on-tcp.py
TestSlaveBadParameters-1/etc/plugin/__init__.py TestSlaveBadParameters-1/etc/plugin/__init__.py
TestSlaveBadParameters-1/etc/plugin/buildout-TestSlaveBadParameters-1-status.py TestSlaveBadParameters-1/etc/plugin/buildout-TestSlaveBadParameters-1-status.py
TestSlaveBadParameters-1/etc/plugin/caddy_cached.py TestSlaveBadParameters-1/etc/plugin/caddy_cached.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv4_http.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv4_https.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv6_http.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv6_https.py
TestSlaveBadParameters-1/etc/plugin/caddy_ssl_cached.py TestSlaveBadParameters-1/etc/plugin/caddy_ssl_cached.py
TestSlaveBadParameters-1/etc/plugin/check-_default-path-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_default-path-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv4-test-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv4-test-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv4-test-unsafe-ipv4-packet-list-test.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv6-test-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv6-test-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-nocomma-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-nocomma-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-unsafe-re6st-optimal-test.py
TestSlaveBadParameters-1/etc/plugin/check-_server-alias-same-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_server-alias-same-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-http-port-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-http-port-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-https-port-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-https-port-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-free-disk-space.py TestSlaveBadParameters-1/etc/plugin/check-free-disk-space.py
TestSlaveBadParameters-1/etc/plugin/frontend-caddy-configuration-promise.py TestSlaveBadParameters-1/etc/plugin/frontend-caddy-configuration-promise.py
TestSlaveBadParameters-1/etc/plugin/monitor-bootstrap-status.py TestSlaveBadParameters-1/etc/plugin/monitor-bootstrap-status.py
TestSlaveBadParameters-1/etc/plugin/monitor-http-frontend.py TestSlaveBadParameters-1/etc/plugin/monitor-http-frontend.py
TestSlaveBadParameters-1/etc/plugin/monitor-httpd-listening-on-tcp.py TestSlaveBadParameters-1/etc/plugin/monitor-httpd-listening-on-tcp.py
TestSlaveBadParameters-1/etc/plugin/nginx-configuration-promise.py TestSlaveBadParameters-1/etc/plugin/nginx-configuration-promise.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv4_http.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv4_https.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv6_http.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv6_https.py
TestSlaveBadParameters-1/etc/plugin/re6st-connectivity.py
TestSlaveBadParameters-1/etc/plugin/trafficserver-cache-availability.py TestSlaveBadParameters-1/etc/plugin/trafficserver-cache-availability.py
TestSlaveBadParameters-1/etc/plugin/trafficserver-port-listening.py TestSlaveBadParameters-1/etc/plugin/trafficserver-port-listening.py
\ No newline at end of file
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