]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: Monitoring: Grafana: Fix IPv6
authorSebastian Wagner <sewagner@redhat.com>
Mon, 18 Oct 2021 13:04:46 +0000 (15:04 +0200)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 2 Nov 2021 09:01:23 +0000 (10:01 +0100)
Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
(cherry picked from commit bb2cb3ea3a9704cf124b5342fb2a974e8618cc01)

Conflicts:
src/pybind/mgr/cephadm/tests/test_ssh.py

src/pybind/mgr/cephadm/services/monitoring.py
src/pybind/mgr/cephadm/templates/services/grafana/ceph-dashboard.yml.j2
src/pybind/mgr/cephadm/tests/fixtures.py
src/pybind/mgr/cephadm/tests/test_cephadm.py

index d86c5a8803a6dd33553bdea3d79663aa23776f35..46af5b4727c34da6092d65499a1835eea58d5899 100644 (file)
@@ -2,6 +2,7 @@ import errno
 import logging
 import os
 from typing import List, Any, Tuple, Dict, Optional, cast
+from urllib.parse import urlparse
 
 from mgr_module import HandleCommandResult
 
@@ -32,7 +33,8 @@ class GrafanaService(CephadmService):
             assert dd.hostname is not None
             addr = dd.ip if dd.ip else self._inventory_get_addr(dd.hostname)
             port = dd.ports[0] if dd.ports else 9095
-            prom_services.append(addr + ':' + str(port))
+            prom_services.append(build_url(scheme='http', host=addr, port=port))
+
             deps.append(dd.name())
         grafana_data_sources = self.mgr.template.render(
             'services/grafana/ceph-dashboard.yml.j2', {'hosts': prom_services})
index 8946cac0a09895c919636bd57179d0644c55cbca..170e6f246f6df6f40b37c705c2c1541913b5ef11 100644 (file)
@@ -1,17 +1,17 @@
 # {{ cephadm_managed }}
 deleteDatasources:
-{% for host in hosts %} 
+{% for host in hosts %}
   - name: 'Dashboard{{ loop.index }}'
     orgId: 1
 {% endfor %}
 
 datasources:
-{% for host in hosts %} 
+{% for host in hosts %}
   - name: 'Dashboard{{ loop.index }}'
     type: 'prometheus'
     access: 'proxy'
     orgId: 1
-    url: 'http://{{ host }}'
+    url: '{{ host }}'
     basicAuth: false
     isDefault: {{ 'true' if loop.first else 'false' }}
     editable: false
index 11983737bcacf0fe2d48b15c781c51c4e7e7fb56..6a31395291fa12a036b68b760f9542f84d3e2487 100644 (file)
@@ -56,6 +56,14 @@ def with_cephadm_module(module_options=None, store=None):
                 'modified': datetime_to_str(datetime_now()),
                 'fsid': 'foobar',
             })
+        if '_ceph_get/mgr_map' not in store:
+            m.mock_store_set('_ceph_get', 'mgr_map', {
+                'services': {
+                    'dashboard': 'http://[::1]:8080',
+                    'prometheus': 'http://[::1]:8081'
+                },
+                'modules': ['dashboard', 'prometheus'],
+            })
         for k, v in store.items():
             m._ceph_set_store(k, v)
 
@@ -70,7 +78,7 @@ def wait(m, c):
 
 
 @contextmanager
-def with_host(m: CephadmOrchestrator, name, addr='1.2.3.4', refresh_hosts=True):
+def with_host(m: CephadmOrchestrator, name, addr='1::4', refresh_hosts=True):
     # type: (CephadmOrchestrator, str) -> None
     with mock.patch("cephadm.utils.resolve_ip", return_value=addr):
         wait(m, m.add_host(HostSpec(hostname=name)))
index 9593a3073eed339d361a2ae39dcb94c923f50dfd..a4475b73afaa1c60e800043e07d6e700eac01106 100644 (file)
@@ -86,19 +86,19 @@ class TestCephadm(object):
     def test_host(self, cephadm_module):
         assert wait(cephadm_module, cephadm_module.get_hosts()) == []
         with with_host(cephadm_module, 'test'):
-            assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1.2.3.4')]
+            assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1::4')]
 
             # Be careful with backward compatibility when changing things here:
             assert json.loads(cephadm_module.get_store('inventory')) == \
-                {"test": {"hostname": "test", "addr": "1.2.3.4", "labels": [], "status": ""}}
+                {"test": {"hostname": "test", "addr": "1::4", "labels": [], "status": ""}}
 
             with with_host(cephadm_module, 'second', '1.2.3.5'):
                 assert wait(cephadm_module, cephadm_module.get_hosts()) == [
-                    HostSpec('test', '1.2.3.4'),
+                    HostSpec('test', '1::4'),
                     HostSpec('second', '1.2.3.5')
                 ]
 
-            assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1.2.3.4')]
+            assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1::4')]
         assert wait(cephadm_module, cephadm_module.get_hosts()) == []
 
     @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
@@ -422,7 +422,7 @@ spec:
                 with mock.patch("cephadm.module.CephadmOrchestrator.mon_command") as _mon_cmd:
                     CephadmServe(cephadm_module)._check_daemons()
                     _mon_cmd.assert_any_call(
-                        {'prefix': 'dashboard set-grafana-api-url', 'value': 'https://1.2.3.4:3000'},
+                        {'prefix': 'dashboard set-grafana-api-url', 'value': 'https://[1::4]:3000'},
                         None)
 
     @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
@@ -927,7 +927,7 @@ spec:
     @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
     @mock.patch("subprocess.run", None)
     @mock.patch("cephadm.module.CephadmOrchestrator.rados", mock.MagicMock())
-    @mock.patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '1.2.3.4')
+    @mock.patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '1::4')
     def test_iscsi(self, cephadm_module):
         with with_host(cephadm_module, 'test'):
             ps = PlacementSpec(hosts=['test'], count=1)
@@ -1136,12 +1136,12 @@ spec:
             assert "Host 'test' not found" in err
 
             out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
-            assert out == HostSpec('test', '1.2.3.4', status='Offline').to_json()
+            assert out == HostSpec('test', '1::4', status='Offline').to_json()
 
             _get_connection.side_effect = None
             assert CephadmServe(cephadm_module)._check_host('test') is None
             out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
-            assert out == HostSpec('test', '1.2.3.4').to_json()
+            assert out == HostSpec('test', '1::4').to_json()
 
     @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
     def test_dont_touch_offline_or_maintenance_host_daemons(self, cephadm_module):