Skip to content

Commit a020831

Browse files
authored
[CCLM] Make --network-for-live-migration optional arg (#4053)
##### Short description: Depending on the clusters' setup, it may not be required to patch the `liveMigrationConfig` in HCO. Making it an optional argument. ##### More details: ##### What this PR does / why we need it: ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: ##### jira-ticket: <!-- full-ticket-url needs to be provided. This would add a link to the pull request to the jira and close it when the pull request is merged If the task is not tracked by a Jira ticket, just write "NONE". --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added an optional CLI option to specify a network name for cross-cluster live-migration tests. When provided, tests will apply and use that network; when omitted, network configuration is skipped and tests proceed without it. The test suite now accepts and honors a user-supplied network name and handles its absence gracefully. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent efd31ab commit a020831

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ def pytest_addoption(parser):
328328
"--remote_cluster_password",
329329
help="Password for the remote cluster for cross-cluster tests",
330330
)
331+
session_group.addoption(
332+
"--network-for-live-migration",
333+
help=(
334+
"Network name for live migration in cross-cluster tests. "
335+
"If not provided, HCO's liveMigrationConfig.network will not be set by the tests setup"
336+
),
337+
)
331338

332339
# CI group
333340
ci_group.addoption(

tests/storage/cross_cluster_live_migration/conftest.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@
4343

4444
LOGGER = logging.getLogger(__name__)
4545

46-
LIVE_MIGRATION_NETWORK_NAME = "lm-network"
46+
47+
@pytest.fixture(scope="session")
48+
def network_for_live_migration_name(request):
49+
"""
50+
Get the network name for live migration from CLI arguments.
51+
"""
52+
network_name = request.session.config.getoption("--network-for-live-migration")
53+
if not network_name:
54+
LOGGER.info("--network-for-live-migration not provided, skipping network configuration")
55+
return network_name
4756

4857

4958
@pytest.fixture(scope="session")
@@ -129,19 +138,25 @@ def local_cluster_enabled_feature_gate_and_configured_hco_live_migration_network
129138

130139

131140
@pytest.fixture(scope="package")
132-
def local_cluster_network_for_live_migration(admin_client, hco_namespace):
141+
def local_cluster_network_for_live_migration(admin_client, hco_namespace, network_for_live_migration_name):
142+
if not network_for_live_migration_name:
143+
return None
133144
return NetworkAttachmentDefinition(
134-
name=LIVE_MIGRATION_NETWORK_NAME,
145+
name=network_for_live_migration_name,
135146
namespace=hco_namespace.name,
136147
client=admin_client,
137148
ensure_exists=True,
138149
)
139150

140151

141152
@pytest.fixture(scope="package")
142-
def remote_cluster_network_for_live_migration(remote_admin_client, remote_cluster_hco_namespace):
153+
def remote_cluster_network_for_live_migration(
154+
remote_admin_client, remote_cluster_hco_namespace, network_for_live_migration_name
155+
):
156+
if not network_for_live_migration_name:
157+
return None
143158
return NetworkAttachmentDefinition(
144-
name=LIVE_MIGRATION_NETWORK_NAME,
159+
name=network_for_live_migration_name,
145160
namespace=remote_cluster_hco_namespace.name,
146161
client=remote_admin_client,
147162
ensure_exists=True,

tests/storage/cross_cluster_live_migration/utils.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from typing import Generator
23

34
from kubernetes.dynamic import DynamicClient
@@ -11,59 +12,65 @@
1112
from utilities.infra import get_daemonset_by_name
1213
from utilities.virt import VirtualMachineForTests, migrate_vm_and_verify, wait_for_virt_handler_pods_network_updated
1314

15+
LOGGER = logging.getLogger(__name__)
16+
1417

1518
def enable_feature_gate_and_configure_hco_live_migration_network(
1619
hyperconverged_resource: HyperConverged,
1720
client: DynamicClient,
18-
network_for_live_migration: NetworkAttachmentDefinition,
1921
hco_namespace: Namespace,
22+
network_for_live_migration: NetworkAttachmentDefinition | None = None,
2023
) -> Generator[None, None, None]:
2124
"""
22-
Enable decentralized live migration feature gate and configure HCO live migration network.
25+
Enable decentralized live migration feature gate and optionally configure HCO live migration network.
2326
2427
Args:
2528
hyperconverged_resource: The HyperConverged resource to patch
2629
client: The DynamicClient for the cluster
27-
network_for_live_migration: The NetworkAttachmentDefinition for live migration
2830
hco_namespace: The HCO namespace
31+
network_for_live_migration: The NetworkAttachmentDefinition for live migration,
32+
or None to skip network configuration
2933
3034
Yields:
3135
None
3236
"""
33-
virt_handler_daemonset = get_daemonset_by_name(
34-
admin_client=client,
35-
daemonset_name=VIRT_HANDLER,
36-
namespace_name=hco_namespace.name,
37-
)
37+
spec_patch = {"featureGates": {"decentralizedLiveMigration": True}}
38+
39+
# Only configure network if provided
40+
virt_handler_daemonset = None
41+
if network_for_live_migration:
42+
LOGGER.info("Adding live migration network configuration to HCO spec patch")
43+
spec_patch["liveMigrationConfig"] = {"network": network_for_live_migration.name}
44+
45+
virt_handler_daemonset = get_daemonset_by_name(
46+
admin_client=client,
47+
daemonset_name=VIRT_HANDLER,
48+
namespace_name=hco_namespace.name,
49+
)
3850

3951
with ResourceEditorValidateHCOReconcile(
40-
patches={
41-
hyperconverged_resource: {
42-
"spec": {
43-
"featureGates": {"decentralizedLiveMigration": True},
44-
"liveMigrationConfig": {"network": network_for_live_migration.name},
45-
}
46-
}
47-
},
52+
patches={hyperconverged_resource: {"spec": spec_patch}},
4853
list_resource_reconcile=[KubeVirt],
4954
wait_for_reconcile_post_update=True,
5055
admin_client=client,
5156
):
57+
if network_for_live_migration and virt_handler_daemonset:
58+
wait_for_virt_handler_pods_network_updated(
59+
client=client,
60+
namespace=hco_namespace,
61+
network_name=network_for_live_migration.name,
62+
virt_handler_daemonset=virt_handler_daemonset,
63+
)
64+
yield
65+
66+
if network_for_live_migration and virt_handler_daemonset:
5267
wait_for_virt_handler_pods_network_updated(
5368
client=client,
5469
namespace=hco_namespace,
5570
network_name=network_for_live_migration.name,
5671
virt_handler_daemonset=virt_handler_daemonset,
72+
migration_network=False,
5773
)
58-
yield
59-
60-
wait_for_virt_handler_pods_network_updated(
61-
client=client,
62-
namespace=hco_namespace,
63-
network_name=network_for_live_migration.name,
64-
virt_handler_daemonset=virt_handler_daemonset,
65-
migration_network=False,
66-
)
6774

6875

6976
def verify_compute_live_migration_after_cclm(

0 commit comments

Comments
 (0)