ClickHouse/tests/integration/test_catboost_model_config_reload/test.py

78 lines
2.0 KiB
Python
Raw Normal View History

import os
import sys
import time
import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance(
"node",
stay_alive=True,
main_configs=["config/models_config.xml", "config/catboost_lib.xml"],
)
def copy_file_to_container(local_path, dist_path, container_id):
os.system(
"docker cp {local} {cont_id}:{dist}".format(
local=local_path, cont_id=container_id, dist=dist_path
)
)
config = """<clickhouse>
2021-04-01 12:12:34 +00:00
<models_config>/etc/clickhouse-server/model/{model_config}</models_config>
</clickhouse>"""
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
copy_file_to_container(
os.path.join(SCRIPT_DIR, "model/."),
"/etc/clickhouse-server/model",
node.docker_id,
)
node.restart_clickhouse()
yield cluster
finally:
cluster.shutdown()
2021-04-01 12:12:34 +00:00
def change_config(model_config):
node.replace_config(
"/etc/clickhouse-server/config.d/models_config.xml",
config.format(model_config=model_config),
)
2021-04-01 12:12:34 +00:00
node.query("SYSTEM RELOAD CONFIG;")
def test(started_cluster):
2021-04-25 02:25:46 +00:00
if node.is_built_with_memory_sanitizer():
pytest.skip("Memory Sanitizer cannot work with third-party shared libraries")
2021-04-01 16:17:25 +00:00
# Set config with the path to the first model.
change_config("model_config.xml")
node.query("SELECT modelEvaluate('model1', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);")
2021-04-01 16:17:25 +00:00
# Change path to the second model in config.
2021-04-01 12:12:34 +00:00
change_config("model_config2.xml")
# Check that the new model is loaded.
node.query("SELECT modelEvaluate('model2', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);")
# Check that the old model was unloaded.
node.query_and_get_error(
"SELECT modelEvaluate('model1', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);"
)