]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: update host when adding host that already exists
authorDaniel Pivonka <dpivonka@redhat.com>
Thu, 12 Aug 2021 18:25:23 +0000 (14:25 -0400)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 2 Nov 2021 09:01:23 +0000 (10:01 +0100)
update addr and labels of existing host
this prevents labels being removed if a host is readded
or addr being set to 127.0.... if readding host active mgr is on

Fixes: https://tracker.ceph.com/issues/51667
Signed-off-by: Daniel Pivonka <dpivonka@redhat.com>
(cherry picked from commit 0facfac91fd8f71e5a8b869d818e7c2b07b93516)

src/pybind/mgr/cephadm/inventory.py
src/pybind/mgr/cephadm/module.py

index cd398221123e549a581a17c2dcddf519893c374f..d4db7761c8a9ed81012aa2cc0c962e6e95905082 100644 (file)
@@ -93,8 +93,16 @@ class Inventory:
             raise OrchestratorError('host %s does not exist' % host)
 
     def add_host(self, spec: HostSpec) -> None:
-        self._inventory[spec.hostname] = spec.to_json()
-        self.save()
+        if spec.hostname in self._inventory:
+            # addr
+            if self.get_addr(spec.hostname) != spec.addr:
+                self.set_addr(spec.hostname, spec.addr)
+            # labels
+            for label in spec.labels:
+                self.add_label(spec.hostname, label)
+        else:
+            self._inventory[spec.hostname] = spec.to_json()
+            self.save()
 
     def rm_host(self, host: str) -> None:
         self.assert_host(host)
@@ -602,6 +610,17 @@ class HostCache():
         self.registry_login_queue.add(host)
         self.last_client_files[host] = {}
 
+    def refresh_all_host_info(self, host):
+        # type: (str) -> None
+
+        self.last_host_check.pop(host, None)
+        self.daemon_refresh_queue.append(host)
+        self.registry_login_queue.add(host)
+        self.device_refresh_queue.append(host)
+        self.last_facts_update.pop(host, None)
+        self.osdspec_previews_refresh_queue.append(host)
+        self.last_autotune.pop(host, None)
+
     def invalidate_host_daemons(self, host):
         # type: (str) -> None
         self.daemon_refresh_queue.append(host)
index b1793535aded024cc8fcf5ecfad1cac9f87374ae..6a99cc40a38c168c159a41f880fb615483e0751e 100644 (file)
@@ -1413,6 +1413,11 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
         ]
 
     def _check_valid_addr(self, host: str, addr: str) -> str:
+        # make sure mgr is not resolving own ip
+        if addr in self.get_mgr_id():
+            raise OrchestratorError(
+                "Can not automatically resolve ip address of host where active mgr is running. Please explicitly provide the address.")
+
         # make sure hostname is resolvable before trying to make a connection
         try:
             ip_addr = utils.resolve_ip(addr)
@@ -1462,6 +1467,9 @@ Then run the following:
         if spec.addr == spec.hostname and ip_addr:
             spec.addr = ip_addr
 
+        if spec.hostname in self.inventory and self.inventory.get_addr(spec.hostname) != spec.addr:
+            self.cache.refresh_all_host_info(spec.hostname)
+
         # prime crush map?
         if spec.location:
             self.check_mon_command({