Skip to content

Commit d84f6fe

Browse files
doc: Documenting the database
1 parent 1c0db02 commit d84f6fe

File tree

7 files changed

+242
-71
lines changed

7 files changed

+242
-71
lines changed

diracx-cli/src/diracx/cli/internal/config.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ def set_user_as_pilot_user(
190190
sub: Annotated[str, typer.Option()],
191191
pilot_preferred_username: Annotated[str, typer.Option()],
192192
):
193+
"""Set a user as a pilot.
194+
195+
*Warning*: This requires an existing VO, and also a group and a pilot dedicated to the pilot.
196+
"""
193197
config_repo = TypeAdapter(ConfigSourceUrl).validate_python(config_repo)
194198
if config_repo.scheme != "git+file" or config_repo.path is None:
195199
raise NotImplementedError("Only git+file:// URLs are supported")
@@ -200,45 +204,52 @@ def set_user_as_pilot_user(
200204

201205
# The VO has to exist
202206
if vo not in config.Registry:
203-
typer.echo(f"ERROR: Virtual Organization {vo} does not exist", err=True)
207+
typer.secho(
208+
f"ERROR: Virtual Organization {vo} does not exist", err=True, fg="red"
209+
)
204210
raise typer.Exit(1)
205211

206212
# The sub has to exist
207213
if sub not in config.Registry[vo].Users:
208-
typer.echo(
214+
typer.secho(
209215
f"ERROR: User {sub} does not exist. You have to create it first before setting it as a pilot user",
210216
err=True,
217+
fg="red",
211218
)
212219
raise typer.Exit(1)
213220

214221
# The preferred_username has to match the sub
215222
if not config.Registry[vo].Users[sub].PreferedUsername == pilot_preferred_username:
216-
typer.echo(
217-
f"ERROR: User {sub} does not match pilot_preferred_username {pilot_preferred_username}"
223+
typer.secho(
224+
f"ERROR: User {sub} does not match pilot_preferred_username {pilot_preferred_username}",
225+
err=True,
226+
fg="red",
218227
)
219228
raise typer.Exit(1)
220229

221230
# The pilot group has to exist
222231
groups = config.Registry[vo].Groups
223232
if pilot_group not in groups:
224-
typer.echo(
233+
typer.secho(
225234
(
226235
f"ERROR: Group {pilot_group} does not exist."
227236
"You have to create it first before setting it as a pilot group"
228237
),
229238
err=True,
239+
fg="red",
230240
)
231241
raise typer.Exit(1)
232242

233243
# The sub has to be in the pilot group
234244
group_users = groups[pilot_group].Users
235245
if sub not in group_users:
236-
typer.echo(
246+
typer.secho(
237247
(
238248
f"ERROR: User {sub} is not set into the pilot group."
239249
"You have to add it before setting this group as a pilot group"
240250
),
241251
err=True,
252+
fg="red",
242253
)
243254
raise typer.Exit(1)
244255

@@ -251,7 +262,7 @@ def set_user_as_pilot_user(
251262
pilot = config.Operations[vo].Pilot
252263

253264
if pilot is None:
254-
typer.echo("Pilot operation must not be None", err=True)
265+
typer.secho("Pilot operation must not be None", err=True, fg="red")
255266
raise typer.Exit(1)
256267

257268
pilot["GenericPilotGroup"] = pilot_group
@@ -262,8 +273,8 @@ def set_user_as_pilot_user(
262273
config=config,
263274
message=f"Setting user {sub} ({pilot_preferred_username}) as {vo}'s pilot user in group {pilot_group}",
264275
)
265-
typer.echo(f"Successfully set user as pilot to {config_repo}")
266-
typer.echo(f"New config :\n{config}")
276+
typer.secho(f"Successfully set user as pilot to {config_repo}", fg="green")
277+
typer.secho(f"New config :\n{config}", fg="green")
267278

268279

269280
def update_config_and_commit(repo_path: Path, config: Config, message: str):

diracx-cli/tests/test_internal.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,64 @@ def test_add_user(cs_repo, vo, user_group):
222222
assert sub in config.Registry[vo].Users
223223
for group in user_group or [TEST_USER_GROUP]:
224224
assert config.Registry[vo].Groups[group].Users == {sub}
225+
226+
227+
def test_add_pilot_user(cs_repo):
228+
229+
sub = "lhcb:rvandeme"
230+
231+
pilot_group = "pilot_group"
232+
pilot_user = "pilot_user"
233+
234+
config = ConfigSource.create_from_url(backend_url=cs_repo).read_config()
235+
236+
# Add a second group to it
237+
result = runner.invoke(
238+
app,
239+
[
240+
"internal",
241+
"add-group",
242+
cs_repo,
243+
f"--vo={TEST_VO}",
244+
f"--group={pilot_group}",
245+
"--properties",
246+
"GenericPilot",
247+
],
248+
)
249+
assert result.exit_code == 0, result.output
250+
251+
# Add a user to it
252+
result = runner.invoke(
253+
app,
254+
[
255+
"internal",
256+
"add-user",
257+
cs_repo,
258+
f"--vo={TEST_VO}",
259+
f"--sub={sub}",
260+
f"--preferred-username={pilot_user}",
261+
f"--group={pilot_group}",
262+
],
263+
)
264+
assert result.exit_code == 0, result.output
265+
266+
# Set this user as a pilot
267+
result = runner.invoke(
268+
app,
269+
[
270+
"internal",
271+
"set-user-as-pilot-user",
272+
cs_repo,
273+
f"--vo={TEST_VO}",
274+
f"--sub={sub}",
275+
f"--pilot-preferred-username={pilot_user}",
276+
f"--pilot-group={pilot_group}",
277+
],
278+
)
279+
assert result.exit_code == 0, result.output
280+
281+
config = ConfigSource.create_from_url(backend_url=cs_repo).read_config()
282+
283+
# User pilot exists, same for pilot group
284+
assert config.Operations[TEST_VO].Pilot["GenericPilotUser"] == pilot_user
285+
assert config.Operations[TEST_VO].Pilot["GenericPilotGroup"] == pilot_group

diracx-core/src/diracx/core/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def __init__(
130130
self,
131131
data: dict[str, str],
132132
detail: str | None = None,
133-
pilots_that_does_not_exist: set = set(),
133+
non_existing_pilots: set = set(),
134134
):
135135
super().__init__(data, detail)
136-
self.pilots_that_does_not_exist = pilots_that_does_not_exist
136+
self.non_existing_pilots = non_existing_pilots
137137

138138

139139
class PilotAlreadyExistsError(GenericError):

0 commit comments

Comments
 (0)