From: Michael Fritch Date: Fri, 9 Jul 2021 01:35:42 +0000 (-0600) Subject: cephadm: use CephadmContext rather than MagicMock X-Git-Tag: v16.2.6~54^2~40 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=efb0bb05c8cff06f60d00329013953430697cccb;p=ceph.git cephadm: use CephadmContext rather than MagicMock MagicMock hides attribute errors: ``` self = , 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 (cherry picked from commit 4a99b771a4a59671728e072bb27270bba8cb78c8) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 543ee93e3c3..f4c3e756109 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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 = '' diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index adf5661b189..d500fbdf399 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -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': {