|
1 | 1 | import pytest |
2 | | -import uuid |
3 | 2 | from tests.model_registry.constants import ( |
4 | 3 | MODEL_REGISTRY_DB_SECRET_STR_DATA, |
5 | 4 | MR_INSTANCE_NAME, |
6 | | - DB_RESOURCES_NAME, |
| 5 | + DB_BASE_RESOURCES_NAME, |
7 | 6 | NUM_MR_INSTANCES, |
| 7 | + MODEL_REGISTRY_DB_SECRET_ANNOTATIONS, |
| 8 | + OAUTH_PROXY_CONFIG_DICT, |
8 | 9 | ) |
| 10 | +from tests.model_registry.utils import ( |
| 11 | + get_model_registry_db_label_dict, |
| 12 | + get_model_registry_deployment_template_dict, |
| 13 | + get_mr_standard_labels, |
| 14 | + get_mysql_config, |
| 15 | +) |
| 16 | +from utilities.general import generate_random_name |
9 | 17 |
|
10 | | - |
11 | | -ns_name = f"{MR_INSTANCE_NAME}-ns-{str(uuid.uuid4())[:8]}" |
| 18 | +ns_name = generate_random_name(prefix=MR_INSTANCE_NAME, length=2) |
12 | 19 | ns_params = {"ns_name": ns_name} |
13 | 20 |
|
14 | | -db_names = [f"{DB_RESOURCES_NAME}-{i + 1}-{str(uuid.uuid4())[:8]}" for i in range(NUM_MR_INSTANCES)] |
| 21 | +resource_names = [f"{DB_BASE_RESOURCES_NAME}{index}" for index in range(0, NUM_MR_INSTANCES)] |
15 | 22 |
|
16 | | -db_secret_params = [{"db_name": db_name, "ns_name": ns_name} for db_name in db_names] |
| 23 | +db_secret_params = [ |
| 24 | + { |
| 25 | + "name": resource_name, |
| 26 | + "namespace": ns_name, |
| 27 | + "string_data": MODEL_REGISTRY_DB_SECRET_STR_DATA, |
| 28 | + "label": get_model_registry_db_label_dict(db_resource_name=resource_name), |
| 29 | + "annotations": MODEL_REGISTRY_DB_SECRET_ANNOTATIONS, |
| 30 | + } |
| 31 | + for resource_name in resource_names |
| 32 | +] |
17 | 33 |
|
18 | 34 | db_pvc_params = [ |
19 | 35 | { |
20 | | - "db_name": db_name, |
21 | | - "ns_name": ns_name, |
| 36 | + "name": resource_name, |
| 37 | + "namespace": ns_name, |
22 | 38 | "accessmodes": "ReadWriteOnce", |
23 | 39 | "size": "4Gi", |
| 40 | + "label": get_model_registry_db_label_dict(db_resource_name=resource_name), |
24 | 41 | } |
25 | | - for db_name in db_names |
| 42 | + for resource_name in resource_names |
26 | 43 | ] |
27 | | - |
| 44 | +annotation = {"template.openshift.io/expose-uri": r"mysql://{.spec.clusterIP}:{.spec.ports[?(.name==\mysql\)].port}"} |
28 | 45 | db_service_params = [ |
29 | 46 | { |
30 | | - "db_name": db_name, |
| 47 | + "name": resource_name, |
31 | 48 | "ports": [{"name": "mysql", "port": 3306, "protocol": "TCP", "targetPort": 3306}], |
32 | | - "ns_name": ns_name, |
| 49 | + "namespace": ns_name, |
| 50 | + "selector": {"name": resource_name}, |
| 51 | + "label": get_model_registry_db_label_dict(db_resource_name=resource_name), |
| 52 | + "annotations": annotation, |
33 | 53 | } |
34 | | - for db_name in db_names |
| 54 | + for resource_name in resource_names |
35 | 55 | ] |
36 | 56 |
|
37 | 57 | db_deployment_params = [ |
38 | 58 | { |
39 | | - "db_name": db_name, |
40 | | - "ns_name": ns_name, |
| 59 | + "name": resource_name, |
| 60 | + "namespace": ns_name, |
41 | 61 | "replicas": 1, |
42 | 62 | "revision_history_limit": 0, |
| 63 | + "annotations": { |
| 64 | + "template.alpha.openshift.io/wait-for-ready": "true", |
| 65 | + }, |
| 66 | + "label": get_model_registry_db_label_dict(db_resource_name=resource_name), |
| 67 | + "selector": {"matchLabels": {"name": resource_name}}, |
| 68 | + "strategy": {"type": "Recreate"}, |
| 69 | + "template": get_model_registry_deployment_template_dict(secret_name=resource_name, resource_name=resource_name), |
| 70 | + "wait_for_resource": True, |
43 | 71 | } |
44 | | - for db_name in db_names |
| 72 | + for resource_name in resource_names |
45 | 73 | ] |
46 | 74 |
|
47 | 75 | model_registry_instance_params = [ |
48 | 76 | { |
49 | | - "is_model_registry_oauth": True, |
50 | | - "mr_name": f"{MR_INSTANCE_NAME}-{i + 1}", |
51 | | - "db_name": db_name, |
52 | | - "ns_name": ns_name, |
53 | | - "mysql_config": { |
54 | | - "host": f"{db_name}.{ns_name}.svc.cluster.local", |
55 | | - "database": MODEL_REGISTRY_DB_SECRET_STR_DATA["database-name"], |
56 | | - "passwordSecret": {"key": "database-password", "name": db_name}, |
57 | | - "port": 3306, |
58 | | - "skipDBCreation": False, |
59 | | - "username": MODEL_REGISTRY_DB_SECRET_STR_DATA["database-user"], |
60 | | - }, |
| 77 | + "name": f"{MR_INSTANCE_NAME}{index}", |
| 78 | + "namespace": ns_name, |
| 79 | + "label": get_mr_standard_labels(resource_name=f"{MR_INSTANCE_NAME}{index}"), |
| 80 | + "grpc": {}, |
| 81 | + "rest": {}, |
| 82 | + "mysql": get_mysql_config(base_name=f"{DB_BASE_RESOURCES_NAME}{index}", namespace=ns_name), |
| 83 | + "wait_for_resource": True, |
| 84 | + "oauth_proxy": OAUTH_PROXY_CONFIG_DICT, |
61 | 85 | } |
62 | | - for i, db_name in enumerate(db_names) |
| 86 | + for index in range(0, NUM_MR_INSTANCES) |
63 | 87 | ] |
64 | 88 |
|
65 | 89 | # Add this complete set of parameters as a pytest.param tuple to the list. |
|
71 | 95 | db_service_params, |
72 | 96 | db_deployment_params, |
73 | 97 | model_registry_instance_params, |
74 | | - id=f"mr-scenario-{len(db_names)}-instances", # Unique ID for pytest output |
| 98 | + id=f"mr-scenario-{len(resource_names)}-instances", # Unique ID for pytest output |
75 | 99 | ) |
76 | 100 | ] |
0 commit comments