From: Michael Fritch Date: Tue, 17 Mar 2020 04:47:36 +0000 (-0600) Subject: mgr/cephadm: add utils.py X-Git-Tag: v15.2.1~19^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cf53b392912d9d879e25f9da1bcd7a07b11e9524;p=ceph.git mgr/cephadm: add utils.py move `name_to_config_section` and `assert_valid_host` into utils.py Signed-off-by: Michael Fritch (cherry picked from commit 322eea8099616b25a091ac66a1253d1991a0da2c) --- diff --git a/src/pybind/mgr/cephadm/__init__.py b/src/pybind/mgr/cephadm/__init__.py index 4d7a2fcb659da..f390f18c16aaa 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 15e2218ad1992..3590af2605293 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 @@ -900,7 +888,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, @@ -964,7 +952,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...' % @@ -991,7 +979,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!') @@ -1562,7 +1550,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 @@ -2197,7 +2185,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 d30b09b2e03f9..afe06d0752b52 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 0000000000000..3ecbb60d9ea5a --- /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'