示例#1
0
def test_probes_port():
    port = 1234
    host = "127.0.0.1"
    probe = Probe(timeout=20, fnc=check_port, host=host, port=port)
    assert not check_port(host=host, port=port)

    bckgrnd = subprocess.Popen(["nc", "-l", str(port)], stdout=subprocess.PIPE)
    assert probe.run()
    assert not check_port(host=host, port=port)
    bckgrnd.kill()
    assert not check_port(host=host, port=port)

    subprocess.Popen(["nc", "-l", str(port)], stdout=subprocess.PIPE)
    assert probe.run()
    assert not check_port(host=host, port=port)
示例#2
0
def check_localhost_port():
    import logging
    import time
    from conu import DockerBackend, check_port

    backend = DockerBackend(logging_level=logging.DEBUG)
    image = backend.ImageClass(IMAGE_NAME)

    # publish 8080 port
    container = image.run_via_binary(additional_opts=['-p', '8080:8080'])
    time.sleep(2)

    # check it is published correctly
    check_port(host='localhost', port=8080)
    print('Success!')

    # cleanup
    container.delete(force=True)
示例#3
0
    # cleanup
    container.delete(force=True)


def self_cleanup():
    import logging
    import pytest
    from conu import DockerBackend, DockerRunBuilder

    backend = DockerBackend(logging_level=logging.DEBUG)
    image = backend.ImageClass(IMAGE_NAME)

    # alternative of docker run --rm nginx
    run_params = DockerRunBuilder(additional_opts=['--rm'])
    container = image.run_via_binary(run_params)
    assert container.is_running()

    # check container is removed when stopped
    container.stop()
    with pytest.raises(Exception):
        container.inspect()


if __name__ == '__main__':
    basics()
    check_output()
    check_port()
    check_localhost_port()
    mount_container_filesystem()
    self_cleanup()