|
10 | 10 | from _pytest._py.path import LocalPath |
11 | 11 | from _pytest.legacypath import TempdirFactory |
12 | 12 | from _pytest.tmpdir import TempPathFactory |
| 13 | +from kubernetes.dynamic.exceptions import ResourceNotFoundError |
| 14 | + |
| 15 | +from ocp_resources.cluster_service_version import ClusterServiceVersion |
13 | 16 | from ocp_resources.config_map import ConfigMap |
| 17 | +from ocp_resources.deployment import Deployment |
14 | 18 | from ocp_resources.dsc_initialization import DSCInitialization |
| 19 | +from ocp_resources.mariadb_operator import MariadbOperator |
15 | 20 | from ocp_resources.node import Node |
16 | 21 | from ocp_resources.pod import Pod |
17 | 22 | from ocp_resources.secret import Secret |
18 | 23 | from ocp_resources.service import Service |
| 24 | +from ocp_resources.subscription import Subscription |
19 | 25 | from ocp_utilities.monitoring import Prometheus |
20 | 26 | from pyhelper_utils.shell import run_command |
21 | 27 | from pytest import FixtureRequest, Config |
|
26 | 32 | from pytest_testconfig import config as py_config |
27 | 33 | from simple_logger.logger import get_logger |
28 | 34 |
|
| 35 | +from ocp_utilities.operators import uninstall_operator, install_operator |
29 | 36 | from utilities.certificates_utils import create_ca_bundle_file |
30 | 37 | from utilities.data_science_cluster_utils import update_components_in_dsc |
31 | 38 | from utilities.exceptions import ClusterLoginError |
|
42 | 49 | Labels, |
43 | 50 | MinIo, |
44 | 51 | Protocols, |
| 52 | + Timeout, |
| 53 | + OPENSHIFT_OPERATORS, |
45 | 54 | ) |
46 | 55 | from utilities.infra import update_configmap_data |
47 | 56 | from utilities.logger import RedactedString |
| 57 | +from utilities.mariadb_utils import wait_for_mariadb_operator_deployments |
48 | 58 | from utilities.minio import create_minio_data_connection_secret |
49 | | -from utilities.operator_utils import get_csv_related_images |
| 59 | +from utilities.operator_utils import get_csv_related_images, get_cluster_service_version |
50 | 60 |
|
51 | 61 | LOGGER = get_logger(name=__name__) |
52 | 62 |
|
@@ -573,3 +583,59 @@ def autouse_fixtures( |
573 | 583 | ) -> None: |
574 | 584 | """Fixture to control the order of execution of some of the fixtures""" |
575 | 585 | return |
| 586 | + |
| 587 | + |
| 588 | +@pytest.fixture(scope="session") |
| 589 | +def installed_mariadb_operator(admin_client: DynamicClient) -> Generator[None, Any, Any]: |
| 590 | + operator_ns = Namespace(name="openshift-operators", ensure_exists=True) |
| 591 | + operator_name = "mariadb-operator" |
| 592 | + |
| 593 | + mariadb_operator_subscription = Subscription(client=admin_client, namespace=operator_ns.name, name=operator_name) |
| 594 | + |
| 595 | + if not mariadb_operator_subscription.exists: |
| 596 | + install_operator( |
| 597 | + admin_client=admin_client, |
| 598 | + target_namespaces=["openshift-operators"], |
| 599 | + name=operator_name, |
| 600 | + channel="alpha", |
| 601 | + source="community-operators", |
| 602 | + operator_namespace=operator_ns.name, |
| 603 | + timeout=Timeout.TIMEOUT_15MIN, |
| 604 | + install_plan_approval="Manual", |
| 605 | + starting_csv=f"{operator_name}.v0.38.1", |
| 606 | + ) |
| 607 | + |
| 608 | + deployment = Deployment( |
| 609 | + client=admin_client, |
| 610 | + namespace=operator_ns.name, |
| 611 | + name=f"{operator_name}-helm-controller-manager", |
| 612 | + wait_for_resource=True, |
| 613 | + ) |
| 614 | + deployment.wait_for_replicas() |
| 615 | + yield |
| 616 | + uninstall_operator( |
| 617 | + admin_client=admin_client, name=operator_name, operator_namespace=operator_ns.name, clean_up_namespace=False |
| 618 | + ) |
| 619 | + |
| 620 | + |
| 621 | +@pytest.fixture(scope="class") |
| 622 | +def mariadb_operator_cr( |
| 623 | + admin_client: DynamicClient, installed_mariadb_operator: None |
| 624 | +) -> Generator[MariadbOperator, Any, Any]: |
| 625 | + mariadb_csv: ClusterServiceVersion = get_cluster_service_version( |
| 626 | + client=admin_client, prefix="mariadb", namespace=OPENSHIFT_OPERATORS |
| 627 | + ) |
| 628 | + alm_examples: list[dict[str, Any]] = mariadb_csv.get_alm_examples() |
| 629 | + mariadb_operator_cr_dict: dict[str, Any] = next( |
| 630 | + example for example in alm_examples if example["kind"] == "MariadbOperator" |
| 631 | + ) |
| 632 | + if not mariadb_operator_cr_dict: |
| 633 | + raise ResourceNotFoundError(f"No MariadbOperator dict found in alm_examples for CSV {mariadb_csv.name}") |
| 634 | + |
| 635 | + mariadb_operator_cr_dict["metadata"]["namespace"] = OPENSHIFT_OPERATORS |
| 636 | + with MariadbOperator(kind_dict=mariadb_operator_cr_dict) as mariadb_operator_cr: |
| 637 | + mariadb_operator_cr.wait_for_condition( |
| 638 | + condition="Deployed", status=mariadb_operator_cr.Condition.Status.TRUE, timeout=Timeout.TIMEOUT_10MIN |
| 639 | + ) |
| 640 | + wait_for_mariadb_operator_deployments(mariadb_operator=mariadb_operator_cr) |
| 641 | + yield mariadb_operator_cr |
0 commit comments