lib/network_utils.pm

network_utils

Functional methods to operate on network

setup_static_network

setup_static_network(ip => '10.0.2.15', gw => '10.0.2.1');

Configure static IP on SUT with setting up default GW. Also doing test ping to 10.0.2.2 to check that network is alive Set DNS server defined via required variable STATIC_DNS_SERVER

iface

iface([$quantity]);

Return first NIC which is not loopback

can_upload_logs

can_upload_logs([$gw]);

Returns if can ping worker host gateway

recover_network

recover_network([ip => $ip] [, gw => $gw]);

Recover network with static config if is feasible, returns if can ping GW. Main use case is post_fail_hook, to be able to upload logs.

Accepts following parameters :

ip => allowing to specify certain IP which would be used for recovery in case skiped '10.0.2.15/24' will be used as fallback.

gw => allowing to specify default gateway. Fallback to worker IP in case nothing specified.

ifc_exists

ifc_exists([$ifc]);

Return if ifconfig exists.

ifc_is_up

ifc_is_up([$ifc]);

Return only if network status is UP.

genmac

Generate custom MAC address. Used for Xen domU testing, to define MAC address once for whole test suite lifecycle.

genmac(['aa:bb:cc'])

cidr_to_netmask

Converts CIDR notation to a netmask string in IPv4 address format.

Sets the link speed, duplex settings, and autoneg status for specified NICs. Accepts hash reference containing NICs and their settings.

set_nics_link_speed_duplex({
  nics => ['eth0', 'eth1'],
  speed => 1000,       # Speed in Mbps
  duplex => 'full',    # Duplex type: 'full' or 'half'
  autoneg => 'off'     # Auto-negotiation: 'on' or 'off'
});

check_connectivity_to_host_with_retry

Checks connectivity from a specified bonding interface to a host.

This function pings a designated host from a specified bonding interface. It uses the function validate_script_output_retry to retry the ping command multiple times.

check_connectivity_to_host_with_retry('bond0', '192.168.1.1');

get_nics

Retrieves a list of network interfaces, excluding specified ones and the loopback interface.

This function scans for network interfaces available on the system, optionally ignoring specified interfaces and always excluding the loopback interface. It's particularly useful for scripts that need to dynamically determine which network interfaces to operate on, allowing for exclusion of interfaces that are not of interest.

get_nics(['bond0', 'bond1']);

is_nm_used

Check if NetworkManager service is active.

is_wicked_used

Check if wicked service is active.