]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: adding logic to close ports when removing a daemon 46780/head
authorRedouane Kachach <rkachach@redhat.com>
Tue, 26 Apr 2022 10:30:38 +0000 (12:30 +0200)
committerAdam King <adking@redhat.com>
Tue, 21 Jun 2022 17:21:06 +0000 (13:21 -0400)
Fixes: https://tracker.ceph.com/issues/52906
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
(cherry picked from commit 4deb546ffd67ac8f05d2788150764a26b5671b87)

Conflicts:
src/pybind/mgr/cephadm/serve.py

src/cephadm/cephadm
src/pybind/mgr/cephadm/serve.py

index ad78d783b1f0a3d2a4701b5bdda65d36f8799d3e..c24400278e4dbea200b8d0b1baf0093f63dffa66 100755 (executable)
@@ -6207,6 +6207,18 @@ def command_rm_daemon(ctx):
             CephadmDaemon.uninstall(ctx, ctx.fsid, daemon_type, daemon_id)
         call_throws(ctx, ['rm', '-rf', data_dir])
 
+    if 'tcp_ports' in ctx and ctx.tcp_ports is not None:
+        ports: List[int] = [int(p) for p in ctx.tcp_ports.split()]
+        try:
+            fw = Firewalld(ctx)
+            fw.close_ports(ports)
+            fw.apply_rules()
+        except RuntimeError as e:
+            # in case we cannot close the ports we will remove
+            # the daemon but keep them open.
+            logger.warning(f' Error when trying to close ports: {e}')
+
+
 ##################################
 
 
@@ -8533,6 +8545,9 @@ def _get_parser():
         required=True,
         action=CustomValidation,
         help='daemon name (type.id)')
+    parser_rm_daemon.add_argument(
+        '--tcp-ports',
+        help='List of tcp ports to close in the host firewall')
     parser_rm_daemon.add_argument(
         '--fsid',
         required=True,
index d7f9e6b9940d4f8c977864b50e5fa9e34706cbfd..7e84583da1b7839fdc82bd20bcd55234ea67eadc 100644 (file)
@@ -1188,11 +1188,15 @@ class CephadmServe:
         with set_exception_subject('service', daemon.service_id(), overwrite=True):
 
             self.mgr.cephadm_services[daemon_type_to_service(daemon_type)].pre_remove(daemon)
-
             # NOTE: we are passing the 'force' flag here, which means
             # we can delete a mon instances data.
-            args = ['--name', name, '--force']
-            self.log.info('Removing daemon %s from %s' % (name, host))
+            dd = self.mgr.cache.get_daemon(daemon.daemon_name)
+            if dd.ports:
+                args = ['--name', name, '--force', '--tcp-ports', ' '.join(map(str, dd.ports))]
+            else:
+                args = ['--name', name, '--force']
+
+            self.log.info('Removing daemon %s from %s -- ports %s' % (name, host, dd.ports))
             out, err, code = self._run_cephadm(
                 host, name, 'rm-daemon', args)
             if not code: