From: John Mulligan Date: Wed, 1 May 2024 14:55:27 +0000 (-0400) Subject: mgr/smb: add create_only arg for handler apply function X-Git-Tag: testing/wip-pdonnell-testing-20240622.145006-debug~50^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=83ee0c9fdc2170704a2e31fbcb8fb75681e39692;p=ceph-ci.git mgr/smb: add create_only arg for handler apply function Add a create_only argument to the handler class apply function. This flag is used to prevent modification of existing resources. This flag will be use by 'cluster create' and 'share create' commands to make them true to their names and not sneaky modify-or-create commands. Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/handler.py b/src/pybind/mgr/smb/handler.py index 1bf96557f6b..7047f372c6b 100644 --- a/src/pybind/mgr/smb/handler.py +++ b/src/pybind/mgr/smb/handler.py @@ -342,7 +342,12 @@ class ClusterConfigHandler: f' orch {self._orch!r}' ) - def apply(self, inputs: Iterable[SMBResource]) -> ResultGroup: + def apply( + self, inputs: Iterable[SMBResource], *, create_only: bool = False + ) -> ResultGroup: + """Apply resource configuration changes. + Set `create_only` to disable changing existing resource values. + """ log.debug('applying changes to internal data store') results = ResultGroup() staging = _Staging(self.internal_store) @@ -351,7 +356,9 @@ class ClusterConfigHandler: for resource in incoming: staging.stage(resource) for resource in incoming: - results.append(self._check(resource, staging)) + results.append( + self._check(resource, staging, create_only=create_only) + ) except ErrorResult as err: results.append(err) except Exception as err: @@ -428,9 +435,22 @@ class ClusterConfigHandler: log.debug("search found %d resources", len(out)) return out - def _check(self, resource: SMBResource, staging: _Staging) -> Result: + def _check( + self, + resource: SMBResource, + staging: _Staging, + *, + create_only: bool = False, + ) -> Result: """Check/validate a staged resource.""" log.debug('staging resource: %r', resource) + if create_only: + if not staging.is_new(resource): + return Result( + resource, + success=False, + msg='a resource with the same ID already exists', + ) try: if isinstance( resource, (resources.Cluster, resources.RemovedCluster)