From 7402c17755b332cc9a06e88516621e575f0d1cce Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Thu, 25 Jul 2024 08:11:35 +0200 Subject: [PATCH] CLI: Fix `verdi storage migrate` for profile without broker (#6550) The command needs to make sure the daemon of the profile is not running so it instantiates the `DaemonClient` but this raises for profiles that do not define a broker. Since the daemon cannot be started for brokerless profiles anyway the command does not have to check in this case. --- src/aiida/cmdline/commands/cmd_storage.py | 10 ++++++---- tests/cmdline/commands/test_storage.py | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/aiida/cmdline/commands/cmd_storage.py b/src/aiida/cmdline/commands/cmd_storage.py index 5382ff455f..c4fd17601a 100644 --- a/src/aiida/cmdline/commands/cmd_storage.py +++ b/src/aiida/cmdline/commands/cmd_storage.py @@ -41,12 +41,14 @@ def storage_migrate(force): from aiida.engine.daemon.client import get_daemon_client from aiida.manage import get_manager - client = get_daemon_client() - if client.is_daemon_running: - echo.echo_critical('Migration aborted, the daemon for the profile is still running.') - manager = get_manager() profile = manager.get_profile() + + if profile.process_control_backend: + client = get_daemon_client() + if client.is_daemon_running: + echo.echo_critical('Migration aborted, the daemon for the profile is still running.') + storage_cls = profile.storage_cls if not force: diff --git a/tests/cmdline/commands/test_storage.py b/tests/cmdline/commands/test_storage.py index 8c374885a2..eb629d013f 100644 --- a/tests/cmdline/commands/test_storage.py +++ b/tests/cmdline/commands/test_storage.py @@ -35,6 +35,15 @@ def tests_storage_info(aiida_localhost, run_cli_command): assert node.node_type in result.output +@pytest.mark.usefixtures('stopped_daemon_client') +def tests_storage_migrate_no_broker(aiida_config_tmp, aiida_profile_factory, run_cli_command): + """Test the ``verdi storage migrate`` command for a profile without a broker.""" + with aiida_profile_factory(aiida_config_tmp) as profile: + assert profile.process_control_backend is None + result = run_cli_command(cmd_storage.storage_migrate, parameters=['--force'], use_subprocess=False) + assert 'Migrating to the head of the main branch' in result.output + + @pytest.mark.usefixtures('stopped_daemon_client') def tests_storage_migrate_force(run_cli_command): """Test the ``verdi storage migrate`` command (with force option)."""