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
9 changes: 7 additions & 2 deletions libs/vm/factory.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

from kubernetes.dynamic import DynamicClient
from pytest_testconfig import config as py_config
Comment thread
yossisegev marked this conversation as resolved.
Comment thread
yossisegev marked this conversation as resolved.

from libs.vm.spec import CPU, Devices, Domain, Memory, Metadata, Template, VMISpec, VMSpec
from libs.vm.vm import BaseVirtualMachine, container_image, containerdisk_storage
from utilities.constants import OS_FLAVOR_FEDORA, Images
from utilities import constants
from utilities.constants import MULTIARCH, OS_FLAVOR_FEDORA


def fedora_vm(
Expand All @@ -29,14 +31,17 @@ def fedora_vm(


def fedora_image() -> str:
return container_image(base_image=Images.Fedora.FEDORA_CONTAINER_IMAGE)
return container_image(base_image=constants.Images.Fedora.FEDORA_CONTAINER_IMAGE)


def _fill_vm_spec_defaults(spec: VMSpec | None) -> VMSpec:
spec = spec or base_vmspec()

vmi_spec = spec.template.spec

if not vmi_spec.architecture and py_config.get("cluster_type") == MULTIARCH:
cpu_arch = py_config.get("cpu_arch")
vmi_spec.architecture = cpu_arch
vmi_spec.domain.devices = vmi_spec.domain.devices or Devices(rng={})
vmi_spec.domain.devices.disks = vmi_spec.domain.devices.disks or []
vmi_spec.volumes = vmi_spec.volumes or []
Expand Down
1 change: 1 addition & 0 deletions libs/vm/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Metadata:
@dataclass
class VMISpec:
domain: Domain
architecture: str | None = None
networks: list[Network] | None = None
volumes: list[Volume] | None = None
terminationGracePeriodSeconds: int | None = None # noqa: N815
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@
"""

import ipaddress
from typing import Final

import pytest

from libs.net.traffic_generator import TcpServer, client_server_active_connection, is_tcp_connection
from libs.net.traffic_generator import VMTcpClient as TcpClient
from libs.net.vmspec import lookup_iface_status_ip, lookup_primary_network
from libs.vm.vm import BaseVirtualMachine
from tests.network.libs import cloudinit
from tests.network.user_defined_network.ip_specification.libipspec import (
ip_address_annotation,
read_guest_interface_ipv4,
)
from utilities.constants import PUBLIC_DNS_SERVER_IP
from utilities.virt import migrate_vm_and_verify

FIRST_GUEST_IFACE_NAME: Final[str] = "eth0"


@pytest.mark.ipv4
@pytest.mark.single_nic
Expand Down Expand Up @@ -62,7 +58,7 @@ def test_vm_is_started_with_successful_connectivity(
- IP address to specify on under-test VM.

Steps:
1. Set IP address on under-test VM through annotation and cloud-init network-data.
1. Set IP address on under-test VM through annotation.
2. Start the VM and wait for the Ip to be reported on the VMI status.
3. Establish TCP connectivity from the ref VM to the under-test VM.

Expand All @@ -75,22 +71,16 @@ def test_vm_is_started_with_successful_connectivity(
template_annotations=ip_address_annotation(ip_address=ip_to_request, network_name=vm_logical_net_name)
)

netdata = cloudinit.NetworkData(
Comment thread
yossisegev marked this conversation as resolved.
ethernets={
FIRST_GUEST_IFACE_NAME: cloudinit.EthernetDevice(
addresses=[str(ip_to_request)],
gateway4=str(next(ipaddress.ip_network(address=ip_to_request, strict=False).hosts())),
)
}
)
vm_under_test.add_cloud_init(netdata=netdata)

vm_under_test.start()
vm_under_test.wait_for_agent_connected()
assigned_ip = lookup_iface_status_ip(vm=vm_under_test, iface_name=vm_logical_net_name, ip_family=4)

assert assigned_ip == ip_to_request.ip
assert read_guest_interface_ipv4(vm=vm_under_test, interface_name=FIRST_GUEST_IFACE_NAME) == ip_to_request
guest_ipv4 = read_guest_interface_ipv4(
vm=vm_under_test,
interface_name=vm_under_test.vmi.interfaces[0].interfaceName,
Comment thread
yossisegev marked this conversation as resolved.
Comment thread
yossisegev marked this conversation as resolved.
)
assert guest_ipv4 == ip_to_request

with client_server_active_connection(
client_vm=vm_for_connectivity_ref,
Expand All @@ -106,7 +96,7 @@ def test_successful_external_connectivity(self, vm_under_test: BaseVirtualMachin

Preconditions:
- Running under-test VM, with a primary UDN network and an IP address specified
(through annotation & cloud-init).
(through annotation).

Steps:
1. Execute a ping command from the under-test VM to the external IP address.
Expand All @@ -126,7 +116,7 @@ def test_seamless_cluster_connectivity_is_preserved_over_live_migration(

Preconditions:
- Running under-test VM, with a primary UDN network and an IP address specified
(through annotation & cloud-init).
(through annotation).
- Running connectivity reference VM, with a primary UDN network.
- Established TCP connectivity from the ref VM to the under-test VM.

Expand Down Expand Up @@ -154,7 +144,7 @@ def test_ip_address_is_preserved_over_power_cycle(

Preconditions:
- Running under-test VM, with a primary UDN network and an IP address specified
(through annotation & cloud-init).
(through annotation).
- The specified IP address on the under-test VM.

Steps:
Expand All @@ -170,4 +160,8 @@ def test_ip_address_is_preserved_over_power_cycle(
assigned_ip = lookup_iface_status_ip(vm=vm_under_test, iface_name=vm_logical_net_name, ip_family=4)

assert assigned_ip == ip_to_request.ip
assert read_guest_interface_ipv4(vm=vm_under_test, interface_name=FIRST_GUEST_IFACE_NAME) == ip_to_request
guest_ipv4 = read_guest_interface_ipv4(
vm=vm_under_test,
interface_name=vm_under_test.vmi.interfaces[0].interfaceName,
)
assert guest_ipv4 == ip_to_request