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, [])
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()
def httpd_cmd(broker): """ Function to search the output of ``ps auxcww`` to find all running Apache webserver processes and extract the binary path. Returns: list: List of the binary paths to each running process """ return get_running_commands(broker[Ps], broker[HostContext], ['httpd', ])
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', ])
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', ])
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' ])