]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: extract a cross_check_resource function from handler class
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 2 Jul 2025 17:30:14 +0000 (13:30 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 2 Jul 2025 20:28:11 +0000 (16:28 -0400)
Move the sequence of if-isinstance checks out of the class into a
function that can be called (and tested) on it's own. This prepares
for additional future refactoring of this area.

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

index 73e635521bb188b7406b8423d60caf9dcf1cf383..e66cdb1c71e3d11b95b7ee331a6e6337af1ce24c 100644 (file)
@@ -492,25 +492,12 @@ class ClusterConfigHandler:
                     msg='a resource with the same ID already exists',
                 )
         try:
-            if isinstance(
-                resource, (resources.Cluster, resources.RemovedCluster)
-            ):
-                _check_cluster(resource, staging)
-            elif isinstance(
-                resource, (resources.Share, resources.RemovedShare)
-            ):
-                _check_share(
-                    resource,
-                    staging,
-                    self._path_resolver,
-                    self._earmark_resolver,
-                )
-            elif isinstance(resource, resources.JoinAuth):
-                _check_join_auths(resource, staging)
-            elif isinstance(resource, resources.UsersAndGroups):
-                _check_users_and_groups(resource, staging)
-            else:
-                raise TypeError('not a valid smb resource')
+            cross_check_resource(
+                resource,
+                staging,
+                path_resolver=self._path_resolver,
+                earmark_resolver=self._earmark_resolver,
+            )
         except ErrorResult as err:
             log.debug('rejected resource: %r', resource)
             return err
@@ -789,6 +776,30 @@ def order_resources(
     return sorted(resource_objs, key=_keyfunc)
 
 
+def cross_check_resource(
+    resource: SMBResource,
+    staging: _Staging,
+    *,
+    path_resolver: PathResolver,
+    earmark_resolver: EarmarkResolver,
+) -> None:
+    if isinstance(resource, (resources.Cluster, resources.RemovedCluster)):
+        _check_cluster(resource, staging)
+    elif isinstance(resource, (resources.Share, resources.RemovedShare)):
+        _check_share(
+            resource,
+            staging,
+            path_resolver,
+            earmark_resolver,
+        )
+    elif isinstance(resource, resources.JoinAuth):
+        _check_join_auths(resource, staging)
+    elif isinstance(resource, resources.UsersAndGroups):
+        _check_users_and_groups(resource, staging)
+    else:
+        raise TypeError('not a valid smb resource')
+
+
 def _check_cluster(cluster: ClusterRef, staging: _Staging) -> None:
     """Check that the cluster resource can be updated."""
     if cluster.intent == Intent.PRESENT: