]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: use known host addr
authorSage Weil <sage@newdream.net>
Fri, 21 May 2021 17:31:31 +0000 (13:31 -0400)
committerSage Weil <sage@newdream.net>
Thu, 27 May 2021 16:00:20 +0000 (12:00 -0400)
If the host IP/addr is known, use that.  The addr might even be a FQDN
instead of an IP address, in which case we want to look that up instead
of the bare hostname.

Signed-off-by: Sage Weil <sage@newdream.net>
src/pybind/mgr/cephadm/services/ingress.py
src/pybind/mgr/cephadm/services/iscsi.py
src/pybind/mgr/cephadm/tests/test_services.py

index ca0648f373174f1082ea2bec1de512da4d40ebfd..f78f558a2d8f8a309375456c9bce09a7147b0a20 100644 (file)
@@ -99,7 +99,7 @@ class IngressService(CephService):
                     assert(d.ports)
                     servers.append({
                         'name': f"{spec.backend_service}.{rank}",
-                        'ip': d.ip or resolve_ip(str(d.hostname)),
+                        'ip': d.ip or resolve_ip(self.mgr.inventory.get_addr(str(d.hostname))),
                         'port': d.ports[0],
                     })
                 else:
@@ -114,7 +114,7 @@ class IngressService(CephService):
             servers = [
                 {
                     'name': d.name(),
-                    'ip': d.ip or resolve_ip(str(d.hostname)),
+                    'ip': d.ip or resolve_ip(self.mgr.inventory.get_addr(str(d.hostname))),
                     'port': d.ports[0],
                 } for d in daemons if d.ports
             ]
@@ -232,7 +232,7 @@ class IngressService(CephService):
         # other_ips in conf file and converter to ips
         if host in hosts:
             hosts.remove(host)
-        other_ips = [resolve_ip(h) for h in hosts]
+        other_ips = [resolve_ip(self.mgr.inventory.get_addr(h)) for h in hosts]
 
         keepalived_conf = self.mgr.template.render(
             'services/ingress/keepalived.conf.j2',
@@ -243,7 +243,7 @@ class IngressService(CephService):
                 'interface': interface,
                 'state': state,
                 'other_ips': other_ips,
-                'host_ip': resolve_ip(host),
+                'host_ip': resolve_ip(self.mgr.inventory.get_addr(host)),
             }
         )
 
index 82b08a206c98f26530df7b4a46a8dd235b14acab..c87307e1b73641e9bfeb57583176a618b98e82fb 100644 (file)
@@ -96,7 +96,7 @@ class IscsiService(CephService):
                 if not spec:
                     logger.warning('No ServiceSpec found for %s', dd)
                     continue
-                ip = utils.resolve_ip(dd.hostname)
+                ip = utils.resolve_ip(self.mgr.inventory.get_addr(dd.hostname))
                 # IPv6 URL encoding requires square brackets enclosing the ip
                 if type(ip_address(ip)) is IPv6Address:
                     ip = f'[{ip}]'
index 46dfbab4d973fc0c14f3052cee4de744a7bdf101..2c32dffd9738ab8a4e595c80b4fa7f9f62d32496 100644 (file)
@@ -16,6 +16,11 @@ from orchestrator import OrchestratorError
 from orchestrator._interface import DaemonDescription
 
 
+class FakeInventory:
+    def get_addr(self, name: str) -> str:
+        return '1.2.3.4'
+
+
 class FakeMgr:
     def __init__(self):
         self.config = ''
@@ -23,6 +28,7 @@ class FakeMgr:
         self.mon_command = MagicMock(side_effect=self._check_mon_command)
         self.template = MagicMock()
         self.log = MagicMock()
+        self.inventory = FakeInventory()
 
     def _check_mon_command(self, cmd_dict, inbuf=None):
         prefix = cmd_dict.get('prefix')