# SPDX-License-Identifier: BSD-3-Clause
---
- name: Test configuring bridges
  hosts: all
  vars:
    interface: "LSR-TST-br31"
    cloned_mac: "12:23:34:45:56:70"
  tasks:
    - name: Add test bridge
      include_role:
        name: linux-system-roles.network
      vars:
        network_connections:
          - name: "{{ interface }}"
            interface_name: "{{ interface }}"
            state: up
            type: bridge
            ip:
              dhcp4: false
              auto6: true
            cloned_mac: "{{ cloned_mac }}"

    - name: Verify ifcfg MACADDR entry
      command: >-
        grep ^MACADDR= /etc/sysconfig/network-scripts/ifcfg-{{ interface }}
      register: cloned_mac_address_init
      changed_when: false
      when:
        - network_provider == "initscripts"

    - name: Verify nmcli cloned-mac-address entry
      command: >-
        nmcli -f 802-3-ethernet.cloned-mac-address con show {{ interface }}
      register: cloned_mac_address_nm
      ignore_errors: true
      changed_when: false
      when:
        - network_provider == "nm"

    - name: Assert that cloned-mac-address addresses are configured correctly
      assert:
        that:
          - >-
            cloned_mac_address_init.stdout is not defined or
            cloned_mac_address_init.stdout.find(cloned_mac) != -1
          - >-
            cloned_mac_address_nm.stdout is not defined or
            cloned_mac_address_nm.stdout.find(cloned_mac) != -1
        msg: "cloned-mac-address is configured incorrectly"

    - name: Include the tasks 'down_profile+delete_interface.yml'
      include_tasks: tasks/down_profile+delete_interface.yml
      vars:
        profile: "{{ interface }}"

    - name: Include the task 'remove_profile.yml'
      include_tasks: tasks/remove_profile.yml
      vars:
        profile: "{{ interface }}"

    - name: Verify network state restored to default
      include_tasks: tasks/check_network_dns.yml
