]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: create deployment_utils module
authorJohn Mulligan <jmulligan@redhat.com>
Sun, 5 Nov 2023 21:03:53 +0000 (16:03 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 30 Nov 2023 21:55:59 +0000 (16:55 -0500)
Create a deployment_utils module for deployment related functions that
don't have a better home.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/deployment_utils.py [new file with mode: 0644]
src/cephadm/tests/test_cephadm.py

index 959676ba3af17be99bc8673a48dadcd4356169e1..14b064a95428b78757c4548ad52579a1b8840ba2 100755 (executable)
@@ -176,6 +176,7 @@ from cephadmlib.container_daemon_form import (
 from cephadmlib.sysctl import install_sysctl, migrate_sysctl_dir
 from cephadmlib.firewalld import Firewalld, update_firewalld
 from cephadmlib import templating
+from cephadmlib.deployment_utils import to_deployment_container
 
 
 FuncT = TypeVar('FuncT', bound=Callable)
@@ -5257,36 +5258,6 @@ def command_registry_login(ctx: CephadmContext) -> int:
 ##################################
 
 
-def to_deployment_container(
-    ctx: CephadmContext, ctr: CephContainer
-) -> CephContainer:
-    """Given a standard ceph container instance return a CephContainer
-    prepared for a deployment as a daemon, having the extra args and
-    custom configurations added.
-    NOTE: The `ctr` object is mutated before being returned.
-    """
-    if 'extra_container_args' in ctx and ctx.extra_container_args:
-        ctr.container_args.extend(ctx.extra_container_args)
-    if 'extra_entrypoint_args' in ctx and ctx.extra_entrypoint_args:
-        ctr.args.extend(ctx.extra_entrypoint_args)
-    ccfiles = fetch_custom_config_files(ctx)
-    if ccfiles:
-        mandatory_keys = ['mount_path', 'content']
-        for conf in ccfiles:
-            if all(k in conf for k in mandatory_keys):
-                mount_path = conf['mount_path']
-                assert ctr.identity
-                file_path = os.path.join(
-                    ctx.data_dir,
-                    ctr.identity.fsid,
-                    'custom_config_files',
-                    ctr.identity.daemon_name,
-                    os.path.basename(mount_path)
-                )
-                ctr.volume_mounts[file_path] = mount_path
-    return ctr
-
-
 def get_deployment_type(
     ctx: CephadmContext, ident: 'DaemonIdentity',
 ) -> DeploymentType:
diff --git a/src/cephadm/cephadmlib/deployment_utils.py b/src/cephadm/cephadmlib/deployment_utils.py
new file mode 100644 (file)
index 0000000..908fa97
--- /dev/null
@@ -0,0 +1,35 @@
+import os
+
+from .container_types import CephContainer
+from .context import CephadmContext
+from cephadmlib.context_getters import fetch_custom_config_files
+
+
+def to_deployment_container(
+    ctx: CephadmContext, ctr: CephContainer
+) -> CephContainer:
+    """Given a standard ceph container instance return a CephContainer
+    prepared for a deployment as a daemon, having the extra args and
+    custom configurations added.
+    NOTE: The `ctr` object is mutated before being returned.
+    """
+    if 'extra_container_args' in ctx and ctx.extra_container_args:
+        ctr.container_args.extend(ctx.extra_container_args)
+    if 'extra_entrypoint_args' in ctx and ctx.extra_entrypoint_args:
+        ctr.args.extend(ctx.extra_entrypoint_args)
+    ccfiles = fetch_custom_config_files(ctx)
+    if ccfiles:
+        mandatory_keys = ['mount_path', 'content']
+        for conf in ccfiles:
+            if all(k in conf for k in mandatory_keys):
+                mount_path = conf['mount_path']
+                assert ctr.identity
+                file_path = os.path.join(
+                    ctx.data_dir,
+                    ctr.identity.fsid,
+                    'custom_config_files',
+                    ctr.identity.daemon_name,
+                    os.path.basename(mount_path),
+                )
+                ctr.volume_mounts[file_path] = mount_path
+    return ctr
index 6379ce28a1d2e88fe1f4df634a0de9f89c3de6a4..c5d8d19f26d68f43010f083bc75c051453da8b70 100644 (file)
@@ -318,13 +318,17 @@ class TestCephAdm(object):
         with pytest.raises(Exception):
             _cephadm.prepare_dashboard(ctx, 0, 0, lambda _, extra_mounts=None, ___=None : '5', lambda : None)
 
-    @mock.patch('cephadm.logger')
-    @mock.patch('cephadm.fetch_custom_config_files')
-    @mock.patch('cephadm.get_container')
-    def test_to_deployment_container(self, _get_container, _get_config, _logger):
+    def test_to_deployment_container(self, funkypatch):
         """
         test to_deployment_container properly makes use of extra container args and custom conf files
         """
+        from cephadmlib.deployment_utils import to_deployment_container
+
+        funkypatch.patch('cephadm.logger')
+        _get_config = funkypatch.patch(
+            'cephadmlib.deployment_utils.fetch_custom_config_files'
+        )
+        _get_container = funkypatch.patch('cephadm.get_container')
 
         ctx = _cephadm.CephadmContext()
         ctx.config_json = '-'
@@ -358,7 +362,7 @@ class TestCephAdm(object):
             host_network=True,
         )
         c = _cephadm.get_container(ctx, ident)
-        c = _cephadm.to_deployment_container(ctx, c)
+        c = to_deployment_container(ctx, c)
 
         assert '--pids-limit=12345' in c.container_args
         assert '--something' in c.container_args