From cd161238519dd5bc35359cfee5763bc744a3b773 Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:15:33 -0500 Subject: [PATCH 1/8] add ospf parser --- .../cli/show_ip_ospf_neighbor.yaml | 79 +++++++++++++++++++ .../cli/show_ip_ospf_neighbor/15.4(3r)M1.txt | 5 ++ .../cli/show_ip_ospf_neighbor/main.yaml | 41 ++++++++++ .../show_ip_ospf_neighbor/ospf_not_active.txt | 0 tests/test_parser_templates.yaml | 27 ++++--- vars/get_facts_command_map.yaml | 7 ++ 6 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 parser_templates/cli/show_ip_ospf_neighbor.yaml create mode 100644 tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt create mode 100644 tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml create mode 100644 tests/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml new file mode 100644 index 0000000..6a1ab68 --- /dev/null +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -0,0 +1,79 @@ +--- + +- name: show_ip_ospf_neighbor + parser_metadata: + version: 1.0 + command: show ip ospf neighbor + network_os: ios + +- name: match not active + register: not_active + pattern_match: + regex: ".+" + match_all: true + +- name: set_vars ospf state not active + set_vars: + process_state: "not active" + +- name: set_vars ospf state active + set_vars: + process_state: "active" + when: "not_active.0.matches | length > 0" + +- name: match sections + register: context + pattern_match: + regex: "Neighbor.+" + match_all: yes + match_greedy: yes + when: process_state == 'active' + +- name: match lines + register: lines + pattern_match: + regex: "^[0-9a-z.].+" + content: "{{ context.0 }}" + match_all: yes + match_greedy: yes + when: process_state == 'active' + +- name: match neighbors + register: matched_neighbors + loop: "{{ lines }}" + pattern_match: + regex: "(?P^[0-9a-z.]+)\\s+(?P\\d)\\s+(?P([A-Z]|.)+)/(?P([A-Z]|.)+)\\s(?P[0-9][0-9]:[0-5][0-9]:[0-5][0-9])\\s(?P.+\\s)\\s(?P.+)" + content: "{{ item }}" + when: process_state == 'active' + +- name: template ospf values + extend: cisco_ios + register: ospf + export: true + export_as: dict + json_template: + template: + - key: "process_state" + value: "{{ process_state }}" + +- name: template ospf neighbor entries + extend: cisco_ios.ospf + register: neighbors + export: true + export_as: dict + loop: "{{ matched_neighbors }}" + when: process_state == 'active' + json_template: + template: + - key: "{{ item.neighbor }}" + object: + - key: address + value: "{{ item.ip | trim }}" + - key: state + value: "{{ item.state | trim }}" + - key: role + value: "{{ item.role | trim }}" + - key: timer + value: "{{ item.timer | trim}}" + - key: interface + value: "{{ item.interface | trim }}" diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt new file mode 100644 index 0000000..0bbce91 --- /dev/null +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt @@ -0,0 +1,5 @@ + +Neighbor ID Pri State Dead Time Address Interface +ansi06a1.redhat 0 FULL/ - 00:00:37 130.200.191.21 Tunnel821 +ansi07a2.redhat 0 FULL/ - 00:00:32 25.131.8.25 Tunnel825 +rdurtr03ab.ansi 0 FULL/ - 00:00:36 191.11.131.5 Tunnel85 diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml new file mode 100644 index 0000000..dddbedb --- /dev/null +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml @@ -0,0 +1,41 @@ +--- + +### OSPF not active + +- name: not active - parse `show ip ospf neighbor` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_ospf_neighbor.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt') }}" + register: result + +- name: not active - test `show ip ospf neighbor` parser + assert: + that: + - cisco_ios.ospf['process_state'] == 'not active' + +- name: clear facts + meta: clear_facts + +### IOS 15.4(3r)M1.txt + +- name: 15.4(3r)M1.txt - parse `show ip ospf neighbor` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_ospf_neighbor.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt') }}" + register: result + +- name: 15.4(3r)M1.txt - test `show ip ospf neighbor` parser + assert: + that: + - "'ansi06a1.redhat' in cisco_ios.ospf['neighbors']" + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['address'] == '130.200.191.21' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['state'] == 'FULL' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['role'] == '-' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['timer'] == '00:00:37' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['interface'] == 'Tunnel821' + +### Done + +- name: all tests complete + debug: + msg: "All tests for `show ip ospf summary` passed" diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt b/tests/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_parser_templates.yaml b/tests/test_parser_templates.yaml index ca8cf76..369ae41 100755 --- a/tests/test_parser_templates.yaml +++ b/tests/test_parser_templates.yaml @@ -10,17 +10,22 @@ tasks: - - name: Include tests for `show ip bgp summary` - include_tasks: parser_templates/cli/show_ip_bgp_summary/main.yaml - vars: - bgp: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['bgp'] }}" + #- name: Include tests for `show ip bgp summary` + # include_tasks: parser_templates/cli/show_ip_bgp_summary/main.yaml + # vars: + # bgp: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['bgp'] }}" - - name: Include tests for `show ip vrf detail` - include_tasks: parser_templates/cli/show_ip_vrf_detail/main.yaml - vars: - vrfs: "{{ cisco_ios['vrf'] }}" + #- name: Include tests for `show ip vrf detail` + # include_tasks: parser_templates/cli/show_ip_vrf_detail/main.yaml + # vars: + # vrfs: "{{ cisco_ios['vrf'] }}" - - name: Include tests for `show version` - include_tasks: parser_templates/cli/show_version/main.yaml + - name: Include tests for `show ip ospf neighbor` + include_tasks: parser_templates/cli/show_ip_ospf_neighbor/main.yaml vars: - system: "{{ cisco_ios['system'] }}" + system: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['ospf'] }}" + + #- name: Include tests for `show version` + # include_tasks: parser_templates/cli/show_version/main.yaml + # vars: + # system: "{{ cisco_ios['system'] }}" diff --git a/vars/get_facts_command_map.yaml b/vars/get_facts_command_map.yaml index 501fd5b..46fa35a 100644 --- a/vars/get_facts_command_map.yaml +++ b/vars/get_facts_command_map.yaml @@ -60,3 +60,10 @@ - all - vrf - routing + +- command: show ip ospf neighbor + parser: show_ip_ospf_neighbor.yaml + groups: + - all + - ospf + - routing From 1ba88ab4c0904c56cda50e1b3d0ec9f5455b6241 Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:38:45 -0500 Subject: [PATCH 2/8] fix regex --- parser_templates/cli/show_ip_ospf_neighbor.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml index 6a1ab68..3d415d1 100644 --- a/parser_templates/cli/show_ip_ospf_neighbor.yaml +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -42,7 +42,7 @@ register: matched_neighbors loop: "{{ lines }}" pattern_match: - regex: "(?P^[0-9a-z.]+)\\s+(?P\\d)\\s+(?P([A-Z]|.)+)/(?P([A-Z]|.)+)\\s(?P[0-9][0-9]:[0-5][0-9]:[0-5][0-9])\\s(?P.+\\s)\\s(?P.+)" + regex: "(?P^[0-9a-z.]+)\\s+(?P\\d)\\s+(?P([A-Z]|.)+)/(?P([A-Z]|.)+)\\s(?P[0-9][0-9]:[0-5][0-9]:[0-5][0-9])\\s(?P.+\\s)(?P[A-Z].+)" content: "{{ item }}" when: process_state == 'active' From 8a5e405f0fcc0e3bf480544a717ce61ba6e1752c Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:43:38 -0500 Subject: [PATCH 3/8] fix regex --- parser_templates/cli/show_ip_ospf_neighbor.yaml | 6 +++--- .../cli/show_ip_ospf_neighbor/15.4(3r)M1.txt | 2 +- .../cli/show_ip_ospf_neighbor/main.yaml | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml index 3d415d1..8b40fc0 100644 --- a/parser_templates/cli/show_ip_ospf_neighbor.yaml +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -65,10 +65,10 @@ when: process_state == 'active' json_template: template: - - key: "{{ item.neighbor }}" + - key: "{{ item.ip }}" object: - - key: address - value: "{{ item.ip | trim }}" + - key: neighbor_id + value: "{{ item.neighbor | trim }}" - key: state value: "{{ item.state | trim }}" - key: role diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt index 0bbce91..cf872c5 100644 --- a/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt @@ -2,4 +2,4 @@ Neighbor ID Pri State Dead Time Address Interface ansi06a1.redhat 0 FULL/ - 00:00:37 130.200.191.21 Tunnel821 ansi07a2.redhat 0 FULL/ - 00:00:32 25.131.8.25 Tunnel825 -rdurtr03ab.ansi 0 FULL/ - 00:00:36 191.11.131.5 Tunnel85 +ansi06a1.redhat 0 FULL/ - 00:00:36 191.11.131.5 Tunnel85 diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml index dddbedb..b7a89c1 100644 --- a/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml @@ -27,12 +27,12 @@ - name: 15.4(3r)M1.txt - test `show ip ospf neighbor` parser assert: that: - - "'ansi06a1.redhat' in cisco_ios.ospf['neighbors']" - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['address'] == '130.200.191.21' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['state'] == 'FULL' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['role'] == '-' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['timer'] == '00:00:37' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['interface'] == 'Tunnel821' + - "'130.200.191.21' in cisco_ios.ospf['neighbors']" + - cisco_ios.ospf['neighbors']['130.200.191.21']['neighbor_id'] == 'ansi06a1.redhat' + - cisco_ios.ospf['neighbors']['130.200.191.21']['state'] == 'FULL' + - cisco_ios.ospf['neighbors']['130.200.191.21']['role'] == '-' + - cisco_ios.ospf['neighbors']['130.200.191.21']['timer'] == '00:00:37' + - cisco_ios.ospf['neighbors']['130.200.191.21']['interface'] == 'Tunnel821' ### Done From 83da8bb8488f5bcf010ed05a6d5e05ca3c01c683 Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:44:20 -0500 Subject: [PATCH 4/8] fix regex Signed-off-by: willtome --- parser_templates/cli/show_ip_ospf_neighbor.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml index 8b40fc0..4e6cc58 100644 --- a/parser_templates/cli/show_ip_ospf_neighbor.yaml +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -65,7 +65,7 @@ when: process_state == 'active' json_template: template: - - key: "{{ item.ip }}" + - key: "{{ item.ip | trim }}" object: - key: neighbor_id value: "{{ item.neighbor | trim }}" From 008b290a69eb8414feaa95552192e28f19e38b57 Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:15:33 -0500 Subject: [PATCH 5/8] add ospf parser --- .../cli/show_ip_ospf_neighbor.yaml | 79 +++++++++++++++++++ .../cli/show_ip_ospf_neighbor/15.4(3r)M1.txt | 5 ++ .../cli/show_ip_ospf_neighbor/main.yaml | 41 ++++++++++ .../show_ip_ospf_neighbor/ospf_not_active.txt | 0 tests/test_parser_templates.yaml | 26 ++++-- vars/get_facts_command_map.yaml | 7 ++ 6 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 parser_templates/cli/show_ip_ospf_neighbor.yaml create mode 100644 tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt create mode 100644 tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml create mode 100644 tests/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml new file mode 100644 index 0000000..6a1ab68 --- /dev/null +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -0,0 +1,79 @@ +--- + +- name: show_ip_ospf_neighbor + parser_metadata: + version: 1.0 + command: show ip ospf neighbor + network_os: ios + +- name: match not active + register: not_active + pattern_match: + regex: ".+" + match_all: true + +- name: set_vars ospf state not active + set_vars: + process_state: "not active" + +- name: set_vars ospf state active + set_vars: + process_state: "active" + when: "not_active.0.matches | length > 0" + +- name: match sections + register: context + pattern_match: + regex: "Neighbor.+" + match_all: yes + match_greedy: yes + when: process_state == 'active' + +- name: match lines + register: lines + pattern_match: + regex: "^[0-9a-z.].+" + content: "{{ context.0 }}" + match_all: yes + match_greedy: yes + when: process_state == 'active' + +- name: match neighbors + register: matched_neighbors + loop: "{{ lines }}" + pattern_match: + regex: "(?P^[0-9a-z.]+)\\s+(?P\\d)\\s+(?P([A-Z]|.)+)/(?P([A-Z]|.)+)\\s(?P[0-9][0-9]:[0-5][0-9]:[0-5][0-9])\\s(?P.+\\s)\\s(?P.+)" + content: "{{ item }}" + when: process_state == 'active' + +- name: template ospf values + extend: cisco_ios + register: ospf + export: true + export_as: dict + json_template: + template: + - key: "process_state" + value: "{{ process_state }}" + +- name: template ospf neighbor entries + extend: cisco_ios.ospf + register: neighbors + export: true + export_as: dict + loop: "{{ matched_neighbors }}" + when: process_state == 'active' + json_template: + template: + - key: "{{ item.neighbor }}" + object: + - key: address + value: "{{ item.ip | trim }}" + - key: state + value: "{{ item.state | trim }}" + - key: role + value: "{{ item.role | trim }}" + - key: timer + value: "{{ item.timer | trim}}" + - key: interface + value: "{{ item.interface | trim }}" diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt new file mode 100644 index 0000000..0bbce91 --- /dev/null +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt @@ -0,0 +1,5 @@ + +Neighbor ID Pri State Dead Time Address Interface +ansi06a1.redhat 0 FULL/ - 00:00:37 130.200.191.21 Tunnel821 +ansi07a2.redhat 0 FULL/ - 00:00:32 25.131.8.25 Tunnel825 +rdurtr03ab.ansi 0 FULL/ - 00:00:36 191.11.131.5 Tunnel85 diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml new file mode 100644 index 0000000..dddbedb --- /dev/null +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml @@ -0,0 +1,41 @@ +--- + +### OSPF not active + +- name: not active - parse `show ip ospf neighbor` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_ospf_neighbor.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt') }}" + register: result + +- name: not active - test `show ip ospf neighbor` parser + assert: + that: + - cisco_ios.ospf['process_state'] == 'not active' + +- name: clear facts + meta: clear_facts + +### IOS 15.4(3r)M1.txt + +- name: 15.4(3r)M1.txt - parse `show ip ospf neighbor` + command_parser: + file: "{{ playbook_dir }}/../parser_templates/cli/show_ip_ospf_neighbor.yaml" + content: "{{ lookup('file', '{{ playbook_dir }}/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt') }}" + register: result + +- name: 15.4(3r)M1.txt - test `show ip ospf neighbor` parser + assert: + that: + - "'ansi06a1.redhat' in cisco_ios.ospf['neighbors']" + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['address'] == '130.200.191.21' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['state'] == 'FULL' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['role'] == '-' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['timer'] == '00:00:37' + - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['interface'] == 'Tunnel821' + +### Done + +- name: all tests complete + debug: + msg: "All tests for `show ip ospf summary` passed" diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt b/tests/parser_templates/cli/show_ip_ospf_neighbor/ospf_not_active.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_parser_templates.yaml b/tests/test_parser_templates.yaml index 1bebf39..6aeb78c 100755 --- a/tests/test_parser_templates.yaml +++ b/tests/test_parser_templates.yaml @@ -8,6 +8,7 @@ tasks: +<<<<<<< HEAD - name: Include tests for `show interfaces` include_tasks: parser_templates/cli/show_interfaces/main.yaml vars: @@ -17,13 +18,24 @@ include_tasks: parser_templates/cli/show_ip_bgp_summary/main.yaml vars: bgp: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['bgp'] }}" +======= + #- name: Include tests for `show ip bgp summary` + # include_tasks: parser_templates/cli/show_ip_bgp_summary/main.yaml + # vars: + # bgp: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['bgp'] }}" +>>>>>>> add ospf parser - - name: Include tests for `show ip vrf detail` - include_tasks: parser_templates/cli/show_ip_vrf_detail/main.yaml - vars: - vrfs: "{{ cisco_ios['vrf'] }}" + #- name: Include tests for `show ip vrf detail` + # include_tasks: parser_templates/cli/show_ip_vrf_detail/main.yaml + # vars: + # vrfs: "{{ cisco_ios['vrf'] }}" - - name: Include tests for `show version` - include_tasks: parser_templates/cli/show_version/main.yaml + - name: Include tests for `show ip ospf neighbor` + include_tasks: parser_templates/cli/show_ip_ospf_neighbor/main.yaml vars: - system: "{{ cisco_ios['system'] }}" + system: "{{ cisco_ios['vrf']['DEFAULT']['protocols']['ospf'] }}" + + #- name: Include tests for `show version` + # include_tasks: parser_templates/cli/show_version/main.yaml + # vars: + # system: "{{ cisco_ios['system'] }}" diff --git a/vars/get_facts_command_map.yaml b/vars/get_facts_command_map.yaml index 86094d4..2d04544 100644 --- a/vars/get_facts_command_map.yaml +++ b/vars/get_facts_command_map.yaml @@ -61,3 +61,10 @@ - all - vrf - routing + +- command: show ip ospf neighbor + parser: show_ip_ospf_neighbor.yaml + groups: + - all + - ospf + - routing From 02414fc8f2619bbd48ae34e5f5c17f169f250fdb Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:38:45 -0500 Subject: [PATCH 6/8] fix regex --- parser_templates/cli/show_ip_ospf_neighbor.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml index 6a1ab68..3d415d1 100644 --- a/parser_templates/cli/show_ip_ospf_neighbor.yaml +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -42,7 +42,7 @@ register: matched_neighbors loop: "{{ lines }}" pattern_match: - regex: "(?P^[0-9a-z.]+)\\s+(?P\\d)\\s+(?P([A-Z]|.)+)/(?P([A-Z]|.)+)\\s(?P[0-9][0-9]:[0-5][0-9]:[0-5][0-9])\\s(?P.+\\s)\\s(?P.+)" + regex: "(?P^[0-9a-z.]+)\\s+(?P\\d)\\s+(?P([A-Z]|.)+)/(?P([A-Z]|.)+)\\s(?P[0-9][0-9]:[0-5][0-9]:[0-5][0-9])\\s(?P.+\\s)(?P[A-Z].+)" content: "{{ item }}" when: process_state == 'active' From 3812904d77a10c96c772aede7d9aa8c871c21f2f Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:43:38 -0500 Subject: [PATCH 7/8] fix regex --- parser_templates/cli/show_ip_ospf_neighbor.yaml | 6 +++--- .../cli/show_ip_ospf_neighbor/15.4(3r)M1.txt | 2 +- .../cli/show_ip_ospf_neighbor/main.yaml | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml index 3d415d1..8b40fc0 100644 --- a/parser_templates/cli/show_ip_ospf_neighbor.yaml +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -65,10 +65,10 @@ when: process_state == 'active' json_template: template: - - key: "{{ item.neighbor }}" + - key: "{{ item.ip }}" object: - - key: address - value: "{{ item.ip | trim }}" + - key: neighbor_id + value: "{{ item.neighbor | trim }}" - key: state value: "{{ item.state | trim }}" - key: role diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt index 0bbce91..cf872c5 100644 --- a/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/15.4(3r)M1.txt @@ -2,4 +2,4 @@ Neighbor ID Pri State Dead Time Address Interface ansi06a1.redhat 0 FULL/ - 00:00:37 130.200.191.21 Tunnel821 ansi07a2.redhat 0 FULL/ - 00:00:32 25.131.8.25 Tunnel825 -rdurtr03ab.ansi 0 FULL/ - 00:00:36 191.11.131.5 Tunnel85 +ansi06a1.redhat 0 FULL/ - 00:00:36 191.11.131.5 Tunnel85 diff --git a/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml index dddbedb..b7a89c1 100644 --- a/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml +++ b/tests/parser_templates/cli/show_ip_ospf_neighbor/main.yaml @@ -27,12 +27,12 @@ - name: 15.4(3r)M1.txt - test `show ip ospf neighbor` parser assert: that: - - "'ansi06a1.redhat' in cisco_ios.ospf['neighbors']" - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['address'] == '130.200.191.21' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['state'] == 'FULL' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['role'] == '-' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['timer'] == '00:00:37' - - cisco_ios.ospf['neighbors']['ansi06a1.redhat']['interface'] == 'Tunnel821' + - "'130.200.191.21' in cisco_ios.ospf['neighbors']" + - cisco_ios.ospf['neighbors']['130.200.191.21']['neighbor_id'] == 'ansi06a1.redhat' + - cisco_ios.ospf['neighbors']['130.200.191.21']['state'] == 'FULL' + - cisco_ios.ospf['neighbors']['130.200.191.21']['role'] == '-' + - cisco_ios.ospf['neighbors']['130.200.191.21']['timer'] == '00:00:37' + - cisco_ios.ospf['neighbors']['130.200.191.21']['interface'] == 'Tunnel821' ### Done From 845409155c55beabd708dd38a5286a18fb2964dc Mon Sep 17 00:00:00 2001 From: willtome Date: Wed, 5 Dec 2018 15:44:20 -0500 Subject: [PATCH 8/8] fix regex Signed-off-by: willtome --- parser_templates/cli/show_ip_ospf_neighbor.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser_templates/cli/show_ip_ospf_neighbor.yaml b/parser_templates/cli/show_ip_ospf_neighbor.yaml index 8b40fc0..4e6cc58 100644 --- a/parser_templates/cli/show_ip_ospf_neighbor.yaml +++ b/parser_templates/cli/show_ip_ospf_neighbor.yaml @@ -65,7 +65,7 @@ when: process_state == 'active' json_template: template: - - key: "{{ item.ip }}" + - key: "{{ item.ip | trim }}" object: - key: neighbor_id value: "{{ item.neighbor | trim }}"