From 322eea8099616b25a091ac66a1253d1991a0da2c Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Mon, 16 Mar 2020 22:47:36 -0600 Subject: [PATCH] mgr/cephadm: add utils.py move `name_to_config_section` and `assert_valid_host` into utils.py Signed-off-by: Michael Fritch --- src/pybind/mgr/cephadm/__init__.py | 2 +- src/pybind/mgr/cephadm/module.py | 24 ++++++------------------ src/pybind/mgr/cephadm/nfs.py | 4 +++- src/pybind/mgr/cephadm/utils.py | 15 +++++++++++++++ 4 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 src/pybind/mgr/cephadm/utils.py diff --git a/src/pybind/mgr/cephadm/__init__.py b/src/pybind/mgr/cephadm/__init__.py index 4d7a2fcb659..f390f18c16a 100644 --- a/src/pybind/mgr/cephadm/__init__.py +++ b/src/pybind/mgr/cephadm/__init__.py @@ -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 diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 228e4d4946b..980c49d3f9e 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -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, diff --git a/src/pybind/mgr/cephadm/nfs.py b/src/pybind/mgr/cephadm/nfs.py index d30b09b2e03..afe06d0752b 100644 --- a/src/pybind/mgr/cephadm/nfs.py +++ b/src/pybind/mgr/cephadm/nfs.py @@ -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 index 00000000000..3ecbb60d9ea --- /dev/null +++ b/src/pybind/mgr/cephadm/utils.py @@ -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' -- 2.39.5