From: Redouane Kachach Date: Mon, 14 Nov 2022 17:49:42 +0000 (+0100) Subject: mgr/cephadm: fix haproxy monitoring endpoint X-Git-Tag: v18.1.0~476^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9636d9467f7bbcbda31da7809065000c49326dca;p=ceph-ci.git mgr/cephadm: fix haproxy monitoring endpoint Fixes: https://tracker.ceph.com/issues/58021 Signed-off-by: Redouane Kachach --- diff --git a/src/pybind/mgr/cephadm/services/ingress.py b/src/pybind/mgr/cephadm/services/ingress.py index d53d719c287..5e4145d5806 100644 --- a/src/pybind/mgr/cephadm/services/ingress.py +++ b/src/pybind/mgr/cephadm/services/ingress.py @@ -123,6 +123,7 @@ class IngressService(CephService): } for d in daemons if d.ports ] + host_ip = daemon_spec.ip or self.mgr.inventory.get_addr(daemon_spec.host) haproxy_conf = self.mgr.template.render( 'services/ingress/haproxy.cfg.j2', { @@ -135,6 +136,7 @@ class IngressService(CephService): 'ip': "*" if spec.virtual_ips_list else str(spec.virtual_ip).split('/')[0] or daemon_spec.ip or '*', 'frontend_port': daemon_spec.ports[0] if daemon_spec.ports else spec.frontend_port, 'monitor_port': daemon_spec.ports[1] if daemon_spec.ports else spec.monitor_port, + 'local_host_ip': host_ip } ) config_files = { @@ -239,7 +241,8 @@ class IngressService(CephService): if d.daemon_type == 'haproxy': assert d.ports port = d.ports[1] # monitoring port - script = f'/usr/bin/curl {build_url(scheme="http", host=d.ip or "localhost", port=port)}/health' + host_ip = d.ip or self.mgr.inventory.get_addr(d.hostname) + script = f'/usr/bin/curl {build_url(scheme="http", host=host_ip, port=port)}/health' assert script states = [] diff --git a/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 b/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 index 025f081f9e1..060af25dff5 100644 --- a/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 +++ b/src/pybind/mgr/cephadm/templates/services/ingress/haproxy.cfg.j2 @@ -48,7 +48,7 @@ defaults frontend stats mode http bind {{ ip }}:{{ monitor_port }} - bind localhost:{{ monitor_port }} + bind {{ local_host_ip }}:{{ monitor_port }} stats enable stats uri /stats stats refresh 10s diff --git a/src/pybind/mgr/cephadm/tests/test_services.py b/src/pybind/mgr/cephadm/tests/test_services.py index 41bbc13ee44..8789f5e368e 100644 --- a/src/pybind/mgr/cephadm/tests/test_services.py +++ b/src/pybind/mgr/cephadm/tests/test_services.py @@ -903,7 +903,7 @@ class TestIngressService: def test_ingress_config(self, _run_cephadm, cephadm_module: CephadmOrchestrator): _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) - with with_host(cephadm_module, 'test'): + with with_host(cephadm_module, 'test', addr='1.2.3.7'): cephadm_module.cache.update_host_networks('test', { '1.2.3.0/24': { 'if0': ['1.2.3.4/32'] @@ -935,7 +935,7 @@ class TestIngressService: 'keepalived.conf': '# This file is generated by cephadm.\n' 'vrrp_script check_backend {\n ' - 'script "/usr/bin/curl http://localhost:8999/health"\n ' + 'script "/usr/bin/curl http://1.2.3.7:8999/health"\n ' 'weight -20\n ' 'interval 2\n ' 'rise 2\n ' @@ -950,7 +950,7 @@ class TestIngressService: 'auth_type PASS\n ' 'auth_pass 12345\n ' '}\n ' - 'unicast_src_ip 1::4\n ' + 'unicast_src_ip 1.2.3.7\n ' 'unicast_peer {\n ' '}\n ' 'virtual_ipaddress {\n ' @@ -1001,7 +1001,7 @@ class TestIngressService: '\nfrontend stats\n ' 'mode http\n ' 'bind 1.2.3.4:8999\n ' - 'bind localhost:8999\n ' + 'bind 1.2.3.7:8999\n ' 'stats enable\n ' 'stats uri /stats\n ' 'stats refresh 10s\n ' @@ -1016,7 +1016,7 @@ class TestIngressService: 'balance static-rr\n ' 'option httpchk HEAD / HTTP/1.0\n ' 'server ' - + haproxy_generated_conf[1][0] + ' 1::4:80 check weight 100\n' + + haproxy_generated_conf[1][0] + ' 1.2.3.7:80 check weight 100\n' } } @@ -1058,7 +1058,7 @@ class TestIngressService: 'keepalived.conf': '# This file is generated by cephadm.\n' 'vrrp_script check_backend {\n ' - 'script "/usr/bin/curl http://localhost:8999/health"\n ' + 'script "/usr/bin/curl http://[1::4]:8999/health"\n ' 'weight -20\n ' 'interval 2\n ' 'rise 2\n ' @@ -1124,7 +1124,7 @@ class TestIngressService: '\nfrontend stats\n ' 'mode http\n ' 'bind 1.2.3.4:8999\n ' - 'bind localhost:8999\n ' + 'bind 1::4:8999\n ' 'stats enable\n ' 'stats uri /stats\n ' 'stats refresh 10s\n ' @@ -1151,7 +1151,7 @@ class TestIngressService: def test_ingress_config_multi_vips(self, _run_cephadm, cephadm_module: CephadmOrchestrator): _run_cephadm.side_effect = async_side_effect(('{}', '', 0)) - with with_host(cephadm_module, 'test'): + with with_host(cephadm_module, 'test', addr='1.2.3.7'): cephadm_module.cache.update_host_networks('test', { '1.2.3.0/24': { 'if0': ['1.2.3.4/32'] @@ -1184,7 +1184,7 @@ class TestIngressService: 'keepalived.conf': '# This file is generated by cephadm.\n' 'vrrp_script check_backend {\n ' - 'script "/usr/bin/curl http://localhost:8999/health"\n ' + 'script "/usr/bin/curl http://1.2.3.7:8999/health"\n ' 'weight -20\n ' 'interval 2\n ' 'rise 2\n ' @@ -1199,7 +1199,7 @@ class TestIngressService: 'auth_type PASS\n ' 'auth_pass 12345\n ' '}\n ' - 'unicast_src_ip 1::4\n ' + 'unicast_src_ip 1.2.3.7\n ' 'unicast_peer {\n ' '}\n ' 'virtual_ipaddress {\n ' @@ -1250,7 +1250,7 @@ class TestIngressService: '\nfrontend stats\n ' 'mode http\n ' 'bind *:8999\n ' - 'bind localhost:8999\n ' + 'bind 1.2.3.7:8999\n ' 'stats enable\n ' 'stats uri /stats\n ' 'stats refresh 10s\n ' @@ -1265,7 +1265,7 @@ class TestIngressService: 'balance static-rr\n ' 'option httpchk HEAD / HTTP/1.0\n ' 'server ' - + haproxy_generated_conf[1][0] + ' 1::4:80 check weight 100\n' + + haproxy_generated_conf[1][0] + ' 1.2.3.7:80 check weight 100\n' } }