tests: add simple bond tests for both nm and initscripts

* add a helper to create two veth devices with IPv4/IPv6 infra
 * add a bond in active-backup mode with miimon value
 * add two slaves connections for two veth devices
 * check automated IPv4/IPv6 addresses are assigned to master
 * check all connections are present
 * add a helper to delete previously created veth device setup
This commit is contained in:
Vladimír Beneš 2020-06-15 09:58:37 +02:00 committed by Till Maas
parent cfa84c44c4
commit 6e85ffe5f2
5 changed files with 230 additions and 0 deletions

View file

@ -0,0 +1,96 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- hosts: all
vars:
master_profile: bond0
master_device: nm-bond
slave1_profile: bond0.0
dhcp_interface1: test1
slave2_profile: bond0.1
dhcp_interface2: test2
tasks:
- name: "INIT Prepare setup"
debug:
msg: "##################################################"
- import_tasks: tasks/create_test_interfaces_with_dhcp.yml
- import_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ dhcp_interface1 }}"
- import_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ dhcp_interface2 }}"
- block:
- name: "TEST Add Bond with 2 slaves"
debug:
msg: "##################################################"
- import_role:
name: linux-system-roles.network
vars:
network_connections:
# Create a bond master
- name: "{{ master_profile }}"
state: up
type: bond
interface_name: "{{ master_device }}"
bond:
mode: active-backup
miimon: 110
# add an ethernet to the bond
- name: "{{ slave1_profile }}"
state: up
type: ethernet
interface_name: "{{ dhcp_interface1 }}"
master: "{{ master_profile }}"
# add a second ethernet to the bond
- name: "{{ slave2_profile }}"
state: up
type: ethernet
interface_name: "{{ dhcp_interface2 }}"
master: "{{ master_profile }}"
- import_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ master_device }}"
- include_tasks: tasks/assert_profile_present.yml
vars:
profile: "{{ item }}"
loop:
- "{{ master_profile }}"
- "{{ slave1_profile }}"
- "{{ slave2_profile }}"
- command: grep 'Polling Interval' /proc/net/bonding/{{ master_device }}
name: "** TEST check polling interval"
register: result
until: "'110' in result.stdout"
- command: ip -4 a s {{ master_device }}
name: "** TEST check IPv4"
register: result
until: "'192.0.2' in result.stdout"
retries: 20
delay: 2
- command: ip -6 a s {{ master_device }}
name: "** TEST check IPv6"
register: result
until: "'2001' in result.stdout"
retries: 20
delay: 2
always:
- block:
- import_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ slave2_profile }}"
persistent_state: absent
state: down
- name: "{{ slave1_profile }}"
persistent_state: absent
state: down
- name: "{{ master_profile }}"
persistent_state: absent
state: down
ignore_errors: true
- command: ip link del {{ master_device }}
ignore_errors: true
- import_tasks: tasks/remove_test_interfaces_with_dhcp.yml
tags:
- "tests::cleanup"

View file

