def test_driveon_flag():
    cmd_list = [{
        "command": [
            "/bin/sh", "-c",
            "echo " + CommandSequence.PROJECT_SUBST + "; exit 2"
        ]
    }, {
        "command": ["/bin/echo"]
    }, {
        "command": [
            "/bin/sh", "-c",
            "echo " + CommandSequence.PROJECT_SUBST + "; exit 1"
        ]
    }, {
        "command": ["/bin/sh", "-c", "echo " + CommandSequence.PROJECT_SUBST]
    }]
    cmds = CommandSequence(
        CommandSequenceBase("opengrok-master", cmd_list, driveon=True))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/sh -c echo opengrok-master; exit 2': 2,
        '/bin/echo opengrok-master': 0,
        '/bin/sh -c echo opengrok-master; exit 1': 1
    }
    assert cmds.failed
Beispiel #2
0
def test_project_subst():
    cmds = CommandSequence(
        CommandSequenceBase("test-subst", [{
            "command": ["/bin/echo", CommandSequence.PROJECT_SUBST]
        }]))
    cmds.run()
    assert cmds.outputs['/bin/echo test-subst'] == ['test-subst\n']
Beispiel #3
0
 def test_project_subst(self):
     cmds = CommandSequence(
         CommandSequenceBase("test-subst", [{
             "command": ["/bin/echo", CommandSequence.PROJECT_SUBST]
         }]))
     cmds.run()
     self.assertEqual(['test-subst\n'],
                      cmds.outputs['/bin/echo test-subst'])
Beispiel #4
0
def test_terminate_after_non_zero_code():
    cmd_list = [{"command": ["/bin/sh", "-c",
                 "echo " + PROJECT_SUBST + "; exit 255"]},
                {"command": ["/bin/echo"]}]
    cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/sh -c echo opengrok-master; exit 255': 255
    }
def test_terminate_after_non_zero_code():
    cmd_list = [{"command": ["/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 255"]},
                {"command": ["/bin/echo"]}]
    cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/sh -c echo opengrok-master; exit 255': 255
    }
def test_exit_2_handling():
    cmd_list = [{"command": ["/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 2"]},
                {"command": ["/bin/echo"]}]
    cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/sh -c echo opengrok-master; exit 2': 2
    }
    assert not cmds.failed
Beispiel #7
0
def test_exit_2_handling():
    cmd_list = [{"command": ["/bin/sh", "-c",
                 "echo " + PROJECT_SUBST + "; exit 2"]},
                {"command": ["/bin/echo"]}]
    cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/sh -c echo opengrok-master; exit 2': 2
    }
    assert not cmds.failed
def test_run_retcodes():
    cmd_list = [{"command": ["/bin/echo"]},
                {"command": ["/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 0"]},
                {"command": ["/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 1"]}]
    cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/echo opengrok-master': 0,
        '/bin/sh -c echo opengrok-master; exit 0': 0,
        '/bin/sh -c echo opengrok-master; exit 1': 1
    }
Beispiel #9
0
 def test_terminate_after_non_zero_code(self):
     cmds = CommandSequence(
         CommandSequenceBase("opengrok-master", [{
             "command": [
                 "/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 255"
             ]
         }, {
             "command": ["/bin/echo"]
         }]))
     cmds.run()
     self.assertEqual({'/bin/sh -c echo opengrok-master; exit 255': 255},
                      cmds.retcodes)
Beispiel #10
0
def test_run_retcodes():
    cmd_list = [{"command": ["/bin/echo"]},
                {"command": ["/bin/sh", "-c",
                 "echo " + PROJECT_SUBST + "; exit 0"]},
                {"command": ["/bin/sh", "-c",
                 "echo " + PROJECT_SUBST + "; exit 1"]}]
    cmds = CommandSequence(CommandSequenceBase("opengrok-master", cmd_list))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/echo opengrok-master': 0,
        '/bin/sh -c echo opengrok-master; exit 0': 0,
        '/bin/sh -c echo opengrok-master; exit 1': 1
    }
Beispiel #11
0
 def test_exit_2_handling(self):
     cmds = CommandSequence(
         CommandSequenceBase("opengrok-master", [{
             "command": [
                 "/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 2"
             ]
         }, {
             "command": ["/bin/echo"]
         }]))
     cmds.run()
     self.assertEqual({'/bin/sh -c echo opengrok-master; exit 2': 2},
                      cmds.retcodes)
     self.assertFalse(cmds.failed)
