Beispiel #1
0
def test_status_when_not_running():
    st = orderly_web.status("config/basic")
    assert not st.is_running
    assert st.containers["orderly"]["status"] == "missing"
    assert st.containers["web"]["status"] == "missing"
    assert st.volumes == {}
    assert st.network is None
Beispiel #2
0
def test_cli_basic_usage():
    path = "config/noproxy"
    orderly_web.cli.main(["start", path])
    st = orderly_web.status(path)
    assert st.is_running
    assert st.containers["web"]["status"] == "running"

    f = io.StringIO()
    with redirect_stdout(f):
        orderly_web.cli.main(["status", path])
    out = f.getvalue()
    assert str(st).strip() == out.strip()

    stop_args = ["stop", path, "--kill", "--volumes", "--network"]
    orderly_web.cli.main(stop_args)
    st = orderly_web.status(path)
    assert not st.is_running
    assert st.containers["web"]["status"] == "missing"
Beispiel #3
0
def test_status_representation_is_str():
    st = orderly_web.status("config/basic")
    f = io.StringIO()
    with redirect_stdout(f):
        print(st)
    out = f.getvalue()
    assert str(st).strip() == out.strip()
    # __repr__ is called when the object is printed
    assert st.__repr__() == str(st)
Beispiel #4
0
def test_start_and_stop_multiple_workers():
    options = {"orderly": {"workers": 2}}
    path = "config/basic"
    try:
        res = orderly_web.start(path, options=options)
        assert res
        st = orderly_web.status(path)
        assert st.containers["orderly"]["status"] == "running"
        assert st.containers["redis"]["status"] == "running"
        assert st.containers["web"]["status"] == "running"
        assert len(st.container_groups) == 1
        assert "orderly_worker" in st.container_groups
        assert st.container_groups["orderly_worker"]["count"] == 2
        assert len(st.container_groups["orderly_worker"]["status"]) == 2
        assert re.match(
            r"orderly_web_orderly_worker_\w+",
            st.container_groups["orderly_worker"]["status"][0]["name"])
        assert st.container_groups["orderly_worker"]["status"][0]["status"] ==\
            "running"
        assert re.match(
            r"orderly_web_orderly_worker_\w+",
            st.container_groups["orderly_worker"]["status"][1]["name"])
        assert st.container_groups["orderly_worker"]["status"][1]["status"] ==\
            "running"

        # Bring the whole lot down:
        orderly_web.stop(path, kill=True, volumes=True, network=True)
        st = orderly_web.status(path)
        assert not st.is_running
        assert st.containers["orderly"]["status"] == "missing"
        assert st.containers["redis"]["status"] == "missing"
        assert st.containers["web"]["status"] == "missing"
        assert st.container_groups["orderly_worker"]["count"] == 0
        assert len(st.container_groups["orderly_worker"]["status"]) == 0
    finally:
        orderly_web.stop(path, kill=True, volumes=True, network=True)
Beispiel #5
0
def test_status_from_broken_orderly_web():
    path = "config/breaking"
    try:
        start_failed = False
        try:
            orderly_web.start(path)
        except docker.errors.APIError:
            start_failed = True

        assert start_failed

        status = orderly_web.status(path)
        assert str(status) == "Cannot read status from orderly-web because " \
            "it has not started successfully or is in an error state."
    finally:
        orderly_web.stop(path, force=True, network=True, volumes=True)
Beispiel #6
0
def test_start_with_custom_styles():
    path = "config/customcss"
    try:
        options = {"web": {"url": "http://localhost:8888"}}
        res = orderly_web.start(path, options=options)
        assert res
        st = orderly_web.status(path)
        assert st.containers["orderly"]["status"] == "running"
        assert st.containers["web"]["status"] == "running"
        assert st.volumes["css"] == "orderly_web_css"
        assert "documents" not in st.volumes
        assert st.network == "orderly_web_network"

        cfg = fetch_config(path)

        # check that the style volume is really mounted
        api_client = docker.client.from_env().api
        details = api_client.inspect_container(cfg.containers["web"])
        assert len(details['Mounts']) == 3
        css_volume = [
            v for v in details['Mounts']
            if v['Type'] == "volume" and v['Name'] == "orderly_web_css"
        ][0]
        assert css_volume['Name'] == "orderly_web_css"
        assert css_volume['Destination'] == "/static/public/css"

        # check that the style files have been compiled with the custom vars
        web_container = cfg.get_container("web")
        style = string_from_container(web_container,
                                      "/static/public/css/style.css")
        assert "/* Example custom config */" in style

        # check that js files are there also
        res = requests.get("http://localhost:8888/js/index.bundle.js")
        assert res.status_code == 200

        # check that the custom logo is mounted and appears on the page
        logo_mount = [v for v in details['Mounts'] if v['Type'] == "bind"][0]
        expected_destination = "/static/public/img/logo/my-test-logo.png"
        assert logo_mount['Destination'] == expected_destination
        res = requests.get("http://localhost:8888")
        assert """<img src="http://localhost:8888/img/logo/my-test-logo.png"""\
               in res.text
        res = requests.get("http://localhost:8888/img/logo/my-test-logo.png")
        assert res.status_code == 200
    finally:
        orderly_web.stop(path, kill=True, volumes=True, network=True)
