Skip to content

PortChannel or interface down status were not captured because of the 'rescue' block #1244

@wangxin

Description

@wangxin

Description

In the ansible/roles/test/tasks/interface.yml script, there are some logics to do further checking for debugging purpose in case of PortChannels or Interfaces are down.

- block:
  - name: Verify interfaces are up correctly
    assert: { that: "{{ ansible_interface_link_down_ports | length }} == 0" }
  rescue:
  - include: check_fanout_interfaces.yml
    vars:
      check_fanout: true
  - debug: msg="Not all Interfaces are up"

- block:
  - name: Verify port channel interfaces are up correctly
    assert: { that: "'{{ ansible_interface_facts[item]['active'] }}' == 'True'" }
    with_items: "{{ minigraph_portchannels.keys() }}"

  rescue:
  - include: check_sw_vm_interfaces.yml
    vars:
      check_vms: true
  - debug: msg="Not all PortChannels are up '{{ portchannel_status['stdout_lines'] }}' "
    when: portchannel_status is defined

The problem is caused by the "rescue" block. According to ansible documentation https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html:

"This will ‘revert’ the failed status of the task for the run and the play will continue as if it had succeeded."

The consequence is that ansible testing playbooks using this interface.yml file will not be failed as expected when PortChannels or interfaces are down because the failures have been rescued.
NTP_testing.txt

Steps to reproduce the issue:

  1. Bring down a PortChannel.
  2. Run an ansible test.

Describe the results you received:

Describe the results you expected:

Additional information you deem important:

**Output of `show version`:**

```
(paste your output here)
```

**Attach debug file `sudo generate_dump`:**

```
(paste your output here)
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions