Ejemplo n.º 1
0
def mk_orthanc(http_port=8042,
               dcm_port=4242,
               remote_peer=8043,
               remote_mod=4243):

    print("Standing up orthanc fixture")
    dkr_name = "orthanc-{}".format(http_port)

    S = Containerized(
        dkr_name=dkr_name,
        dkr_image="derekmerck/orthanc-confd",
        dkr_ports={
            "8042/tcp": http_port,
            "4242/tcp": dcm_port
        },
        dkr_env={
            "ORTHANC_MOD_0":
            "mod0,ORTHANC,localhost,{}".format(remote_mod),
            "ORTHANC_PEER_0":
            "peer0,http://localhost:{},orthanc,passw0rd!".format(remote_peer)
        })
    S.start_container()

    client = docker.from_env()
    c = client.containers.get(dkr_name)
    print("{}: {}".format(S.dkr_name, c.status))

    return S
Ejemplo n.º 2
0
def mk_redis():

    print("Standing up redis fixture")
    dkr_name = "redis"

    S = Containerized(dkr_name=dkr_name,
                      dkr_image="redis",
                      dkr_ports={"6379/tcp": 6379})
    S.start_container()

    client = docker.from_env()
    c = client.containers.get(dkr_name)
    print("{}: {}".format(S.dkr_name, c.status))

    return S
Ejemplo n.º 3
0
def mk_orthanc(http_port=8042,
               dcm_port=4242,
               remote_peer=8043,
               remote_mod=4243):

    print("Standing up orthanc fixture")
    dkr_name = "orthanc-{}".format(http_port)

    import socket
    host_name = socket.gethostname()
    host_ip = socket.gethostbyname(host_name)

    S = Containerized(dkr_name=dkr_name,
                      dkr_image="derekmerck/orthanc-confd",
                      dkr_ports={
                          "8042/tcp": http_port,
                          "4242/tcp": dcm_port
                      },
                      dkr_env={
                          "ORTHANC_MOD_0":
                          "mod0,ORTHANC{},{},{}".format(
                              remote_mod, host_ip, remote_mod),
                          "ORTHANC_PEER_0":
                          "peer0,http://{}:{},orthanc,passw0rd!".format(
                              host_ip, remote_peer),
                          "ORTHANC_AET":
                          "ORTHANC{}".format(dcm_port),
                          "ORTHANC_VERBOSE":
                          "true"
                      })
    S.start_container()

    client = docker.from_env()
    c = client.containers.get(dkr_name)
    print("{}: {}".format(S.dkr_name, c.status))

    return S
Ejemplo n.º 4
0
def test_containers():

    C = Containerized(dkr_name="testing",
                      dkr_image="alpine",
                      dkr_command="tail -f > /dev/null")

    C.start_container()

    client = docker.from_env()
    c = client.containers.get("testing")
    assert (c.status == "running")

    C.stop_container()
    time.sleep(1)

    with pytest.raises(Exception):
        c = client.containers.get("testing")
Ejemplo n.º 5
0
def test_mock_svcs():

    C.start_swarm()
    C.clean_swarm()

    c = C.api_client()

    admin_stack = find_resource("platform/docker-stacks/admin/admin-stack.yml")
    cmd = ["docker", "stack", "deploy", "-c", admin_stack, "admin"]
    subprocess.run(cmd)

    service_names = [x['Spec']['Name'] for x in c.services()]

    assert ("admin_portainer" in service_names)
    assert ("admin_traefik" in service_names)

    mock_stack = find_resource(
        "platform/docker-stacks/diana-workers/mock-stack.yml")
    cmd = ["docker", "stack", "deploy", "-c", mock_stack, "mock"]

    # Don't forget to set the password, or docker-compose will
    # interpret it as empty rather than default
    os.environ["ORTHANC_PASSWORD"] = "******"
    subprocess.run(cmd)

    service_names = [x['Spec']['Name'] for x in c.services()]

    assert ("mock_diana-mock" in service_names)
    assert ("mock_orthanc-mock" in service_names)

    # Pause to generate some data
    time.sleep(20)

    O = Orthanc(path="orthanc-mock", port=80)
    info = O.gateway._get("statistics")

    # At least 100 new images in the PACS
    assert (info['CountInstances'] > 100)

    C.clean_swarm()
Ejemplo n.º 6
0
def test_swarm():
    Containerized.start_swarm()

    client = Containerized.api_client()
    logging.debug(client.services())
    Containerized.clean_swarm()
    logging.debug(client.services())

    logging.debug(pformat(client.version()))

    api_vers = client.version()["ApiVersion"]
    logging.debug(api_vers)

    assert (len(client.services()) == 0)

    C = Containerized(dkr_name="testing",
                      dkr_image="alpine",
                      dkr_command="tail -f > /dev/null")
    C.start_service()

    assert (len(client.services()) == 1)

    logging.debug(client.services())

    assert ("testing" in client.services()[0]["Spec"]["Name"])

    C.stop_service()