From 5c49070a058beb96a95ed53395b7ae2b87fb3dde Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 3 Oct 2023 13:56:36 -0400 Subject: [PATCH] cephadm: add unit test coverage for deploying monitoring Signed-off-by: John Mulligan --- src/cephadm/tests/test_deploy.py | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/cephadm/tests/test_deploy.py b/src/cephadm/tests/test_deploy.py index d11aca065fbfa..fad142ebbabbe 100644 --- a/src/cephadm/tests/test_deploy.py +++ b/src/cephadm/tests/test_deploy.py @@ -262,3 +262,41 @@ def test_deploy_nvmeof_container(cephadm_fs, monkeypatch): assert f.read() == 'icantbeliveitsnotiscsi' si = os.fstat(f.fileno()) assert (si.st_uid, si.st_gid) == (167, 167) + + +def test_deploy_a_monitoring_container(cephadm_fs, monkeypatch): + mocks = _common_mp(monkeypatch) + _firewalld = mocks['Firewalld'] + _get_ip_addresses = mock.MagicMock(return_value=(['10.10.10.10'], [])) + monkeypatch.setattr('cephadm.get_ip_addresses', _get_ip_addresses) + fsid = 'b01dbeef-701d-9abe-0000-e1e5a47004a7' + with with_cephadm_ctx([]) as ctx: + ctx.container_engine = mock_podman() + ctx.fsid = fsid + ctx.name = 'prometheus.fire' + ctx.image = 'quay.io/titans/prometheus:latest' + ctx.reconfig = False + ctx.config_blobs = { + 'config': 'XXXXXXX', + 'keyring': 'YYYYYY', + 'files': { + 'prometheus.yml': 'bettercallherc', + }, + } + _cephadm._common_deploy(ctx) + + basedir = pathlib.Path(f'/var/lib/ceph/{fsid}/prometheus.fire') + 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/titans/prometheus:latest --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --web.listen-address=:9095 --storage.tsdb.retention.time=15d --storage.tsdb.retention.size=0 --web.external-url=http://10.10.10.10:9095' + ) + _firewalld().open_ports.assert_not_called() + assert not (basedir / 'config').exists() + assert not (basedir / 'keyring').exists() + with open(basedir / 'etc/prometheus/prometheus.yml') as f: + assert f.read() == 'bettercallherc' + si = os.fstat(f.fileno()) + assert (si.st_uid, si.st_gid) == (8765, 8765) -- 2.39.5