---

### BGP not active

- name: not active - parse `show ip bgp summary`
  command_parser:
    file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_bgp_summary.yaml"
    content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_bgp_summary/bgp_not_active.txt') }}"
  register: result

- name: not active - test `show ip bgp summary` parser
  assert:
    that:
      - bgp['process_state'] == 'not active'

- name: clear facts
  meta: clear_facts

### IOS 15.1(2)T5.txt

- name: 15.1(2)T5.txt - parse `show ip bgp summary`
  command_parser:
    file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_bgp_summary.yaml"
    content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_bgp_summary/15.1(2)T5.txt') }}"
  register: result

- name: 15.1(2)T5.txt - test `show ip bgp summary` parser
  assert:
    that:
      - "'10.29.19.70' in bgp['neighbors']"
      - bgp['neighbors']['10.29.19.70']['state_pfxrcd'] | int == 1385
      - bgp['neighbors']['10.29.19.70']['asn'] | int == 7474
      - bgp['neighbors']['10.29.19.70']['ip_version'] | int == 4
      - bgp['neighbors']['10.29.19.70']['timer'] == '4d22h'

- name: clear facts
  meta: clear_facts

### IOS 12.2(33)SXH5.txt

- name: 12.2(33)SXH5.txt - parse `show ip bgp summary`
  command_parser:
    file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_bgp_summary.yaml"
    content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_bgp_summary/12.2(33)SXH5.txt') }}"
  register: result

- name: 12.2(33)SXH5.txt - test `show ip bgp summary` parser
  assert:
    that:
      - "'172.31.32.10' in bgp['neighbors']"
      - "'172.16.32.1' in bgp['neighbors']"
      - bgp['neighbors']['172.31.32.10']['state_pfxrcd'] | int == 114
      - bgp['neighbors']['172.31.32.10']['asn'] | int == 64910
      - bgp['neighbors']['172.31.32.10']['ip_version'] | int == 4
      - bgp['neighbors']['172.31.32.10']['timer'] == '23w5d'
      - bgp['neighbors']['172.16.32.1']['state_pfxrcd'] | int == 136
      - bgp['neighbors']['172.16.32.1']['asn'] | int == 65123
      - bgp['neighbors']['172.16.32.1']['ip_version'] | int == 4
      - "'{{ bgp['neighbors']['172.16.32.1']['timer'] | string }}' == '28w5d'"

- name: clear facts
  meta: clear_facts

### IOS-XE 03.14.00.S

- name: 03.14.00.S.txt - parse `show ip bgp summary`
  command_parser:
    file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_bgp_summary.yaml"
    content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_bgp_summary/03.14.00.S.txt') }}"
  register: result

- name: 03.14.00.S.txt - test `show ip bgp summary` parser
  assert:
    that:
      - "'10.15.17.2' in bgp['neighbors']"
      - "'10.1.19.2' in bgp['neighbors']"
      - "'72.31.0.13' in bgp['neighbors']"
      - bgp['neighbors']['10.15.17.2']['state_pfxrcd'] | int == 1125
      - bgp['neighbors']['10.15.17.2']['asn'] | int == 64785
      - bgp['neighbors']['10.15.17.2']['ip_version'] | int == 4
      - bgp['neighbors']['10.15.17.2']['timer'] == '7w1d'
      - bgp['neighbors']['10.1.19.2']['state_pfxrcd'] == 'Active'
      - bgp['neighbors']['10.1.19.2']['asn'] | int == 1234
      - bgp['neighbors']['10.1.19.2']['ip_version'] | int == 4
      - "'{{ bgp['neighbors']['10.1.19.2']['timer'] | string }}' == '00:00:30'"
      - bgp['neighbors']['72.31.0.13']['state_pfxrcd'] == 'Idle'
      - bgp['neighbors']['72.31.0.13']['asn'] | int == 65004
      - bgp['neighbors']['72.31.0.13']['ip_version'] | int == 4
      - "'{{ bgp['neighbors']['72.31.0.13']['timer'] | string }}' == '10:32:44'"

### Done

- name: all tests complete
  debug:
    msg: "All tests for `show ip bgp summary` passed"
