From: John Mulligan Date: Wed, 2 Jul 2025 17:30:14 +0000 (-0400) Subject: mgr/smb: extract a cross_check_resource function from handler class X-Git-Tag: v21.0.0~256^2~267^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5db0a0cc759fc321e7c1fe2c34ed0c91cab75fca;p=ceph.git mgr/smb: extract a cross_check_resource function from handler class 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 --- diff --git a/src/pybind/mgr/smb/handler.py b/src/pybind/mgr/smb/handler.py index 73e635521bb1..e66cdb1c71e3 100644 --- a/src/pybind/mgr/smb/handler.py +++ b/src/pybind/mgr/smb/handler.py @@ -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: