forked from opendatahub-io/opendatahub-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
121 lines (107 loc) · 4.41 KB
/
conftest.py
File metadata and controls
121 lines (107 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import pytest
from typing import Generator, Any
from ocp_resources.secret import Secret
from ocp_resources.namespace import Namespace
from ocp_resources.service import Service
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
from ocp_resources.deployment import Deployment
from pytest import FixtureRequest
from kubernetes.dynamic import DynamicClient
from tests.model_registry.constants import (
MODEL_REGISTRY_DB_SECRET_STR_DATA,
MODEL_REGISTRY_DB_SECRET_ANNOTATIONS,
)
from tests.model_registry.negative_tests.constants import CUSTOM_NEGATIVE_NS
from tests.model_registry.utils import get_model_registry_deployment_template_dict, get_model_registry_db_label_dict
from utilities.infra import create_ns
DB_RESOURCES_NAME_NEGATIVE = "db-model-registry-negative"
@pytest.fixture(scope="class")
def model_registry_namespace_for_negative_tests(
request: FixtureRequest, admin_client: DynamicClient
) -> Generator[Namespace, Any, Any]:
with create_ns(
name=request.param.get("namespace_name", CUSTOM_NEGATIVE_NS),
client=admin_client,
) as ns:
yield ns
@pytest.fixture(scope="class")
def model_registry_db_service_for_negative_tests(
admin_client: DynamicClient, model_registry_namespace_for_negative_tests: Namespace
) -> Generator[Service, Any, Any]:
with Service(
client=admin_client,
name=DB_RESOURCES_NAME_NEGATIVE,
namespace=model_registry_namespace_for_negative_tests.name,
ports=[
{
"name": "mysql",
"nodePort": 0,
"port": 3306,
"protocol": "TCP",
"appProtocol": "tcp",
"targetPort": 3306,
}
],
selector={
"name": DB_RESOURCES_NAME_NEGATIVE,
},
label=get_model_registry_db_label_dict(db_resource_name=DB_RESOURCES_NAME_NEGATIVE),
annotations={
"template.openshift.io/expose-uri": r"mysql://{.spec.clusterIP}:{.spec.ports[?(.name==\mysql\)].port}",
},
) as mr_db_service:
yield mr_db_service
@pytest.fixture(scope="class")
def model_registry_db_pvc_for_negative_tests(
admin_client: DynamicClient,
model_registry_namespace_for_negative_tests: Namespace,
) -> Generator[PersistentVolumeClaim, Any, Any]:
with PersistentVolumeClaim(
accessmodes="ReadWriteOnce",
name=DB_RESOURCES_NAME_NEGATIVE,
namespace=model_registry_namespace_for_negative_tests.name,
client=admin_client,
size="5Gi",
label=get_model_registry_db_label_dict(db_resource_name=DB_RESOURCES_NAME_NEGATIVE),
) as pvc:
yield pvc
@pytest.fixture(scope="class")
def model_registry_db_secret_negative_test(
admin_client: DynamicClient,
model_registry_namespace_for_negative_tests: Namespace,
) -> Generator[Secret, Any, Any]:
with Secret(
client=admin_client,
name=DB_RESOURCES_NAME_NEGATIVE,
namespace=model_registry_namespace_for_negative_tests.name,
string_data=MODEL_REGISTRY_DB_SECRET_STR_DATA,
label=get_model_registry_db_label_dict(db_resource_name=DB_RESOURCES_NAME_NEGATIVE),
annotations=MODEL_REGISTRY_DB_SECRET_ANNOTATIONS,
) as mr_db_secret:
yield mr_db_secret
@pytest.fixture(scope="class")
def model_registry_db_deployment_negative_test(
admin_client: DynamicClient,
model_registry_namespace_for_negative_tests: Namespace,
model_registry_db_secret_negative_test: Secret,
model_registry_db_pvc_for_negative_tests: PersistentVolumeClaim,
model_registry_db_service_for_negative_tests: Service,
) -> Generator[Deployment, Any, Any]:
with Deployment(
name=DB_RESOURCES_NAME_NEGATIVE,
namespace=model_registry_namespace_for_negative_tests.name,
annotations={
"template.alpha.openshift.io/wait-for-ready": "true",
},
label=get_model_registry_db_label_dict(db_resource_name=DB_RESOURCES_NAME_NEGATIVE),
replicas=1,
revision_history_limit=0,
selector={"matchLabels": {"name": DB_RESOURCES_NAME_NEGATIVE}},
strategy={"type": "Recreate"},
template=get_model_registry_deployment_template_dict(
secret_name=model_registry_db_secret_negative_test.name, resource_name=DB_RESOURCES_NAME_NEGATIVE
),
wait_for_resource=True,
) as mr_db_deployment:
mr_db_deployment.wait_for_replicas(deployed=True)
yield mr_db_deployment