コード例 #1
0
def test_run_plugin_post_echo_x_forwarded_path_reverse_proxy_rewrite():
    s = "pds"
    try:
        apc = echo_pc

        plugin_config.add_plugin_configs([apc])
        plugin.run_container(apc)

        container_name = apc["name"]

        time.sleep(CLIENT_DELAY)

        reverse_proxy_rewrite = "reverse_proxy_path"
        resp = requests.post(f"{base_url}/plugin/{container_name}/index.json", headers={"Content-Type": "application/json", "X-Forwarded-Path": reverse_proxy_rewrite}, json=s)

        assert resp.status_code == 200
        assert resp.json()["data"] == json.dumps(s)
        assert resp.json()["method"] == "POST"
        assert "X-Forwarded-Path" in resp.json()["headers"]
        assert resp.json()["headers"]["X-Forwarded-Path"] == f"{reverse_proxy_rewrite}/v1/plugin/{container_name}"

    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
        plugin_config.delete_plugin_configs({})
コード例 #2
0
def test_run_container_from_init2():
    try:
        apc = echo_pc
        apc2 = echo_pc2
        apcs = [apc, apc2]
        init_plugin_path = "/plugin"
        os.mkdir(init_plugin_path)
        with open(f"{init_plugin_path}/echo.yaml", "w+") as f:
            write_config(apcs, f)
            
        os.environ["INIT_PLUGIN_PATH"] = init_plugin_path

        plugin.init_plugin()
        assert bag_contains(plugin_config.get_plugin_configs({}), apcs)

        container_name = apc["name"]
        container_name2 = apc2["name"]

        time.sleep(CLIENT_DELAY)
        resp = requests.get("http://{host}/".format(host=container_name))

        assert resp.status_code == 200
        assert resp.json()["method"] == "GET"
        resp2 = requests.get("http://{host}/".format(host=container_name2))

        assert resp2.status_code == 200
        assert resp2.json()["method"] == "GET"
        shutil.rmtree(init_plugin_path)
    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
        plugin_config.delete_plugin_configs(apc)
        plugin.stop_container(apc2)
        plugin.remove_container(apc2)
        plugin_config.delete_plugin_configs(apc2)
コード例 #3
0
def test_run_container_from_init_dep():
    apcs = echo_pcs_dep
    try:
        init_plugin_path = "/plugin"
        os.mkdir(init_plugin_path)
        with open(f"{init_plugin_path}/echo.yaml", "w+") as f:
            write_config(apcs, f)
        os.environ["INIT_PLUGIN_PATH"] = init_plugin_path

        plugin.init_plugin()
        assert bag_contains(plugin_config.get_plugin_configs({}), apcs)

        time.sleep(CLIENT_DELAY)
        for apc in apcs:
            container_name = apc["name"]

            resp = requests.get(f"http://{container_name}/")

        assert resp.status_code == 200
        assert resp.json()["method"] == "GET"
        shutil.rmtree(init_plugin_path)
    finally:
        for apc in apcs:
            plugin.stop_container(apc)
            plugin.remove_container(apc)
            plugin_config.delete_plugin_configs(apc)
コード例 #4
0
def test_run_container_get_echo_404():
    try:
        apc = echo_pc

        plugin.run_container(apc)

        container_name = apc["name"]

        time.sleep(CLIENT_DELAY)
        resp = requests.get("http://{host}/?status=404".format(host=container_name))

        assert resp.status_code == 404

    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
コード例 #5
0
def test_run_container_environment_post_echo():
    s = "pds"
    try:
        apc = echo_pc2
        plugin.run_container(apc)

        container_name = apc["name"]

        time.sleep(CLIENT_DELAY)
        resp = requests.post("http://{host}/".format(host=container_name), headers={"Content-Type": "application/json"}, json=s)

        assert resp.status_code == 200
        assert resp.json()["data"] == json.dumps(s)
        assert resp.json()["method"] == "POST"
    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
コード例 #6
0
def test_run_container_post_echo_404():
    s = "pds"
    try:
        apc = echo_pc

        plugin.run_container(apc)

        container_name = apc["name"]

        time.sleep(CLIENT_DELAY)
        resp = requests.post("http://{host}/?status=404".format(host=container_name), headers={"Content-Type": "application/json"}, json=s)

        assert resp.status_code == 404

    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
