Skip to content
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

test: Rewrite tests_bond_options.yml in new testing format #671

Merged
merged 4 commits into from
Feb 15, 2024
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
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
when:
- not network_packages is subset(ansible_facts.packages.keys())
register: __network_package_install
until: __network_package_install is success
retries: 6
delay: 10

- name: Install NetworkManager and nmstate when using network_state variable
package:
Expand Down
2 changes: 1 addition & 1 deletion tests/ensure_provider_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"playbooks/tests_provider.yml": {
MINIMUM_VERSION: "'1.20.0'",
"comment": "# NetworKmanager 1.20.0 added support for forgetting profiles",
EXTRA_RUN_CONDITION: "ansible_distribution != 'RedHat' or\n ansible_distr\
EXTRA_RUN_CONDITION: "ansible_distribution not in ['RedHat', 'CentOS'] or\n ansible_distr\
ibution_major_version | int < 9",
},
"playbooks/tests_eth_pci_address_match.yml": {
Expand Down
2 changes: 2 additions & 0 deletions tests/playbooks/tests_802_1x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@
- name: Update ca trust
command: update-ca-trust
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
2 changes: 2 additions & 0 deletions tests/playbooks/tests_auto_gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,5 @@
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
2 changes: 2 additions & 0 deletions tests/playbooks/tests_bond.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
2 changes: 2 additions & 0 deletions tests/playbooks/tests_bond_cloned_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
12 changes: 12 additions & 0 deletions tests/playbooks/tests_bond_deprecated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ dhcp_interface2 }}"
- name: "Backup the /etc/resolv.conf for initscript"
command: cp -vf /etc/resolv.conf /etc/resolv.conf.bak
when:
- network_provider == "initscripts"
changed_when: false
- name: Test bond device using deprecated 'master' argument
block:
- name: "TEST Add Bond with 2 ports using deprecated 'master' argument"
Expand Down Expand Up @@ -113,3 +118,10 @@
changed_when: false
- name: Import the task 'remove_test_interfaces_with_dhcp.yml'
import_tasks: tasks/remove_test_interfaces_with_dhcp.yml
- name: "Restore the /etc/resolv.conf for initscript"
command: mv -vf /etc/resolv.conf.bak /etc/resolv.conf
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
265 changes: 74 additions & 191 deletions tests/playbooks/tests_bond_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,201 +9,84 @@
dhcp_interface1: test1
port2_profile: bond0.1
dhcp_interface2: test2
lsr_fail_debug:
- __network_connections_result
bond_options_to_assert:
- {key: 'mode', value: '802.3ad'}
- {key: 'ad_actor_sys_prio', value: '65535'}
- {key: 'ad_actor_system', value: '00:00:5e:00:53:5d'}
- {key: 'ad_select', value: 'stable'}
- {key: 'ad_user_port_key', value: '1023'}
# wokeignore:rule=slave
- {key: 'all_slaves_active', value: '1'}
- {key: 'downdelay', value: '0'}
- {key: 'lacp_rate', value: 'slow'}
- {key: 'lp_interval', value: '128'}
- {key: 'miimon', value: '110'}
- {key: 'num_grat_arp', value: '64'}
- {key: 'resend_igmp', value: '225'}
- {key: 'updelay', value: '0'}
- {key: 'use_carrier', value: '1'}
- {key: 'xmit_hash_policy', value: 'encap2+3'}
tasks:
- name: "INIT Prepare setup"
- name: Show playbook name
debug:
msg: "##################################################"
- name: Import the task 'create_test_interfaces_with_dhcp.yml'
import_tasks: tasks/create_test_interfaces_with_dhcp.yml
- name: Import the task 'assert_device_present.yml'
import_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ dhcp_interface1 }}"
- name: Import the task 'assert_device_present.yml'
import_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ dhcp_interface2 }}"
- name: Test bond options
block:
- name: "TEST Add Bond with 2 ports"
debug:
msg: "##################################################"
- name: Configure the bond options
import_role:
name: linux-system-roles.network
vars:
network_connections:
# Create a bond controller
- name: "{{ controller_profile }}"
state: up
type: bond
interface_name: "{{ controller_device }}"
bond:
mode: 802.3ad
ad_actor_sys_prio: 65535
ad_actor_system: 00:00:5e:00:53:5d
ad_select: stable
ad_user_port_key: 1023
all_ports_active: true
downdelay: 0
lacp_rate: slow
lp_interval: 128
miimon: 110
min_links: 0
num_grat_arp: 64
primary_reselect: better
resend_igmp: 225
updelay: 0
use_carrier: true
xmit_hash_policy: encap2+3
ip:
route_metric4: 65535
msg: "this is: playbooks/tests_bond_options.yml"
tags:
- always

# add an ethernet to the bond
- name: "{{ port1_profile }}"
state: up
type: ethernet
interface_name: "{{ dhcp_interface1 }}"
controller: "{{ controller_profile }}"
# add a second ethernet to the bond
- name: "{{ port2_profile }}"
state: up
type: ethernet
interface_name: "{{ dhcp_interface2 }}"
controller: "{{ controller_profile }}"
- name: Import the task 'assert_device_present.yml'
import_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ controller_device }}"
- name: Include the task 'assert_profile_present.yml'
include_tasks: tasks/assert_profile_present.yml
- name: Test the bond options
tags:
- tests::bond:create
block:
- name: Include the task 'run_test.yml'
include_tasks: tasks/run_test.yml
vars:
profile: "{{ item }}"
loop:
- "{{ controller_profile }}"
- "{{ port1_profile }}"
- "{{ port2_profile }}"
lsr_description: Given two DHCP-enabled network interfaces,
when creating a bond profile with them,
then the controller device and bond port profiles are present and
the specified bond options are set for the controller device.
lsr_setup:
- tasks/create_test_interfaces_with_dhcp.yml
- tasks/assert_dhcp_device_present.yml
lsr_test:
- tasks/create_bond_profile.yml
lsr_assert:
- tasks/assert_controller_device_present.yml
- tasks/assert_bond_port_profile_present.yml
- tasks/assert_bond_options.yml
lsr_cleanup:
- tasks/cleanup_bond_profile+device.yml
- tasks/remove_test_interfaces_with_dhcp.yml

- name: "** TEST check bond settings"
command: cat
/sys/class/net/{{ controller_device }}/bonding/'{{ item.key }}'
register: result
until: "'{{ item.value }}' in result.stdout"
loop:
- {key: 'mode', value: '802.3ad'}
- {key: 'ad_actor_sys_prio', value: '65535'}
- {key: 'ad_actor_system', value: '00:00:5e:00:53:5d'}
- {key: 'ad_select', value: 'stable'}
- {key: 'ad_user_port_key', value: '1023'}
# wokeignore:rule=slave
- {key: 'all_slaves_active', value: '1'}
- {key: 'downdelay', value: '0'}
- {key: 'lacp_rate', value: 'slow'}
- {key: 'lp_interval', value: '128'}
- {key: 'miimon', value: '110'}
- {key: 'num_grat_arp', value: '64'}
- {key: 'resend_igmp', value: '225'}
- {key: 'updelay', value: '0'}
- {key: 'use_carrier', value: '1'}
- {key: 'xmit_hash_policy', value: 'encap2+3'}
changed_when: false
- name: "Reset bond options to assert"
set_fact:
bond_options_to_assert:
- {key: 'mode', value: 'active-backup'}
- {key: 'arp_interval', value: '60'}
- {key: 'arp_ip_target', value: '192.0.2.128'}
- {key: 'arp_validate', value: 'none'}
- {key: 'primary', value: '{{ dhcp_interface1 }}'}

- name: "** TEST check IPv4"
command: ip -4 a s {{ controller_device }}
register: result
until: "'192.0.2' in result.stdout"
retries: 20
delay: 2
changed_when: false
- name: "** TEST check IPv6"
command: ip -6 a s {{ controller_device }}
register: result
until: "'2001' in result.stdout"
retries: 20
delay: 2
changed_when: false

