@@ -152,11 +152,13 @@ def _factory(provider_name: str) -> list[Dict[str, Any]]:
152152
153153@pytest .fixture (scope = "class" )
154154def vector_io_secret (
155+ pytestconfig : pytest .Config ,
155156 unprivileged_client : DynamicClient ,
156157 unprivileged_model_namespace : Namespace ,
158+ teardown_resources : bool ,
157159) -> Generator [Secret , Any , Any ]:
158160 """Create a secret for the vector I/O providers"""
159- with Secret (
161+ secret = Secret (
160162 client = unprivileged_client ,
161163 namespace = unprivileged_model_namespace .name ,
162164 name = "vector-io-secret" ,
@@ -167,37 +169,55 @@ def vector_io_secret(
167169 "pgvector-password" : PGVECTOR_PASSWORD ,
168170 "milvus-token" : MILVUS_TOKEN ,
169171 },
170- ) as secret :
172+ ensure_exists = pytestconfig .option .post_upgrade ,
173+ teardown = teardown_resources ,
174+ )
175+ if pytestconfig .option .post_upgrade :
171176 yield secret
177+ secret .clean_up ()
178+ else :
179+ with secret :
180+ yield secret
172181
173182
174183@pytest .fixture (scope = "class" )
175184def etcd_deployment (
185+ pytestconfig : pytest .Config ,
176186 unprivileged_client : DynamicClient ,
177187 unprivileged_model_namespace : Namespace ,
188+ teardown_resources : bool ,
178189) -> Generator [Deployment , Any , Any ]:
179190 """Deploy an etcd instance for vector I/O provider testing."""
180- with Deployment (
191+ deployment = Deployment (
181192 client = unprivileged_client ,
182193 namespace = unprivileged_model_namespace .name ,
183194 name = "vector-io-etcd-deployment" ,
184195 replicas = 1 ,
185196 selector = {"matchLabels" : {"app" : "etcd" }},
186197 strategy = {"type" : "Recreate" },
187198 template = get_etcd_deployment_template (),
188- teardown = True ,
189- ) as deployment :
199+ teardown = teardown_resources ,
200+ ensure_exists = pytestconfig .option .post_upgrade ,
201+ )
202+ if pytestconfig .option .post_upgrade :
190203 deployment .wait_for_replicas (deployed = True , timeout = 120 )
191204 yield deployment
205+ deployment .clean_up ()
206+ else :
207+ with deployment :
208+ deployment .wait_for_replicas (deployed = True , timeout = 120 )
209+ yield deployment
192210
193211
194212@pytest .fixture (scope = "class" )
195213def etcd_service (
214+ pytestconfig : pytest .Config ,
196215 unprivileged_client : DynamicClient ,
197216 unprivileged_model_namespace : Namespace ,
217+ teardown_resources : bool ,
198218) -> Generator [Service , Any , Any ]:
199219 """Create a service for the etcd deployment."""
200- with Service (
220+ service = Service (
201221 client = unprivileged_client ,
202222 namespace = unprivileged_model_namespace .name ,
203223 name = "vector-io-etcd-service" ,
@@ -209,24 +229,33 @@ def etcd_service(
209229 ],
210230 selector = {"app" : "etcd" },
211231 wait_for_resource = True ,
212- ) as service :
232+ ensure_exists = pytestconfig .option .post_upgrade ,
233+ teardown = teardown_resources ,
234+ )
235+ if pytestconfig .option .post_upgrade :
213236 yield service
237+ service .clean_up ()
238+ else :
239+ with service :
240+ yield service
214241
215242
216243@pytest .fixture (scope = "class" )
217244def remote_milvus_deployment (
245+ pytestconfig : pytest .Config ,
218246 unprivileged_client : DynamicClient ,
219247 unprivileged_model_namespace : Namespace ,
220248 etcd_deployment : Deployment ,
221249 etcd_service : Service ,
222250 vector_io_secret : Secret ,
251+ teardown_resources : bool ,
223252) -> Generator [Deployment , Any , Any ]:
224253 """Deploy a remote Milvus instance for vector I/O provider testing."""
225254 _ = etcd_deployment
226255 _ = etcd_service
227256 _ = vector_io_secret
228257
229- with Deployment (
258+ deployment = Deployment (
230259 client = unprivileged_client ,
231260 namespace = unprivileged_model_namespace .name ,
232261 name = "vector-io-milvus-deployment" ,
@@ -235,22 +264,31 @@ def remote_milvus_deployment(
235264 selector = {"matchLabels" : {"app" : "milvus-standalone" }},
236265 strategy = {"type" : "Recreate" },
237266 template = get_milvus_deployment_template (),
238- teardown = True ,
239- ) as deployment :
267+ teardown = teardown_resources ,
268+ ensure_exists = pytestconfig .option .post_upgrade ,
269+ )
270+ if pytestconfig .option .post_upgrade :
240271 deployment .wait_for_replicas (deployed = True , timeout = 240 )
241272 yield deployment
273+ deployment .clean_up ()
274+ else :
275+ with deployment :
276+ deployment .wait_for_replicas (deployed = True , timeout = 240 )
277+ yield deployment
242278
243279
244280@pytest .fixture (scope = "class" )
245281def milvus_service (
282+ pytestconfig : pytest .Config ,
246283 unprivileged_client : DynamicClient ,
247284 unprivileged_model_namespace : Namespace ,
248285 remote_milvus_deployment : Deployment ,
286+ teardown_resources : bool ,
249287) -> Generator [Service , Any , Any ]:
250288 """Create a service for the remote Milvus deployment."""
251289 _ = remote_milvus_deployment
252290
253- with Service (
291+ service = Service (
254292 client = unprivileged_client ,
255293 namespace = unprivileged_model_namespace .name ,
256294 name = "vector-io-milvus-service" ,
@@ -263,8 +301,15 @@ def milvus_service(
263301 ],
264302 selector = {"app" : "milvus-standalone" },
265303 wait_for_resource = True ,
266- ) as service :
304+ ensure_exists = pytestconfig .option .post_upgrade ,
305+ teardown = teardown_resources ,
306+ )
307+ if pytestconfig .option .post_upgrade :
267308 yield service
309+ service .clean_up ()
310+ else :
311+ with service :
312+ yield service
268313
269314
270315def get_milvus_deployment_template () -> Dict [str , Any ]:
@@ -344,14 +389,16 @@ def get_etcd_deployment_template() -> Dict[str, Any]:
344389
345390@pytest .fixture (scope = "class" )
346391def pgvector_deployment (
392+ pytestconfig : pytest .Config ,
347393 unprivileged_client : DynamicClient ,
348394 unprivileged_model_namespace : Namespace ,
349395 vector_io_secret : Secret ,
396+ teardown_resources : bool ,
350397) -> Generator [Deployment , Any , Any ]:
351398 """Deploy a PGVector instance for vector I/O provider testing."""
352399 _ = vector_io_secret
353400
354- with Deployment (
401+ deployment = Deployment (
355402 client = unprivileged_client ,
356403 namespace = unprivileged_model_namespace .name ,
357404 name = "vector-io-pgvector-deployment" ,
@@ -360,22 +407,31 @@ def pgvector_deployment(
360407 selector = {"matchLabels" : {"app" : "pgvector" }},
361408 strategy = {"type" : "Recreate" },
362409 template = get_pgvector_deployment_template (),
363- teardown = True ,
364- ) as deployment :
410+ teardown = teardown_resources ,
411+ ensure_exists = pytestconfig .option .post_upgrade ,
412+ )
413+ if pytestconfig .option .post_upgrade :
365414 deployment .wait_for_replicas (deployed = True , timeout = 240 )
366415 yield deployment
416+ deployment .clean_up ()
417+ else :
418+ with deployment :
419+ deployment .wait_for_replicas (deployed = True , timeout = 240 )
420+ yield deployment
367421
368422
369423@pytest .fixture (scope = "class" )
370424def pgvector_service (
425+ pytestconfig : pytest .Config ,
371426 unprivileged_client : DynamicClient ,
372427 unprivileged_model_namespace : Namespace ,
373428 pgvector_deployment : Deployment ,
429+ teardown_resources : bool ,
374430) -> Generator [Service , Any , Any ]:
375431 """Create a service for the PGVector deployment."""
376432 _ = pgvector_deployment
377433
378- with Service (
434+ service = Service (
379435 client = unprivileged_client ,
380436 namespace = unprivileged_model_namespace .name ,
381437 name = "vector-io-pgvector-service" ,
@@ -388,8 +444,15 @@ def pgvector_service(
388444 ],
389445 selector = {"app" : "pgvector" },
390446 wait_for_resource = True ,
391- ) as service :
447+ ensure_exists = pytestconfig .option .post_upgrade ,
448+ teardown = teardown_resources ,
449+ )
450+ if pytestconfig .option .post_upgrade :
392451 yield service
452+ service .clean_up ()
453+ else :
454+ with service :
455+ yield service
393456
394457
395458def get_pgvector_deployment_template () -> Dict [str , Any ]:
@@ -439,14 +502,16 @@ def get_pgvector_deployment_template() -> Dict[str, Any]:
439502
440503@pytest .fixture (scope = "class" )
441504def qdrant_deployment (
505+ pytestconfig : pytest .Config ,
442506 unprivileged_client : DynamicClient ,
443507 unprivileged_model_namespace : Namespace ,
444508 vector_io_secret : Secret ,
509+ teardown_resources : bool ,
445510) -> Generator [Deployment , Any , Any ]:
446511 """Deploy a Qdrant instance for vector I/O provider testing."""
447512 _ = vector_io_secret
448513
449- with Deployment (
514+ deployment = Deployment (
450515 client = unprivileged_client ,
451516 namespace = unprivileged_model_namespace .name ,
452517 name = "vector-io-qdrant-deployment" ,
@@ -455,22 +520,31 @@ def qdrant_deployment(
455520 selector = {"matchLabels" : {"app" : "qdrant" }},
456521 strategy = {"type" : "Recreate" },
457522 template = get_qdrant_deployment_template (),
458- teardown = True ,
459- ) as deployment :
523+ teardown = teardown_resources ,
524+ ensure_exists = pytestconfig .option .post_upgrade ,
525+ )
526+ if pytestconfig .option .post_upgrade :
460527 deployment .wait_for_replicas (deployed = True , timeout = 240 )
461528 yield deployment
529+ deployment .clean_up ()
530+ else :
531+ with deployment :
532+ deployment .wait_for_replicas (deployed = True , timeout = 240 )
533+ yield deployment
462534
463535
464536@pytest .fixture (scope = "class" )
465537def qdrant_service (
538+ pytestconfig : pytest .Config ,
466539 unprivileged_client : DynamicClient ,
467540 unprivileged_model_namespace : Namespace ,
468541 qdrant_deployment : Deployment ,
542+ teardown_resources : bool ,
469543) -> Generator [Service , Any , Any ]:
470544 """Create a service for the Qdrant deployment."""
471545 _ = qdrant_deployment
472546
473- with Service (
547+ service = Service (
474548 client = unprivileged_client ,
475549 namespace = unprivileged_model_namespace .name ,
476550 name = "vector-io-qdrant-service" ,
@@ -488,8 +562,15 @@ def qdrant_service(
488562 ],
489563 selector = {"app" : "qdrant" },
490564 wait_for_resource = True ,
491- ) as service :
565+ ensure_exists = pytestconfig .option .post_upgrade ,
566+ teardown = teardown_resources ,
567+ )
568+ if pytestconfig .option .post_upgrade :
492569 yield service
570+ service .clean_up ()
571+ else :
572+ with service :
573+ yield service
493574
494575
495576def get_qdrant_deployment_template () -> Dict [str , Any ]:
0 commit comments