Skip to content

Commit 2b907bd

Browse files
committed
change: Move OCI fixture closer to the usage
1 parent 1037683 commit 2b907bd

File tree

2 files changed

+131
-119
lines changed

2 files changed

+131
-119
lines changed

tests/conftest.py

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from ocp_resources.mariadb_operator import MariadbOperator
2020
from ocp_resources.node import Node
2121
from ocp_resources.pod import Pod
22-
from ocp_resources.route import Route
2322
from ocp_resources.secret import Secret
2423
from ocp_resources.service import Service
2524
from ocp_resources.subscription import Subscription
@@ -50,7 +49,6 @@
5049
DscComponents,
5150
Labels,
5251
MinIo,
53-
OCIRegistry,
5452
Protocols,
5553
Timeout,
5654
OPENSHIFT_OPERATORS,
@@ -567,123 +565,6 @@ def minio_data_connection(
567565
yield secret
568566

569567

570-
# OCI Registry
571-
@pytest.fixture(scope="class")
572-
def oci_namespace(admin_client: DynamicClient) -> Generator[Namespace, Any, Any]:
573-
with create_ns(
574-
name=f"{OCIRegistry.Metadata.NAME}-{shortuuid.uuid().lower()}",
575-
admin_client=admin_client,
576-
) as ns:
577-
yield ns
578-
579-
580-
@pytest.fixture(scope="class")
581-
def oci_registry_pod_with_minio(
582-
request: FixtureRequest,
583-
admin_client: DynamicClient,
584-
oci_namespace: Namespace,
585-
minio_service: Service,
586-
) -> Generator[Pod, Any, Any]:
587-
pod_labels = {Labels.Openshift.APP: OCIRegistry.Metadata.NAME}
588-
589-
if labels := request.param.get("labels"):
590-
pod_labels.update(labels)
591-
592-
minio_fqdn = f"{minio_service.name}.{minio_service.namespace}.svc.cluster.local"
593-
minio_endpoint = f"{minio_fqdn}:{MinIo.Metadata.DEFAULT_PORT}"
594-
595-
with Pod(
596-
client=admin_client,
597-
name=OCIRegistry.Metadata.NAME,
598-
namespace=oci_namespace.name,
599-
containers=[
600-
{
601-
"args": request.param.get("args"),
602-
"env": [
603-
{"name": "ZOT_STORAGE_STORAGEDRIVER_NAME", "value": OCIRegistry.Storage.STORAGE_DRIVER},
604-
{
605-
"name": "ZOT_STORAGE_STORAGEDRIVER_ROOTDIRECTORY",
606-
"value": OCIRegistry.Storage.STORAGE_DRIVER_ROOT_DIRECTORY,
607-
},
608-
{"name": "ZOT_STORAGE_STORAGEDRIVER_BUCKET", "value": MinIo.Buckets.MODELMESH_EXAMPLE_MODELS},
609-
{"name": "ZOT_STORAGE_STORAGEDRIVER_REGION", "value": OCIRegistry.Storage.STORAGE_DRIVER_REGION},
610-
{"name": "ZOT_STORAGE_STORAGEDRIVER_REGIONENDPOINT", "value": f"http://{minio_endpoint}"},
611-
{"name": "ZOT_STORAGE_STORAGEDRIVER_ACCESSKEY", "value": MinIo.Credentials.ACCESS_KEY_VALUE},
612-
{"name": "ZOT_STORAGE_STORAGEDRIVER_SECRETKEY", "value": MinIo.Credentials.SECRET_KEY_VALUE},
613-
{
614-
"name": "ZOT_STORAGE_STORAGEDRIVER_SECURE",
615-
"value": OCIRegistry.Storage.STORAGE_STORAGEDRIVER_SECURE,
616-
},
617-
{
618-
"name": "ZOT_STORAGE_STORAGEDRIVER_FORCEPATHSTYLE",
619-
"value": OCIRegistry.Storage.STORAGE_STORAGEDRIVER_FORCEPATHSTYLE,
620-
},
621-
{"name": "ZOT_HTTP_ADDRESS", "value": OCIRegistry.Metadata.DEFAULT_HTTP_ADDRESS},
622-
{"name": "ZOT_HTTP_PORT", "value": str(OCIRegistry.Metadata.DEFAULT_PORT)},
623-
{"name": "ZOT_LOG_LEVEL", "value": "info"},
624-
],
625-
"image": request.param.get("image", OCIRegistry.PodConfig.REGISTRY_IMAGE),
626-
"name": OCIRegistry.Metadata.NAME,
627-
"securityContext": {
628-
"allowPrivilegeEscalation": False,
629-
"capabilities": {"drop": ["ALL"]},
630-
"runAsNonRoot": True,
631-
"seccompProfile": {"type": "RuntimeDefault"},
632-
},
633-
"volumeMounts": [
634-
{
635-
"name": "zot-data",
636-
"mountPath": "/var/lib/registry",
637-
}
638-
],
639-
}
640-
],
641-
volumes=[
642-
{
643-
"name": "zot-data",
644-
"emptyDir": {},
645-
}
646-
],
647-
label=pod_labels,
648-
annotations=request.param.get("annotations"),
649-
) as oci_pod:
650-
oci_pod.wait_for_condition(condition="Ready", status="True")
651-
yield oci_pod
652-
653-
654-
@pytest.fixture(scope="class")
655-
def oci_registry_service(admin_client: DynamicClient, oci_namespace: Namespace) -> Generator[Service, Any, Any]:
656-
with Service(
657-
client=admin_client,
658-
name=OCIRegistry.Metadata.NAME,
659-
namespace=oci_namespace.name,
660-
ports=[
661-
{
662-
"name": f"{OCIRegistry.Metadata.NAME}-port",
663-
"port": OCIRegistry.Metadata.DEFAULT_PORT,
664-
"protocol": Protocols.TCP,
665-
"targetPort": OCIRegistry.Metadata.DEFAULT_PORT,
666-
}
667-
],
668-
selector={
669-
Labels.Openshift.APP: OCIRegistry.Metadata.NAME,
670-
},
671-
session_affinity="ClientIP",
672-
) as oci_service:
673-
yield oci_service
674-
675-
676-
@pytest.fixture(scope="class")
677-
def oci_registry_route(admin_client: DynamicClient, oci_registry_service: Service) -> Generator[Route, Any, Any]:
678-
with Route(
679-
client=admin_client,
680-
name=OCIRegistry.Metadata.NAME,
681-
namespace=oci_registry_service.namespace,
682-
service=oci_registry_service.name,
683-
) as oci_route:
684-
yield oci_route
685-
686-
687568
@pytest.fixture(scope="session")
688569
def nodes(admin_client: DynamicClient) -> Generator[list[Node], Any, Any]:
689570
yield list(Node.get(dyn_client=admin_client))
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import pytest
2+
from typing import Any, Generator
3+
import shortuuid
4+
from pytest import FixtureRequest
5+
6+
from ocp_resources.namespace import Namespace
7+
from ocp_resources.pod import Pod
8+
from ocp_resources.route import Route
9+
from ocp_resources.service import Service
10+
11+
from utilities.infra import create_ns
12+
from utilities.constants import OCIRegistry, MinIo, Protocols, Labels
13+
14+
from kubernetes.dynamic import DynamicClient
15+
16+
17+
# OCI Registry
18+
@pytest.fixture(scope="class")
19+
def oci_namespace(admin_client: DynamicClient) -> Generator[Namespace, Any, Any]:
20+
with create_ns(
21+
name=f"{OCIRegistry.Metadata.NAME}-{shortuuid.uuid().lower()}",
22+
admin_client=admin_client,
23+
) as ns:
24+
yield ns
25+
26+
27+
@pytest.fixture(scope="class")
28+
def oci_registry_pod_with_minio(
29+
request: FixtureRequest,
30+
admin_client: DynamicClient,
31+
oci_namespace: Namespace,
32+
minio_service: Service,
33+
) -> Generator[Pod, Any, Any]:
34+
pod_labels = {Labels.Openshift.APP: OCIRegistry.Metadata.NAME}
35+
36+
if labels := request.param.get("labels"):
37+
pod_labels.update(labels)
38+
39+
minio_fqdn = f"{minio_service.name}.{minio_service.namespace}.svc.cluster.local"
40+
minio_endpoint = f"{minio_fqdn}:{MinIo.Metadata.DEFAULT_PORT}"
41+
42+
with Pod(
43+
client=admin_client,
44+
name=OCIRegistry.Metadata.NAME,
45+
namespace=oci_namespace.name,
46+
containers=[
47+
{
48+
"args": request.param.get("args"),
49+
"env": [
50+
{"name": "ZOT_STORAGE_STORAGEDRIVER_NAME", "value": OCIRegistry.Storage.STORAGE_DRIVER},
51+
{
52+
"name": "ZOT_STORAGE_STORAGEDRIVER_ROOTDIRECTORY",
53+
"value": OCIRegistry.Storage.STORAGE_DRIVER_ROOT_DIRECTORY,
54+
},
55+
{"name": "ZOT_STORAGE_STORAGEDRIVER_BUCKET", "value": MinIo.Buckets.MODELMESH_EXAMPLE_MODELS},
56+
{"name": "ZOT_STORAGE_STORAGEDRIVER_REGION", "value": OCIRegistry.Storage.STORAGE_DRIVER_REGION},
57+
{"name": "ZOT_STORAGE_STORAGEDRIVER_REGIONENDPOINT", "value": f"http://{minio_endpoint}"},
58+
{"name": "ZOT_STORAGE_STORAGEDRIVER_ACCESSKEY", "value": MinIo.Credentials.ACCESS_KEY_VALUE},
59+
{"name": "ZOT_STORAGE_STORAGEDRIVER_SECRETKEY", "value": MinIo.Credentials.SECRET_KEY_VALUE},
60+
{
61+
"name": "ZOT_STORAGE_STORAGEDRIVER_SECURE",
62+
"value": OCIRegistry.Storage.STORAGE_STORAGEDRIVER_SECURE,
63+
},
64+
{
65+
"name": "ZOT_STORAGE_STORAGEDRIVER_FORCEPATHSTYLE",
66+
"value": OCIRegistry.Storage.STORAGE_STORAGEDRIVER_FORCEPATHSTYLE,
67+
},
68+
{"name": "ZOT_HTTP_ADDRESS", "value": OCIRegistry.Metadata.DEFAULT_HTTP_ADDRESS},
69+
{"name": "ZOT_HTTP_PORT", "value": str(OCIRegistry.Metadata.DEFAULT_PORT)},
70+
{"name": "ZOT_LOG_LEVEL", "value": "info"},
71+
],
72+
"image": request.param.get("image", OCIRegistry.PodConfig.REGISTRY_IMAGE),
73+
"name": OCIRegistry.Metadata.NAME,
74+
"securityContext": {
75+
"allowPrivilegeEscalation": False,
76+
"capabilities": {"drop": ["ALL"]},
77+
"runAsNonRoot": True,
78+
"seccompProfile": {"type": "RuntimeDefault"},
79+
},
80+
"volumeMounts": [
81+
{
82+
"name": "zot-data",
83+
"mountPath": "/var/lib/registry",
84+
}
85+
],
86+
}
87+
],
88+
volumes=[
89+
{
90+
"name": "zot-data",
91+
"emptyDir": {},
92+
}
93+
],
94+
label=pod_labels,
95+
annotations=request.param.get("annotations"),
96+
) as oci_pod:
97+
oci_pod.wait_for_condition(condition="Ready", status="True")
98+
yield oci_pod
99+
100+
101+
@pytest.fixture(scope="class")
102+
def oci_registry_service(admin_client: DynamicClient, oci_namespace: Namespace) -> Generator[Service, Any, Any]:
103+
with Service(
104+
client=admin_client,
105+
name=OCIRegistry.Metadata.NAME,
106+
namespace=oci_namespace.name,
107+
ports=[
108+
{
109+
"name": f"{OCIRegistry.Metadata.NAME}-port",
110+
"port": OCIRegistry.Metadata.DEFAULT_PORT,
111+
"protocol": Protocols.TCP,
112+
"targetPort": OCIRegistry.Metadata.DEFAULT_PORT,
113+
}
114+
],
115+
selector={
116+
Labels.Openshift.APP: OCIRegistry.Metadata.NAME,
117+
},
118+
session_affinity="ClientIP",
119+
) as oci_service:
120+
yield oci_service
121+
122+
123+
@pytest.fixture(scope="class")
124+
def oci_registry_route(admin_client: DynamicClient, oci_registry_service: Service) -> Generator[Route, Any, Any]:
125+
with Route(
126+
client=admin_client,
127+
name=OCIRegistry.Metadata.NAME,
128+
namespace=oci_registry_service.namespace,
129+
service=oci_registry_service.name,
130+
) as oci_route:
131+
yield oci_route

0 commit comments

Comments
 (0)