]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: file copy moved to seperate method
authorPaul Cuzner <pcuzner@redhat.com>
Tue, 17 Nov 2020 20:29:14 +0000 (09:29 +1300)
committerPaul Cuzner <pcuzner@redhat.com>
Tue, 17 Nov 2020 20:29:14 +0000 (09:29 +1300)
Moving to a separate method, means the copy can be
mocked out within the unit tests.

In addition, the the generate_config call has been removed
from the add_cephadm_exporter since it's not needed.

Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
src/pybind/mgr/cephadm/module.py

index 528d0d35a553b01a5c4d97b2fe42776c9c6f2c29..b31e3d4b09fc5f7c0cf15104f88bd974fda072cd 100644 (file)
@@ -1876,19 +1876,12 @@ To check that the host is reachable:
 
             if daemon_spec.daemon_type == 'cephadm-exporter':
                 if not reconfig:
-                    # Use tee (from coreutils) to create a copy of cephadm on the target
-                    self.log.info(f"Deploying cephadm binary to {daemon_spec.host}")
-                    with self._remote_connection(daemon_spec.host) as tpl:
-                        conn, _connr = tpl
-                        _out, err, code = remoto.process.check(
-                            conn,
-                            ['tee', '-', '/var/lib/ceph/{}/cephadm'.format(self._cluster_fsid)],
-                            stdin=self._cephadm.encode('utf-8'))
-                        if code:
-                            # creation of the file failed on the target, so abort the deploy
-                            msg = f"Unable to deploy the cephadm binary to {daemon_spec.host}"
-                            self.log.warning(msg)
-                            return msg
+                    assert daemon_spec.host
+                    deploy_ok = self._deploy_cephadm_binary(daemon_spec.host)
+                    if not deploy_ok:
+                        msg = f"Unable to deploy the cephadm binary to {daemon_spec.host}"
+                        self.log.warning(msg)
+                        return msg
 
             cephadm_config, deps = self.cephadm_services[daemon_spec.daemon_type].generate_config(
                 daemon_spec)
@@ -1956,6 +1949,17 @@ To check that the host is reachable:
                     daemon_spec.name(), OrchestratorEvent.ERROR, f'Failed to {what}: {err}')
             return msg
 
+    def _deploy_cephadm_binary(self, host: str) -> bool:
+        # Use tee (from coreutils) to create a copy of cephadm on the target machine
+        self.log.info(f"Deploying cephadm binary to {host}")
+        with self._remote_connection(host) as tpl:
+            conn, _connr = tpl
+            _out, _err, code = remoto.process.check(
+                conn,
+                ['tee', '-', '/var/lib/ceph/{}/cephadm'.format(self._cluster_fsid)],
+                stdin=self._cephadm.encode('utf-8'))
+        return code == 0
+
     @forall_hosts
     def _remove_daemons(self, name, host) -> str:
         return self._remove_daemon(name, host)
@@ -2266,8 +2270,7 @@ To check that the host is reachable:
         # type: (ServiceSpec) -> List[str]
         return self._add_daemon('cephadm-exporter',
                                 spec,
-                                self.cephadm_exporter_service.prepare_create,
-                                self.cephadm_exporter_service.generate_config)
+                                self.cephadm_exporter_service.prepare_create)
 
     @trivial_completion
     def apply_cephadm_exporter(self, spec) -> str: