]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: apply hostname/addr checks to 'orch host set-addr' too 41107/head
authorSage Weil <sage@newdream.net>
Mon, 3 May 2021 16:09:09 +0000 (12:09 -0400)
committerSage Weil <sage@newdream.net>
Tue, 4 May 2021 12:21:19 +0000 (08:21 -0400)
Signed-off-by: Sage Weil <sage@newdream.net>
src/pybind/mgr/cephadm/module.py

index 29373c9e8b87c5ce511bce14ce060b60798eab17..fa904b21e3ae8a1ef06433af4ac401c562e1e187 100644 (file)
@@ -1359,25 +1359,18 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
             )
         ]
 
-    def _add_host(self, spec):
-        # type: (HostSpec) -> str
-        """
-        Add a host to be managed by the orchestrator.
-
-        :param host: host name
-        """
-        assert_valid_host(spec.hostname)
+    def _check_valid_addr(self, host: str, addr: str) -> None:
         # make sure hostname is resolvable before trying to make a connection
         try:
-            utils.resolve_ip(spec.addr)
+            utils.resolve_ip(addr)
         except OrchestratorError as e:
             msg = str(e) + f'''
-You may need to supply an address for {spec.addr}
+You may need to supply an address for {addr}
 
 Please make sure that the host is reachable and accepts connections using the cephadm SSH key
 To add the cephadm SSH key to the host:
 > ceph cephadm get-pub-key > ~/ceph.pub
-> ssh-copy-id -f -i ~/ceph.pub {self.ssh_user}@{spec.addr}
+> ssh-copy-id -f -i ~/ceph.pub {self.ssh_user}@{addr}
 
 To check that the host is reachable open a new shell with the --no-hosts flag:
 > cephadm shell --no-hosts
@@ -1386,19 +1379,30 @@ Then run the following:
 > ceph cephadm get-ssh-config > ssh_config
 > ceph config-key get mgr/cephadm/ssh_identity_key > ~/cephadm_private_key
 > chmod 0600 ~/cephadm_private_key
-> ssh -F ssh_config -i ~/cephadm_private_key {self.ssh_user}@{spec.addr}'''
+> ssh -F ssh_config -i ~/cephadm_private_key {self.ssh_user}@{addr}'''
             raise OrchestratorError(msg)
 
-        out, err, code = CephadmServe(self)._run_cephadm(spec.hostname, cephadmNoImage, 'check-host',
-                                                         ['--expect-hostname', spec.hostname],
-                                                         addr=spec.addr,
-                                                         error_ok=True, no_fsid=True)
+        out, err, code = CephadmServe(self)._run_cephadm(
+            host, cephadmNoImage, 'check-host',
+            ['--expect-hostname', host],
+            addr=addr,
+            error_ok=True, no_fsid=True)
         if code:
             # err will contain stdout and stderr, so we filter on the message text to
             # only show the errors
             errors = [_i.replace("ERROR: ", "") for _i in err if _i.startswith('ERROR')]
-            raise OrchestratorError('New host %s (%s) failed check(s): %s' % (
-                spec.hostname, spec.addr, errors))
+            raise OrchestratorError('Host %s (%s) failed check(s): %s' % (
+                host, addr, errors))
+
+    def _add_host(self, spec):
+        # type: (HostSpec) -> str
+        """
+        Add a host to be managed by the orchestrator.
+
+        :param host: host name
+        """
+        assert_valid_host(spec.hostname)
+        self._check_valid_addr(spec.hostname, spec.addr)
 
         # prime crush map?
         if spec.location:
@@ -1438,6 +1442,7 @@ Then run the following:
 
     @handle_orch_error
     def update_host_addr(self, host: str, addr: str) -> str:
+        self._check_valid_addr(host, addr)
         self.inventory.set_addr(host, addr)
         self._reset_con(host)
         self.event.set()  # refresh stray health check