Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/storage/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@

TEST_FILE_NAME = "test-file.txt"
TEST_FILE_CONTENT = "test-content"

STORAGE_CLASS_A = "storage_class_a"
STORAGE_CLASS_B = "storage_class_b"

NO_STORAGE_CLASS_FAILURE_MESSAGE = (
f"Test failed: {'{storage_class}'} storage class is not deployed. "
f"Available storage classes: {'{cluster_storage_classes_names}'}. "
"Ensure the correct storage_class is set in the global_config, "
"or override it with the pytest params: "
f"--tc={STORAGE_CLASS_A}:<storage_class_name> "
f"--tc={STORAGE_CLASS_B}:<storage_class_name>"
)
59 changes: 50 additions & 9 deletions tests/storage/cross_cluster_live_migration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
import requests
import yaml
from kubernetes.dynamic import DynamicClient
from kubernetes.dynamic.exceptions import NotFoundError
from ocp_resources.data_source import DataSource
from ocp_resources.datavolume import DataVolume
Expand All @@ -18,6 +19,7 @@
from ocp_resources.resource import get_client
from ocp_resources.route import Route
from ocp_resources.secret import Secret
from ocp_resources.storage_class import StorageClass
from ocp_resources.storage_map import StorageMap
from ocp_resources.virtual_machine_cluster_instancetype import (
VirtualMachineClusterInstancetype,
Expand All @@ -33,6 +35,7 @@
configure_hco_live_migration_network,
get_vm_boot_id_via_console,
)
from tests.storage.utils import get_storage_class_for_storage_migration
from utilities.artifactory import (
get_artifactory_config_map,
get_artifactory_secret,
Expand Down Expand Up @@ -345,22 +348,53 @@ def local_cluster_mtv_provider_for_local_cluster(admin_client, mtv_namespace):


@pytest.fixture(scope="module")
def remote_cluster_storage_classes_names(remote_admin_client: DynamicClient) -> list[str]:
"""Get list of all storage class names available in the remote cluster."""
Comment thread
jpeimer marked this conversation as resolved.
return [sc.name for sc in list(StorageClass.get(client=remote_admin_client))]


@pytest.fixture(scope="class")
def remote_cluster_source_storage_class(
request: pytest.FixtureRequest, remote_cluster_storage_classes_names: list[str]
) -> str:
"""Storage class for creating VMs in the remote cluster before migration."""
return get_storage_class_for_storage_migration(
storage_class=request.param["source_storage_class"],
cluster_storage_classes_names=remote_cluster_storage_classes_names,
)


@pytest.fixture(scope="class")
def local_cluster_target_storage_class(request: pytest.FixtureRequest, cluster_storage_classes_names: list[str]) -> str:
"""Storage class for migrated VMs in the local cluster."""
return get_storage_class_for_storage_migration(
storage_class=request.param["target_storage_class"],
cluster_storage_classes_names=cluster_storage_classes_names,
)


@pytest.fixture(scope="class")
def local_cluster_mtv_storage_map(
admin_client, local_cluster_mtv_provider_for_local_cluster, local_cluster_mtv_provider_for_remote_cluster
admin_client,
local_cluster_mtv_provider_for_local_cluster,
local_cluster_mtv_provider_for_remote_cluster,
unique_suffix,
remote_cluster_source_storage_class,
local_cluster_target_storage_class,
):
"""
Create a StorageMap resource for MTV migration.
Maps storage classes between source and destination clusters.
"""
mapping = [
{
"source": {"name": py_config["default_storage_class"]},
"destination": {"storageClass": py_config["default_storage_class"]},
"source": {"name": remote_cluster_source_storage_class},
"destination": {"storageClass": local_cluster_target_storage_class},
}
]
with StorageMap(
client=admin_client,
name="storage-map",
name=f"storage-map-{unique_suffix}",
namespace=local_cluster_mtv_provider_for_local_cluster.namespace,
source_provider_name=local_cluster_mtv_provider_for_remote_cluster.name,
source_provider_namespace=local_cluster_mtv_provider_for_remote_cluster.namespace,
Expand Down Expand Up @@ -429,7 +463,10 @@ def remote_cluster_rhel10_data_source(remote_admin_client, remote_cluster_golden

@pytest.fixture(scope="class")
def vm_for_cclm_from_template_with_data_source(
remote_admin_client, remote_cluster_source_test_namespace, remote_cluster_rhel10_data_source
remote_admin_client,
remote_cluster_source_test_namespace,
remote_cluster_rhel10_data_source,
remote_cluster_source_storage_class,
):
with VirtualMachineForTests(
name="vm-from-template-and-data-source",
Expand All @@ -438,7 +475,7 @@ def vm_for_cclm_from_template_with_data_source(
os_flavor=OS_FLAVOR_RHEL,
data_volume_template=data_volume_template_with_source_ref_dict(
data_source=remote_cluster_rhel10_data_source,
storage_class=py_config["default_storage_class"],
storage_class=remote_cluster_source_storage_class,
),
memory_guest=Images.Rhel.DEFAULT_MEMORY_SIZE,
) as vm:
Expand All @@ -448,7 +485,10 @@ def vm_for_cclm_from_template_with_data_source(

@pytest.fixture(scope="class")
def vm_for_cclm_with_instance_type(
remote_admin_client, remote_cluster_source_test_namespace, remote_cluster_rhel10_data_source
remote_admin_client,
remote_cluster_source_test_namespace,
remote_cluster_rhel10_data_source,
remote_cluster_source_storage_class,
):
with VirtualMachineForTests(
name="vm-with-instance-type",
Expand All @@ -459,7 +499,7 @@ def vm_for_cclm_with_instance_type(
vm_preference=VirtualMachineClusterPreference(name=RHEL10_PREFERENCE, client=remote_admin_client),
data_volume_template=data_volume_template_with_source_ref_dict(
data_source=remote_cluster_rhel10_data_source,
storage_class=py_config["default_storage_class"],
storage_class=remote_cluster_source_storage_class,
),
) as vm:
vm.start()
Expand Down Expand Up @@ -490,6 +530,7 @@ def remote_cluster_artifactory_config_map_scope_class(remote_admin_client, remot
def vm_for_cclm_windows_with_instance_type(
remote_admin_client,
remote_cluster_source_test_namespace,
remote_cluster_source_storage_class,
remote_cluster_artifactory_secret_scope_class,
remote_cluster_artifactory_config_map_scope_class,
):
Expand All @@ -505,7 +546,7 @@ def vm_for_cclm_windows_with_instance_type(
cert_configmap_name=remote_cluster_artifactory_config_map_scope_class.name,
),
size=Images.Windows.CONTAINER_DISK_DV_SIZE,
storage_class=py_config["default_storage_class"],
storage_class=remote_cluster_source_storage_class,
)
dv.to_dict()
dv.res["metadata"].pop("namespace", None)
Expand Down
Loading