Ejemplo n.º 1
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'
Ejemplo n.º 2
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()
Ejemplo n.º 3
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)
Ejemplo n.º 4
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',
    ])
Ejemplo n.º 5
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',
    ])
Ejemplo n.º 6
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)
Ejemplo n.º 7
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, [])
Ejemplo n.º 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_eo_cmd = PsEoCmd(context_wrap(PS_EO_CMD_LINES, strip=False))
    ps_combiner = Ps(ps_alxwww, ps_auxww, ps_aux, ps_ef, ps_auxcww, ps_eo,
                     ps_eo_cmd)
    env = {'ps_combiner': ps_combiner}
    failed, total = doctest.testmod(ps, globs=env)
    assert failed == 0
Ejemplo n.º 9
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'
    ])