]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: add utils.py
authorMichael Fritch <mfritch@suse.com>
Tue, 17 Mar 2020 04:47:36 +0000 (22:47 -0600)
committerMichael Fritch <mfritch@suse.com>
Wed, 25 Mar 2020 22:26:14 +0000 (16:26 -0600)
move `name_to_config_section` and `assert_valid_host` into utils.py

Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/cephadm/__init__.py
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/nfs.py
src/pybind/mgr/cephadm/utils.py [new file with mode: 0644]

index 4d7a2fcb659dae2b5fedb316b33ffdf2dfded698..f390f18c16aaacde7e142cd485dacdc48135f23c 100644 (file)
@@ -3,4 +3,4 @@ import os
 if 'UNITTEST' in os.environ:
     import tests
 
-from .module import CephadmOrchestrator, name_to_config_section
+from .module import CephadmOrchestrator
index 228e4d4946be59ad71cc48a259fa54ddec3c9ed8..980c49d3f9e3cf8b332921c0f69f4313fb1adac9 100644 (file)
@@ -40,6 +40,7 @@ from orchestrator import OrchestratorError, OrchestratorValidationError, HostSpe
     CLICommandMeta
 
 from . import remotes
+from . import utils
 from .nfs import NFSGanesha
 from .osd import RemoveUtil, OSDRemoval
 
@@ -97,19 +98,6 @@ except ImportError:
             self.cleanup()
 
 
-def name_to_config_section(name):
-    """
-    Map from daemon names to ceph entity names (as seen in config)
-    """
-    daemon_type = name.split('.', 1)[0]
-    if daemon_type in ['rgw', 'rbd-mirror', 'nfs', 'crash']:
-        return 'client.' + name
-    elif daemon_type in ['mon', 'osd', 'mds', 'mgr', 'client']:
-        return name
-    else:
-        return 'mon'
-
-
 class SpecStore():
     def __init__(self, mgr):
         # type: (CephadmOrchestrator) -> None
@@ -907,7 +895,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                     'prefix': 'config set',
                     'name': 'container_image',
                     'value': target_name,
-                    'who': name_to_config_section(daemon_type + '.' + d.daemon_id),
+                    'who': utils.name_to_config_section(daemon_type + '.' + d.daemon_id),
                 })
                 self._daemon_action(
                     d.daemon_type,
@@ -971,7 +959,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                 })
             to_clean = []
             for section in image_settings.keys():
-                if section.startswith(name_to_config_section(daemon_type) + '.'):
+                if section.startswith(utils.name_to_config_section(daemon_type) + '.'):
                     to_clean.append(section)
             if to_clean:
                 self.log.debug('Upgrade: Cleaning up container_image for %s...' %
@@ -998,7 +986,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
             ret, image, err = self.mon_command({
                 'prefix': 'config rm',
                 'name': 'container_image',
-                'who': name_to_config_section(daemon_type),
+                'who': utils.name_to_config_section(daemon_type),
             })
 
         self.log.info('Upgrade: Complete!')
@@ -1587,7 +1575,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
                     # get container image
                     ret, image, err = self.mon_command({
                         'prefix': 'config get',
-                        'who': name_to_config_section(entity),
+                        'who': utils.name_to_config_section(entity),
                         'key': 'container_image',
                     })
                     image = image.strip() # type: ignore
@@ -2229,7 +2217,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule):
             if daemon_type == 'mon':
                 ename = 'mon.'
             else:
-                ename = name_to_config_section(daemon_type + '.' + daemon_id)
+                ename = utils.name_to_config_section(daemon_type + '.' + daemon_id)
             ret, keyring, err = self.mon_command({
                 'prefix': 'auth get',
                 'entity': ename,
index d30b09b2e03f959c0b7d2398e10c38d0c1c05f02..afe06d0752b52657f8cf8c6620567e7749f5deb6 100644 (file)
@@ -7,6 +7,8 @@ from ceph.deployment.service_spec import NFSServiceSpec
 import cephadm
 from orchestrator import OrchestratorError
 
+from . import utils
+
 logger = logging.getLogger(__name__)
 
 class NFSGanesha(object):
@@ -41,7 +43,7 @@ class NFSGanesha(object):
 
     def get_keyring_entity(self):
         # type: () -> str
-        return cephadm.name_to_config_section(self.get_rados_user())
+        return utils.name_to_config_section(self.get_rados_user())
 
     def get_or_create_keyring(self, entity=None):
         # type: (Optional[str]) -> str
diff --git a/src/pybind/mgr/cephadm/utils.py b/src/pybind/mgr/cephadm/utils.py
new file mode 100644 (file)
index 0000000..3ecbb60
--- /dev/null
@@ -0,0 +1,15 @@
+import re
+
+from orchestrator import OrchestratorError
+
+def name_to_config_section(name):
+    """
+    Map from daemon names to ceph entity names (as seen in config)
+    """
+    daemon_type = name.split('.', 1)[0]
+    if daemon_type in ['rgw', 'rbd-mirror', 'nfs', 'crash']:
+        return 'client.' + name
+    elif daemon_type in ['mon', 'osd', 'mds', 'mgr', 'client']:
+        return name
+    else:
+        return 'mon'