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)
##################################
-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:
--- /dev/null
+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
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 = '-'
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