From dd8f59a1e88313d61f16e4b43bb47247dc64e71f Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 3 Oct 2023 12:50:44 -0400 Subject: [PATCH] cephadm: add unit test coverage for deploying keepalived Signed-off-by: John Mulligan --- src/cephadm/tests/test_deploy.py | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/cephadm/tests/test_deploy.py b/src/cephadm/tests/test_deploy.py index 6fd36cc6eb1..4c0b5c845f7 100644 --- a/src/cephadm/tests/test_deploy.py +++ b/src/cephadm/tests/test_deploy.py @@ -1,3 +1,4 @@ +import os import pathlib import unittest from unittest import mock @@ -84,3 +85,57 @@ def test_deploy_snmp_container(cephadm_fs, monkeypatch): assert basedir.is_dir() assert not (basedir / 'config').exists() assert not (basedir / 'keyring').exists() + + +def test_deploy_keepalived_container(cephadm_fs, monkeypatch): + _call = mock.MagicMock(return_value=('', '', 0)) + monkeypatch.setattr('cephadmlib.container_types.call', _call) + _call_throws = mock.MagicMock(return_value=0) + monkeypatch.setattr( + 'cephadmlib.container_types.call_throws', _call_throws + ) + _firewalld = mock.MagicMock() + _firewalld().external_ports.get.return_value = [] + monkeypatch.setattr('cephadm.Firewalld', _firewalld) + _extract_uid_gid = mock.MagicMock() + _extract_uid_gid.return_value = (8765, 8765) + monkeypatch.setattr('cephadm.extract_uid_gid', _extract_uid_gid) + _install_sysctl = mock.MagicMock() + monkeypatch.setattr('cephadm.install_sysctl', _install_sysctl) + fsid = 'b01dbeef-701d-9abe-0000-e1e5a47004a7' + with with_cephadm_ctx([]) as ctx: + ctx.container_engine = mock_podman() + ctx.fsid = fsid + ctx.name = 'keepalived.uiop' + ctx.image = 'quay.io/eeranimated/keepalived:latest' + ctx.reconfig = False + ctx.config_blobs = { + 'destination': '192.168.100.10:8899', + 'config': 'XXXXXXX', + 'keyring': 'YYYYYY', + 'files': { + 'keepalived.conf': 'neversayneveragain', + }, + } + _cephadm._common_deploy(ctx) + + basedir = pathlib.Path(f'/var/lib/ceph/{fsid}/keepalived.uiop') + assert basedir.is_dir() + with open(basedir / 'unit.run') as f: + runfile_lines = f.read().splitlines() + assert 'podman' in runfile_lines[-1] + assert runfile_lines[-1].endswith('quay.io/eeranimated/keepalived:latest') + _firewalld().open_ports.assert_not_called() + assert not (basedir / 'config').exists() + assert not (basedir / 'keyring').exists() + with open(basedir / 'keepalived.conf') as f: + assert f.read() == 'neversayneveragain' + with open(basedir / 'keepalived.conf') as f: + assert f.read() == 'neversayneveragain' + si = os.fstat(f.fileno()) + assert (si.st_uid, si.st_gid) == (8765, 8765) + assert (basedir / 'keepalived').is_dir() + si = (basedir / 'keepalived').stat() + assert (si.st_uid, si.st_gid) == (8765, 8765) + assert _install_sysctl.call_count == 1 + assert len(_install_sysctl.call_args[0][-1].get_sysctl_settings()) > 1 -- 2.39.5