Skip to content

Commit 00f2f71

Browse files
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 <[email protected]>
1 parent e05121f commit 00f2f71

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/pybind/mgr/smb/module.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def cluster_create(
8686
"""Create an smb cluster"""
8787
domain_settings = None
8888
user_group_settings = None
89+
to_apply: List[resources.SMBResource] = []
8990

9091
if domain_realm or domain_join_ref or domain_join_user_pass:
9192
join_sources: List[resources.JoinSource] = []
@@ -108,13 +109,21 @@ def cluster_create(
108109
'a domain join username & password value'
109110
' must contain a "%" separator'
110111
)
112+
rname = handler.rand_name(cluster_id)
111113
join_sources.append(
112114
resources.JoinSource(
113-
source_type=JoinSourceType.PASSWORD,
115+
source_type=JoinSourceType.RESOURCE,
116+
ref=rname,
117+
)
118+
)
119+
to_apply.append(
120+
resources.JoinAuth(
121+
auth_id=rname,
114122
auth=resources.JoinAuthValues(
115123
username=username,
116124
password=password,
117125
),
126+
linked_to_cluster=cluster_id,
118127
)
119128
)
120129
domain_settings = resources.DomainSettings(
@@ -140,15 +149,22 @@ def cluster_create(
140149
for unpw in define_user_pass or []:
141150
username, password = unpw.split('%', 1)
142151
users.append({'name': username, 'password': password})
143-
user_group_settings += [
152+
rname = handler.rand_name(cluster_id)
153+
user_group_settings.append(
144154
resources.UserGroupSource(
145-
source_type=UserGroupSourceType.INLINE,
155+
source_type=UserGroupSourceType.RESOURCE, ref=rname
156+
)
157+
)
158+
to_apply.append(
159+
resources.UsersAndGroups(
160+
users_groups_id=rname,
146161
values=resources.UserGroupSettings(
147162
users=users,
148163
groups=[],
149164
),
165+
linked_to_cluster=cluster_id,
150166
)
151-
]
167+
)
152168

153169
pspec = resources.WrappedPlacementSpec.wrap(
154170
PlacementSpec.from_string(placement)
@@ -161,7 +177,8 @@ def cluster_create(
161177
custom_dns=custom_dns,
162178
placement=pspec,
163179
)
164-
return self._handler.apply([cluster]).one()
180+
to_apply.append(cluster)
181+
return self._handler.apply(to_apply).squash(cluster)
165182

166183
@cli.SMBCommand('cluster rm', perm='rw')
167184
def cluster_rm(self, cluster_id: str) -> handler.Result:

src/pybind/mgr/smb/tests/test_smb.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,24 @@ def test_cluster_create_ad1(tmodule):
490490
assert len(result.src.domain_settings.join_sources) == 1
491491
assert (
492492
result.src.domain_settings.join_sources[0].source_type
493-
== smb.enums.JoinSourceType.PASSWORD
493+
== smb.enums.JoinSourceType.RESOURCE
494494
)
495+
assert result.src.domain_settings.join_sources[0].ref.startswith('fizzle')
496+
assert 'additional_results' in result.status
497+
assert len(result.status['additional_results']) == 1
495498
assert (
496-
result.src.domain_settings.join_sources[0].auth.username
497-
== 'Administrator'
499+
result.status['additional_results'][0]['resource']['resource_type']
500+
== 'ceph.smb.join.auth'
498501
)
499502
assert (
500-
result.src.domain_settings.join_sources[0].auth.password == 'Passw0rd'
503+
result.status['additional_results'][0]['resource'][
504+
'linked_to_cluster'
505+
]
506+
== 'fizzle'
501507
)
508+
assert result.status['additional_results'][0]['resource'][
509+
'auth_id'
510+
].startswith('fizzle')
502511

503512

504513
def test_cluster_create_ad2(tmodule):

0 commit comments

Comments
 (0)