]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: use CephadmContext rather than MagicMock
authorMichael Fritch <mfritch@suse.com>
Fri, 9 Jul 2021 01:35:42 +0000 (19:35 -0600)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 10 Aug 2021 14:32:12 +0000 (16:32 +0200)
MagicMock hides attribute errors:

```
self = <cephadm.CephadmContext object at 0x7f1121e62370>, name = 'config_json'

    def __getattr__(self, name: str) -> Any:
        if '_conf' in self.__dict__ and hasattr(self._conf, name):
            return getattr(self._conf, name)
        elif '_args' in self.__dict__ and hasattr(self._args, name):
            return getattr(self._args, name)
        else:
>           return super().__getattribute__(name)
E           AttributeError: 'CephadmContext' object has no attribute 'config_json'
```

Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit 4a99b771a4a59671728e072bb27270bba8cb78c8)

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 543ee93e3c3646e47d411bc90419c7c8cffd2942..f4c3e756109e21dcf57fabcf78a00a87403a5605 100755 (executable)
@@ -2177,7 +2177,9 @@ def create_daemon_dirs(ctx, fsid, daemon_type, daemon_id, uid, gid,
             f.write(keyring)
 
     if daemon_type in Monitoring.components.keys():
-        config_json: Dict[str, Any] = get_parm(ctx.config_json)
+        config_json: Dict[str, Any] = dict()
+        if 'config_json' in ctx:
+            config_json = get_parm(ctx.config_json)
 
         # Set up directories specific to the monitoring component
         config_dir = ''
index adf5661b189a6b0d91dc71e413f2b37dcfaccfe7..d500fbdf3991c26327f7336ab60b8c8376c6dd5d 100644 (file)
@@ -1166,7 +1166,7 @@ class TestMonitoring(object):
         daemon_type = 'prometheus'
         uid, gid = 50, 50
         daemon_id = 'home'
-        ctx = mock.Mock()
+        ctx = cd.CephadmContext()
         ctx.data_dir = '/somedir'
         files = {
             'files': {