mirror of https://github.com/milvus-io/milvus.git
test: modify search iterator V2 case about alias/db/rbac for milvus client (#39400)
issue: #37548 Signed-off-by: qixuan <673771573@qq.com>pull/38303/merge
parent
fdb968d0ea
commit
228bff5e7b
|
@ -154,7 +154,7 @@ class TestMilvusClientV2Base(Base):
|
|||
return res, check_result
|
||||
|
||||
@trace()
|
||||
def search_interator(self, client, collection_name, data, batch_size=20, limit=100, filter=None, output_fields=None,
|
||||
def search_iterator(self, client, collection_name, data, batch_size, limit=-1, filter=None, output_fields=None,
|
||||
search_params=None, timeout=None, check_task=None, check_items=None, **kwargs):
|
||||
timeout = TIMEOUT if timeout is None else timeout
|
||||
kwargs.update({"timeout": timeout})
|
||||
|
|
|
@ -429,6 +429,7 @@ class ResponseChecker:
|
|||
search_iterator = search_res
|
||||
pk_list = []
|
||||
while True:
|
||||
try:
|
||||
res = search_iterator.next()
|
||||
if len(res) == 0:
|
||||
log.info("search iteration finished, close")
|
||||
|
@ -449,6 +450,9 @@ class ResponseChecker:
|
|||
else:
|
||||
assert distance <= check_items["range_filter"]
|
||||
pk_list.extend(res.ids())
|
||||
except Exception as e:
|
||||
assert check_items["err_msg"] in str(e)
|
||||
return False
|
||||
assert len(pk_list) == len(set(pk_list))
|
||||
log.info("check: total %d results" % len(pk_list))
|
||||
|
||||
|
|
|
@ -597,9 +597,9 @@ class TestMilvusClientRbacAdvance(TestMilvusClientV2Base):
|
|||
roles, _ = self.list_roles(client)
|
||||
for role in roles:
|
||||
if role not in ['admin', 'public']:
|
||||
res, _ = self.describe_role(client, role)
|
||||
if res['privileges']:
|
||||
for privilege in res['privileges']:
|
||||
role_info, _ = self.describe_role(client, role)
|
||||
if role_info:
|
||||
for privilege in role_info.get("privileges", []):
|
||||
self.revoke_privilege(client, role, privilege["object_type"],
|
||||
privilege["privilege"], privilege["object_name"])
|
||||
self.drop_role(client, role)
|
||||
|
@ -615,6 +615,7 @@ class TestMilvusClientRbacAdvance(TestMilvusClientV2Base):
|
|||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator permission deny after switch to no permission db
|
||||
"""
|
||||
batch_size = 20
|
||||
uri = f"http://{cf.param_info.param_host}:{cf.param_info.param_port}"
|
||||
client, _ = self.init_milvus_client(uri=uri, token="root:Milvus")
|
||||
my_db = cf.gen_unique_str(prefix)
|
||||
|
@ -647,14 +648,10 @@ class TestMilvusClientRbacAdvance(TestMilvusClientV2Base):
|
|||
|
||||
# 5. search_iterator
|
||||
vectors_to_search = rng.random((1, default_dim))
|
||||
self.search_interator(client, collection_name, vectors_to_search, use_rbac_mul_db=True, another_db=my_db,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size, use_rbac_mul_db=True, another_db=my_db,
|
||||
check_task=CheckTasks.check_permission_deny)
|
||||
client, _ = self.init_milvus_client(uri=uri, token="root:Milvus")
|
||||
self.revoke_privilege(client, role_name, "Collection", "Search", collection_name, 'default')
|
||||
self.revoke_privilege(client, role_name, "Collection", "Insert", collection_name, my_db)
|
||||
self.revoke_role(client, user_name=user_name, role_name=role_name)
|
||||
self.release_collection(client, collection_name)
|
||||
self.drop_collection(client, collection_name)
|
||||
self.using_database(client, 'default')
|
||||
self.release_collection(client, collection_name)
|
||||
self.drop_collection(client, collection_name)
|
|
@ -42,13 +42,14 @@ class TestMilvusClientSearchInteratorInValid(TestMilvusClientV2Base):
|
|||
yield request.param
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/39045")
|
||||
# @pytest.mark.skip("https://github.com/milvus-io/milvus/issues/39045")
|
||||
def test_milvus_client_search_iterator_using_mul_db(self, search_params):
|
||||
"""
|
||||
target: test search iterator(high level api) case about mul db
|
||||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator error after switch to another db
|
||||
"""
|
||||
batch_size = 20
|
||||
client = self._client()
|
||||
collection_name = cf.gen_unique_str(prefix)
|
||||
my_db = cf.gen_unique_str(prefix)
|
||||
|
@ -75,21 +76,23 @@ class TestMilvusClientSearchInteratorInValid(TestMilvusClientV2Base):
|
|||
# 5. search_iterator
|
||||
vectors_to_search = rng.random((1, default_dim))
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, search_params=search_params,
|
||||
error_msg = "alias or database may have been changed"
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size, search_params=search_params,
|
||||
use_mul_db=True, another_db=my_db,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={})
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={ct.err_code: 1, ct.err_msg: error_msg})
|
||||
self.release_collection(client, collection_name)
|
||||
self.drop_collection(client, collection_name)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.skip("https://github.com/milvus-io/milvus/issues/39087")
|
||||
# @pytest.mark.skip("https://github.com/milvus-io/milvus/issues/39087")
|
||||
def test_milvus_client_search_iterator_alias_different_col(self, search_params):
|
||||
"""
|
||||
target: test search iterator(high level api) case about alias
|
||||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator error after alter alias
|
||||
"""
|
||||
batch_size = 20
|
||||
client = self._client()
|
||||
collection_name = cf.gen_unique_str(prefix)
|
||||
collection_name_new = cf.gen_unique_str(prefix)
|
||||
|
@ -114,10 +117,10 @@ class TestMilvusClientSearchInteratorInValid(TestMilvusClientV2Base):
|
|||
# 3. search_iterator
|
||||
vectors_to_search = rng.random((1, default_dim))
|
||||
search_params = {"params": search_params}
|
||||
error_msg = "" # todo
|
||||
self.search_interator(client, alias, vectors_to_search, search_params=search_params,
|
||||
error_msg = "alias or database may have been changed"
|
||||
self.search_iterator(client, alias, vectors_to_search, batch_size, search_params=search_params,
|
||||
use_alias=True, another_collection=collection_name_new,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={ct.err_code: 1, ct.err_msg: error_msg})
|
||||
self.release_collection(client, collection_name)
|
||||
self.drop_collection(client, collection_name)
|
||||
|
@ -153,6 +156,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator successfully
|
||||
"""
|
||||
batch_size = 20
|
||||
client = self._client()
|
||||
collection_name = cf.gen_unique_str(prefix)
|
||||
self.using_database(client, "default")
|
||||
|
@ -175,7 +179,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
vectors_to_search = rng.random((1, default_dim))
|
||||
insert_ids = [i for i in range(default_nb)]
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, search_params=search_params,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size, search_params=search_params,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": len(vectors_to_search),
|
||||
|
@ -192,6 +196,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator successfully
|
||||
"""
|
||||
batch_size = 20
|
||||
client = self._client()
|
||||
collection_name = cf.gen_unique_str(prefix)
|
||||
dim = 128
|
||||
|
@ -218,7 +223,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
vectors_to_search = rng.random((1, default_dim))
|
||||
insert_ids = [i for i in range(default_nb)]
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, filter="nullable_field>=10",
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size, filter="nullable_field>=10",
|
||||
search_params=search_params,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
|
@ -235,6 +240,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator successfully
|
||||
"""
|
||||
batch_size = 20
|
||||
client = self._client()
|
||||
collection_name = cf.gen_unique_str(prefix)
|
||||
# 1. create collection
|
||||
|
@ -260,7 +266,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
vectors_to_search = rng.random((1, default_dim))
|
||||
insert_ids = [i for i in range(default_nb)]
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, new_name, vectors_to_search, search_params=search_params,
|
||||
self.search_iterator(client, new_name, vectors_to_search, batch_size, search_params=search_params,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": len(vectors_to_search),
|
||||
|
@ -276,6 +282,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator successfully
|
||||
"""
|
||||
batch_size = 20
|
||||
client = self._client()
|
||||
collection_name = cf.gen_unique_str(prefix)
|
||||
# 1. create collection
|
||||
|
@ -296,7 +303,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
vectors_to_search = rng.random((1, default_dim))
|
||||
insert_ids = [i for i in range(default_nb)]
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, search_params=search_params,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size, search_params=search_params,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": len(vectors_to_search),
|
||||
|
@ -310,6 +317,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
method: create connection, collection, insert and search iterator
|
||||
expected: search iterator successfully
|
||||
"""
|
||||
batch_size = 20
|
||||
client = self._client()
|
||||
collection_name = cf.gen_unique_str(prefix)
|
||||
# 1. create collection
|
||||
|
@ -324,7 +332,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
# 3. search_iterator
|
||||
vectors_to_search = rng.random((1, default_dim))
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, search_params=search_params,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size, search_params=search_params,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
"nq": len(vectors_to_search),
|
||||
|
@ -355,7 +363,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
# 3. search_iterator
|
||||
vectors_to_search = rng.random((1, default_dim))
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
limit=default_limit, search_params=search_params,
|
||||
output_fields=[default_primary_key_field_name],
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
|
@ -389,7 +397,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
vectors_to_search = rng.random((1, default_dim))
|
||||
search_params = {"params": search_params}
|
||||
search_params.update({"metric_type": metric_type})
|
||||
self.search_interator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
limit=default_limit, search_params=search_params,
|
||||
output_fields=[default_primary_key_field_name],
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
|
@ -426,7 +434,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
insert_ids.remove(insert_id)
|
||||
limit = default_nb - delete_num
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
search_params=search_params, limit=default_nb,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
|
@ -463,7 +471,7 @@ class TestMilvusClientSearchInteratorValid(TestMilvusClientV2Base):
|
|||
insert_ids.remove(insert_id)
|
||||
limit = default_nb - delete_num
|
||||
search_params = {"params": search_params}
|
||||
self.search_interator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
self.search_iterator(client, collection_name, vectors_to_search, batch_size=default_batch_size,
|
||||
search_params=search_params, limit=default_nb,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"enable_milvus_client_api": True,
|
||||
|
|
Loading…
Reference in New Issue