2021-05-11 17:59:29 +08:00
|
|
|
import pytest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append("..")
|
2021-06-04 09:35:34 +08:00
|
|
|
from base.connections_wrapper import ApiConnectionsWrapper
|
|
|
|
from base.collection_wrapper import ApiCollectionWrapper
|
|
|
|
from base.partition_wrapper import ApiPartitionWrapper
|
|
|
|
from base.index_wrapper import ApiIndexWrapper
|
|
|
|
from base.utility_wrapper import ApiUtilityWrapper
|
2021-06-09 09:21:35 +08:00
|
|
|
from base.schema_wrapper import ApiCollectionSchemaWrapper, ApiFieldSchemaWrapper
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-09 16:19:48 +08:00
|
|
|
from config.log_config import log_config
|
2021-05-20 11:03:45 +08:00
|
|
|
from utils.util_log import test_log as log
|
|
|
|
from common import common_func as cf
|
2021-05-27 10:26:35 +08:00
|
|
|
from common import common_type as ct
|
2021-06-08 13:19:35 +08:00
|
|
|
from check.param_check import ip_check, number_check
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ParamInfo:
|
|
|
|
def __init__(self):
|
2021-05-13 12:17:15 +08:00
|
|
|
self.param_host = ""
|
2021-05-11 17:59:29 +08:00
|
|
|
self.param_port = ""
|
|
|
|
self.param_handler = ""
|
|
|
|
|
2021-05-13 12:17:15 +08:00
|
|
|
def prepare_param_info(self, host, port, handler):
|
|
|
|
self.param_host = host
|
2021-05-11 17:59:29 +08:00
|
|
|
self.param_port = port
|
|
|
|
self.param_handler = handler
|
|
|
|
|
|
|
|
|
|
|
|
param_info = ParamInfo()
|
|
|
|
|
|
|
|
|
|
|
|
class Base:
|
|
|
|
""" Initialize class object """
|
2021-06-04 09:35:34 +08:00
|
|
|
connection_wrap = None
|
|
|
|
collection_wrap = None
|
|
|
|
partition_wrap = None
|
|
|
|
index_wrap = None
|
|
|
|
utility_wrap = None
|
2021-06-09 09:21:35 +08:00
|
|
|
collection_schema_wrap = None
|
|
|
|
field_schema_wrap = None
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
def setup_class(self):
|
|
|
|
log.info("[setup_class] Start setup class...")
|
|
|
|
|
|
|
|
def teardown_class(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setup(self):
|
2021-06-02 19:21:33 +08:00
|
|
|
log.info(("*" * 35) + " setup " + ("*" * 35))
|
2021-06-04 09:35:34 +08:00
|
|
|
self.connection_wrap = ApiConnectionsWrapper()
|
|
|
|
self.collection_wrap = ApiCollectionWrapper()
|
|
|
|
self.partition_wrap = ApiPartitionWrapper()
|
|
|
|
self.index_wrap = ApiIndexWrapper()
|
|
|
|
self.utility_wrap = ApiUtilityWrapper()
|
2021-06-09 09:21:35 +08:00
|
|
|
self.collection_schema_wrap = ApiCollectionSchemaWrapper()
|
|
|
|
self.field_schema_wrap = ApiFieldSchemaWrapper()
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
def teardown(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
log.info(("*" * 35) + " teardown " + ("*" * 35))
|
|
|
|
|
|
|
|
try:
|
|
|
|
""" Drop collection before disconnect """
|
|
|
|
if self.collection_wrap is not None and self.collection_wrap.collection is not None:
|
|
|
|
self.collection_wrap.drop()
|
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
2021-06-01 18:49:31 +08:00
|
|
|
try:
|
|
|
|
""" Delete connection and reset configuration"""
|
2021-06-04 09:35:34 +08:00
|
|
|
res = self.connection_wrap.list_connections()
|
2021-06-02 19:21:33 +08:00
|
|
|
for i in res[0]:
|
2021-06-04 09:35:34 +08:00
|
|
|
self.connection_wrap.remove_connection(i[0])
|
2021-06-01 18:49:31 +08:00
|
|
|
except Exception as e:
|
|
|
|
pass
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
def initialize_env(self, request):
|
|
|
|
""" clean log before testing """
|
2021-05-13 12:17:15 +08:00
|
|
|
host = request.config.getoption("--host")
|
2021-05-11 17:59:29 +08:00
|
|
|
port = request.config.getoption("--port")
|
|
|
|
handler = request.config.getoption("--handler")
|
2021-06-08 13:19:35 +08:00
|
|
|
clean_log = request.config.getoption("--clean_log")
|
|
|
|
|
|
|
|
""" params check """
|
|
|
|
assert ip_check(host) and number_check(port)
|
|
|
|
|
|
|
|
""" modify log files """
|
2021-06-09 16:19:48 +08:00
|
|
|
cf.modify_file(file_path_list=[log_config.log_debug, log_config.log_info, log_config.log_err], is_modify=clean_log)
|
2021-06-08 13:19:35 +08:00
|
|
|
|
|
|
|
log.info("#" * 80)
|
|
|
|
log.info("[initialize_milvus] Log cleaned up, start testing...")
|
2021-05-13 12:17:15 +08:00
|
|
|
param_info.prepare_param_info(host, port, handler)
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
2021-06-05 10:25:34 +08:00
|
|
|
class TestcaseBase(Base):
|
2021-05-11 17:59:29 +08:00
|
|
|
"""
|
|
|
|
Additional methods;
|
|
|
|
Public methods that can be used to add cases.
|
|
|
|
"""
|
|
|
|
|
2021-06-01 18:49:31 +08:00
|
|
|
@pytest.fixture(scope="module", params=ct.get_invalid_strs)
|
2021-05-27 10:26:35 +08:00
|
|
|
def get_invalid_string(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
2021-06-01 18:49:31 +08:00
|
|
|
@pytest.fixture(scope="module", params=cf.gen_simple_index())
|
2021-05-27 10:26:35 +08:00
|
|
|
def get_index_param(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
2021-05-13 12:17:15 +08:00
|
|
|
def _connect(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
""" Add an connection and create the connect """
|
|
|
|
self.connection_wrap.add_connection(default={"host": param_info.param_host, "port": param_info.param_port})
|
2021-06-08 10:35:35 +08:00
|
|
|
res, is_succ = self.connection_wrap.connect(alias='default')
|
|
|
|
if not is_succ:
|
|
|
|
raise res
|
2021-05-13 12:17:15 +08:00
|
|
|
return res
|
2021-06-08 10:35:35 +08:00
|
|
|
|
2021-06-07 12:15:35 +08:00
|
|
|
def init_collection_wrap(self, name=None, data=None, schema=None, check_task=None, **kwargs):
|
|
|
|
name = cf.gen_unique_str('coll_') if name is None else name
|
|
|
|
schema = cf.gen_default_collection_schema() if schema is None else schema
|
|
|
|
if self.connection_wrap.get_connection(alias='default')[0] is None:
|
|
|
|
self._connect()
|
|
|
|
collection_w = ApiCollectionWrapper()
|
2021-06-07 14:14:37 +08:00
|
|
|
collection_w.init_collection(name=name, data=data, schema=schema,
|
2021-06-07 12:15:35 +08:00
|
|
|
check_task=check_task, **kwargs)
|
|
|
|
return collection_w
|
|
|
|
|
2021-06-08 10:35:35 +08:00
|
|
|
def init_partition_wrap(self, collection_wrap=None, name=None, description=None,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-05-27 10:26:35 +08:00
|
|
|
name = cf.gen_unique_str("partition_") if name is None else name
|
2021-06-07 12:15:35 +08:00
|
|
|
description = cf.gen_unique_str("partition_des_") if description is None else description
|
|
|
|
collection_wrap = self.init_collection_wrap() if collection_wrap is None else collection_wrap
|
|
|
|
partition_wrap = ApiPartitionWrapper()
|
2021-06-07 16:41:35 +08:00
|
|
|
partition_wrap.init_partition(collection_wrap.collection, name, description,
|
|
|
|
check_task=check_task, check_items=check_items,
|
|
|
|
**kwargs)
|
2021-06-07 12:15:35 +08:00
|
|
|
return partition_wrap
|