Skip to content

Commit

Permalink
Merge branch 'main' into fix/6448/s6-notification-polling-check
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz authored Jun 7, 2024
2 parents 09e4fc9 + f553f80 commit 152cbba
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
47 changes: 38 additions & 9 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ def command_create_profile(
_, storage_entry_point = get_entry_point_from_class(storage_cls.__module__, storage_cls.__name__)
assert storage_entry_point is not None

if kwargs.pop('use_rabbitmq'):
broker_backend = 'core.rabbitmq'
broker_config = {
key: kwargs.get(key)
for key in (
'broker_protocol',
'broker_username',
'broker_password',
'broker_host',
'broker_port',
'broker_virtual_host',
)
}
else:
broker_backend = None
broker_config = None

try:
profile = create_profile(
ctx.obj.config,
Expand All @@ -62,15 +79,8 @@ def command_create_profile(
institution=institution,
storage_backend=storage_entry_point.name,
storage_config=kwargs,
broker_backend='core.rabbitmq',
broker_config={
'broker_protocol': 'amqp',
'broker_username': 'guest',
'broker_password': 'guest',
'broker_host': '127.0.0.1',
'broker_port': 5672,
'broker_virtual_host': '',
},
broker_backend=broker_backend,
broker_config=broker_config,
)
except (ValueError, TypeError, exceptions.EntryPointError, exceptions.StorageMigrationError) as exception:
echo.echo_critical(str(exception))
Expand All @@ -93,6 +103,25 @@ def command_create_profile(
setup.SETUP_USER_FIRST_NAME(),
setup.SETUP_USER_LAST_NAME(),
setup.SETUP_USER_INSTITUTION(),
setup.SETUP_USE_RABBITMQ(),
setup.SETUP_BROKER_PROTOCOL(
prompt_fn=lambda ctx: ctx.params['use_rabbitmq'], required_fn=lambda ctx: ctx.params['use_rabbitmq']
),
setup.SETUP_BROKER_USERNAME(
prompt_fn=lambda ctx: ctx.params['use_rabbitmq'], required_fn=lambda ctx: ctx.params['use_rabbitmq']
),
setup.SETUP_BROKER_PASSWORD(
prompt_fn=lambda ctx: ctx.params['use_rabbitmq'], required_fn=lambda ctx: ctx.params['use_rabbitmq']
),
setup.SETUP_BROKER_HOST(
prompt_fn=lambda ctx: ctx.params['use_rabbitmq'], required_fn=lambda ctx: ctx.params['use_rabbitmq']
),
setup.SETUP_BROKER_PORT(
prompt_fn=lambda ctx: ctx.params['use_rabbitmq'], required_fn=lambda ctx: ctx.params['use_rabbitmq']
),
setup.SETUP_BROKER_VIRTUAL_HOST(
prompt_fn=lambda ctx: ctx.params['use_rabbitmq'], required_fn=lambda ctx: ctx.params['use_rabbitmq']
),
],
)
def profile_setup():
Expand Down
9 changes: 9 additions & 0 deletions src/aiida/cmdline/params/options/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ def get_quicksetup_password(ctx, param, value):
cls=options.interactive.InteractiveOption,
)

SETUP_USE_RABBITMQ = options.OverridableOption(
'--use-rabbitmq/--no-use-rabbitmq',
prompt='Use RabbitMQ?',
is_flag=True,
default=True,
cls=options.interactive.InteractiveOption,
help='Whether to configure the RabbitMQ broker. Required to enable the daemon and submitting processes.',
)

SETUP_BROKER_PROTOCOL = QUICKSETUP_BROKER_PROTOCOL.clone(
prompt='Broker protocol',
required=True,
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/manage/configuration/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def process_control_backend(self) -> str | None:
@property
def process_control_config(self) -> Dict[str, Any]:
"""Return the configuration required by the process control backend."""
return self._attributes[self.KEY_PROCESS][self.KEY_PROCESS_CONFIG]
return self._attributes[self.KEY_PROCESS][self.KEY_PROCESS_CONFIG] or {}

def set_process_controller(self, name: str, config: Dict[str, Any]) -> None:
"""Set the process control backend and its configuration.
Expand Down
5 changes: 3 additions & 2 deletions src/aiida/storage/sqlite_dos/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def initialise_database(self) -> None:


class SqliteDosStorage(PsqlDosBackend):
"""A lightweight backend intended for demos and testing.
"""A lightweight storage that is easy to install.
This backend implementation uses an Sqlite database and
This backend implementation uses an SQLite database and a disk-objectstore container as the file repository. As
such, this storage plugin does not require any services, making it easy to install and use on most systems.
"""

migrator = SqliteDosMigrator
Expand Down
13 changes: 13 additions & 0 deletions tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,16 @@ def test_setup_email_required(run_cli_command, isolated_config, tmp_path, entry_
else:
result = run_cli_command(cmd_profile.profile_setup, options, use_subprocess=False, raises=True)
assert 'Invalid value for --email: The option is required for storages that are not read-only.' in result.output


def test_setup_no_use_rabbitmq(run_cli_command, isolated_config):
"""Test the ``--no-use-rabbitmq`` option."""
profile_name = 'profile-no-broker'
options = ['core.sqlite_dos', '-n', '--email', 'a@a', '--profile', profile_name, '--no-use-rabbitmq']

result = run_cli_command(cmd_profile.profile_setup, options, use_subprocess=False)
assert f'Created new profile `{profile_name}`.' in result.output
assert profile_name in isolated_config.profile_names
profile = isolated_config.get_profile(profile_name)
assert profile.process_control_backend is None
assert profile.process_control_config == {}

0 comments on commit 152cbba

Please sign in to comment.