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
|
2023-08-24 13:07:26 +00:00
|
|
|
import helpers.s3_url_proxy_tests_util as proxy_util
|
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__)
|
2022-03-22 16:39:58 +00:00
|
|
|
cluster.add_instance(
|
|
|
|
"node", main_configs=["configs/config.d/storage_conf.xml"], with_minio=True
|
|
|
|
)
|
2020-04-29 08:39:00 +00:00
|
|
|
logging.info("Starting cluster...")
|
|
|
|
cluster.start()
|
|
|
|
logging.info("Cluster started")
|
|
|
|
|
2023-08-24 13:07:26 +00:00
|
|
|
proxy_util.run_resolver(cluster, os.path.dirname(__file__))
|
2020-05-08 10:53:12 +00:00
|
|
|
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:
|
2023-08-24 13:07:26 +00:00
|
|
|
assert False, f"{http_methods} method not found in logs of {proxy_instance}"
|
2020-04-29 08:39:00 +00:00
|
|
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
@pytest.mark.parametrize("policy", ["s3", "s3_with_resolver"])
|
2020-05-08 10:53:12 +00:00
|
|
|
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='{}'
|
2022-03-22 16:39:58 +00:00
|
|
|
""".format(
|
|
|
|
policy
|
|
|
|
)
|
2020-04-29 08:39:00 +00:00
|
|
|
)
|
|
|
|
node.query("INSERT INTO s3_test VALUES (0,'data'),(1,'data')")
|
2022-03-22 16:39:58 +00:00
|
|
|
assert (
|
|
|
|
node.query("SELECT * FROM s3_test order by id FORMAT Values")
|
|
|
|
== "(0,'data'),(1,'data')"
|
|
|
|
)
|
2020-04-29 08:39:00 +00:00
|
|
|
|
2023-05-03 18:06:46 +00:00
|
|
|
node.query("DROP TABLE IF EXISTS s3_test SYNC")
|
2020-04-29 08:39:00 +00:00
|
|
|
|
|
|
|
for proxy in ["proxy1", "proxy2"]:
|
2020-09-28 08:53:52 +00:00
|
|
|
check_proxy_logs(cluster, proxy, ["PUT", "GET"])
|