From: John Mulligan Date: Wed, 14 Jun 2023 16:01:23 +0000 (-0400) Subject: cephadm: add a test case to cover generating init containers X-Git-Tag: v19.0.0~711^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=555395fb292c8bd765d86fcffac04c048635e899;p=ceph.git cephadm: add a test case to cover generating init containers Add a test case that covers the act of setting init_containers in the deploy config on a custom container instance. This test executes custom containers that both specify custom volume_mounts and not, which are expected to "inherit" the volume_mounts of the primary container's config. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/tests/test_custom_container.py b/src/cephadm/tests/test_custom_container.py index d98e37450265..cc7cb7d2f403 100644 --- a/src/cephadm/tests/test_custom_container.py +++ b/src/cephadm/tests/test_custom_container.py @@ -135,3 +135,103 @@ def test_deploy_custom_container(cephadm_fs): for l in runfile_lines if not l.startswith(('#', 'set', '/usr/bin/podman run')) ]), 'remaining commands should be "rms"' + + +def test_deploy_custom_container_and_inits(cephadm_fs): + fsid = 'b01dbeef-701d-9abe-0000-e1e5a47004a7' + with with_cephadm_ctx([]) as ctx: + ctx.container_engine = mock_podman() + ctx.fsid = fsid + ctx.name = 'container.tdccai' + ctx.reconfig = False + ctx.allow_ptrace = False + ctx.image = 'quay.io/foobar/quux:latest' + ctx.extra_entrypoint_args = [ + '--label', + 'treepollenparty', + '--servers', + '192.168.8.42,192.168.8.43,192.168.12.11', + ] + ctx.init_containers = [ + { + 'entrypoint': '/usr/local/bin/prepare.sh', + 'volume_mounts': { + 'data1': '/var/lib/myapp', + }, + }, + { + 'entrypoint': '/usr/local/bin/populate.sh', + 'entrypoint_args': [ + '--source=https://my.cool.example.com/samples/geo.1.txt', + ], + }, + ] + ctx.config_blobs = { + 'dirs': ['data1', 'data2'], + 'volume_mounts': { + 'data1': '/var/lib/myapp', + 'data2': '/srv', + }, + } + + _cephadm._common_deploy(ctx) + + with open(f'/var/lib/ceph/{fsid}/container.tdccai/unit.run') as f: + runfile_lines = f.read().splitlines() + assert 'set -e' in runfile_lines + assert len(runfile_lines) > 2 + assert runfile_lines[-1] == ( + '/usr/bin/podman run' + ' --rm --ipc=host --stop-signal=SIGTERM --init' + ' --name ceph-b01dbeef-701d-9abe-0000-e1e5a47004a7-container-tdccai' + ' -d --log-driver journald' + ' --conmon-pidfile /run/ceph-b01dbeef-701d-9abe-0000-e1e5a47004a7@container.tdccai.service-pid' + ' --cidfile /run/ceph-b01dbeef-701d-9abe-0000-e1e5a47004a7@container.tdccai.service-cid' + ' --cgroups=split --no-hosts' + ' -e CONTAINER_IMAGE=quay.io/foobar/quux:latest' + ' -e NODE_NAME=host1' + ' -v /var/lib/ceph/b01dbeef-701d-9abe-0000-e1e5a47004a7/container.tdccai/data1:/var/lib/myapp' + ' -v /var/lib/ceph/b01dbeef-701d-9abe-0000-e1e5a47004a7/container.tdccai/data2:/srv' + ' quay.io/foobar/quux:latest' + ' --label treepollenparty --servers 192.168.8.42,192.168.8.43,192.168.12.11' + ) + assert all([ + l.startswith('! /usr/bin/podman rm') + for l in runfile_lines + if not l.startswith(('#', 'set', '/usr/bin/podman run')) + ]), 'remaining commands should be "rms"' + + idx = runfile_lines.index('# init container cleanup') + assert idx > 0 + assert runfile_lines[idx + 1].startswith('! /usr/bin/podman rm') + assert runfile_lines[idx + 2].startswith('! /usr/bin/podman rm') + + idx = runfile_lines.index('# init container 0: ceph-b01dbeef-701d-9abe-0000-e1e5a47004a7-container-tdccai-init') + assert idx > 0 + assert runfile_lines[idx + 1] == ( + '/usr/bin/podman run' + ' --stop-signal=SIGTERM' + ' --entrypoint /usr/local/bin/prepare.sh' + ' --name ceph-b01dbeef-701d-9abe-0000-e1e5a47004a7-container-tdccai-init' + ' -e CONTAINER_IMAGE=quay.io/foobar/quux:latest' + ' -v /var/lib/ceph/b01dbeef-701d-9abe-0000-e1e5a47004a7/container.tdccai/data1:/var/lib/myapp' + ' quay.io/foobar/quux:latest' + ) + assert runfile_lines[idx + 2].startswith('! /usr/bin/podman rm') + assert runfile_lines[idx + 3].startswith('! /usr/bin/podman rm') + + idx = runfile_lines.index('# init container 1: ceph-b01dbeef-701d-9abe-0000-e1e5a47004a7-container-tdccai-init') + assert idx > 0 + assert runfile_lines[idx + 1] == ( + '/usr/bin/podman run' + ' --stop-signal=SIGTERM' + ' --entrypoint /usr/local/bin/populate.sh' + ' --name ceph-b01dbeef-701d-9abe-0000-e1e5a47004a7-container-tdccai-init' + ' -e CONTAINER_IMAGE=quay.io/foobar/quux:latest' + ' -v /var/lib/ceph/b01dbeef-701d-9abe-0000-e1e5a47004a7/container.tdccai/data1:/var/lib/myapp' + ' -v /var/lib/ceph/b01dbeef-701d-9abe-0000-e1e5a47004a7/container.tdccai/data2:/srv' + ' quay.io/foobar/quux:latest' + ' --source=https://my.cool.example.com/samples/geo.1.txt' + ) + assert runfile_lines[idx + 2].startswith('! /usr/bin/podman rm') + assert runfile_lines[idx + 3].startswith('! /usr/bin/podman rm')