Skip to content

Commit 2119fc9

Browse files
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: a5cde6e Reported-by: Anoop C S <[email protected]> Signed-off-by: John Mulligan <[email protected]>
1 parent f25386f commit 2119fc9

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/pybind/mgr/smb/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def _search_resources(self, matcher: _Matcher) -> List[SMBResource]:
411411
for cluster_id in self.cluster_ids():
412412
if (resources.Cluster, cluster_id) in matcher:
413413
out.append(self._cluster_entry(cluster_id).get_cluster())
414-
for share_id in cluster_shares[cluster_id]:
414+
for share_id in cluster_shares.get(cluster_id, []):
415415
if (resources.Share, cluster_id, share_id) in matcher:
416416
out.append(
417417
self._share_entry(

src/pybind/mgr/smb/tests/test_smb.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,58 @@ def test_show_invalid_input(tmodule):
737737
_example_cfg_1(tmodule)
738738
with pytest.raises(smb.cli.InvalidInputValue):
739739
tmodule.show(['ceph.smb.export'])
740+
741+
742+
def test_show_cluster_without_shares(tmodule):
743+
# this cluster will have no shares associated with it
744+
tmodule._internal_store.overwrite(
745+
{
746+
'clusters.foo': {
747+
'resource_type': 'ceph.smb.cluster',
748+
'cluster_id': 'foo',
749+
'auth_mode': 'active-directory',
750+
'intent': 'present',
751+
'domain_settings': {
752+
'realm': 'dom1.example.com',
753+
'join_sources': [
754+
{
755+
'source_type': 'resource',
756+
'ref': 'foo',
757+
}
758+
],
759+
},
760+
},
761+
'join_auths.foo': {
762+
'resource_type': 'ceph.smb.join.auth',
763+
'auth_id': 'foo',
764+
'intent': 'present',
765+
'auth': {
766+
'username': 'testadmin',
767+
'password': 'Passw0rd',
768+
},
769+
},
770+
}
771+
)
772+
773+
res, body, status = tmodule.show.command(['ceph.smb.cluster.foo'])
774+
assert res == 0
775+
assert (
776+
body.strip()
777+
== """
778+
{
779+
"resource_type": "ceph.smb.cluster",
780+
"cluster_id": "foo",
781+
"auth_mode": "active-directory",
782+
"intent": "present",
783+
"domain_settings": {
784+
"realm": "dom1.example.com",
785+
"join_sources": [
786+
{
787+
"source_type": "resource",
788+
"ref": "foo"
789+
}
790+
]
791+
}
792+
}
793+
""".strip()
794+
)

0 commit comments

Comments
 (0)