Skip to content

Commit 5db0a0c

Browse files
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 <[email protected]>
1 parent 51a098d commit 5db0a0c

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/pybind/mgr/smb/handler.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -492,25 +492,12 @@ def _check(
492492
msg='a resource with the same ID already exists',
493493
)
494494
try:
495-
if isinstance(
496-
resource, (resources.Cluster, resources.RemovedCluster)
497-
):
498-
_check_cluster(resource, staging)
499-
elif isinstance(
500-
resource, (resources.Share, resources.RemovedShare)
501-
):
502-
_check_share(
503-
resource,
504-
staging,
505-
self._path_resolver,
506-
self._earmark_resolver,
507-
)
508-
elif isinstance(resource, resources.JoinAuth):
509-
_check_join_auths(resource, staging)
510-
elif isinstance(resource, resources.UsersAndGroups):
511-
_check_users_and_groups(resource, staging)
512-
else:
513-
raise TypeError('not a valid smb resource')
495+
cross_check_resource(
496+
resource,
497+
staging,
498+
path_resolver=self._path_resolver,
499+
earmark_resolver=self._earmark_resolver,
500+
)
514501
except ErrorResult as err:
515502
log.debug('rejected resource: %r', resource)
516503
return err
@@ -789,6 +776,30 @@ def _keyfunc(r: SMBResource) -> int:
789776
return sorted(resource_objs, key=_keyfunc)
790777

791778

779+
def cross_check_resource(
780+
resource: SMBResource,
781+
staging: _Staging,
782+
*,
783+
path_resolver: PathResolver,
784+
earmark_resolver: EarmarkResolver,
785+
) -> None:
786+
if isinstance(resource, (resources.Cluster, resources.RemovedCluster)):
787+
_check_cluster(resource, staging)
788+
elif isinstance(resource, (resources.Share, resources.RemovedShare)):
789+
_check_share(
790+
resource,
791+
staging,
792+
path_resolver,
793+
earmark_resolver,
794+
)
795+
elif isinstance(resource, resources.JoinAuth):
796+
_check_join_auths(resource, staging)
797+
elif isinstance(resource, resources.UsersAndGroups):
798+
_check_users_and_groups(resource, staging)
799+
else:
800+
raise TypeError('not a valid smb resource')
801+
802+
792803
def _check_cluster(cluster: ClusterRef, staging: _Staging) -> None:
793804
"""Check that the cluster resource can be updated."""
794805
if cluster.intent == Intent.PRESENT:

0 commit comments

Comments
 (0)