Пример #1
0
    def test_should_return_false_if_exit_code_is_not_0(self):
        def mockreturn(command):
            return (1, "an invalid output")

        mock_container = MockContainer()
        with patch.object(mock_container, "exec_run", mockreturn):
            is_reachable = hostname_reachable_from_container(
                mock_container, "hostname", "port", "timeout")
            assert not is_reachable
Пример #2
0
    def test_should_return_false_if_exec_throws(self):
        def mockreturn(command):
            raise

        mock_container = MockContainer()
        with patch.object(mock_container, "exec_run", mockreturn):
            is_reachable = hostname_reachable_from_container(
                mock_container, "hostname", "port", "timeout")
            assert not is_reachable
Пример #3
0
def is_server_in_warning_state(container, hostname):
    not_reachable_on_default_port = \
        network_utils.hostname_not_reachable_from_container(
            container, hostname, DEFAULT_PORT, CONNECTION_TIMEOUT)

    reachable_on_https_port = \
        network_utils.hostname_reachable_from_container(
            container, hostname, HTTPS_PORT, CONNECTION_TIMEOUT)

    return not_reachable_on_default_port and reachable_on_https_port
Пример #4
0
def test_should_return_true_if_exit_code_is_0(mocker):
    def mockreturn(command):
        return (0, "a valid output")

    mock_container = MockContainer()
    mocker.patch.object(mock_container, 'exec_run', mockreturn)

    is_reachable = hostname_reachable_from_container(mock_container,
                                                     "hostname", "port",
                                                     "timeout")
    assert is_reachable
Пример #5
0
def is_host_reachable_from_container(container, hostname, primary_port,
                                     secondary_port):
    return network_utils.hostname_reachable_from_container(
        container, hostname, primary_port,
        CONNECTION_TIMEOUT) or network_utils.hostname_reachable_from_container(
            container, hostname, secondary_port, CONNECTION_TIMEOUT)