Beispiel #1
0
def test_check_ps_common_count(levels, reference):
    _cpu_info, parsed_lines = ps_section.parse_ps(
        splitter("(on,105,30,00:00:{:02}/03:59:39,902) single"))
    lines_with_node_name: List[Tuple[Optional[str], ps_utils.PsInfo,
                                     List[str]]] = [
                                         (None, ps_info, cmd_line)
                                         for (ps_info,
                                              cmd_line) in parsed_lines
                                     ]

    params = {
        "process": "~test",
        "user": None,
        "levels": levels,
    }

    output = list(
        ps_utils.check_ps_common(
            label="Processes",
            item="empty",
            params=params,  # type: ignore[arg-type]
            process_lines=lines_with_node_name,
            cpu_cores=1,
            total_ram_map={},
        ))
    assert output == reference
Beispiel #2
0
    def time_info(service, agent_info, check_time, cputime, cpu_cores):
        with on_time(datetime.datetime.utcfromtimestamp(check_time), "CET"):
            _cpu_info, parsed_lines = ps_section.parse_ps(splitter(agent_info.format(cputime)))
            lines_with_node_name: List[Tuple[Optional[str], ps_utils.ps_info, List[str]]] = [
                (None, ps_info, cmd_line) for (ps_info, cmd_line) in parsed_lines]

            return list(ps_utils.check_ps_common(
                label="Processes",
                item=service.item,
                params=service.parameters,  # type: ignore[arg-type]
                process_lines=lines_with_node_name,
                cpu_cores=cpu_cores,
                total_ram=None,
            ))
Beispiel #3
0
    def time_info(service, agent_info, check_time, cputime, cpu_cores):
        with on_time(datetime.datetime.utcfromtimestamp(check_time), "CET"):
            _cpu_info, parsed_lines = ps_section.parse_ps(
                splitter(agent_info.format(cputime)))
            lines_with_node_name = [(None, ps_info, cmd_line)
                                    for (ps_info, cmd_line) in parsed_lines]

            return list(
                ps_utils.check_ps_common(
                    label="Processes",
                    item=service.item,
                    params=service.parameters,
                    process_lines=lines_with_node_name,
                    cpu_cores=cpu_cores,
                    total_ram_map={},
                ))
Beispiel #4
0
    def run_check_ps_common_with_elapsed_time(check_time, cputime):
        with on_time(check_time, "CET"):
            agent_info = """(on,2275004,434008,00:00:49/26:58,25576) firefox
(on,1869920,359836,00:01:23/6:57,25664) firefox
(on,7962644,229660,00:00:10/26:56,25758) firefox
(on,1523536,83064,00:{:02}:00/26:55,25898) firefox"""
            _cpu_info, parsed_lines = ps_section.parse_ps(splitter(agent_info.format(cputime)))
            lines_with_node_name: List[Tuple[Optional[str], ps_utils.ps_info, List[str]]] = [
                (None, ps_info, cmd_line) for (ps_info, cmd_line) in parsed_lines]

            return list(ps_utils.check_ps_common(
                label="Processes",
                item='firefox',
                params=params,  # type: ignore[arg-type]
                process_lines=lines_with_node_name,
                cpu_cores=cpu_cores,
                total_ram=None,
            ))
Beispiel #5
0
def test_check_ps_common(inv_item, reference):
    parsed: List = []
    for info in generate_inputs():
        _cpu_cores, data = ps_section.parse_ps(info)
        parsed.extend((None, ps_info, cmd_line) for (ps_info, cmd_line) in data)
    total_ram = 1024**3 if "emacs" in inv_item.item else None
    with on_time(1540375342, "CET"):
        factory_defaults = {"levels": (1, 1, 99999, 99999)}
        factory_defaults.update(inv_item.parameters)
        test_result = list(ps_utils.check_ps_common(
            label="Processes",
            item=inv_item.item,
            params=factory_defaults,  # type: ignore[arg-type]
            process_lines=parsed,
            cpu_cores=1,
            total_ram=total_ram,
        ))
        assert test_result == reference
