From: John Mulligan Date: Wed, 10 Jul 2024 13:50:45 +0000 (-0400) Subject: mgr/smb: fix ceph smb show when a cluster has not associated shares X-Git-Tag: testing/wip-vshankar-testing-20240718.183435-debug~33^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2119fc9330941d4863fce97356b77acb7635d4b3;p=ceph-ci.git mgr/smb: fix ceph smb show when a cluster has not associated shares Fix an error condition in the `ceph smb show` command. When the ceph smb show command was run after creating a usersgroups and cluster resource but no shares resources the following traceback was seen: ``` Error EINVAL: Traceback (most recent call last): File "/usr/share/ceph/mgr/mgr_module.py", line 1910, in _handle_command return CLICommand.COMMANDS[cmd['prefix']].call(self, cmd, inbuf) File "/usr/share/ceph/mgr/mgr_module.py", line 507, in call return self.func(mgr, **kwargs) File "/usr/share/ceph/mgr/object_format.py", line 592, in _format_response robj = f(*args, **kwargs) File "/usr/share/ceph/mgr/smb/module.py", line 258, in show resources = self._handler.matching_resources(resource_names) File "/usr/share/ceph/mgr/smb/handler.py", line 403, in matching_resources return self._search_resources(matcher) File "/usr/share/ceph/mgr/smb/handler.py", line 414, in _search_resources for share_id in cluster_shares[cluster_id]: KeyError: 'smbcluster' ``` Fixes: a5cde6ebe940 Reported-by: Anoop C S Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/handler.py b/src/pybind/mgr/smb/handler.py index 84702e72f78..f230d7952d7 100644 --- a/src/pybind/mgr/smb/handler.py +++ b/src/pybind/mgr/smb/handler.py @@ -411,7 +411,7 @@ class ClusterConfigHandler: for cluster_id in self.cluster_ids(): if (resources.Cluster, cluster_id) in matcher: out.append(self._cluster_entry(cluster_id).get_cluster()) - for share_id in cluster_shares[cluster_id]: + for share_id in cluster_shares.get(cluster_id, []): if (resources.Share, cluster_id, share_id) in matcher: out.append( self._share_entry( diff --git a/src/pybind/mgr/smb/tests/test_smb.py b/src/pybind/mgr/smb/tests/test_smb.py index 4ee55e0aa90..8943123f9d1 100644 --- a/src/pybind/mgr/smb/tests/test_smb.py +++ b/src/pybind/mgr/smb/tests/test_smb.py @@ -737,3 +737,58 @@ def test_show_invalid_input(tmodule): _example_cfg_1(tmodule) with pytest.raises(smb.cli.InvalidInputValue): tmodule.show(['ceph.smb.export']) + + +def test_show_cluster_without_shares(tmodule): + # this cluster will have no shares associated with it + tmodule._internal_store.overwrite( + { + 'clusters.foo': { + 'resource_type': 'ceph.smb.cluster', + 'cluster_id': 'foo', + 'auth_mode': 'active-directory', + 'intent': 'present', + 'domain_settings': { + 'realm': 'dom1.example.com', + 'join_sources': [ + { + 'source_type': 'resource', + 'ref': 'foo', + } + ], + }, + }, + 'join_auths.foo': { + 'resource_type': 'ceph.smb.join.auth', + 'auth_id': 'foo', + 'intent': 'present', + 'auth': { + 'username': 'testadmin', + 'password': 'Passw0rd', + }, + }, + } + ) + + res, body, status = tmodule.show.command(['ceph.smb.cluster.foo']) + assert res == 0 + assert ( + body.strip() + == """ +{ + "resource_type": "ceph.smb.cluster", + "cluster_id": "foo", + "auth_mode": "active-directory", + "intent": "present", + "domain_settings": { + "realm": "dom1.example.com", + "join_sources": [ + { + "source_type": "resource", + "ref": "foo" + } + ] + } +} + """.strip() + )