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
7 changes: 7 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ def pytest_addoption(parser):
"--remote_cluster_password",
help="Password for the remote cluster for cross-cluster tests",
)
session_group.addoption(
Comment thread
jpeimer marked this conversation as resolved.
"--network-for-live-migration",
help=(
"Network name for live migration in cross-cluster tests. "
"If not provided, HCO's liveMigrationConfig.network will not be set by the tests setup"
),
)

# CI group
ci_group.addoption(
Expand Down
25 changes: 20 additions & 5 deletions tests/storage/cross_cluster_live_migration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@

LOGGER = logging.getLogger(__name__)

LIVE_MIGRATION_NETWORK_NAME = "lm-network"

@pytest.fixture(scope="session")
def network_for_live_migration_name(request):
"""
Get the network name for live migration from CLI arguments.
"""
network_name = request.session.config.getoption("--network-for-live-migration")
if not network_name:
LOGGER.info("--network-for-live-migration not provided, skipping network configuration")
return network_name
Comment thread
jpeimer marked this conversation as resolved.


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -129,19 +138,25 @@ def local_cluster_enabled_feature_gate_and_configured_hco_live_migration_network


@pytest.fixture(scope="package")
def local_cluster_network_for_live_migration(admin_client, hco_namespace):
def local_cluster_network_for_live_migration(admin_client, hco_namespace, network_for_live_migration_name):
if not network_for_live_migration_name:
return None
return NetworkAttachmentDefinition(
name=LIVE_MIGRATION_NETWORK_NAME,
name=network_for_live_migration_name,
namespace=hco_namespace.name,
client=admin_client,
ensure_exists=True,
)


@pytest.fixture(scope="package")
def remote_cluster_network_for_live_migration(remote_admin_client, remote_cluster_hco_namespace):
def remote_cluster_network_for_live_migration(
remote_admin_client, remote_cluster_hco_namespace, network_for_live_migration_name
):
if not network_for_live_migration_name:
return None
return NetworkAttachmentDefinition(
name=LIVE_MIGRATION_NETWORK_NAME,
name=network_for_live_migration_name,
namespace=remote_cluster_hco_namespace.name,
client=remote_admin_client,
ensure_exists=True,
Expand Down
57 changes: 32 additions & 25 deletions tests/storage/cross_cluster_live_migration/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Generator

from kubernetes.dynamic import DynamicClient
Expand All @@ -11,59 +12,65 @@
from utilities.infra import get_daemonset_by_name
from utilities.virt import VirtualMachineForTests, migrate_vm_and_verify, wait_for_virt_handler_pods_network_updated

LOGGER = logging.getLogger(__name__)


def enable_feature_gate_and_configure_hco_live_migration_network(
hyperconverged_resource: HyperConverged,
client: DynamicClient,
network_for_live_migration: NetworkAttachmentDefinition,
hco_namespace: Namespace,
network_for_live_migration: NetworkAttachmentDefinition | None = None,
) -> Generator[None, None, None]:
"""
Enable decentralized live migration feature gate and configure HCO live migration network.
Enable decentralized live migration feature gate and optionally configure HCO live migration network.

Args:
hyperconverged_resource: The HyperConverged resource to patch
client: The DynamicClient for the cluster
network_for_live_migration: The NetworkAttachmentDefinition for live migration
hco_namespace: The HCO namespace
network_for_live_migration: The NetworkAttachmentDefinition for live migration,
or None to skip network configuration

Yields:
None
"""
virt_handler_daemonset = get_daemonset_by_name(
admin_client=client,
daemonset_name=VIRT_HANDLER,
namespace_name=hco_namespace.name,
)
spec_patch = {"featureGates": {"decentralizedLiveMigration": True}}

# Only configure network if provided
virt_handler_daemonset = None
if network_for_live_migration:
LOGGER.info("Adding live migration network configuration to HCO spec patch")
spec_patch["liveMigrationConfig"] = {"network": network_for_live_migration.name}

virt_handler_daemonset = get_daemonset_by_name(
admin_client=client,
daemonset_name=VIRT_HANDLER,
namespace_name=hco_namespace.name,
)

with ResourceEditorValidateHCOReconcile(
patches={
hyperconverged_resource: {
"spec": {
"featureGates": {"decentralizedLiveMigration": True},
"liveMigrationConfig": {"network": network_for_live_migration.name},
}
}
},
patches={hyperconverged_resource: {"spec": spec_patch}},
list_resource_reconcile=[KubeVirt],
wait_for_reconcile_post_update=True,
admin_client=client,
):
if network_for_live_migration and virt_handler_daemonset:
wait_for_virt_handler_pods_network_updated(
client=client,
namespace=hco_namespace,
network_name=network_for_live_migration.name,
virt_handler_daemonset=virt_handler_daemonset,
)
yield

if network_for_live_migration and virt_handler_daemonset:
wait_for_virt_handler_pods_network_updated(
client=client,
namespace=hco_namespace,
network_name=network_for_live_migration.name,
virt_handler_daemonset=virt_handler_daemonset,
migration_network=False,
)
yield

wait_for_virt_handler_pods_network_updated(
client=client,
namespace=hco_namespace,
network_name=network_for_live_migration.name,
virt_handler_daemonset=virt_handler_daemonset,
migration_network=False,
)


def verify_compute_live_migration_after_cclm(
Expand Down