Commit 0c8191c3 authored by Łukasz Nowak's avatar Łukasz Nowak

fix "caddy-frontend: Publish only active slaves from main partition"

Use safe JSON serialisation/deserialisation, as otherwise unusual
slave_references can lead to issues and also character case is not kept.

Also care about case of log access user, which was undetected since
slave_reference in tests were always lowercase.
parent 96e2d9a6
...@@ -26,11 +26,11 @@ md5sum = 6fd023f0d29421d8579f0b3351473bb0 ...@@ -26,11 +26,11 @@ md5sum = 6fd023f0d29421d8579f0b3351473bb0
[template-apache-replicate] [template-apache-replicate]
filename = instance-apache-replicate.cfg.in filename = instance-apache-replicate.cfg.in
md5sum = 15d6b5b00ab1f74d42863c90f2537981 md5sum = c9d667f8491d2efe41acc4dbd3b78b87
[template-slave-list] [template-slave-list]
filename = templates/apache-custom-slave-list.cfg.in filename = templates/apache-custom-slave-list.cfg.in
md5sum = 439a4e415bef9d44b37bee4d5e4aa924 md5sum = 028ca41fdf7a758ba701ccc5e449419a
[template-slave-configuration] [template-slave-configuration]
filename = templates/custom-virtualhost.conf.in filename = templates/custom-virtualhost.conf.in
...@@ -38,7 +38,7 @@ md5sum = 54ae95597a126ae552c3a913ddf29e5e ...@@ -38,7 +38,7 @@ md5sum = 54ae95597a126ae552c3a913ddf29e5e
[template-replicate-publish-slave-information] [template-replicate-publish-slave-information]
filename = templates/replicate-publish-slave-information.cfg.in filename = templates/replicate-publish-slave-information.cfg.in
md5sum = 73e3d1e55a98a3c4d25a1618aa584fff md5sum = 696ef7690f51a521cc6f6c9d9d5d844e
[template-caddy-frontend-configuration] [template-caddy-frontend-configuration]
filename = templates/Caddyfile.in filename = templates/Caddyfile.in
......
...@@ -224,11 +224,13 @@ custom-group = ${dynamic-publish-slave-information:rendered} ...@@ -224,11 +224,13 @@ custom-group = ${dynamic-publish-slave-information:rendered}
{% endfor %} {% endfor %}
[active-slave-instance] [active-slave-instance]
{% set active_slave_instance_list = [] %}
{% for slave_instance in slave_instance_list %} {% for slave_instance in slave_instance_list %}
{# Provide a list of slave titles send by master, in order to filter out already destroyed slaves #} {# Provide a list of slave titles send by master, in order to filter out already destroyed slaves #}
{# Note: This functionality is not yet covered by tests, please modify with care #} {# Note: This functionality is not yet covered by tests, please modify with care #}
{{ slave_instance['slave_title'] }} = active {% do active_slave_instance_list.append(slave_instance['slave_title']) %}
{% endfor %} {% endfor %}
active-slave-instance-list = {{ json_module.dumps(active_slave_instance_list) }}
[dynamic-publish-slave-information] [dynamic-publish-slave-information]
< = jinja2-template-base < = jinja2-template-base
......
...@@ -87,7 +87,7 @@ output = {{ plugin_directory }}/${:name} ...@@ -87,7 +87,7 @@ output = {{ plugin_directory }}/${:name}
{# Add slave log directory to the slave log access dict #} {# Add slave log directory to the slave log access dict #}
{% do slave_log_dict.__setitem__(slave_reference, slave_log_folder) %} {% do slave_log_dict.__setitem__(slave_reference, slave_log_folder) %}
{% set slave_log_access_url = 'https://' + slave_reference + ':${'+ slave_password_section +':passwd}@[' + frontend_configuration.get('caddy-ipv6') + ']:' + frontend_configuration.get('caddy-https-port') + '/' + slave_reference.lower() + '/' %} {% set slave_log_access_url = 'https://' + slave_reference.lower() + ':${'+ slave_password_section +':passwd}@[' + frontend_configuration.get('caddy-ipv6') + ']:' + frontend_configuration.get('caddy-https-port') + '/' + slave_reference.lower() + '/' %}
{% do slave_publish_dict.__setitem__('log-access', slave_log_access_url) %} {% do slave_publish_dict.__setitem__('log-access', slave_log_access_url) %}
{% do slave_publish_dict.__setitem__('slave-reference', slave_reference) %} {% do slave_publish_dict.__setitem__('slave-reference', slave_reference) %}
{% do slave_publish_dict.__setitem__('public-ipv4', public_ipv4) %} {% do slave_publish_dict.__setitem__('public-ipv4', public_ipv4) %}
......
...@@ -35,10 +35,11 @@ ...@@ -35,10 +35,11 @@
{% endfor %} {% endfor %}
# Publish information for each slave # Publish information for each slave
{% set active_slave_instance_list = json_module.loads(active_slave_instance_dict['active-slave-instance-list']) %}
{% for slave_reference, slave_information in slave_information_dict.iteritems() %} {% for slave_reference, slave_information in slave_information_dict.iteritems() %}
{# Filter out destroyed, so not existing anymore, slaves #} {# Filter out destroyed, so not existing anymore, slaves #}
{# Note: This functionality is not yet covered by tests, please modify with care #} {# Note: This functionality is not yet covered by tests, please modify with care #}
{% if slave_reference in active_slave_instance_dict %} {% if slave_reference in active_slave_instance_list %}
{% set publish_section_title = 'publish-%s' % slave_reference %} {% set publish_section_title = 'publish-%s' % slave_reference %}
{% do part_list.append(publish_section_title) %} {% do part_list.append(publish_section_title) %}
[{{ publish_section_title }}] [{{ publish_section_title }}]
......
...@@ -825,7 +825,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -825,7 +825,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
return { return {
'empty': { 'empty': {
}, },
'url': { 'Url': {
'url': cls.backend_url, 'url': cls.backend_url,
}, },
'url_https-url': { 'url_https-url': {
...@@ -1203,7 +1203,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1203,7 +1203,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
) )
def test_url(self): def test_url(self):
parameter_dict = self.parseSlaveParameterDict('url') parameter_dict = self.parseSlaveParameterDict('Url')
self.assertLogAccessUrlWithPop(parameter_dict) self.assertLogAccessUrlWithPop(parameter_dict)
self.assertEqual( self.assertEqual(
...@@ -1265,7 +1265,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s { ...@@ -1265,7 +1265,7 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
# check that try_duration == 5 in the test_url slave # check that try_duration == 5 in the test_url slave
slave_configuration_file = glob.glob(os.path.join( slave_configuration_file = glob.glob(os.path.join(
self.instance_path, '*', 'etc', '*slave-conf.d', '_url.conf'))[0] self.instance_path, '*', 'etc', '*slave-conf.d', '_Url.conf'))[0]
with open(slave_configuration_file) as fh: with open(slave_configuration_file) as fh:
content = fh.read() content = fh.read()
self.assertTrue('try_duration 5s' in content) self.assertTrue('try_duration 5s' in content)
......
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