From: John Mulligan Date: Tue, 30 Apr 2024 13:22:03 +0000 (-0400) Subject: mgr/smb: convert smb module cluster create to use linked resources X-Git-Tag: v20.0.0~1768^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=00f2f716601637264f43bf758e159ca52ca43082;p=ceph.git mgr/smb: convert smb module cluster create to use linked resources Convert the smb mgr module cli to use linked join auth and users-and-groups resources when created on the `cluster create` command line. These linked resources with have semi-ranodmized names and be linked to the cluster that we're creating on the CLI. Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/module.py b/src/pybind/mgr/smb/module.py index fff7fc46925..a6eef0cb4fb 100644 --- a/src/pybind/mgr/smb/module.py +++ b/src/pybind/mgr/smb/module.py @@ -86,6 +86,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): """Create an smb cluster""" domain_settings = None user_group_settings = None + to_apply: List[resources.SMBResource] = [] if domain_realm or domain_join_ref or domain_join_user_pass: join_sources: List[resources.JoinSource] = [] @@ -108,13 +109,21 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'a domain join username & password value' ' must contain a "%" separator' ) + rname = handler.rand_name(cluster_id) join_sources.append( resources.JoinSource( - source_type=JoinSourceType.PASSWORD, + source_type=JoinSourceType.RESOURCE, + ref=rname, + ) + ) + to_apply.append( + resources.JoinAuth( + auth_id=rname, auth=resources.JoinAuthValues( username=username, password=password, ), + linked_to_cluster=cluster_id, ) ) domain_settings = resources.DomainSettings( @@ -140,15 +149,22 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): for unpw in define_user_pass or []: username, password = unpw.split('%', 1) users.append({'name': username, 'password': password}) - user_group_settings += [ + rname = handler.rand_name(cluster_id) + user_group_settings.append( resources.UserGroupSource( - source_type=UserGroupSourceType.INLINE, + source_type=UserGroupSourceType.RESOURCE, ref=rname + ) + ) + to_apply.append( + resources.UsersAndGroups( + users_groups_id=rname, values=resources.UserGroupSettings( users=users, groups=[], ), + linked_to_cluster=cluster_id, ) - ] + ) pspec = resources.WrappedPlacementSpec.wrap( PlacementSpec.from_string(placement) @@ -161,7 +177,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): custom_dns=custom_dns, placement=pspec, ) - return self._handler.apply([cluster]).one() + to_apply.append(cluster) + return self._handler.apply(to_apply).squash(cluster) @cli.SMBCommand('cluster rm', perm='rw') def cluster_rm(self, cluster_id: str) -> handler.Result: diff --git a/src/pybind/mgr/smb/tests/test_smb.py b/src/pybind/mgr/smb/tests/test_smb.py index 85bf98a85cf..09380cad869 100644 --- a/src/pybind/mgr/smb/tests/test_smb.py +++ b/src/pybind/mgr/smb/tests/test_smb.py @@ -490,15 +490,24 @@ def test_cluster_create_ad1(tmodule): assert len(result.src.domain_settings.join_sources) == 1 assert ( result.src.domain_settings.join_sources[0].source_type - == smb.enums.JoinSourceType.PASSWORD + == smb.enums.JoinSourceType.RESOURCE ) + assert result.src.domain_settings.join_sources[0].ref.startswith('fizzle') + assert 'additional_results' in result.status + assert len(result.status['additional_results']) == 1 assert ( - result.src.domain_settings.join_sources[0].auth.username - == 'Administrator' + result.status['additional_results'][0]['resource']['resource_type'] + == 'ceph.smb.join.auth' ) assert ( - result.src.domain_settings.join_sources[0].auth.password == 'Passw0rd' + result.status['additional_results'][0]['resource'][ + 'linked_to_cluster' + ] + == 'fizzle' ) + assert result.status['additional_results'][0]['resource'][ + 'auth_id' + ].startswith('fizzle') def test_cluster_create_ad2(tmodule):