- name: Reconfigure the bond options
import_role:
name: linux-system-roles.network
- name: Reconfigure the bond options
tags:
- tests::states:reconfigure
block:
- name: Include the task 'run_test.yml'
include_tasks: tasks/run_test.yml
vars:
network_connections:
# Create a bond controller
- name: "{{ controller_profile }}"
state: up
type: bond
interface_name: "{{ controller_device }}"
bond:
mode: active-backup
arp_interval: 60
arp_ip_target: 192.0.2.128
arp_validate: none
primary: "{{ dhcp_interface1 }}"
ip:
route_metric4: 65535
# add an ethernet to the bond
- name: "{{ port1_profile }}"
state: up
type: ethernet
interface_name: "{{ dhcp_interface1 }}"
controller: "{{ controller_profile }}"
# add a second ethernet to the bond
- name: "{{ port2_profile }}"
state: up
type: ethernet
interface_name: "{{ dhcp_interface2 }}"
controller: "{{ controller_profile }}"
- name: "** TEST check bond settings"
command: cat
/sys/class/net/{{ controller_device }}/bonding/'{{ item.key }}'
register: result
until: "'{{ item.value }}' in result.stdout"
loop:
- {key: 'mode', value: 'active-backup'}
- {key: 'arp_interval', value: '60'}
- {key: 'arp_ip_target', value: '192.0.2.128'}
- {key: 'arp_validate', value: 'none'}
- {key: 'primary', value: '{{ dhcp_interface1 }}'}
changed_when: false

- name: "** TEST check IPv4"
command: ip -4 a s {{ controller_device }}
register: result
until: "'192.0.2' in result.stdout"
retries: 20
delay: 2
changed_when: false
- name: "** TEST check IPv6"
command: ip -6 a s {{ controller_device }}
register: result
until: "'2001' in result.stdout"
retries: 20
delay: 2
changed_when: false

always:
- name: Clean up the test devices and the connection profiles
tags:
- "tests::cleanup"
block:
- name: Import network role
import_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ port2_profile }}"
persistent_state: absent
state: down
- name: "{{ port1_profile }}"
persistent_state: absent
state: down
- name: "{{ controller_profile }}"
persistent_state: absent
state: down
failed_when: false
- name: Delete the device '{{ controller_device }}'
command: ip link del {{ controller_device }}
failed_when: false
changed_when: false
- name: Import the task 'remove_test_interfaces_with_dhcp.yml'
import_tasks: tasks/remove_test_interfaces_with_dhcp.yml
lsr_description: Given two DHCP-enabled network interfaces,
when creating a bond profile with them,
then the controller device and bond port profiles are present and
the specified bond options are set for the controller device.
lsr_setup:
- tasks/create_test_interfaces_with_dhcp.yml
- tasks/assert_dhcp_device_present.yml
lsr_test:
- tasks/create_bond_profile_reconfigure.yml
lsr_assert:
- tasks/assert_bond_options.yml
lsr_cleanup:
- tasks/cleanup_bond_profile+device.yml
- tasks/remove_test_interfaces_with_dhcp.yml
- tasks/check_network_dns.yml
2 changes: 2 additions & 0 deletions tests/playbooks/tests_bond_removal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,5 @@
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
6 changes: 6 additions & 0 deletions tests/playbooks/tests_bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@
import_playbook: run_tasks.yml
vars:
task: tasks/assert_device_absent.yml

- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
6 changes: 6 additions & 0 deletions tests/playbooks/tests_bridge_cloned_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"

- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
2 changes: 2 additions & 0 deletions tests/playbooks/tests_checkpoint_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@
- name: Delete the device '{{ interface }}'
command: ip link del "{{ interface }}"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
1 change: 1 addition & 0 deletions tests/playbooks/tests_dummy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
- tasks/assert_device_present.yml
lsr_cleanup:
- tasks/cleanup_profile+device.yml
- tasks/check_network_dns.yml
2 changes: 2 additions & 0 deletions tests/playbooks/tests_eth_dns_support.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...
2 changes: 2 additions & 0 deletions tests/playbooks/tests_eth_pci_address_match.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@
persistent_state: absent
state: down
failed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
Loading
Loading