From 64b4a16b36af987440b63d97f4e2a4d1422ff97b Mon Sep 17 00:00:00 2001 From: Adam King Date: Thu, 18 Nov 2021 15:22:39 -0500 Subject: [PATCH] mgr/cephadm: re-use old ip when re-adding hosts if necessary When a host is re-added without an explicit ip we can default to the old ip we had stored for the host rather than either keeping the loopback address or throwing an exception. We only want to actually error when the only options left are error or use a resolved loopback address Fixes: https://tracker.ceph.com/issues/53438 Signed-off-by: Adam King (cherry picked from commit 7e8d8317bef1b35cddd99950e503f57710002e80) Conflicts: src/pybind/mgr/cephadm/module.py --- src/pybind/mgr/cephadm/module.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 1479d8ca261fd..732eb2eccb971 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1,5 +1,6 @@ import json import errno +import ipaddress import logging import re import shlex @@ -1456,11 +1457,6 @@ 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) @@ -1483,6 +1479,15 @@ Then run the following: > ssh -F ssh_config -i ~/cephadm_private_key {self.ssh_user}@{addr}''' raise OrchestratorError(msg) + if ipaddress.ip_address(ip_addr).is_loopback and host == addr: + # if this is a re-add, use old address. otherwise error + if host not in self.inventory or self.inventory.get_addr(host) == host: + raise OrchestratorError( + (f'Cannot automatically resolve ip address of host {host}. Ip resolved to loopback address: {ip_addr}\n' + + f'Please explicitly provide the address (ceph orch host add {host} --addr )')) + self.log.debug( + f'Received loopback address resolving ip for {host}: {ip_addr}. Falling back to previous address.') + ip_addr = self.inventory.get_addr(host) out, err, code = CephadmServe(self)._run_cephadm( host, cephadmNoImage, 'check-host', ['--expect-hostname', host], -- 2.39.5