Skip to content

Commit

Permalink
CLI: Add the verdi profile configure-rabbitmq
Browse files Browse the repository at this point in the history
Now that profiles can be created without defining a broker, a command
is needed that can add a RabbitMQ connection configuration. The new
command `verdi profile configure-rabbitmq` enables a broker for a
profile if it wasn't already, and allows configuring the connection
parameters.
  • Loading branch information
sphuber committed Jun 7, 2024
1 parent f553f80 commit 93c0d01
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
14 changes: 7 additions & 7 deletions docs/source/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ Below is a list with all available subcommands.
--help Show this message and exit.
Commands:
delete Delete one or more profiles.
list Display a list of all available profiles.
set-default Set a profile as the default profile.
setdefault (Deprecated) Set a profile as the default profile (use `verdi profile set-
default`).
setup Set up a new profile.
show Show details for a profile.
configure-rabbitmq Configure RabbitMQ for a profile.
delete Delete one or more profiles.
list Display a list of all available profiles.
set-default Set a profile as the default profile.
setdefault (Deprecated) Set a profile as the default profile.
setup Set up a new profile.
show Show details for a profile.
.. _reference:command-line:verdi-quicksetup:
Expand Down
22 changes: 21 additions & 1 deletion src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ def profile_setup():
"""Set up a new profile."""


@verdi_profile.command('configure-rabbitmq') # type: ignore[arg-type]
@arguments.PROFILE(default=defaults.get_default_profile)
@setup.SETUP_BROKER_PROTOCOL()
@setup.SETUP_BROKER_USERNAME()
@setup.SETUP_BROKER_PASSWORD()
@setup.SETUP_BROKER_HOST()
@setup.SETUP_BROKER_PORT()
@setup.SETUP_BROKER_VIRTUAL_HOST()
@options.NON_INTERACTIVE()
@click.pass_context
def profile_configure_rabbitmq(ctx, profile, **kwargs):
"""Configure RabbitMQ for a profile.
Enable RabbitMQ for a profile that was created without a broker, or reconfigure existing connection details.
"""
profile.set_process_controller(name='core.rabbitmq', config=kwargs)
ctx.obj.config.update_profile(profile)
ctx.obj.config.store()


@verdi_profile.command('list')
def profile_list():
"""Display a list of all available profiles."""
Expand Down Expand Up @@ -179,7 +199,7 @@ def profile_show(profile):
@verdi_profile.command('setdefault', deprecated='Please use `verdi profile set-default` instead.')
@arguments.PROFILE(required=True, default=None)
def profile_setdefault(profile):
"""Set a profile as the default profile (use `verdi profile set-default`)."""
"""Set a profile as the default profile."""
_profile_set_default(profile)


Expand Down
2 changes: 2 additions & 0 deletions src/aiida/cmdline/params/options/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def get_profile_attribute_default(attribute_tuple, ctx):
try:
data = ctx.params['profile'].dictionary
for part in parts:
if data is None:
return default
data = data[part]
return data
except KeyError:
Expand Down
23 changes: 23 additions & 0 deletions tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,26 @@ def test_setup_no_use_rabbitmq(run_cli_command, isolated_config):
profile = isolated_config.get_profile(profile_name)
assert profile.process_control_backend is None
assert profile.process_control_config == {}


def test_configure_rabbitmq(run_cli_command, isolated_config):
"""Test the ``verdi profile configure-rabbitmq`` command."""
profile_name = 'profile'

# First setup a profile without a broker configured
options = ['core.sqlite_dos', '-n', '--email', 'a@a', '--profile', profile_name, '--no-use-rabbitmq']
run_cli_command(cmd_profile.profile_setup, options, use_subprocess=False)
profile = isolated_config.get_profile(profile_name)
assert profile.process_control_backend is None
assert profile.process_control_config == {}

# Now run the command to configure the broker
options = [profile_name, '-n']
run_cli_command(cmd_profile.profile_configure_rabbitmq, options, use_subprocess=False)
assert profile.process_control_backend == 'core.rabbitmq'

# Call it again to check it works to reconfigure existing broker connection parameters
options = [profile_name, '-n', '--broker-host', 'rabbitmq.broker.com']
run_cli_command(cmd_profile.profile_configure_rabbitmq, options, use_subprocess=False)
assert profile.process_control_backend == 'core.rabbitmq'
assert profile.process_control_config['broker_host'] == 'rabbitmq.broker.com'

0 comments on commit 93c0d01

Please sign in to comment.