|
1 | 1 | import json |
2 | 2 | from typing import Final |
3 | 3 |
|
4 | | -from kubernetes.dynamic import DynamicClient |
5 | | - |
6 | | -from libs.net.cluster import ipv4_supported_cluster, ipv6_supported_cluster |
7 | 4 | from libs.net.traffic_generator import IPERF_SERVER_PORT, TcpServer |
8 | | -from libs.vm.factory import base_vmspec, fedora_vm |
9 | | -from libs.vm.spec import CloudInitNoCloud, Interface, Multus, Network |
10 | | -from libs.vm.vm import BaseVirtualMachine, add_volume_disk, cloudinitdisk_storage |
11 | | -from tests.network.libs import cloudinit |
| 5 | +from libs.vm.vm import BaseVirtualMachine |
12 | 6 |
|
13 | 7 | BANDWIDTH_SECONDARY_IFACE_NAME: Final[str] = "secondary" |
14 | 8 | BANDWIDTH_RATE_BPS: Final[int] = 10_000_000 # 10 Mbps |
@@ -84,64 +78,3 @@ def assert_bidir_throughput_within_limit( |
84 | 78 | f"Measured {direction} throughput {throughput_bps:.0f} bps exceeds " |
85 | 79 | f"configured limit {rate_bps} bps for {server_ip}" |
86 | 80 | ) |
87 | | - |
88 | | - |
89 | | -def secondary_network_vm( |
90 | | - namespace: str, |
91 | | - name: str, |
92 | | - client: DynamicClient, |
93 | | - nad_name: str, |
94 | | - secondary_iface_name: str, |
95 | | - secondary_iface_addresses: list[str], |
96 | | -) -> BaseVirtualMachine: |
97 | | - """Create a Fedora VM with a masquerade primary interface and a secondary Linux bridge interface. |
98 | | -
|
99 | | - Args: |
100 | | - namespace: Namespace to deploy the VM in. |
101 | | - name: VM name. |
102 | | - client: Kubernetes dynamic client. |
103 | | - nad_name: NetworkAttachmentDefinition name for the secondary interface. |
104 | | - secondary_iface_name: Name of the secondary network interface in the VM spec. |
105 | | - secondary_iface_addresses: CIDR addresses to assign to the secondary interface via cloud-init. |
106 | | - """ |
107 | | - spec = base_vmspec() |
108 | | - spec.template.spec.domain.devices.interfaces = [ # type: ignore |
109 | | - Interface(name="default", masquerade={}), |
110 | | - Interface(name=secondary_iface_name, bridge={}), |
111 | | - ] |
112 | | - spec.template.spec.networks = [ |
113 | | - Network(name="default", pod={}), |
114 | | - Network(name=secondary_iface_name, multus=Multus(networkName=nad_name)), |
115 | | - ] |
116 | | - |
117 | | - ethernets = {} |
118 | | - primary = _masquerade_iface_cloud_init() |
119 | | - if primary: |
120 | | - ethernets["eth0"] = primary |
121 | | - ethernets["eth1"] = cloudinit.EthernetDevice(addresses=secondary_iface_addresses) |
122 | | - |
123 | | - userdata = cloudinit.UserData(users=[]) |
124 | | - disk, volume = cloudinitdisk_storage( |
125 | | - data=CloudInitNoCloud( |
126 | | - networkData=cloudinit.asyaml(no_cloud=cloudinit.NetworkData(ethernets=ethernets)), |
127 | | - userData=cloudinit.format_cloud_config(userdata=userdata), |
128 | | - ) |
129 | | - ) |
130 | | - spec.template.spec = add_volume_disk(vmi_spec=spec.template.spec, volume=volume, disk=disk) |
131 | | - return fedora_vm(namespace=namespace, name=name, client=client, spec=spec) |
132 | | - |
133 | | - |
134 | | -def _masquerade_iface_cloud_init() -> cloudinit.EthernetDevice | None: |
135 | | - """Return cloud-init ethernet config for a masquerade (primary) interface. |
136 | | -
|
137 | | - Returns: |
138 | | - EthernetDevice with static IPv6 and optional DHCP4, or None if IPv6 is not supported. |
139 | | - """ |
140 | | - if not ipv6_supported_cluster(): |
141 | | - return None |
142 | | - return cloudinit.EthernetDevice( |
143 | | - addresses=["fd10:0:2::2/120"], |
144 | | - gateway6="fd10:0:2::1", |
145 | | - dhcp4=ipv4_supported_cluster(), |
146 | | - dhcp6=False, |
147 | | - ) |
0 commit comments