@ -0,0 +1,73 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Install dnsmasq
package:
name: dnsmasq
state: present
- name: Create test interfaces
shell: |
# NM to see veth devices starting with test* as managed after ip add..
echo 'ENV{ID_NET_DRIVER}=="veth",\
ENV{INTERFACE}=="test*", \
ENV{NM_UNMANAGED}="0"' >/etc/udev/rules.d/88-veth.rules
udevadm control --reload-rules
udevadm settle --timeout=5
# Setuptwo devices with IPv4/IPv6 auto support
ip link add {{dhcp_interface1}} type veth peer name {{dhcp_interface1}}p
ip link set {{dhcp_interface1}}p up
ip link add {{dhcp_interface2}} type veth peer name {{dhcp_interface2}}p
ip link set {{dhcp_interface2}}p up
# Create the 'testbr' - providing both 10.x ipv4 and 2620:52:0 ipv6 dhcp
ip link add name testbr type bridge forward_delay 0
ip link set testbr up
ip addr add 192.0.2.1/24 dev testbr
ip -6 addr add 2001:DB8::1/32 dev testbr
if grep 'release 6' /etc/redhat-release; then
# We need bridge-utils and radvd only in rhel6
if ! rpm -q --quiet radvd; then yum -y install radvd; fi
if ! rpm -q --quiet bridge-utils; then yum -y install bridge-utils; fi
# We need to add iptables rule to allow dhcp request
iptables -I INPUT -i testbr -p udp --dport 67:68 --sport 67:68 -j ACCEPT
# Add {{dhcp_interface1}}, {{dhcp_interface2}} peers into the testbr
brctl addif testbr {{dhcp_interface1}}p
brctl addif testbr {{dhcp_interface2}}p
# in RHEL6 /run is not present
mkdir -p /run
# and dnsmasq does not support ipv6
dnsmasq \
--pid-file=/run/dhcp_testbr.pid \
--dhcp-leasefile=/run/dhcp_testbr.lease \
--dhcp-range=192.0.2.1,192.0.2.254,240 \
--interface=testbr --bind-interfaces
# start radvd for ipv6
echo 'interface testbr {' > /etc/radvd.conf
echo ' AdvSendAdvert on;' >> /etc/radvd.conf
echo ' prefix 2001:DB8::/64 { ' >> /etc/radvd.conf
echo ' AdvOnLink on; }; ' >> /etc/radvd.conf
echo ' }; ' >> /etc/radvd.conf
# enable ipv6 forwarding
sysctl -w net.ipv6.conf.all.forwarding=1
service radvd restart
else
ip link set {{dhcp_interface1}}p master testbr
ip link set {{dhcp_interface2}}p master testbr
# Run joint DHCP4/DHCP6 server with RA enabled in veth namespace
dnsmasq \
--pid-file=/run/dhcp_testbr.pid \
--dhcp-leasefile=/run/dhcp_testbr.lease \
--dhcp-range=192.0.2.1,192.0.2.254,240 \
--dhcp-range=2001:DB8::10,2001:DB8::1FF,slaac,64,240 \
--enable-ra --interface=testbr --bind-interfaces
fi

View file

@ -0,0 +1,25 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Remove test interfaces
shell: |
ip link delete {{dhcp_interface1}}
ip link delete {{dhcp_interface2}}
ip link delete testbr
# Remove udev rule for NM to see veth devices starting with test*.....
rm -rf /etc/udev/rules.d/88-veth.rules
udevadm control --reload-rules
udevadm settle --timeout=5
- name: Stop dnsmasq/radvd services
shell: |
pkill -F /run/dhcp_testbr.pid
rm -rf /run/dhcp_testbr.pid
rm -rf /run/dhcp_testbr.lease
if grep 'release 6' /etc/redhat-release; then
# Stop radvd server
service radvd stop
iptables -D INPUT -i testbr -p udp --dport 67:68 --sport 67:68 -j ACCEPT
fi

View file

@ -0,0 +1,13 @@
# SPDX-License-Identifier: BSD-3-Clause
# This file was generated by ensure_provider_tests.py
---
- hosts: all
name: Run playbook 'playbooks/tests_bond.yml' with initscripts as provider
tasks:
- name: Set network provider to 'initscripts'
set_fact:
network_provider: initscripts
tags:
- always
- import_playbook: playbooks/tests_bond.yml

23
tests/tests_bond_nm.yml Normal file
View file

@ -0,0 +1,23 @@
# SPDX-License-Identifier: BSD-3-Clause
# This file was generated by ensure_provider_tests.py
---
# set network provider and gather facts
- hosts: all
name: Run playbook 'playbooks/tests_bond.yml' with nm as provider
tasks:
- name: Set network provider to 'nm'
set_fact:
network_provider: nm
tags:
- always
# workaround for: https://github.com/ansible/ansible/issues/27973
# There is no way in Ansible to abort a playbook hosts with specific OS
# releases Therefore we include the playbook with the tests only if the hosts
# would support it.
# The test requires or should run with NetworkManager, therefore it cannot run
# on RHEL/CentOS 6
- import_playbook: playbooks/tests_bond.yml
when:
- ansible_distribution_major_version != '6'