]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: use pyfakefs during `test_create_daemon_dirs_prometheus` 42289/head
authorMichael Fritch <mfritch@suse.com>
Fri, 9 Jul 2021 19:35:52 +0000 (13:35 -0600)
committerMichael Fritch <mfritch@suse.com>
Mon, 12 Jul 2021 04:37:12 +0000 (22:37 -0600)
convert test to use the `cephadm_fs` fixture

Signed-off-by: Michael Fritch <mfritch@suse.com>
src/cephadm/tests/test_cephadm.py

index f664ac4c482efeecfeadb98ceb5e2e020c143e0b..66e6e3b4140ba676289bad90d5625bf78619ec32 100644 (file)
@@ -1,6 +1,7 @@
 # type: ignore
 
 import errno
+import json
 import mock
 import os
 import pytest
@@ -977,14 +978,7 @@ class TestMonitoring(object):
         version = cd.Monitoring.get_version(ctx, 'container_id', daemon_type)
         assert version == '0.16.1'
 
-    @mock.patch('cephadm.os.fchown')
-    @mock.patch('cephadm.get_parm')
-    @mock.patch('cephadm.makedirs')
-    @mock.patch('cephadm.open')
-    @mock.patch('cephadm.make_log_dir')
-    @mock.patch('cephadm.make_data_dir')
-    def test_create_daemon_dirs_prometheus(self, make_data_dir, make_log_dir, _open, makedirs,
-                                           get_parm, fchown):
+    def test_create_daemon_dirs_prometheus(self, cephadm_fs):
         """
         Ensures the required and optional files given in the configuration are
         created and mapped correctly inside the container. Tests absolute and
@@ -997,13 +991,12 @@ class TestMonitoring(object):
         daemon_id = 'home'
         ctx = cd.CephadmContext()
         ctx.data_dir = '/somedir'
-        files = {
+        ctx.config_json = json.dumps({
             'files': {
                 'prometheus.yml': 'foo',
                 '/etc/prometheus/alerting/ceph_alerts.yml': 'bar'
             }
-        }
-        get_parm.return_value = files
+        })
 
         cd.create_daemon_dirs(ctx,
                               fsid,
@@ -1020,14 +1013,17 @@ class TestMonitoring(object):
             daemon_type=daemon_type,
             daemon_id=daemon_id
         )
-        assert _open.call_args_list == [
-            mock.call('{}/etc/prometheus/prometheus.yml'.format(prefix), 'w',
-                 encoding='utf-8'),
-            mock.call('{}/etc/prometheus/alerting/ceph_alerts.yml'.format(prefix), 'w',
-                 encoding='utf-8'),
-        ]
-        assert mock.call().__enter__().write('foo') in _open.mock_calls
-        assert mock.call().__enter__().write('bar') in _open.mock_calls
+
+        expected = {
+            'etc/prometheus/prometheus.yml': 'foo',
+            'etc/prometheus/alerting/ceph_alerts.yml': 'bar',
+        }
+
+        for file,content in expected.items():
+            file = os.path.join(prefix, file)
+            assert os.path.exists(file)
+            with open(file) as f:
+                assert f.read() == content
 
 
 class TestBootstrap(object):