]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: use service_name method of daemon identity
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 17 Nov 2023 16:23:47 +0000 (11:23 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 2 Jan 2024 14:30:20 +0000 (09:30 -0500)
Use the new service_name method of the DaemonIdentity type in some basic
cases where string concatenation was being used.
I also converted the name of the agent's helper method to match and made
it private to avoid future confusion.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/container_daemon_form.py
src/cephadm/tests/test_agent.py

index 79f5bab5f246fd37664e17a328103fda1aaeedc8..dcb62c9517e487d183aa8f9d98ef921119522370 100755 (executable)
@@ -930,9 +930,8 @@ def _update_container_args_for_podman(
 ) -> None:
     if not isinstance(ctx.container_engine, Podman):
         return
-    service_name = f'{ident.unit_name}.service'
     container_args.extend(
-        ctx.container_engine.service_args(ctx, service_name)
+        ctx.container_engine.service_args(ctx, ident.service_name)
     )
 
 
@@ -1394,19 +1393,19 @@ class CephadmAgent(DaemonForm):
         with write_new(meta_file_path) as f:
             f.write(json.dumps(meta, indent=4) + '\n')
 
-        unit_file_path = os.path.join(self.ctx.unit_dir, self.unit_name())
+        unit_file_path = os.path.join(self.ctx.unit_dir, self._service_name())
         with write_new(unit_file_path) as f:
             f.write(self.unit_file())
 
         call_throws(self.ctx, ['systemctl', 'daemon-reload'])
-        call(self.ctx, ['systemctl', 'stop', self.unit_name()],
+        call(self.ctx, ['systemctl', 'stop', self._service_name()],
              verbosity=CallVerbosity.DEBUG)
-        call(self.ctx, ['systemctl', 'reset-failed', self.unit_name()],
+        call(self.ctx, ['systemctl', 'reset-failed', self._service_name()],
              verbosity=CallVerbosity.DEBUG)
-        call_throws(self.ctx, ['systemctl', 'enable', '--now', self.unit_name()])
+        call_throws(self.ctx, ['systemctl', 'enable', '--now', self._service_name()])
 
-    def unit_name(self) -> str:
-        return '{}.service'.format(get_unit_name(self.fsid, self.daemon_type, self.daemon_id))
+    def _service_name(self) -> str:
+        return self.identity.service_name
 
     def unit_run(self) -> str:
         py3 = shutil.which('python3')
index 693b0cf8df0bc0d43b9b27cf53785d88d5958afc..1fc6960d652098b77f78f1007be1371f58c00ea7 100644 (file)
@@ -157,9 +157,8 @@ def daemon_to_container(
     if auto_podman_mounts and _is_podman:
         ctx.container_engine.update_mounts(ctx, container_mounts)
     if auto_podman_args and _is_podman:
-        service_name = f'{daemon.identity.unit_name}.service'
         container_args.extend(
-            ctx.container_engine.service_args(ctx, service_name)
+            ctx.container_engine.service_args(ctx, daemon.identity.service_name)
         )
 
     return CephContainer.for_daemon(
index 38c35e35583073f4ff78bb008287abb3141c309c..4904cb4f61fc1f8406e29c5cd402e2fe03f017ee 100644 (file)
@@ -69,17 +69,18 @@ def test_agent_deploy_daemon_unit(_call_throws, cephadm_fs):
         _check_file(f'{AGENT_DIR}/unit.meta', json.dumps({'meta': 'data'}, indent=4) + '\n')
 
         # check unit file was created correctly
-        _check_file(f'{ctx.unit_dir}/{agent.unit_name()}', agent.unit_file())
+        svcname = agent._service_name()
+        _check_file(f'{ctx.unit_dir}/{svcname}', agent.unit_file())
 
         expected_call_throws_calls = [
             mock.call(ctx, ['systemctl', 'daemon-reload']),
-            mock.call(ctx, ['systemctl', 'enable', '--now', agent.unit_name()]),
+            mock.call(ctx, ['systemctl', 'enable', '--now', svcname]),
         ]
         _call_throws.assert_has_calls(expected_call_throws_calls)
 
         expected_call_calls = [
-            mock.call(ctx, ['systemctl', 'stop', agent.unit_name()], verbosity=_cephadm.CallVerbosity.DEBUG),
-            mock.call(ctx, ['systemctl', 'reset-failed', agent.unit_name()], verbosity=_cephadm.CallVerbosity.DEBUG),
+            mock.call(ctx, ['systemctl', 'stop', svcname], verbosity=_cephadm.CallVerbosity.DEBUG),
+            mock.call(ctx, ['systemctl', 'reset-failed', svcname], verbosity=_cephadm.CallVerbosity.DEBUG),
         ]
         _cephadm.call.assert_has_calls(expected_call_calls)