]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: split _check_cluster function body into two functions
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 11 Oct 2024 18:20:03 +0000 (14:20 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Sat, 12 Oct 2024 17:37:33 +0000 (13:37 -0400)
Split the _check_cluster function body into two functions, one to check
the cluster resource when it is being removed and one for when the
cluster is present in the configuration. This matches the split already
done for checking the join auth and users-and-groups resources.

Best-viewed-with: git diff -w / Ignore whitespace

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/handler.py

index 7b993d5b60df5b3b0dbc3264ee754398fb0ed668..fe82564ee72e0d12f1c5dc6081fc3fece394e485 100644 (file)
@@ -788,22 +788,29 @@ def order_resources(
 
 def _check_cluster(cluster: ClusterRef, staging: _Staging) -> None:
     """Check that the cluster resource can be updated."""
-    if cluster.intent == Intent.REMOVED:
-        share_ids = ShareEntry.ids(staging)
-        clusters_used = {cid for cid, _ in share_ids}
-        if cluster.cluster_id in clusters_used:
-            raise ErrorResult(
-                cluster,
-                msg="cluster in use by shares",
-                status={
-                    'shares': [
-                        shid
-                        for cid, shid in share_ids
-                        if cid == cluster.cluster_id
-                    ]
-                },
-            )
-        return
+    if cluster.intent == Intent.PRESENT:
+        return _check_cluster_present(cluster, staging)
+    return _check_cluster_removed(cluster, staging)
+
+
+def _check_cluster_removed(cluster: ClusterRef, staging: _Staging) -> None:
+    share_ids = ShareEntry.ids(staging)
+    clusters_used = {cid for cid, _ in share_ids}
+    if cluster.cluster_id in clusters_used:
+        raise ErrorResult(
+            cluster,
+            msg="cluster in use by shares",
+            status={
+                'shares': [
+                    shid
+                    for cid, shid in share_ids
+                    if cid == cluster.cluster_id
+                ]
+            },
+        )
+
+
+def _check_cluster_present(cluster: ClusterRef, staging: _Staging) -> None:
     assert isinstance(cluster, resources.Cluster)
     cluster.validate()
     for auth_ref in _auth_refs(cluster):