diff --git a/config.yaml b/config.yaml index 3b736a44..8d5488a2 100644 --- a/config.yaml +++ b/config.yaml @@ -273,6 +273,11 @@ options: description: | Connect timeout configuration in ms for haproxy, used in HA configurations. If not provided, default value of 9000ms is used. + haproxy-expose-stats: + type: boolean + default: False + description: | + If True, exposes stats interface externally. enforce-ssl: type: boolean default: False diff --git a/hooks/horizon_contexts.py b/hooks/horizon_contexts.py index 3e6e53f9..39668252 100644 --- a/hooks/horizon_contexts.py +++ b/hooks/horizon_contexts.py @@ -84,7 +84,8 @@ class HorizonHAProxyContext(OSContextGenerator): 'dash_insecure': [80, 70], 'dash_secure': [443, 433] }, - 'prefer_ipv6': config('prefer-ipv6') + 'prefer_ipv6': config('prefer-ipv6'), + 'haproxy_expose_stats': config('haproxy-expose-stats') } return ctxt diff --git a/templates/haproxy.cfg b/templates/haproxy.cfg index e55ed17f..f645f55c 100644 --- a/templates/haproxy.cfg +++ b/templates/haproxy.cfg @@ -34,7 +34,7 @@ defaults {%- endif %} listen stats - bind {{ local_host }}:{{ stat_port }} + bind {% if haproxy_expose_stats %}{{ haproxy_host }}{% else %}{{ local_host }}{% endif %}:{{ stat_port }} mode http stats enable stats hide-version diff --git a/unit_tests/test_horizon_contexts.py b/unit_tests/test_horizon_contexts.py index d76ecd87..e57fd550 100644 --- a/unit_tests/test_horizon_contexts.py +++ b/unit_tests/test_horizon_contexts.py @@ -697,7 +697,8 @@ class TestHorizonContexts(CharmTestCase): {'units': {'openstack-dashboard-0': '10.5.0.1'}, 'service_ports': {'dash_insecure': [80, 70], 'dash_secure': [443, 433]}, - 'prefer_ipv6': False}) + 'prefer_ipv6': False, + 'haproxy_expose_stats': False}) _open.assert_called_with('/etc/default/haproxy', 'w') self.assertTrue(_file.write.called) self.get_relation_ip.assert_called_with('cluster') @@ -717,11 +718,27 @@ class TestHorizonContexts(CharmTestCase): 'openstack-dashboard-2': '10.5.0.3'}, 'service_ports': {'dash_insecure': [80, 70], 'dash_secure': [443, 433]}, - 'prefer_ipv6': False}) + 'prefer_ipv6': False, + 'haproxy_expose_stats': False}) _open.assert_called_with('/etc/default/haproxy', 'w') self.assertTrue(_file.write.called) self.get_relation_ip.assert_called_with('cluster') + def test_HorizonHAProxyContext_expose_stats(self): + self.test_config.set('haproxy-expose-stats', True) + self.relation_ids.return_value = [] + self.local_unit.return_value = 'openstack-dashboard/0' + self.get_relation_ip.return_value = "10.5.0.1" + with patch_open() as (_open, _file): + self.assertEquals(horizon_contexts.HorizonHAProxyContext()(), + {'units': {'openstack-dashboard-0': '10.5.0.1'}, + 'service_ports': {'dash_insecure': [80, 70], + 'dash_secure': [443, 433]}, + 'prefer_ipv6': False, + 'haproxy_expose_stats': True}) + _open.assert_called_with('/etc/default/haproxy', 'w') + self.assertTrue(_file.write.called) + def test_RouterSettingContext(self): self.test_config.set('profile', 'cisco') self.assertEqual(horizon_contexts.RouterSettingContext()(),