@@ -22,75 +22,105 @@ def guardrails_orchestrator(
2222 request : FixtureRequest ,
2323 admin_client : DynamicClient ,
2424 model_namespace : Namespace ,
25+ teardown_resources : bool ,
26+ pytestconfig : pytest .Config ,
2527) -> Generator [GuardrailsOrchestrator , Any , Any ]:
2628 gorch_kwargs = {
2729 "client" : admin_client ,
2830 "name" : GUARDRAILS_ORCHESTRATOR_NAME ,
2931 "namespace" : model_namespace .name ,
30- "log_level" : "DEBUG" ,
31- "replicas" : 1 ,
32- "wait_for_resource" : True ,
3332 }
34-
35- if request .param .get ("auto_config" ):
36- gorch_kwargs ["auto_config" ] = request .param .get ("auto_config" )
37-
38- if request .param .get ("orchestrator_config" ):
39- orchestrator_config = request .getfixturevalue (argname = "orchestrator_config" )
40- gorch_kwargs ["orchestrator_config" ] = orchestrator_config .name
41-
42- if request .param .get ("enable_guardrails_gateway" ):
43- gorch_kwargs ["enable_guardrails_gateway" ] = True
44-
45- if request .param .get ("guardrails_gateway_config" ):
46- guardrails_gateway_config = request .getfixturevalue (argname = "guardrails_gateway_config" )
47- gorch_kwargs ["guardrails_gateway_config" ] = guardrails_gateway_config .name
48-
49- if enable_built_in_detectors := request .param .get ("enable_built_in_detectors" ):
50- gorch_kwargs ["enable_built_in_detectors" ] = enable_built_in_detectors
51-
52- if request .param .get ("otel_exporter_config" ):
53- metrics_endpoint = request .getfixturevalue (argname = "otelcol_metrics_endpoint" )
54- traces_endpoint = request .getfixturevalue (argname = "tempo_traces_endpoint" )
55- gorch_kwargs ["otel_exporter" ] = {
56- "otlpProtocol" : "grpc" ,
57- "otlpMetricsEndpoint" : metrics_endpoint ,
58- "otlpTracesEndpoint" : traces_endpoint ,
59- "enableMetrics" : True ,
60- "enableTracing" : True ,
61- }
62-
63- with GuardrailsOrchestrator (** gorch_kwargs ) as gorch :
64- gorch_deployment = Deployment (name = gorch .name , namespace = gorch .namespace , wait_for_resource = True )
65- gorch_deployment .wait_for_replicas ()
33+ if pytestconfig .option .post_upgrade :
34+ gorch = GuardrailsOrchestrator (** gorch_kwargs , ensure_exists = True )
6635 yield gorch
36+ gorch .clean_up ()
37+ else :
38+ gorch_kwargs ["log_level" ] = "DEBUG"
39+ gorch_kwargs ["replicas" ] = 1
40+ gorch_kwargs ["wait_for_resource" ] = True
41+ if request .param .get ("auto_config" ):
42+ gorch_kwargs ["auto_config" ] = request .param .get ("auto_config" )
43+
44+ if request .param .get ("orchestrator_config" ):
45+ orchestrator_config = request .getfixturevalue (argname = "orchestrator_config" )
46+ gorch_kwargs ["orchestrator_config" ] = orchestrator_config .name
47+
48+ if request .param .get ("enable_guardrails_gateway" ):
49+ gorch_kwargs ["enable_guardrails_gateway" ] = True
50+
51+ if request .param .get ("guardrails_gateway_config" ):
52+ guardrails_gateway_config = request .getfixturevalue (argname = "guardrails_gateway_config" )
53+ gorch_kwargs ["guardrails_gateway_config" ] = guardrails_gateway_config .name
54+
55+ if enable_built_in_detectors := request .param .get ("enable_built_in_detectors" ):
56+ gorch_kwargs ["enable_built_in_detectors" ] = enable_built_in_detectors
57+
58+ if request .param .get ("otel_exporter_config" ):
59+ metrics_endpoint = request .getfixturevalue (argname = "otelcol_metrics_endpoint" )
60+ traces_endpoint = request .getfixturevalue (argname = "tempo_traces_endpoint" )
61+ gorch_kwargs ["otel_exporter" ] = {
62+ "otlpProtocol" : "grpc" ,
63+ "otlpMetricsEndpoint" : metrics_endpoint ,
64+ "otlpTracesEndpoint" : traces_endpoint ,
65+ "enableMetrics" : True ,
66+ "enableTracing" : True ,
67+ }
68+
69+ with GuardrailsOrchestrator (** gorch_kwargs , teardown = teardown_resources ) as gorch :
70+ gorch_deployment = Deployment (name = gorch .name , namespace = gorch .namespace , wait_for_resource = True )
71+ gorch_deployment .wait_for_replicas ()
72+ yield gorch
6773
6874
6975@pytest .fixture (scope = "class" )
7076def orchestrator_config (
71- request : FixtureRequest , admin_client : DynamicClient , model_namespace : Namespace
77+ request : FixtureRequest ,
78+ admin_client : DynamicClient ,
79+ model_namespace : Namespace ,
80+ teardown_resources : bool ,
81+ pytestconfig : pytest .Config ,
7282) -> Generator [ConfigMap , Any , Any ]:
73- with ConfigMap (
74- client = admin_client ,
75- name = "fms-orchestr8-config-nlp" ,
76- namespace = model_namespace .name ,
77- data = request .param ["orchestrator_config_data" ],
78- ) as cm :
83+ if pytestconfig .option .post_upgrade :
84+ cm = ConfigMap (
85+ client = admin_client , name = "fms-orchestr8-config-nlp" , namespace = model_namespace .name , ensure_exists = True
86+ )
7987 yield cm
88+ cm .clean_up ()
89+ else :
90+ with ConfigMap (
91+ client = admin_client ,
92+ name = "fms-orchestr8-config-nlp" ,
93+ namespace = model_namespace .name ,
94+ data = request .param ["orchestrator_config_data" ],
95+ teardown = teardown_resources ,
96+ ) as cm :
97+ yield cm
8098
8199
82100@pytest .fixture (scope = "class" )
83101def guardrails_gateway_config (
84- request : FixtureRequest , admin_client : DynamicClient , model_namespace : Namespace
102+ request : FixtureRequest ,
103+ admin_client : DynamicClient ,
104+ model_namespace : Namespace ,
105+ teardown_resources : bool ,
106+ pytestconfig : pytest .Config ,
85107) -> Generator [ConfigMap , Any , Any ]:
86- with ConfigMap (
87- client = admin_client ,
88- name = "fms-orchestr8-config-gateway" ,
89- namespace = model_namespace .name ,
90- label = {Labels .Openshift .APP : "fmstack-nlp" },
91- data = request .param ["guardrails_gateway_config_data" ],
92- ) as cm :
108+ if pytestconfig .option .post_upgrade :
109+ cm = ConfigMap (
110+ client = admin_client , name = "fms-orchestr8-config-gateway" , namespace = model_namespace .name , ensure_exists = True
111+ )
93112 yield cm
113+ cm .clean_up ()
114+ else :
115+ with ConfigMap (
116+ client = admin_client ,
117+ name = "fms-orchestr8-config-gateway" ,
118+ namespace = model_namespace .name ,
119+ label = {Labels .Openshift .APP : "fmstack-nlp" },
120+ data = request .param ["guardrails_gateway_config_data" ],
121+ teardown = teardown_resources ,
122+ ) as cm :
123+ yield cm
94124
95125
96126@pytest .fixture (scope = "class" )
@@ -142,23 +172,13 @@ def guardrails_orchestrator_health_route(
142172 admin_client : DynamicClient ,
143173 model_namespace : Namespace ,
144174 guardrails_orchestrator : GuardrailsOrchestrator ,
145- ) -> Generator [ Route , Any , Any ] :
146- guardrails_orchestrator_health_route = Route (
175+ ) -> Route :
176+ return Route (
147177 name = f"{ guardrails_orchestrator .name } -health" ,
148178 namespace = guardrails_orchestrator .namespace ,
149179 wait_for_resource = True ,
150180 ensure_exists = True ,
151181 )
152- with ResourceEditor (
153- patches = {
154- guardrails_orchestrator_health_route : {
155- "metadata" : {
156- "annotations" : {Annotations .HaproxyRouterOpenshiftIo .TIMEOUT : "10m" },
157- }
158- }
159- }
160- ):
161- yield guardrails_orchestrator_health_route
162182
163183
164184@pytest .fixture
@@ -177,20 +197,10 @@ def guardrails_orchestrator_gateway_route(
177197 admin_client : DynamicClient ,
178198 model_namespace : Namespace ,
179199 guardrails_orchestrator : GuardrailsOrchestrator ,
180- ) -> Generator [ Route , Any , Any ] :
181- guardrails_orchestrator_gateway_route = Route (
200+ ) -> Route :
201+ return Route (
182202 name = f"{ guardrails_orchestrator .name } -gateway" ,
183203 namespace = guardrails_orchestrator .namespace ,
184204 wait_for_resource = True ,
185205 ensure_exists = True ,
186206 )
187- with ResourceEditor (
188- patches = {
189- guardrails_orchestrator_gateway_route : {
190- "metadata" : {
191- "annotations" : {Annotations .HaproxyRouterOpenshiftIo .TIMEOUT : "10m" },
192- }
193- }
194- }
195- ):
196- yield guardrails_orchestrator_gateway_route
0 commit comments