]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add a test case to cover generating init containers
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 14 Jun 2023 16:01:23 +0000 (12:01 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 9 Aug 2023 17:48:07 +0000 (13:48 -0400)
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 <jmulligan@redhat.com>
src/cephadm/tests/test_custom_container.py

index d98e37450265c7a0e8e1b060e045b3a029d7212c..cc7cb7d2f403d6b6f0d19034f6ef5c1322322283 100644 (file)
@@ -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')