コード例 #7
0
def test_run_container_get_echo():
    try:
        apc = echo_pc

        plugin.run_container(apc)

        container_name = apc["name"]

        time.sleep(CLIENT_DELAY)
        resp = requests.get(f"http://{container_name}/")

        assert resp.status_code == 200
        assert resp.json()["method"] == "GET"

    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
コード例 #8
0
def test_run_container_get():
    with tempfile.TemporaryDirectory(prefix="/tmp/") as temp_dir_name:
        os.chmod(temp_dir_name, 0o755)
        s = "pds"
        with open(os.path.join(temp_dir_name, "index.json"), "w+") as f:
            f.write(json.dumps(s))

        try:
            apc = pc(temp_dir_name)
            plugin.run_container(apc)

            container_name = apc["name"]

            resp = requests.get("http://{host}/index.json".format(host=container_name))

            assert resp.status_code == 200
            assert resp.json() == s
        finally:
            plugin.stop_container(apc)
            plugin.remove_container(apc)
コード例 #9
0
def test_run_plugin_get_echo_x_forwarded_path():
    try:
        apc = echo_pc
        
        plugin_config.add_plugin_configs([apc])
        plugin.run_container(apc)
        
        container_name = apc["name"]

        time.sleep(CLIENT_DELAY)
        resp = requests.get(f"{base_url}/plugin/{container_name}/index.json")

        assert resp.status_code == 200
        assert resp.json()["method"] == "GET"
        assert "X-Forwarded-Path" in resp.json()["headers"]
        assert resp.json()["headers"]["X-Forwarded-Path"] == f"/v1/plugin/{container_name}"

    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
        plugin_config.delete_plugin_configs({})
コード例 #10
0
def test_run_container_get_relative_path():
    host_cwd_mount = os.environ["HOST_CWD_MOUNT"]
    with tempfile.TemporaryDirectory(prefix=os.path.join(host_cwd_mount, "")) as temp_dir_name:
        _, basename = os.path.split(temp_dir_name)
        os.chmod(temp_dir_name, 0o755)
        s = "pds"
        with open(os.path.join(temp_dir_name, "index.json"), "w+") as f:
            f.write(json.dumps(s))

        try:
            apc = pc(f"./{basename}")
            plugin.run_container(apc)

            container_name = apc["name"]

            resp = requests.get("http://{host}/index.json".format(host=container_name))

            assert resp.status_code == 200
            assert resp.json() == s
        finally:
            plugin.stop_container(apc)
            plugin.remove_container(apc)
コード例 #11
0
def test_run_container_from_init_env():
    try:
        apc = echo_pc
        apcs = [apc]
        init_plugin_path = "/plugin"
        os.mkdir(init_plugin_path)
        with open(f"{init_plugin_path}/echo.yaml", "w+") as f:
            f.write('''
services:
  echo:
    image: tx-router-test-flask-echo-server:${TAG}
    environment: {}
    port: 80
    environment:
      HOST: 0.0.0.0
      PORT: "80"
    volumes: []
''')
        os.environ["INIT_PLUGIN_PATH"] = init_plugin_path
        os.environ["TAG"] = tag
        plugin.init_plugin()
        del os.environ["TAG"]
        del os.environ["INIT_PLUGIN_PATH"]
        assert bag_contains(plugin_config.get_plugin_configs({}), apcs)

        container_name = apc["name"]

        time.sleep(CLIENT_DELAY)
        resp = requests.get("http://{host}/".format(host=container_name))

        assert resp.status_code == 200
        assert resp.json()["method"] == "GET"
        shutil.rmtree(init_plugin_path)
    finally:
        plugin.stop_container(apc)
        plugin.remove_container(apc)
        plugin_config.delete_plugin_configs(apc)
コード例 #12
0
def delete_containers():
    for pc in plugin_config.get_plugin_configs({}):
        plugin.stop_container(pc)
        plugin.remove_container(pc)
コード例 #13
0
def delete_plugin_container(name):
    pc = plugin_config.get_plugin_config(name)
    plugin.stop_container(pc)
    plugin.remove_container(pc)