mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +00:00
Add an integration test
This commit is contained in:
parent
914fd27d5b
commit
c71835ebec
0
tests/integration/test_placement_info/__init__.py
Normal file
0
tests/integration/test_placement_info/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
<clickhouse>
|
||||
<placement>
|
||||
<use_imds>0</use_imds>
|
||||
<availability_zone>ci-test-1b</availability_zone>
|
||||
</placement>
|
||||
</clickhouse>
|
@ -0,0 +1,6 @@
|
||||
<clickhouse>
|
||||
<placement>
|
||||
<use_imds>0</use_imds>
|
||||
<availability_zone_from_file>/tmp/node-zone</availability_zone_from_file>
|
||||
</placement>
|
||||
</clickhouse>
|
8
tests/integration/test_placement_info/configs/imds.xml
Normal file
8
tests/integration/test_placement_info/configs/imds.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<clickhouse>
|
||||
<s3>
|
||||
<use_environment_credentials>1</use_environment_credentials>
|
||||
</s3>
|
||||
<placement>
|
||||
<use_imds>1</use_imds>
|
||||
</placement>
|
||||
</clickhouse>
|
@ -0,0 +1,5 @@
|
||||
<clickhouse>
|
||||
<placement>
|
||||
<use_imds>0</use_imds>
|
||||
</placement>
|
||||
</clickhouse>
|
@ -0,0 +1,30 @@
|
||||
import http.server
|
||||
import sys
|
||||
|
||||
|
||||
class RequestHandler(http.server.BaseHTTPRequestHandler):
|
||||
def get_response(self):
|
||||
if self.path == "/":
|
||||
return "OK", 200
|
||||
|
||||
if self.path == "/latest/meta-data/placement/availability-zone":
|
||||
return "ci-test-1a", 200
|
||||
|
||||
# Resource not found.
|
||||
return 404
|
||||
|
||||
def do_HEAD(self):
|
||||
response, code = self.get_response()
|
||||
self.send_response(code)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.send_header("Content-Length", len(response.encode()))
|
||||
self.end_headers()
|
||||
return response, code
|
||||
|
||||
def do_GET(self):
|
||||
response, _ = self.do_HEAD()
|
||||
self.wfile.write(response.encode())
|
||||
|
||||
|
||||
httpd = http.server.HTTPServer(("0.0.0.0", int(sys.argv[1])), RequestHandler)
|
||||
httpd.serve_forever()
|
82
tests/integration/test_placement_info/test.py
Normal file
82
tests/integration/test_placement_info/test.py
Normal file
@ -0,0 +1,82 @@
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
from helpers.mock_servers import start_mock_servers
|
||||
import os
|
||||
import time
|
||||
|
||||
METADATA_SERVER_HOSTNAME = "resolver"
|
||||
METADATA_SERVER_PORT = 8080
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
node_imds = cluster.add_instance(
|
||||
"node_imds",
|
||||
with_minio=True,
|
||||
main_configs=["configs/imds.xml"],
|
||||
env_variables={
|
||||
"AWS_EC2_METADATA_SERVICE_ENDPOINT": f"http://{METADATA_SERVER_HOSTNAME}:{METADATA_SERVER_PORT}",
|
||||
},
|
||||
stay_alive=True,
|
||||
)
|
||||
node_config_value = cluster.add_instance(
|
||||
"node_config_value",
|
||||
main_configs=["configs/config_value.xml"],
|
||||
)
|
||||
node_file_value = cluster.add_instance(
|
||||
"node_file_value",
|
||||
main_configs=["configs/file_value.xml"],
|
||||
stay_alive=True,
|
||||
)
|
||||
node_missing_value = cluster.add_instance(
|
||||
"node_missing_value",
|
||||
main_configs=["configs/missing_value.xml"],
|
||||
)
|
||||
|
||||
def start_metadata_server():
|
||||
script_dir = os.path.join(os.path.dirname(__file__), "metadata_servers")
|
||||
start_mock_servers(
|
||||
cluster,
|
||||
script_dir,
|
||||
[
|
||||
(
|
||||
"simple_server.py",
|
||||
METADATA_SERVER_HOSTNAME,
|
||||
METADATA_SERVER_PORT,
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def start_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
start_metadata_server()
|
||||
yield
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_placement_info_from_imds():
|
||||
node_imds.stop_clickhouse(kill=True)
|
||||
node_imds.start_clickhouse()
|
||||
|
||||
node_imds.query("SYSTEM FLUSH LOGS")
|
||||
assert node_imds.contains_in_log("CloudPlacementInfo: Loaded info: availability_zone: ci-test-1a")
|
||||
|
||||
|
||||
def test_placement_info_from_config():
|
||||
node_config_value.query("SYSTEM FLUSH LOGS")
|
||||
assert node_config_value.contains_in_log("CloudPlacementInfo: Loaded info: availability_zone: ci-test-1b")
|
||||
|
||||
def test_placement_info_from_file():
|
||||
node_file_value.exec_in_container(["bash", "-c", "echo ci-test-1c > /tmp/node-zone"])
|
||||
|
||||
node_file_value.stop_clickhouse(kill=True)
|
||||
node_file_value.start_clickhouse()
|
||||
|
||||
node_file_value.query("SYSTEM FLUSH LOGS")
|
||||
assert node_file_value.contains_in_log("CloudPlacementInfo: Loaded info: availability_zone: ci-test-1c")
|
||||
|
||||
def test_placement_info_missing_data():
|
||||
node_missing_value.query("SYSTEM FLUSH LOGS")
|
||||
assert node_missing_value.contains_in_log("CloudPlacementInfo: Availability zone info not found")
|
Loading…
Reference in New Issue
Block a user