---

# LLDP Topology Tests

- name: Gather lldp topology
  eos_command:
    commands: "show lldp neighbors detail | json"
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: lldp_topology_state
  tags:
    - lldp_topology

- name: Validate lldp topology when there is no domain name
  assert:
    that:
      - lldp_topology_state.stdout[0].lldpNeighbors[ethernet_interface.key].lldpNeighborInfo[0] is defined
      - lldp_topology_state.stdout[0].lldpNeighbors[ethernet_interface.key].lldpNeighborInfo[0].systemName == ethernet_interface.value.peer
      - lldp_topology_state.stdout[0].lldpNeighbors[ethernet_interface.key].lldpNeighborInfo[0].neighborInterfaceInfo.interfaceId == "\"" + ethernet_interface.value.peer_interface + "\""
    fail_msg: "{{ lldp_topology_state.stdout[0].lldpNeighbors[ethernet_interface.key].lldpNeighborInfo[0].systemName | default('Interface Down') }} - {{ lldp_topology_state.stdout[0].lldpNeighbors[ethernet_interface.key].lldpNeighborInfo[0].neighborInterfaceInfo.interfaceId | default('N/A') | replace('\"','') }}"
    quiet: true
  loop: "{{ ethernet_interfaces | default({}, true) | dict2items }}"
  loop_control:
    loop_var: ethernet_interface
  when: |
    (ethernet_interfaces is defined and ethernet_interfaces is not none) and
    (ethernet_interface.value.peer is defined and ethernet_interface.value.peer is not none) and
    (ethernet_interface.value.peer_interface is defined and ethernet_interface.value.peer_interface is not none) and
    (hostvars[ethernet_interface.value.peer] is defined and hostvars[ethernet_interface.value.peer] is not none)
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: lldp_topology_results
  tags:
    - lldp_topology
