def status(all_profiles): """Print the status of the current daemon or all daemons. Returns exit code 0 if all requested daemons are running, else exit code 3. """ from aiida.engine.daemon.client import get_daemon_client config = get_config() if all_profiles is True: profiles = [profile for profile in config.profiles if not profile.is_test_profile] else: profiles = [config.current_profile] daemons_running = [] for profile in profiles: client = get_daemon_client(profile.name) delete_stale_pid_file(client) click.secho('Profile: ', fg='red', bold=True, nl=False) click.secho('{}'.format(profile.name), bold=True) result = get_daemon_status(client) echo.echo(result) daemons_running.append(client.is_daemon_running) if not all(daemons_running): sys.exit(3)
def test_daemon_worker_timeout(): """Test `get_daemon_status` output if a daemon worker cannot be reached by the circus daemon.""" client = get_daemon_client() literal = """\ Daemon is running as PID 111015 since 2019-12-17 11:42:18 Active workers [1]: PID MEM % CPU % started ----- ------- ------- --------- 4990 - - - Use verdi daemon [incr | decr] [num] to increase / decrease the amount of workers""" compare_string_literals(get_daemon_status(client), literal)
def test_daemon_working(): """Test `get_daemon_status` output if everything is working normally with a single worker.""" client = get_daemon_client() literal = """\ Daemon is running as PID 111015 since 2019-12-17 11:42:18 Active workers [1]: PID MEM % CPU % started ----- ------- ------- ------------------- 4990 0.231 0 2019-12-17 12:27:38 Use verdi daemon [incr | decr] [num] to increase / decrease the amount of workers""" assert get_daemon_status(client) == literal assert client.is_daemon_running
def status(all_profiles): """ Print the status of the current daemon or all daemons """ if all_profiles is True: profiles = [ p for p in get_profiles_list() if not p.startswith('test_') ] else: profiles = [get_current_profile_name()] for profile_name in profiles: client = DaemonClient(profile_name) click.secho('Profile: ', fg='red', bold=True, nl=False) click.secho('{}'.format(profile_name), bold=True) result = get_daemon_status(client) click.echo(result)
def status(all_profiles): """Print the status of the current daemon or all daemons.""" from aiida.engine.daemon.client import get_daemon_client config = get_config() if all_profiles is True: profiles = [ profile for profile in config.profiles if not profile.is_test_profile ] else: profiles = [config.current_profile] for profile in profiles: client = get_daemon_client(profile.name) delete_stale_pid_file(client) click.secho('Profile: ', fg='red', bold=True, nl=False) click.secho('{}'.format(profile.name), bold=True) result = get_daemon_status(client) echo.echo(result)
def verdi_status(no_rmq): """Print status of AiiDA services.""" # pylint: disable=broad-except,too-many-statements from aiida.cmdline.utils.daemon import get_daemon_status, delete_stale_pid_file from aiida.common.utils import Capturing from aiida.manage.external.rmq import get_rmq_url from aiida.manage.manager import get_manager from aiida.manage.configuration.settings import AIIDA_CONFIG_FOLDER exit_code = ExitCode.SUCCESS print_status(ServiceStatus.UP, 'config dir', AIIDA_CONFIG_FOLDER) manager = get_manager() profile = manager.get_profile() if profile is None: print_status(ServiceStatus.WARNING, 'profile', 'no profile configured yet') echo.echo_info( 'Configure a profile by running `verdi quicksetup` or `verdi setup`.' ) return try: profile = manager.get_profile() print_status(ServiceStatus.UP, 'profile', 'On profile {}'.format(profile.name)) except Exception as exc: print_status(ServiceStatus.ERROR, 'profile', 'Unable to read AiiDA profile', exception=exc) sys.exit(ExitCode.CRITICAL ) # stop here - without a profile we cannot access anything # Getting the repository repo_folder = 'undefined' try: repo_folder = profile.repository_path except Exception as exc: print_status(ServiceStatus.ERROR, 'repository', 'Error with repo folder', exception=exc) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'repository', repo_folder) # Getting the postgres status by trying to get a database cursor database_data = [ profile.database_username, profile.database_hostname, profile.database_port ] try: with override_log_level(): # temporarily suppress noisy logging backend = manager.get_backend() backend.cursor() except Exception: print_status(ServiceStatus.DOWN, 'postgres', 'Unable to connect as {}@{}:{}'.format(*database_data)) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'postgres', 'Connected as {}@{}:{}'.format(*database_data)) # Getting the rmq status if not no_rmq: try: with Capturing(capture_stderr=True): with override_log_level( ): # temporarily suppress noisy logging comm = manager.create_communicator(with_orm=False) comm.stop() except Exception as exc: print_status(ServiceStatus.ERROR, 'rabbitmq', 'Unable to connect to rabbitmq', exception=exc) exit_code = ExitCode.CRITICAL else: print_status(ServiceStatus.UP, 'rabbitmq', 'Connected to {}'.format(get_rmq_url())) # Getting the daemon status try: client = manager.get_daemon_client() delete_stale_pid_file(client) daemon_status = get_daemon_status(client) daemon_status = daemon_status.split('\n')[ 0] # take only the first line if client.is_daemon_running: print_status(ServiceStatus.UP, 'daemon', daemon_status) else: print_status(ServiceStatus.WARNING, 'daemon', daemon_status) exit_code = ExitCode.SUCCESS # A daemon that is not running is not a failure except Exception as exc: print_status(ServiceStatus.ERROR, 'daemon', 'Error getting daemon status', exception=exc) exit_code = ExitCode.CRITICAL # Note: click does not forward return values to the exit code, see https://github.com/pallets/click/issues/747 sys.exit(exit_code)
def test_daemon_not_running(): """Test `get_daemon_status` output when the daemon is not running.""" client = get_daemon_client() assert 'The daemon is not running' in get_daemon_status(client) assert not client.is_daemon_running
def test_circus_timeout(): """Test `get_daemon_status` output when the circus daemon process cannot be reached.""" client = get_daemon_client() assert 'Call to the circus controller timed out' in get_daemon_status( client)