From: John Mulligan Date: Fri, 11 Oct 2024 18:20:03 +0000 (-0400) Subject: mgr/smb: split _check_cluster function body into two functions X-Git-Tag: v20.0.0~725^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2f7fe668fe21da13bfe94f12d029433ff237bd0c;p=ceph.git mgr/smb: split _check_cluster function body into two functions 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 --- diff --git a/src/pybind/mgr/smb/handler.py b/src/pybind/mgr/smb/handler.py index 7b993d5b60df..fe82564ee72e 100644 --- a/src/pybind/mgr/smb/handler.py +++ b/src/pybind/mgr/smb/handler.py @@ -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):