Beispiel #1
0
def test_is_ceph_monitor():
    ps_auxcww = PsAuxcww(context_wrap(PsAuxcww_CEPH))
    ps = Ps(None, None, None, None, ps_auxcww, None, None)
    result = IsCephMonitor(ps)
    assert isinstance(result, IsCephMonitor)

    ps_auxcww = PsAuxcww(context_wrap(PsAuxcww_NO_CEPH))
    ps = Ps(None, None, None, None, ps_auxcww, None, None)
    with pytest.raises(SkipComponent):
        IsCephMonitor(ps)
Beispiel #2
0
def test_psalxwww_and_psauxww_and_psaux_parsers():
    ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES))
    ps_auxww = PsAuxww(context_wrap(PS_AUXWW_LINES))
    ps_aux = PsAux(context_wrap(PS_AUX_LINES))
    ps = Ps(ps_alxwww, ps_auxww, ps_aux, None, None, None, None)
    len(ps.processes) == 5
    ps = ps[1]
    assert ps['PID'] == 1
    assert ps['USER'] == 'root'
    assert ps['UID'] == 0
    assert ps['PPID'] == 0
    assert ps['%CPU'] == 0.1
    assert ps['%MEM'] == 0.0
    assert ps['VSZ'] == 195712.0
    assert ps['RSS'] == 7756.0
    assert ps['STAT'] == 'Ss'
    assert ps['TTY'] == '?'
    assert ps['START'] == '2019'
    assert ps['TIME'] == '478:05'
    assert ps[
        'COMMAND'] == '/usr/lib/systemd/systemd --switched-root --system --deserialize 21'
    assert ps['COMMAND_NAME'] == 'systemd'
    assert ps['F'] == '4'
    assert ps['PRI'] == 20
    assert ps['NI'] == '0'
    assert ps['WCHAN'] == 'ep_pol'
Beispiel #3
0
def test_combiner_api():
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES))
    ps = Ps(None, None, None, None, ps_auxcww, None, None)
    assert ps.pids == [1, 2, 3, 8, 9, 11]
    assert len(ps.processes) == 6
    assert ps.processes[0]
    assert 'systemd' in ps.commands
    assert len(ps.search(USER='******')) == 6
    assert 'systemd' in ps
    assert ps[1] == {
        '%CPU': 0.1,
        '%MEM': 0.0,
        'ARGS': '',
        'COMMAND': 'systemd',
        'COMMAND_NAME': 'systemd',
        'F': None,
        'NI': None,
        'PID': 1,
        'PPID': None,
        'PRI': None,
        'RSS': 7756.0,
        'START': '2019',
        'STAT': 'Ss',
        'TIME': '477:10',
        'TTY': '?',
        'UID': None,
        'USER': '******',
        'VSZ': 195712.0,
        'WCHAN': None
    }
    assert ps[1000] is None
    assert [proc for proc in ps]
Beispiel #4
0
def test_psalxwww_and_psauxww_and_psaux_and_psef_and_psauxcww_and_ps_eo_cmd_parsers(
):
    ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES))
    ps_auxww = PsAuxww(context_wrap(PS_AUXWW_LINES))
    ps_aux = PsAux(context_wrap(PS_AUX_LINES))
    ps_ef = PsEf(context_wrap(PS_EF_LINES))
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES))
    ps_eo_cmd = PsEoCmd(context_wrap(PS_EO_CMD_LINES, strip=False))
    ps_combiner = Ps(ps_alxwww, ps_auxww, ps_aux, ps_ef, ps_auxcww, None,
                     ps_eo_cmd)
    len(ps_combiner.processes) == 9
    ps = ps_combiner[1]
    assert ps['PID'] == 1
    assert ps['USER'] == 'root'
    assert ps['UID'] == 0
    assert ps['PPID'] == 0
    assert ps['%CPU'] == 0.1
    assert ps['%MEM'] == 0.0
    assert ps['VSZ'] == 195712.0
    assert ps['RSS'] == 7756.0
    assert ps['STAT'] == 'Ss'
    assert ps['TTY'] == '?'
    assert ps['START'] == '2019'
    assert ps['TIME'] == '478:05'
    assert ps[
        'COMMAND'] == '/usr/lib/systemd/systemd --switched-root --system --deserialize 21'
    assert ps['COMMAND_NAME'] == 'systemd'
    assert ps['F'] == '4'
    assert ps['PRI'] == 20
    assert ps['NI'] == '0'
    assert ps['WCHAN'] == 'ep_pol'

    assert ps_combiner[13]['COMMAND'] == '/usr/bin/python3.6'
Beispiel #5
0
def test_get_running_commands_missing():
    pseo = PsEoCmd(context_wrap(PS_EO_CMD_MISSING))
    ps = Ps(None, None, None, None, None, None, pseo)
    assert ps is not None
    ctx = FakeContext()

    results = get_running_commands(ps, ctx, ['httpd', 'java'])
    assert set(results) == set()
