Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Add the verdi profile configure-rabbitmq command #6454

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."""
GeigerJ2 marked this conversation as resolved.
Show resolved Hide resolved
_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
GeigerJ2 marked this conversation as resolved.
Show resolved Hide resolved
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'
Loading