|
9 | 9 | from ocp_resources.data_science_cluster import DataScienceCluster |
10 | 10 | from ocp_resources.deployment import Deployment |
11 | 11 |
|
12 | | -from ocp_resources.model_registry import ModelRegistry |
| 12 | +from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry |
13 | 13 | from schemathesis.specs.openapi.schemas import BaseOpenAPISchema |
14 | 14 | from schemathesis.generation.stateful.state_machine import APIStateMachine |
15 | 15 | from schemathesis.core.transport import Response |
|
29 | 29 | DB_RESOURCES_NAME, |
30 | 30 | MODEL_REGISTRY_DB_SECRET_STR_DATA, |
31 | 31 | MODEL_REGISTRY_DB_SECRET_ANNOTATIONS, |
| 32 | + OAUTH_PROXY_CONFIG_DICT, |
| 33 | + MODEL_REGISTRY_STANDARD_LABELS, |
32 | 34 | ) |
33 | 35 | from utilities.constants import Labels |
34 | 36 | from tests.model_registry.utils import ( |
|
37 | 39 | get_model_registry_deployment_template_dict, |
38 | 40 | get_model_registry_db_label_dict, |
39 | 41 | wait_for_pods_running, |
| 42 | + create_model_registry_instance, |
40 | 43 | ) |
41 | | -from utilities.constants import Annotations, Protocols, DscComponents |
| 44 | +from utilities.constants import Protocols, DscComponents |
42 | 45 | from model_registry import ModelRegistry as ModelRegistryClient |
43 | 46 | from semver import Version |
44 | 47 | from utilities.infra import get_product_version |
@@ -145,53 +148,113 @@ def model_registry_db_deployment( |
145 | 148 |
|
146 | 149 | @pytest.fixture(scope="class") |
147 | 150 | def model_registry_instance( |
148 | | - admin_client: DynamicClient, |
149 | 151 | model_registry_namespace: str, |
150 | | - model_registry_db_deployment: Deployment, |
151 | | - model_registry_db_secret: Secret, |
152 | | - model_registry_db_service: Service, |
| 152 | + model_registry_mysql_config: dict[str, Any], |
153 | 153 | ) -> Generator[ModelRegistry, Any, Any]: |
154 | | - with ModelRegistry( |
155 | | - name=MR_INSTANCE_NAME, |
| 154 | + """Creates a model registry instance with service mesh configuration.""" |
| 155 | + with create_model_registry_instance( |
156 | 156 | namespace=model_registry_namespace, |
157 | | - label={ |
158 | | - Annotations.KubernetesIo.NAME: MR_INSTANCE_NAME, |
159 | | - Annotations.KubernetesIo.INSTANCE: MR_INSTANCE_NAME, |
160 | | - Annotations.KubernetesIo.PART_OF: MR_OPERATOR_NAME, |
161 | | - Annotations.KubernetesIo.CREATED_BY: MR_OPERATOR_NAME, |
162 | | - }, |
| 157 | + name=MR_INSTANCE_NAME, |
| 158 | + labels=MODEL_REGISTRY_STANDARD_LABELS, |
163 | 159 | grpc={}, |
164 | 160 | rest={}, |
165 | 161 | istio=ISTIO_CONFIG_DICT, |
166 | | - mysql={ |
167 | | - "host": f"{model_registry_db_deployment.name}.{model_registry_db_deployment.namespace}.svc.cluster.local", |
168 | | - "database": model_registry_db_secret.string_data["database-name"], |
169 | | - "passwordSecret": {"key": "database-password", "name": DB_RESOURCES_NAME}, |
170 | | - "port": 3306, |
171 | | - "skipDBCreation": False, |
172 | | - "username": model_registry_db_secret.string_data["database-user"], |
173 | | - }, |
| 162 | + mysql=model_registry_mysql_config, |
| 163 | + wait_for_resource=True, |
| 164 | + ) as mr: |
| 165 | + mr.wait_for_condition(condition="Available", status="True") |
| 166 | + yield mr |
| 167 | + |
| 168 | + |
| 169 | +@pytest.fixture(scope="class") |
| 170 | +def model_registry_instance_oauth_proxy( |
| 171 | + model_registry_namespace: str, |
| 172 | + model_registry_mysql_config: dict[str, Any], |
| 173 | +) -> Generator[ModelRegistry, Any, Any]: |
| 174 | + """Creates a model registry instance with oauth proxy configuration.""" |
| 175 | + with create_model_registry_instance( |
| 176 | + namespace=model_registry_namespace, |
| 177 | + name=MR_INSTANCE_NAME, |
| 178 | + labels=MODEL_REGISTRY_STANDARD_LABELS, |
| 179 | + grpc={}, |
| 180 | + rest={}, |
| 181 | + oauth_proxy=OAUTH_PROXY_CONFIG_DICT, |
| 182 | + mysql=model_registry_mysql_config, |
174 | 183 | wait_for_resource=True, |
175 | 184 | ) as mr: |
176 | 185 | mr.wait_for_condition(condition="Available", status="True") |
177 | 186 | yield mr |
178 | 187 |
|
179 | 188 |
|
| 189 | +@pytest.fixture(scope="class") |
| 190 | +def model_registry_mysql_config( |
| 191 | + model_registry_db_deployment: Deployment, model_registry_db_secret: Secret |
| 192 | +) -> dict[str, Any]: |
| 193 | + return { |
| 194 | + "host": f"{model_registry_db_deployment.name}.{model_registry_db_deployment.namespace}.svc.cluster.local", |
| 195 | + "database": model_registry_db_secret.string_data["database-name"], |
| 196 | + "passwordSecret": {"key": "database-password", "name": model_registry_db_deployment.name}, |
| 197 | + "port": 3306, |
| 198 | + "skipDBCreation": False, |
| 199 | + "username": model_registry_db_secret.string_data["database-user"], |
| 200 | + } |
| 201 | + |
| 202 | + |
180 | 203 | @pytest.fixture(scope="class") |
181 | 204 | def model_registry_instance_service( |
182 | 205 | admin_client: DynamicClient, |
183 | 206 | model_registry_namespace: str, |
184 | 207 | model_registry_instance: ModelRegistry, |
185 | 208 | ) -> Service: |
| 209 | + """ |
| 210 | + Get the service for the regular model registry instance. |
| 211 | + Args: |
| 212 | + admin_client: The admin client |
| 213 | + model_registry_namespace: The namespace where the model registry is deployed |
| 214 | + model_registry_instance: The model registry instance to get the service for |
| 215 | + Returns: |
| 216 | + Service: The service for the model registry instance |
| 217 | + """ |
| 218 | + return get_mr_service_by_label( |
| 219 | + client=admin_client, |
| 220 | + ns=Namespace(name=model_registry_namespace), |
| 221 | + mr_instance=model_registry_instance, |
| 222 | + ) |
| 223 | + |
| 224 | + |
| 225 | +@pytest.fixture(scope="class") |
| 226 | +def model_registry_instance_oauth_service( |
| 227 | + admin_client: DynamicClient, |
| 228 | + model_registry_namespace: str, |
| 229 | + model_registry_instance_oauth_proxy: ModelRegistry, |
| 230 | +) -> Service: |
| 231 | + """ |
| 232 | + Get the service for the OAuth proxy model registry instance. |
| 233 | + Args: |
| 234 | + admin_client: The admin client |
| 235 | + model_registry_namespace: The namespace where the model registry is deployed |
| 236 | + model_registry_instance_oauth_proxy: The OAuth proxy model registry instance |
| 237 | + Returns: |
| 238 | + Service: The service for the OAuth proxy model registry instance |
| 239 | + """ |
186 | 240 | return get_mr_service_by_label( |
187 | | - client=admin_client, ns=Namespace(name=model_registry_namespace), mr_instance=model_registry_instance |
| 241 | + client=admin_client, |
| 242 | + ns=Namespace(name=model_registry_namespace), |
| 243 | + mr_instance=model_registry_instance_oauth_proxy, |
188 | 244 | ) |
189 | 245 |
|
190 | 246 |
|
191 | 247 | @pytest.fixture(scope="class") |
192 | 248 | def model_registry_instance_rest_endpoint( |
193 | 249 | model_registry_instance_service: Service, |
194 | 250 | ) -> str: |
| 251 | + """ |
| 252 | + Get the REST endpoint for the model registry instance. |
| 253 | + Args: |
| 254 | + model_registry_instance_service: The service for the model registry instance |
| 255 | + Returns: |
| 256 | + str: The REST endpoint for the model registry instance |
| 257 | + """ |
195 | 258 | return get_endpoint_from_mr_service(svc=model_registry_instance_service, protocol=Protocols.REST) |
196 | 259 |
|
197 | 260 |
|
@@ -262,9 +325,29 @@ def updated_dsc_component_state_scope_class( |
262 | 325 |
|
263 | 326 |
|
264 | 327 | @pytest.fixture(scope="class") |
265 | | -def model_registry_client(current_client_token: str, model_registry_instance_rest_endpoint: str) -> ModelRegistryClient: |
266 | | - # address and port need to be split in the client instantiation |
267 | | - server, port = model_registry_instance_rest_endpoint.split(":") |
| 328 | +def model_registry_client( |
| 329 | + request: FixtureRequest, |
| 330 | + current_client_token: str, |
| 331 | +) -> ModelRegistryClient: |
| 332 | + """ |
| 333 | + Get a client for the model registry instance. |
| 334 | + Args: |
| 335 | + request: The pytest request object |
| 336 | + current_client_token: The current client token |
| 337 | + Returns: |
| 338 | + ModelRegistryClient: A client for the model registry instance |
| 339 | + """ |
| 340 | + # Get the service fixture name from the request |
| 341 | + service_fixture = getattr(request, "param", {}).get("service_fixture", "model_registry_instance_service") |
| 342 | + |
| 343 | + # Get the service from the fixture |
| 344 | + service = request.getfixturevalue(argname=service_fixture) |
| 345 | + |
| 346 | + # Get the REST endpoint |
| 347 | + rest_endpoint = get_endpoint_from_mr_service(svc=service, protocol=Protocols.REST) |
| 348 | + |
| 349 | + # Create the client |
| 350 | + server, port = rest_endpoint.split(":") |
268 | 351 | return ModelRegistryClient( |
269 | 352 | server_address=f"{Protocols.HTTPS}://{server}", |
270 | 353 | port=port, |
|
0 commit comments