Beispiel #6
0
def test_cmd_and_pkg_not_found():
    pseo = PsEoCmd(context_wrap(PS_EO_CMD))
    ps = Ps(None, None, None, None, None, None, pseo)
    broker = dr.Broker()
    broker[HostContext] = FakeContext()
    broker[Ps] = ps

    with pytest.raises(SkipComponent):
        cmd_and_pkg(broker)
Beispiel #7
0
def test_get_running_commands_one():
    pseo = PsEoCmd(context_wrap(PS_EO_CMD_ONE))
    ps = Ps(None, None, None, None, None, None, pseo)
    assert ps is not None
    ctx = FakeContext()

    results = get_running_commands(ps, ctx, ['httpd'])
    assert set(results) == set([
        '/usr/sbin/httpd',
    ])
Beispiel #8
0
def test_get_running_commands_cmd_exception():
    pseo = PsEoCmd(context_wrap(PS_EO_CMD_EXCEPTION))
    ps = Ps(None, pseo, None, None, None, None, pseo)
    assert ps is not None
    ctx = FakeContext()

    results = get_running_commands(ps, ctx, ['httpd', 'java'])
    assert set(results) == set([
        '/usr/bin/java',
    ])
Beispiel #9
0
def test_cmd_and_pkg():
    pseo = PsEoCmd(context_wrap(PS_EO_CMD))
    ps = Ps(None, None, None, None, None, None, pseo)
    broker = dr.Broker()
    broker[HostContext] = FakeContext()
    broker[Ps] = ps

    result = cmd_and_pkg(broker)
    assert result is not None
    assert sorted(result.content) == sorted(EXPECTED.content)
Beispiel #10
0
def test_pseo_parser():
    ps_eo = PsEo(context_wrap(PS_EO_LINES, strip=False))
    ps = Ps(None, None, None, None, None, ps_eo, None)
    assert len(ps.processes) == 6
    proc = ps[1]
    assert proc['USER'] is None
    assert proc['TTY'] is None
    assert proc['%CPU'] is None
    assert proc['%MEM'] is None
    assert proc['COMMAND'] == proc['COMMAND_NAME']
Beispiel #11
0
def test_get_running_commands_exception():
    pseo = PsEoCmd(context_wrap(PS_EO_CMD_MISSING))
    ps = Ps(None, None, None, None, None, None, pseo)
    assert ps is not None
    ctx = FakeContext()

    with pytest.raises(TypeError):
        get_running_commands(ps, ctx, 'not_a_list')

    with pytest.raises(TypeError):
        get_running_commands(ps, ctx, [])
Beispiel #12
0
def test_docs():
    ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES))
    ps_auxww = PsAuxww(context_wrap(PS_AUXWW_LINES))
    ps_aux = PsAux(context_wrap(PS_AUX_LINES))
    ps_ef = PsEf(context_wrap(PS_EF_LINES))
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES))
    ps_eo = PsEo(context_wrap(PS_EO_LINES, strip=False))
    ps_combiner = Ps(ps_alxwww, ps_auxww, ps_aux, ps_ef, ps_auxcww, ps_eo)
    env = {'ps_combiner': ps_combiner}
    failed, total = doctest.testmod(ps, globs=env)
    assert failed == 0
Beispiel #13
0
def test_pmlog_summary_args_no_pmloger_file(isfile):
    ros = RosConfig(context_wrap(ROS_CONFIG))
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW))
    ps = Ps(None, None, None, None, ps_auxcww, None, None)

    broker = dr.Broker()
    broker[Ps] = ps
    broker[RosConfig] = ros

    with pytest.raises(SkipComponent):
        pmlog_summary_args(broker)
Beispiel #14
0
def test_pmlog_summary_args(isfile, exists):
    # Case 1: OK
    ros = RosConfig(context_wrap(ROS_CONFIG))
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW))
    ps = Ps(None, None, None, None, ps_auxcww, None, None)

    broker = dr.Broker()
    broker[Ps] = ps
    broker[RosConfig] = ros

    pcp_log_date = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
    mock_file = "/var/log/pcp/pmlogger/ros/%s.index" % (pcp_log_date)

    result = pmlog_summary_args(broker)

    metrics = ' '.join(sorted([i.strip() for i in ROS_CONFIG.split('\n')[1:5]]))
    expected = '{0} {1}'.format(mock_file, metrics)
    assert result == expected

    # Case 2 NG metrics
    ros = RosConfig(context_wrap(ROS_CONFIG_NG))
    broker = dr.Broker()
    broker[Ps] = ps
    broker[RosConfig] = ros

    with pytest.raises(SkipComponent):
        pmlog_summary_args(broker)

    # Case 3 No pmloger proc in ps
    ros = RosConfig(context_wrap(ROS_CONFIG))
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_NG))
    ps = Ps(None, None, None, None, ps_auxcww, None, None)
    broker = dr.Broker()
    broker[Ps] = ps
    broker[RosConfig] = ros

    with pytest.raises(SkipComponent):
        pmlog_summary_args(broker)
