-
Notifications
You must be signed in to change notification settings - Fork 71
[WIP]Add vnic_info metric test for NAD reference change #5090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
b7e75dd
a383cdf
fcc50e7
0be6484
a7fb8e7
b31abcc
108e9d6
30dbdcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import ipaddress | ||
| import logging | ||
| from collections.abc import Generator | ||
|
OhadRevah marked this conversation as resolved.
Outdated
OhadRevah marked this conversation as resolved.
Outdated
OhadRevah marked this conversation as resolved.
Outdated
|
||
| from functools import cache | ||
|
|
||
| from pytest_testconfig import py_config | ||
|
|
@@ -29,3 +30,23 @@ def ipv6_supported_cluster() -> bool: | |
|
|
||
| def _cluster_ip_family_supported(ip_family: int) -> bool: | ||
| return any(ipaddress.ip_network(ip).version == ip_family for ip in py_config.get("cluster_service_network")) | ||
|
|
||
|
|
||
| def cluster_vlan_iterator() -> Generator[int]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Simply put, from my perspective
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is clearer than the current implementation Now we can use this fixture like this |
||
| """Yield VLAN IDs from the cluster config one at a time. | ||
|
|
||
| The underlying VLAN list is read from py_config once and cached. Each call | ||
| returns a fresh iterator so every fixture invocation starts from the beginning. | ||
| Raises ValueError when all VLANs have been consumed. | ||
| """ | ||
| vlans = _cluster_vlans() | ||
| yield from vlans | ||
| raise ValueError(f"vlans list is exhausted. Current list size is {len(vlans)} and all vlans are in use.") | ||
|
OhadRevah marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| @cache | ||
| def _cluster_vlans() -> list[int]: | ||
| vlans = py_config["vlans"] | ||
| if not isinstance(vlans, list): | ||
| vlans = vlans.split(",") | ||
| return [int(v) for v in vlans] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| from ocp_resources.resource import Resource, ResourceEditor | ||
| from timeout_sampler import retry | ||
|
|
||
| from tests.network.libs.apimachinery import dict_normalization_for_dataclass | ||
| from libs.net.apimachinery import dict_normalization_for_dataclass | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test Execution Plan Run smoke tests: False Run gating tests: False Affected tests to run New test (primary deliverable of this PR):
Import-path-only refactors (
Real tests (cluster required)
Happy path (new observability test end-to-end): Regression (existing NAD-ref-change tests still collect after fixture relocation): |
||
| WAIT_FOR_STATUS_TIMEOUT_SEC = 120 | ||
| WAIT_FOR_STATUS_INTERVAL_SEC = 5 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import ipaddress | ||
| from collections.abc import Callable | ||
| from copy import deepcopy | ||
| from typing import Any, Final | ||
|
|
||
| from kubernetes.dynamic.client import ResourceField | ||
|
|
@@ -206,7 +207,7 @@ def wait_for_ifaces_status( | |
|
|
||
|
|
||
| def wait_for_vmi_condition_status( | ||
| vm: BaseVirtualMachine, | ||
| vm: VirtualMachine, | ||
| condition: str, | ||
| status: str = ResourceConstants.Condition.Status.TRUE, | ||
| timeout: int = 300, | ||
|
|
@@ -249,7 +250,7 @@ def wait_for_vmi_condition_status( | |
|
|
||
|
|
||
| def wait_for_no_vmi_condition( | ||
| vm: BaseVirtualMachine, | ||
| vm: VirtualMachine, | ||
| condition: str, | ||
| timeout: int = 300, | ||
| resource_version: str | None = None, | ||
|
|
@@ -299,3 +300,23 @@ def _vmi_condition_not_set(existing_conditions: list[ResourceField], required_co | |
| for cond in existing_conditions | ||
| if cond.type == required_condition | ||
| ) | ||
|
|
||
|
|
||
| def update_nad_references(vm: BaseVirtualMachine, nad_name_by_net: dict[str, str]) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All defensive checks are redundant - you can use the helper as is |
||
| """Update secondary network NAD references and wait for the change to be fully applied. | ||
|
|
||
| Patches the VM spec atomically, then waits for the MigrationRequired condition to | ||
| appear (change detected) and disappear (migration completed). | ||
|
|
||
| Args: | ||
| vm: The virtual machine to update. | ||
| nad_name_by_net: Mapping of interface name to new NAD name. | ||
| """ | ||
| resource_version = vm.vmi.instance.metadata.resourceVersion | ||
| networks = deepcopy(vm.template_spec.networks) or [] | ||
| for network in networks: | ||
| if network.name in nad_name_by_net and network.multus: | ||
| network.multus.networkName = nad_name_by_net[network.name] | ||
| vm.set_networks(networks=networks) | ||
| wait_for_vmi_condition_status(vm=vm, condition="MigrationRequired", resource_version=resource_version) | ||
|
OhadRevah marked this conversation as resolved.
Outdated
|
||
| wait_for_no_vmi_condition(vm=vm, condition="MigrationRequired") | ||
Uh oh!
There was an error while loading. Please reload this page.