def test_driveon_flag():
    cmd_list = [{"command": ["/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 2"]},
                {"command": ["/bin/echo"]},
                {"command": ["/bin/sh", "-c",
                             "echo " + CommandSequence.PROJECT_SUBST +
                             "; exit 1"]},
                {"command": ["/bin/sh", "-c",
                             "echo " + CommandSequence.PROJECT_SUBST]}]
    cmds = CommandSequence(CommandSequenceBase("opengrok-master",
                                               cmd_list, driveon=True))
    cmds.run()
    assert cmds.retcodes == {
        '/bin/sh -c echo opengrok-master; exit 2': 2,
        '/bin/echo opengrok-master': 0,
        '/bin/sh -c echo opengrok-master; exit 1': 1
    }
    assert cmds.failed
Beispiel #13
0
def test_cleanup():
    with tempfile.TemporaryDirectory() as tmpdir:
        file_foo = os.path.join(tmpdir, "foo")
        file_bar = os.path.join(tmpdir, "bar")
        cleanup_list = [{"command": ["/usr/bin/touch", file_foo]},
                        {"command": ["/bin/cat", "/totallynonexistent"]},
                        {"command": ["/usr/bin/touch", file_bar]}]
        # Running 'cat' on non-existing entry causes it to return 1.
        cmd = ["/bin/cat", "/foobar"]
        cmd_list = [{"command": cmd}]
        commands = CommandSequence(CommandSequenceBase("test-cleanup-list",
                                                       cmd_list,
                                                       cleanup=cleanup_list))
        assert commands is not None
        commands.run()
        assert list(commands.retcodes.values()) == [1]
        assert os.path.isfile(file_foo)
        assert os.path.isfile(file_bar)
Beispiel #14
0
def test_restful_fail(monkeypatch):
    class MockResponse:
        def p(self):
            raise HTTPError("foo")

        def __init__(self):
            self.status_code = 500
            self.raise_for_status = self.p

    def mock_response(uri, headers, data, params, proxies, timeout):
        return MockResponse()

    commands = CommandSequence(
        CommandSequenceBase("test-cleanup-list",
                            [{CALL_PROPERTY: {"uri": 'http://foo', "method": 'PUT', "data": 'data'}}]))
    assert commands is not None
    with monkeypatch.context() as m:
        m.setattr("requests.put", mock_response)
        commands.run()
        assert commands.check([]) == 1
Beispiel #15
0
def test_restful_fail(monkeypatch):
    class MockResponse:
        def p(self):
            raise HTTPError("foo")

        def __init__(self):
            self.status_code = 500
            self.raise_for_status = self.p

    def mock_response(verb, uri, headers, data):
        return MockResponse()

    commands = CommandSequence(
        CommandSequenceBase("test-cleanup-list",
                            [{'command': ['http://foo', 'PUT', 'data']}]))
    assert commands is not None
    with monkeypatch.context() as m:
        m.setattr("opengrok_tools.utils.restful.do_api_call",
                  mock_response)
        commands.run()
        assert commands.check([]) == 1
Beispiel #16
0
 def test_run_retcodes(self):
     cmds = CommandSequence(
         CommandSequenceBase("opengrok-master", [{
             "command": ["/bin/echo"]
         }, {
             "command": [
                 "/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 0"
             ]
         }, {
             "command": [
                 "/bin/sh", "-c",
                 "echo " + CommandSequence.PROJECT_SUBST + "; exit 1"
             ]
         }]))
     cmds.run()
     self.assertEqual(
         {
             '/bin/echo opengrok-master': 0,
             '/bin/sh -c echo opengrok-master; exit 0': 0,
             '/bin/sh -c echo opengrok-master; exit 1': 1
         }, cmds.retcodes)
def test_project_subst():
    cmd_list = [{"command": ["/bin/echo", CommandSequence.PROJECT_SUBST]}]
    cmds = CommandSequence(CommandSequenceBase("test-subst", cmd_list))
    cmds.run()

    assert cmds.outputs['/bin/echo test-subst'] == ['test-subst\n']