]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add more thorough test coverage to unit file generation
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 17 Jul 2023 13:24:14 +0000 (09:24 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 3 Nov 2023 22:51:47 +0000 (18:51 -0400)
Add tests that check the generation of the standard systemd unit
for cephadm services. This test ensures that non trivial changes
to the content of these files are noticed.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/tests/test_unit_file.py

index 193baff35a78917eba4fd731e093cc376a2fd54d..0ebd84be3e84a1ae263edefc78b815d2fcaea5f6 100644 (file)
@@ -21,17 +21,21 @@ from cephadmlib.constants import CGROUPS_SPLIT_PODMAN_VERSION
 _cephadm = import_cephadm()
 
 
+def _get_unit_file(ctx, fsid):
+    return str(_cephadm.get_unit_file(ctx, fsid))
+
+
 def test_docker_engine_requires_docker():
     ctx = _cephadm.CephadmContext()
     ctx.container_engine = mock_docker()
-    r = _cephadm.get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
+    r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
     assert 'Requires=docker.service' in r
 
 
 def test_podman_engine_does_not_req_docker():
     ctx = _cephadm.CephadmContext()
     ctx.container_engine = mock_podman()
-    r = _cephadm.get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
+    r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
     assert 'Requires=docker.service' not in r
 
 
@@ -40,7 +44,7 @@ def test_podman_engine_forking_service():
     # and related parameters
     ctx = _cephadm.CephadmContext()
     ctx.container_engine = mock_podman()
-    r = _cephadm.get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
+    r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
     assert 'Type=forking' in r
     assert 'PIDFile=' in r
     assert 'ExecStartPre' in r
@@ -51,6 +55,93 @@ def test_podman_with_split_cgroups_sets_delegate():
     ctx = _cephadm.CephadmContext()
     ctx.container_engine = mock_podman()
     ctx.container_engine.version = CGROUPS_SPLIT_PODMAN_VERSION
-    r = _cephadm.get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
+    r = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
     assert 'Type=forking' in r
     assert 'Delegate=yes' in r
+
+
+def _ignore_blank_lines(value):
+    return [v for v in value.splitlines() if v]
+
+
+def test_new_docker():
+    ctx = _cephadm.CephadmContext()
+    ctx.container_engine = mock_docker()
+    ru = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
+    assert _ignore_blank_lines(ru) == [
+        '# generated by cephadm',
+        '[Unit]',
+        'Description=Ceph %i for 9b9d7609-f4d5-4aba-94c8-effa764d96c9',
+        '# According to:',
+        '#   http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget',
+        '# these can be removed once ceph-mon will dynamically change network',
+        '# configuration.',
+        'After=network-online.target local-fs.target time-sync.target docker.service',
+        'Wants=network-online.target local-fs.target time-sync.target',
+        'Requires=docker.service',
+        'PartOf=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
+        'Before=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
+        '[Service]',
+        'LimitNOFILE=1048576',
+        'LimitNPROC=1048576',
+        'EnvironmentFile=-/etc/environment',
+        'ExecStart=/bin/bash '
+        '/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.run',
+        "ExecStop=-/bin/bash -c 'bash "
+        "/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.stop'",
+        'ExecStopPost=-/bin/bash '
+        '/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.poststop',
+        'KillMode=none',
+        'Restart=on-failure',
+        'RestartSec=10s',
+        'TimeoutStartSec=200',
+        'TimeoutStopSec=120',
+        'StartLimitInterval=30min',
+        'StartLimitBurst=5',
+        '[Install]',
+        'WantedBy=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
+    ]
+
+
+def test_new_podman():
+    ctx = _cephadm.CephadmContext()
+    ctx.container_engine = mock_podman()
+    ctx.container_engine.version = CGROUPS_SPLIT_PODMAN_VERSION
+    ru = _get_unit_file(ctx, '9b9d7609-f4d5-4aba-94c8-effa764d96c9')
+    assert _ignore_blank_lines(ru) == [
+        '# generated by cephadm',
+        '[Unit]',
+        'Description=Ceph %i for 9b9d7609-f4d5-4aba-94c8-effa764d96c9',
+        '# According to:',
+        '#   http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget',
+        '# these can be removed once ceph-mon will dynamically change network',
+        '# configuration.',
+        'After=network-online.target local-fs.target time-sync.target',
+        'Wants=network-online.target local-fs.target time-sync.target',
+        'PartOf=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
+        'Before=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
+        '[Service]',
+        'LimitNOFILE=1048576',
+        'LimitNPROC=1048576',
+        'EnvironmentFile=-/etc/environment',
+        'ExecStart=/bin/bash '
+        '/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.run',
+        "ExecStop=-/bin/bash -c 'bash "
+        "/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.stop'",
+        'ExecStopPost=-/bin/bash '
+        '/var/lib/ceph/9b9d7609-f4d5-4aba-94c8-effa764d96c9/%i/unit.poststop',
+        'KillMode=none',
+        'Restart=on-failure',
+        'RestartSec=10s',
+        'TimeoutStartSec=200',
+        'TimeoutStopSec=120',
+        'StartLimitInterval=30min',
+        'StartLimitBurst=5',
+        'ExecStartPre=-/bin/rm -f %t/%n-pid %t/%n-cid',
+        'ExecStopPost=-/bin/rm -f %t/%n-pid %t/%n-cid',
+        'Type=forking',
+        'PIDFile=%t/%n-pid',
+        'Delegate=yes',
+        '[Install]',
+        'WantedBy=ceph-9b9d7609-f4d5-4aba-94c8-effa764d96c9.target',
+    ]