]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/smb: fix ceph smb show when a cluster has not associated shares
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 10 Jul 2024 13:50:45 +0000 (09:50 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 10 Jul 2024 13:55:05 +0000 (09:55 -0400)
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 <anoopcs@cryptolab.net>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/handler.py
src/pybind/mgr/smb/tests/test_smb.py

index 84702e72f7885a5d99ee517ddae01e7671d049b4..f230d7952d70a0c4c5befe501adaf0306e5fae5e 100644 (file)
@@ -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(
index 4ee55e0aa90d1dbd46aa3caace53b65d9b370877..8943123f9d11cfbbe263b55a1c444f08128710b2 100644 (file)
@@ -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()
+    )