Example #1
0
def test_httpd_V_RHEL6():
    hv1 = HV(context_wrap(HTTPDV1))
    hv2 = HWV(context_wrap(HTTPDV2, path='httpd.worker_-V'))
    hv3 = HEV(context_wrap(HTTPDV3, path='httpd.event_-V'))
    ps = PsAuxcww(context_wrap(PS_WORKER))
    rh = RedhatRelease(context_wrap(RHEL6))
    result = HttpdV(rh, ps, hv1, hv3, hv2)
    assert result["Server MPM"] == "worker"
    assert result[
        "Server version"] == "apache/2.4.6 (red hat enterprise linux)"
    assert result["forked"] == "yes (variable process count)"
    assert "APR_HAVE_IPV6" in result['Server compiled with']
    assert result['Server compiled with']['APR_HAS_MMAP'] is True
    assert result['Server compiled with'][
        'APR_HAVE_IPV6'] == "IPv4-mapped addresses enabled"
    assert result['Server compiled with'][
        'DEFAULT_PIDLOG'] == "/run/httpd/httpd.pid"

    ps = PsAuxcww(context_wrap(PS_EVENT))
    result = HttpdV(rh, ps, hv1, hv3, hv2)
    assert result["Server MPM"] == "event"
    assert result[
        "Server version"] == "apache/2.4.6 (red hat enterprise linux)"
    assert result["forked"] == "yes (variable process count)"
    assert "APR_HAVE_IPV6" not in result['Server compiled with']
    assert result['Server compiled with']['APR_HAS_MMAP'] is True
Example #2
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)
Example #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]
Example #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'
Example #5
0
def test_httpd_V_failed():
    hv1 = HV(context_wrap(HTTPDV1))
    hv2 = HWV(context_wrap(HTTPDV2, path='httpd.worker_-V'))
    ps = PsAuxcww(context_wrap(PS_EVENT))
    rh = RedhatRelease(context_wrap(RHEL6))
    with pytest.raises(SkipComponent) as sc:
        HttpdV(rh, ps, hv1, None, hv2)
    assert "Unable to get the valid `httpd -V` command" in str(sc)
Example #6
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)
def test_doc_examples():
    sem1 = IpcsSI(context_wrap(IPCS_S_I_1))
    sem2 = IpcsSI(context_wrap(IPCS_S_I_2))
    sem3 = IpcsSI(context_wrap(IPCS_S_I_3))
    sem4 = IpcsSI(context_wrap(IPCS_S_I_4))
    sem6 = IpcsSI(context_wrap(IPCS_S_I_6))
    sems = IpcsS(context_wrap(IPCS_S))
    ps = PsAuxcww(context_wrap(PsAuxcww_OUT))
    env = {'oph_sem': IpcsSemaphores(sems, [sem1, sem2, sem3, sem4, sem6], ps)}
    failed, total = doctest.testmod(ipcs_semaphores, globs=env)
    assert failed == 0
Example #8
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
Example #9
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)
Example #10
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']
Example #11
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
Example #12
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)
Example #13
0
def test_ipcs_semaphores():
    sem1 = IpcsSI(context_wrap(IPCS_S_I_1))
    sem2 = IpcsSI(context_wrap(IPCS_S_I_2))
    sem3 = IpcsSI(context_wrap(IPCS_S_I_3))
    sem4 = IpcsSI(context_wrap(IPCS_S_I_4))
    sem5 = IpcsSI(context_wrap(IPCS_S_I_5))
    sem6 = IpcsSI(context_wrap(IPCS_S_I_6))
    sems = IpcsS(context_wrap(IPCS_S))
    ps = PsAuxcww(context_wrap(PsAuxcww_OUT))
    rst = IpcsSemaphores(sems, [sem1, sem2, sem3, sem4, sem5, sem6], ps)
    rst.get_sem('65536').pid_list == ['0', '2265', '4390', '6151', '6152']
    rst.count_of_all_sems() == 6
    rst.count_of_all_sems(owner='apache') == 5
    rst.count_of_orphan_sems() == 5
    rst.count_of_orphan_sems() == 3
    rst.count_of_orphan_sems('postgres') == 0
    i = 0
    for sem in rst:
        i += 1
    assert i == rst.count_of_all_sems()
    rst.orphan_sems() == ['622502', '622602', '655371']
    rst.orphan_sems('apache') == ['622502', '622602', '655371']
    rst.orphan_sems('postgres') == []
Example #14
0
def test_compute_node():
    ps = PsAuxcww(context_wrap(PS_OSP_COMPUTE))
    result = IsOpenStackCompute(ps)
    assert isinstance(result, IsOpenStackCompute)
Example #15
0
def test_controller_node():
    ps = PsAuxcww(context_wrap(PS_OSP_CONTROLLER))
    with pytest.raises(SkipComponent) as e:
        IsOpenStackCompute(ps)
    assert "Not OpenStack Compute node" in str(e)
Example #16
0
def test_director_node():
    # A director act as an Compute as well as a Controller node.
    ps = PsAuxcww(context_wrap(PS_OSP_DIRECTOR))
    result = IsOpenStackCompute(ps)
    assert isinstance(result, IsOpenStackCompute)
Example #17
0
def test_generic_process():
    """The ``psauxcww`` does not have ``nova-compute`` process."""
    ps = PsAuxcww(context_wrap(PS_MULTIPATHD))
    with pytest.raises(SkipComponent) as e:
        IsOpenStackCompute(ps)
    assert "Not OpenStack Compute node" in str(e)