-
Notifications
You must be signed in to change notification settings - Fork 68
WIP: net: Introduce dual-stream primary network tests #4774
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
Open
azhivovk
wants to merge
3
commits into
RedHatQE:main
Choose a base branch
from
azhivovk:new_rhcos9-10_tests_part2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from typing import Final | ||
|
|
||
| from ocp_resources.node import Node | ||
| from ocp_resources.resource import ResourceEditor | ||
|
|
||
| from libs.vm.vm import BaseVirtualMachine | ||
|
|
||
| HOSTNAME_LABEL: Final[str] = "kubernetes.io/hostname" | ||
| RHCOS_9_VERSION_PREFIX: Final[str] = "Red Hat Enterprise Linux CoreOS 9" | ||
| RHCOS_10_VERSION_PREFIX: Final[str] = "Red Hat Enterprise Linux CoreOS 10" | ||
|
|
||
|
|
||
| def node_by_rhcos_version(workers: list[Node], rhcos_version_prefix: str) -> Node: | ||
| """Return the first worker node whose OS image starts with the given RHCOS version prefix. | ||
|
|
||
| Args: | ||
| workers: List of worker nodes to search. | ||
| rhcos_version_prefix: Expected prefix of the node osImage field (e.g. "Red Hat Enterprise Linux CoreOS 9"). | ||
|
|
||
| Returns: | ||
| The first matching Node. | ||
|
|
||
| Raises: | ||
| ValueError: If no worker node matches the prefix. | ||
| """ | ||
| for node in workers: | ||
| if node.instance.status.nodeInfo.osImage.startswith(rhcos_version_prefix): | ||
| return node | ||
| raise ValueError(f"No worker node found with RHCOS version prefix: {rhcos_version_prefix!r}") | ||
|
|
||
|
|
||
| def update_vm_node_selector(vm: BaseVirtualMachine, node: Node) -> None: | ||
| """Patch the VM spec to pin it to the given node via nodeSelector. | ||
|
|
||
| Args: | ||
| vm: VirtualMachine to update. | ||
| node: Target worker node. | ||
| """ | ||
| ResourceEditor( | ||
| patches={vm: {"spec": {"template": {"spec": {"nodeSelector": {HOSTNAME_LABEL: node.hostname}}}}}} | ||
| ).update() |
43 changes: 43 additions & 0 deletions
43
tests/network/primary_network/rhel9_rhel10_cluster/conftest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from collections.abc import Generator | ||
|
|
||
| import pytest | ||
| from kubernetes.dynamic import DynamicClient | ||
| from ocp_resources.namespace import Namespace | ||
| from ocp_resources.node import Node | ||
|
|
||
| from libs.vm.vm import BaseVirtualMachine | ||
| from tests.network.primary_network.rhel9_rhel10_cluster.lib_helpers import primary_network_vm | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def primary_server_vm( | ||
| unprivileged_client: DynamicClient, | ||
| namespace: Namespace, | ||
| rhcos9_node: Node, | ||
| ) -> Generator[BaseVirtualMachine]: | ||
| with primary_network_vm( | ||
| namespace=namespace.name, | ||
| name="server-vm", | ||
| client=unprivileged_client, | ||
| node=rhcos9_node, | ||
| ) as vm: | ||
| vm.start(wait=True) | ||
| vm.wait_for_agent_connected() | ||
| yield vm | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def primary_client_vm( | ||
| unprivileged_client: DynamicClient, | ||
| namespace: Namespace, | ||
| rhcos9_node: Node, | ||
| ) -> Generator[BaseVirtualMachine]: | ||
| with primary_network_vm( | ||
| namespace=namespace.name, | ||
| name="client-vm", | ||
| client=unprivileged_client, | ||
| node=rhcos9_node, | ||
| ) as vm: | ||
| vm.start(wait=True) | ||
| vm.wait_for_agent_connected() | ||
| yield vm |
47 changes: 47 additions & 0 deletions
47
tests/network/primary_network/rhel9_rhel10_cluster/lib_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| from kubernetes.dynamic import DynamicClient | ||
| from ocp_resources.node import Node | ||
|
|
||
| from libs.vm.factory import base_vmspec, fedora_vm | ||
| from libs.vm.spec import CloudInitNoCloud, Devices, Interface, Network | ||
| from libs.vm.vm import BaseVirtualMachine, add_volume_disk, cloudinitdisk_storage | ||
| from tests.network.libs import cloudinit | ||
| from tests.network.libs.cloudinit import primary_iface_cloud_init | ||
| from tests.network.libs.nodes import HOSTNAME_LABEL | ||
|
|
||
|
|
||
| def primary_network_vm( | ||
| namespace: str, | ||
| name: str, | ||
| client: DynamicClient, | ||
| node: Node, | ||
| ) -> BaseVirtualMachine: | ||
| """Create a Fedora VM connected to the primary (masquerade) network only, pinned to a node. | ||
|
|
||
| Configures a static IPv6 address on the primary interface when the cluster supports IPv6. | ||
|
|
||
| Args: | ||
| namespace: Namespace in which the VM will be created. | ||
| name: Name of the VM. | ||
| client: Kubernetes dynamic client. | ||
| node: Worker node to pin the VM to via nodeSelector. | ||
|
|
||
| Returns: | ||
| Configured BaseVirtualMachine object (not yet started). | ||
| """ | ||
| spec = base_vmspec() | ||
| spec.template.spec.domain.devices = Devices(interfaces=[Interface(name="default", masquerade={})]) | ||
| spec.template.spec.networks = [Network(name="default", pod={})] | ||
| spec.template.spec.nodeSelector = {HOSTNAME_LABEL: node.hostname} | ||
|
|
||
| primary = primary_iface_cloud_init() | ||
| if primary is not None: | ||
| userdata = cloudinit.UserData(users=[]) | ||
| disk, volume = cloudinitdisk_storage( | ||
| data=CloudInitNoCloud( | ||
| networkData=cloudinit.asyaml(no_cloud=cloudinit.NetworkData(ethernets={"eth0": primary})), | ||
| userData=cloudinit.format_cloud_config(userdata=userdata), | ||
| ) | ||
| ) | ||
| spec.template.spec = add_volume_disk(vmi_spec=spec.template.spec, volume=volume, disk=disk) | ||
|
|
||
| return fedora_vm(namespace=namespace, name=name, client=client, spec=spec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.