Beispiel #7
0
def test_without_github_app_for_montagu():
    path = "config/basic"
    options = {
        "web": {
            "auth": {
                "montagu": True,
                "montagu_url": "montagu",
                "montagu_api_url": "montagu/api",
                "github_key": None,
                "github_secret": None
            }
        }
    }
    res = orderly_web.start(path, options=options)
    assert res
    st = orderly_web.status(path)
    assert st.containers["orderly"]["status"] == "running"
    assert st.containers["web"]["status"] == "running"
    assert st.network == "orderly_web_network"

    orderly_web.stop(path, kill=True, volumes=True, network=True)
Beispiel #8
0
def test_start_with_montagu_config():
    path = "config/montagu"
    try:
        res = orderly_web.start(path)
        assert res
        st = orderly_web.status(path)
        assert st.containers["orderly"]["status"] == "running"
        assert st.containers["web"]["status"] == "running"
        assert st.network == "orderly_web_network"

        cfg = fetch_config(path)
        web = cfg.get_container("web")
        web_config = string_from_container(
            web, "/etc/orderly/web/config.properties").split("\n")

        assert "montagu.url=http://montagu" in web_config
        assert "montagu.api_url=http://montagu/api" in web_config
        assert 'auth.github_org=' in web_config
        assert 'auth.github_team=' in web_config

    finally:
        orderly_web.stop(path, kill=True, volumes=True, network=True)
Beispiel #9
0
def test_start_and_stop():
    path = "config/basic"
    try:
        res = orderly_web.start(path)
        assert res
        st = orderly_web.status(path)
        assert st.containers["orderly"]["status"] == "running"
        assert st.containers["redis"]["status"] == "running"
        assert st.containers["web"]["status"] == "running"
        assert len(st.container_groups) == 1
        assert "orderly_worker" in st.container_groups
        assert st.container_groups["orderly_worker"]["scale"] == 1
        assert st.container_groups["orderly_worker"]["count"] == 1
        assert len(st.container_groups["orderly_worker"]["status"]) == 1
        assert re.match(
            r"orderly_web_orderly_worker_\w+",
            st.container_groups["orderly_worker"]["status"][0]["name"])
        assert st.container_groups["orderly_worker"]["status"][0]["status"] ==\
            "running"
        assert st.volumes["orderly"] == "orderly_web_volume"
        assert st.volumes["documents"] == "orderly_web_documents"
        assert st.volumes["redis"] == "orderly_web_redis_data"
        assert st.network == "orderly_web_network"

        f = io.StringIO()
        with redirect_stdout(f):
            res = orderly_web.start(path)
            msg = f.getvalue().strip()
        assert not res
        assert msg.endswith("please run orderly-web stop")

        cfg = fetch_config(path)
        web = cfg.get_container("web")
        ports = web.attrs["HostConfig"]["PortBindings"]
        assert list(ports.keys()) == ["8888/tcp"]
        dat = json.loads(http_get("http://localhost:8888/api/v1"))
        assert dat["status"] == "success"

        web_config = string_from_container(
            web, "/etc/orderly/web/config.properties").split("\n")

        assert "app.url=https://localhost" in web_config
        assert "auth.github_key=notarealid" in web_config
        assert "auth.github_secret=notarealsecret" in web_config
        assert "orderly.server=http://orderly_web_orderly:8321" in web_config

        # Trivial check that the proxy container works too:
        proxy = cfg.get_container("proxy")
        ports = proxy.attrs["HostConfig"]["PortBindings"]
        assert set(ports.keys()) == set(["443/tcp", "80/tcp"])
        dat = json.loads(http_get("http://localhost/api/v1"))
        assert dat["status"] == "success"
        dat = json.loads(http_get("https://localhost/api/v1"))
        assert dat["status"] == "success"

        # Orderly volume contains only the stripped down example from
        # the URL, not the whole demo:
        orderly = cfg.get_container("orderly")
        src = exec_safely(orderly, ["ls", "/orderly/src"])[1]
        src_contents = src.decode("UTF-8").strip().split("\n")
        assert set(src_contents) == set(["README.md", "example"])

        # Bring the whole lot down:
        orderly_web.stop(path, kill=True, volumes=True, network=True)
        st = orderly_web.status(path)
        assert not st.is_running
        assert st.containers["orderly"]["status"] == "missing"
        assert st.containers["redis"]["status"] == "missing"
        assert st.containers["web"]["status"] == "missing"
        assert st.container_groups["orderly_worker"]["scale"] == 1
        assert st.container_groups["orderly_worker"]["count"] == 0
        assert len(st.container_groups["orderly_worker"]["status"]) == 0
        assert st.volumes == {}
        assert st.network is None
        # really removed?
        with docker_client() as cl:
            assert not network_exists(cl, cfg.network)
            assert not volume_exists(cl, cfg.volumes["orderly"])
            assert not container_exists(cl, cfg.containers["proxy"])
    finally:
        orderly_web.stop(path, kill=True, volumes=True, network=True)