# SPDX-License-Identifier: BSD-3-Clause
---
- name: Play for testing bond options
  hosts: all
  vars:
    controller_profile: bond0
    controller_device: nm-bond
    port1_profile: bond0.0
    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: Show playbook name
      debug:
        msg: "this is: playbooks/tests_bond_options.yml"
      tags:
        - always

    - name: Test the bond options
      tags:
        - tests::bond:create
      block:
        - name: Include the task 'run_test.yml'
          include_tasks: tasks/run_test.yml
          vars:
            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: "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: Reconfigure the bond options
      tags:
        - tests::states:reconfigure
      block:
        - name: Include the task 'run_test.yml'
          include_tasks: tasks/run_test.yml
          vars:
            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
