From 4d94e465dc330cb082f8ef227773dc0009ce3440 Mon Sep 17 00:00:00 2001 From: zhuwenxing Date: Mon, 18 Jul 2022 17:14:28 +0800 Subject: [PATCH] [test]Add auth optional for test (#18306) Signed-off-by: zhuwenxing --- tests/python_client/base/client_base.py | 9 +++++++-- tests/python_client/common/common_func.py | 8 +++++++- tests/python_client/conftest.py | 23 ++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/tests/python_client/base/client_base.py b/tests/python_client/base/client_base.py index 4913ccb466..3d7cb00419 100644 --- a/tests/python_client/base/client_base.py +++ b/tests/python_client/base/client_base.py @@ -88,8 +88,13 @@ class TestcaseBase(Base): def _connect(self): """ Add a connection and create the connect """ - res, is_succ = self.connection_wrap.connect(alias=DefaultConfig.DEFAULT_USING, host=cf.param_info.param_host, - port=cf.param_info.param_port) + if cf.param_info.param_user and cf.param_info.param_password: + res, is_succ = self.connection_wrap.connect(alias=DefaultConfig.DEFAULT_USING, host=cf.param_info.param_host, + port=cf.param_info.param_port, user=cf.param_info.param_user, + password=cf.param_info.param_password, secure=cf.param_info.param_secure) + else: + res, is_succ = self.connection_wrap.connect(alias=DefaultConfig.DEFAULT_USING, host=cf.param_info.param_host, + port=cf.param_info.param_port) return res def init_collection_wrap(self, name=None, schema=None, shards_num=2, check_task=None, check_items=None, **kwargs): diff --git a/tests/python_client/common/common_func.py b/tests/python_client/common/common_func.py index 2096a4c2a9..52251b175f 100644 --- a/tests/python_client/common/common_func.py +++ b/tests/python_client/common/common_func.py @@ -18,12 +18,18 @@ class ParamInfo: self.param_host = "" self.param_port = "" self.param_handler = "" + self.param_user = "" + self.param_password = "" + self.param_secure = False self.param_replica_num = ct.default_replica_num - def prepare_param_info(self, host, port, handler, replica_num): + def prepare_param_info(self, host, port, handler, replica_num, user, password, secure): self.param_host = host self.param_port = port self.param_handler = handler + self.param_user = user + self.param_password = password + self.param_secure = secure self.param_replica_num = replica_num diff --git a/tests/python_client/conftest.py b/tests/python_client/conftest.py index f9de799178..ab1649d62e 100644 --- a/tests/python_client/conftest.py +++ b/tests/python_client/conftest.py @@ -22,6 +22,9 @@ def pytest_addoption(parser): parser.addoption("--host", action="store", default="localhost", help="service's ip") parser.addoption("--service", action="store", default="", help="service address") parser.addoption("--port", action="store", default=19530, help="service's port") + parser.addoption("--user", action="store", default="", help="user name for connection") + parser.addoption("--password", action="store", default="", help="password for connection") + parser.addoption("--secure", action="store", default=False, help="secure for connection") parser.addoption("--http_port", action="store", default=19121, help="http's port") parser.addoption("--handler", action="store", default="GRPC", help="handler of request") parser.addoption("--tag", action="store", default="all", help="only run tests matching the tag.") @@ -57,6 +60,21 @@ def port(request): return request.config.getoption("--port") +@pytest.fixture +def user(request): + return request.config.getoption("--user") + + +@pytest.fixture +def password(request): + return request.config.getoption("--password") + + +@pytest.fixture +def secure(request): + return request.config.getoption("--secure") + + @pytest.fixture def http_port(request): return request.config.getoption("--http_port") @@ -153,6 +171,9 @@ def initialize_env(request): host = request.config.getoption("--host") port = request.config.getoption("--port") handler = request.config.getoption("--handler") + user = request.config.getoption("--user") + password = request.config.getoption("--password") + secure = request.config.getoption("--secure") clean_log = request.config.getoption("--clean_log") replica_num = request.config.getoption("--replica_num") @@ -167,7 +188,7 @@ def initialize_env(request): log.info("#" * 80) log.info("[initialize_milvus] Log cleaned up, start testing...") - param_info.prepare_param_info(host, port, handler, replica_num) + param_info.prepare_param_info(host, port, handler, replica_num, user, password, secure) @pytest.fixture(params=ct.get_invalid_strs)