Exemplo n.º 1
0
    def check_connection(self):
        """
        Check API connection.
        """
        if self.connected is not None:
            return

        print_msg('checking API connection ...')
        try:
            addr = self.get_value('cluster', 'name')
            print_success(f'- successfully connected to {addr}')
            self.connected = True
        except Exception as e:
            print_error('could not connect to Redis Enterprise REST-API:', e)
            self.connected = False
        print_msg('')
Exemplo n.º 2
0
    def check_connection(self):
        """
        Check SSH connection.
        """
        if self.connected is not None:
            return

        print_msg(f'checking {self.mode} connections ...')
        for target in self.targets:
            try:
                self.exec_uni('pwd', target, True)
                print_success(f'- successfully connected to {target}')
                self.connected = True
            except Exception as e:
                print_error(f'could not connect to host {target}:', e)
                self.connected = False
        print_msg('')
Exemplo n.º 3
0
def load_parameter_map(_suite, _check_func_name, _args):
    """
    Load a parameter map.

    :param _suite: The check suite.
    :param _check_func_name: The check function name.
    :param _args: The parsed arguments.
    :return: A list of tuples.
    """
    if not _args.params:
        return None

    if not _args.check and not _args.suite:
        print_error(
            'sole argument --params not allowed, try using in combination with --suite or --check'
        )
        exit(1)

    if _args.params.endswith('.json'):
        if not os.path.exists(_args.params):
            print_error(
                'could not find parameter map, examine argument of --params')
            exit(1)

        with open(_args.params) as file:
            params = [(_args.params, json.loads(file.read()))]

    else:
        path = f'parameter_maps/{_suite.__class__.__name__.lower()}/{_check_func_name}/'
        loaded_params = {}
        for path in glob.glob(f'{path}*.json'):
            with open(path) as file:
                loaded_params[path] = json.loads(file.read())

        if not loaded_params:
            print_warning(f'- no parameter maps found in {path}\n')
            return None

        params = list(
            filter(
                lambda x: _args.params.lower() in get_parameter_map_name(x[
                    0].lower()), loaded_params.items()))
        if _args.params and not params:
            print_error('could not find paramter map, choose one: {}'.format(
                list(map(get_parameter_map_name, loaded_params.keys()))))
            exit(1)

        elif len(params) > 1:
            print_error('multiple parameter maps found, choose one: {}'.format(
                list(map(get_parameter_map_name, loaded_params.keys()))))
            exit(1)

    return params
Exemplo n.º 4
0
def parse_config(_args):
    """
    Parse configuration file.

    :return: The parsed configuration.
    """
    if not os.path.isfile(_args.config):
        print_error(
            'could not find configuration file, examine argument of --config')
        exit(1)

    config = configparser.ConfigParser()
    with open(_args.config, 'r') as configfile:
        config.read_file(configfile)

    if not is_api_configured(config):
        print_warning('no [api] configuration found')

    if not is_rex_configured(config):
        print_warning('no [ssh], [docker] or [k8s] configuration found')

    return config
Exemplo n.º 5
0
def exec_checks(_suites, _checks, _args, _result_cb, _done_cb=None):
    """
    Execute checks.

    :param _suites: Loaded check suites.
    :param _checks: Found checks.
    :param _args: The parsed arguments.
    :param _result_cb: A result callback.
    :param _done_cb: An optional callback, executed after each check execution.
    """
    executor = CheckExecutor(_result_cb)

    if _args.check and not _checks:
        print_error(
            'could not find a single check, examine argument of --check')
        exit(1)

    elif not _suites:
        print_error('could not find check suite, examine argument of --suite')
        exit(1)

    for check_func, suite in _checks:
        if not _args.no_connection_checks:
            suite.run_connection_checks()
        params = load_parameter_map(suite, check_func.__name__, _args)
        executor.execute(check_func,
                         _params=params[0][1] if params else {},
                         _done_cb=_done_cb)

    wait = True
    try:
        executor.wait(EXECUTOR_TIMEOUT)
    except Exception as e:
        print_error('error executing checks', e)
        wait = False
    finally:
        executor.shutdown(wait)