Beispiel #15
0
def test_psef_parser():
    ps_ef = PsEf(context_wrap(PS_EF_LINES))
    ps = Ps(None, None, None, ps_ef, None, None, None)
    len(ps.processes) == 6
    proc = ps[1]
    assert proc.get('UID') is None
    assert proc.get('C') is None
    assert proc.get('CMD') is None
    assert proc.get('STIME') is None
    assert proc['USER'] == 'root'
    assert proc['%CPU'] == 0
    assert proc[
        'COMMAND'] == '/usr/lib/systemd/systemd --switched-root --system --deserialize 21'
    assert proc['START'] == '2019'
Beispiel #16
0
def test_pseo_and_psauxcww_parsers():
    ps_eo = PsEo(context_wrap(PS_EO_LINES, strip=False))
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES))
    ps = Ps(None, None, None, None, ps_auxcww, ps_eo, None)
    assert len(ps.processes) == 7
    proc9 = ps[9]
    assert proc9['USER'] == 'root'
    assert proc9['TTY'] == '?'
    assert proc9['%CPU'] == 0.1
    assert proc9['%MEM'] == 0.0
    assert proc9['COMMAND'] == proc9['COMMAND_NAME']
    proc10 = ps[10]
    assert proc10['USER'] is None
    assert proc10['TTY'] is None
    assert proc10['%CPU'] is None
    assert proc10['%MEM'] is None
    assert proc10['COMMAND'] == proc10['COMMAND_NAME']
Beispiel #17
0
def test_psauxcww_and_ps_ef_parsers():
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES))
    ps_ef = PsEf(context_wrap(PS_EF_LINES))
    ps = Ps(None, None, None, ps_ef, ps_auxcww, None, None)
    assert len(ps.processes) == 7
    proc1 = ps[1]
    assert proc1[
        'COMMAND'] == '/usr/lib/systemd/systemd --switched-root --system --deserialize 21'
    assert proc1['COMMAND_NAME'] == 'systemd'
    proc9 = ps[9]
    assert proc9['PPID'] == 2
    assert proc9['%CPU'] == 0.1
    assert proc9['%MEM'] == 0.0
    assert proc9['VSZ'] == 0.0
    proc12 = ps[12]
    assert proc12['PPID'] == 2
    assert proc12['%CPU'] == 0.0
    assert proc12['%MEM'] is None
    assert proc12['VSZ'] is None
Beispiel #18
0
def test_type_conversion():
    ps_alxwww = PsAlxwww(context_wrap(PS_ALXWWW_LINES))
    ps_ef = PsEf(context_wrap(PS_EF_LINES))
    ps_auxcww = PsAuxcww(context_wrap(PS_AUXCWW_LINES))
    ps = Ps(ps_alxwww, None, None, ps_ef, ps_auxcww, None, None)
    assert all(isinstance(p['PID'], int) for p in ps.processes)
    assert all(p['UID'] is None or isinstance(p['UID'], int)
               for p in ps.processes)
    assert all(p['PID'] is None or isinstance(p['PID'], int)
               for p in ps.processes)
    assert all(p['%CPU'] is None or isinstance(p['%CPU'], float)
               for p in ps.processes)
    assert all(p['%MEM'] is None or isinstance(p['%MEM'], float)
               for p in ps.processes)
    assert all(p['VSZ'] is None or isinstance(p['VSZ'], float)
               for p in ps.processes)
    assert all(p['RSS'] is None or isinstance(p['RSS'], float)
               for p in ps.processes)
    assert all(p['PRI'] is None or isinstance(p['PRI'], int)
               for p in ps.processes)
Beispiel #19
0
def test_get_running_commands_present():
    pseo = PsEoCmd(context_wrap(PS_EO_CMD))
    ps = Ps(None, None, None, None, None, None, pseo)
    assert ps is not None
    ctx = FakeContext()

    results = get_running_commands(ps, ctx, ['httpd'])
    assert set(results) == set(['/usr/sbin/httpd', '/usr/local/sbin/httpd'])

    results = get_running_commands(ps, ctx, ['java'])
    assert set(results) == set([
        '/usr/bin/java', '/home/user3/apps/pycharm-2021.1.1/jbr/bin/java',
        '/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/bin/java'
    ])

    results = get_running_commands(ps, ctx, ['java', 'httpd'])
    assert set(results) == set([
        '/usr/bin/java', '/home/user3/apps/pycharm-2021.1.1/jbr/bin/java',
        '/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/bin/java',
        '/usr/sbin/httpd', '/usr/local/sbin/httpd'
    ])
Beispiel #20
0
def test_search_ps_alxwww_w_grep():
    p = PsAlxwww(context_wrap(PS_ALXWWW_W_GREP))
    ps = Ps(p, None, None, None, None, None, None)
    assert len(ps.search(COMMAND_NAME__contains='dbus')) == 1