2020-04-29 08:39:00 +00:00
|
|
|
import logging
|
2020-05-08 10:53:12 +00:00
|
|
|
import os
|
2020-09-25 16:15:34 +00:00
|
|
|
import time
|
2020-04-29 08:39:00 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
2020-05-08 10:53:12 +00:00
|
|
|
# Runs simple proxy resolver in python env container.
|
|
|
|
def run_resolver(cluster):
|
|
|
|
container_id = cluster.get_container_id('resolver')
|
|
|
|
current_dir = os.path.dirname(__file__)
|
|
|
|
cluster.copy_file_to_container(container_id, os.path.join(current_dir, "proxy-resolver", "resolver.py"),
|
|
|
|
"resolver.py")
|
2020-06-01 17:16:09 +00:00
|
|
|
cluster.exec_in_container(container_id, ["python", "resolver.py"], detach=True)
|
2020-05-08 10:53:12 +00:00
|
|
|
|
|
|
|
|
2020-04-29 08:39:00 +00:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def cluster():
|
|
|
|
try:
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2020-09-16 04:26:10 +00:00
|
|
|
cluster.add_instance("node",
|
2021-06-29 13:01:15 +00:00
|
|
|
main_configs=["configs/config.d/storage_conf.xml"],
|
2020-09-16 04:26:10 +00:00
|
|
|
with_minio=True)
|
2020-04-29 08:39:00 +00:00
|
|
|
logging.info("Starting cluster...")
|
|
|
|
cluster.start()
|
|
|
|
logging.info("Cluster started")
|
|
|
|
|
2020-05-08 10:53:12 +00:00
|
|
|
run_resolver(cluster)
|
|
|
|
logging.info("Proxy resolver started")
|
|
|
|
|
2020-04-29 08:39:00 +00:00
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
|
2020-09-24 15:57:54 +00:00
|
|
|
def check_proxy_logs(cluster, proxy_instance, http_methods={"POST", "PUT", "GET"}):
|
2020-09-25 16:15:34 +00:00
|
|
|
for i in range(10):
|
|
|
|
logs = cluster.get_container_logs(proxy_instance)
|
2020-09-26 08:47:26 +00:00
|
|
|
# Check with retry that all possible interactions with Minio are present
|
2020-09-25 16:15:34 +00:00
|
|
|
for http_method in http_methods:
|
|
|
|
if logs.find(http_method + " http://minio1") >= 0:
|
|
|
|
return
|
|
|
|
time.sleep(1)
|
|
|
|
else:
|
|
|
|
assert False, "http method not found in logs"
|
2020-04-29 08:39:00 +00:00
|
|
|
|
|
|
|
|
2020-05-08 10:53:12 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"policy", ["s3", "s3_with_resolver"]
|
|
|
|
)
|
|
|
|
def test_s3_with_proxy_list(cluster, policy):
|
2020-04-29 08:39:00 +00:00
|
|
|
node = cluster.instances["node"]
|
|
|
|
|
|
|
|
node.query(
|
|
|
|
"""
|
|
|
|
CREATE TABLE s3_test (
|
|
|
|
id Int64,
|
|
|
|
data String
|
|
|
|
) ENGINE=MergeTree()
|
|
|
|
ORDER BY id
|
2020-05-08 10:53:12 +00:00
|
|
|
SETTINGS storage_policy='{}'
|
2020-04-29 08:39:00 +00:00
|
|
|
"""
|
2020-09-16 04:26:10 +00:00
|
|
|
.format(policy)
|
2020-04-29 08:39:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
node.query("INSERT INTO s3_test VALUES (0,'data'),(1,'data')")
|
|
|
|
assert node.query("SELECT * FROM s3_test order by id FORMAT Values") == "(0,'data'),(1,'data')"
|
|
|
|
|
|
|
|
node.query("DROP TABLE IF EXISTS s3_test NO DELAY")
|
|
|
|
|
|
|
|
for proxy in ["proxy1", "proxy2"]:
|
2020-09-28 08:53:52 +00:00
|
|
|
check_proxy_logs(cluster, proxy, ["PUT", "GET"])
|