Beispiel #6
0
def test_subset_patterns():

    section_ps = ps_section.parse_ps(
        splitter("""(user,0,0,0.5) main
(user,0,0,0.4) main_dev
(user,0,0,0.1) main_dev
(user,0,0,0.5) main_test"""))

    # Boundary in match is necessary otherwise main instance accumulates all
    inv_params: List[Dict] = [{
        'default_params': {
            'cpu_rescale_max': True,
            'levels': (1, 1, 99999, 99999)
        },
        'match': '~(main.*)\\b',
        'descr': '%s',
    }, {}]

    discovered = [
        Service(
            item='main',
            parameters={
                'cpu_rescale_max': True,
                'levels': (1, 1, 99999, 99999),
                'process': '~(main.*)\\b',
                'match_groups': ('main',),
                'user': None,
                'cgroup': (None, False),
            },
        ),
        Service(
            item='main_dev',
            parameters={
                'cpu_rescale_max': True,
                'levels': (1, 1, 99999, 99999),
                'process': '~(main.*)\\b',
                'match_groups': ('main_dev',),
                'user': None,
                'cgroup': (None, False),
            },
        ),
        Service(
            item='main_test',
            parameters={
                'cpu_rescale_max': True,
                'levels': (1, 1, 99999, 99999),
                'process': '~(main.*)\\b',
                'match_groups': ('main_test',),
                'user': None,
                'cgroup': (None, False),
            },
        ),
    ]

    test_discovered = ps_utils.discover_ps(inv_params, section_ps, None, None, None)  # type: ignore[arg-type]
    assert {s.item: s for s in test_discovered} == {s.item: s for s in discovered}  # type: ignore[attr-defined]

    for service, count in zip(discovered, [1, 2, 1]):
        assert isinstance(service.item, str)
        output = list(ps_utils.check_ps_common(
            label="Processes",
            item=service.item,
            params=service.parameters,  # type: ignore[arg-type]
            process_lines=[
                (None, psi, cmd_line) for (psi, cmd_line) in section_ps[1]],
            cpu_cores=1,
            total_ram=None,
        ))
        assert output[0] == Result(state=state.OK, summary="Processes: %s" % count)
Beispiel #7
0
def test_subset_patterns():

    section_ps = ps_section.parse_ps(
        splitter("""(user,0,0,0.5) main
(user,0,0,0.4) main_dev
(user,0,0,0.1) main_dev
(user,0,0,0.5) main_test"""))

    # Boundary in match is necessary otherwise main instance accumulates all
    inv_params: List[Dict] = [
        {
            "default_params": {
                "cpu_rescale_max": True,
                "levels": (1, 1, 99999, 99999)
            },
            "match": "~(main.*)\\b",
            "descr": "%s",
        },
        {},
    ]

    discovered = [
        Service(
            item="main",
            parameters={
                "cpu_rescale_max": True,
                "levels": (1, 1, 99999, 99999),
                "process": "~(main.*)\\b",
                "match_groups": ("main", ),
                "user": None,
                "cgroup": (None, False),
            },
        ),
        Service(
            item="main_dev",
            parameters={
                "cpu_rescale_max": True,
                "levels": (1, 1, 99999, 99999),
                "process": "~(main.*)\\b",
                "match_groups": ("main_dev", ),
                "user": None,
                "cgroup": (None, False),
            },
        ),
        Service(
            item="main_test",
            parameters={
                "cpu_rescale_max": True,
                "levels": (1, 1, 99999, 99999),
                "process": "~(main.*)\\b",
                "match_groups": ("main_test", ),
                "user": None,
                "cgroup": (None, False),
            },
        ),
    ]

    test_discovered = ps_utils.discover_ps(inv_params, section_ps, None, None,
                                           None)
    assert {s.item: s
            for s in test_discovered} == {s.item: s
                                          for s in discovered}

    for service, count in zip(discovered, [1, 2, 1]):
        assert isinstance(service.item, str)
        output = list(
            ps_utils.check_ps_common(
                label="Processes",
                item=service.item,
                params=service.parameters,
                process_lines=[(None, psi, cmd_line)
                               for (psi, cmd_line) in section_ps[1]],
                cpu_cores=1,
                total_ram_map={},
            ))
        assert output[0] == Result(state=state.OK,
                                   summary="Processes: %s" % count)