forked from ansible-network/network-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show ip vrf detail, more tests for show ip bgp summary (ansible-netwo…
…rk#11) * task file per command for future growth plus more tests * merging * cleaning * Seperating tests for each command * tests * working parser template * Interfaces being captured, tests * `show ip vrf detail` parser and more tests (ansible-network#1) * parser for `show ip vrf detail` * more parser tests * Test case for BGP not active. Fixed to pass tests. * forgot the command map...
- Loading branch information
Showing
11 changed files
with
402 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
|
||
- name: show_ip_vrf_detail | ||
parser_metadata: | ||
version: 1.0 | ||
command: show ip vrf detail | ||
network_os: ios | ||
|
||
- name: match vrf section | ||
register: section | ||
pattern_match: | ||
regex: "^VRF \\S+; default RD" | ||
match_all: true | ||
match_greedy: true | ||
|
||
- name: match vrf values | ||
loop: "{{ section }}" | ||
register: vrf | ||
pattern_group: | ||
|
||
- name: match name | ||
pattern_match: | ||
regex: "^VRF (\\S+); default RD" | ||
content: "{{ item }}" | ||
register: name | ||
|
||
- name: match description | ||
pattern_match: | ||
regex: "^ Description: (.*)\\n" | ||
content: "{{ item }}" | ||
register: description | ||
|
||
- name: match route distinguisher | ||
pattern_match: | ||
regex: ".*; default RD (\\d+:\\d+)" | ||
content: "{{ item }}" | ||
register: rd | ||
|
||
- name: match export route target section | ||
pattern_match: | ||
regex: "^ Export VPN route-target communities([\\s\\S]*)^ Import VPN" | ||
content: "{{ item }}" | ||
match_all: true | ||
match_greedy: false | ||
register: export_rt_section | ||
|
||
- name: match import route target section | ||
pattern_match: | ||
regex: "^ Import VPN route-target communities([\\s\\S]*)import route-map" | ||
content: "{{ item }}" | ||
match_all: true | ||
match_greedy: false | ||
register: import_rt_section | ||
|
||
- name: match interface section | ||
pattern_match: | ||
regex: "^ Interfaces:([\\s\\S]*)VRF Table ID" | ||
content: "{{ item }}" | ||
match_all: true | ||
match_greedy: false | ||
register: interface_section | ||
|
||
- name: match vrf nested values | ||
loop: "{{ vrf }}" | ||
loop_control: | ||
loop_var: vrf_item | ||
register: vrf_nested | ||
pattern_group: | ||
|
||
- name: match vrf name | ||
pattern_match: | ||
regex: "(.*)" | ||
content: "{{ vrf_item.name.matches.0 }}" | ||
match_greedy: true | ||
register: name | ||
|
||
- name: match export route targets | ||
pattern_match: | ||
regex: "\\s+RT:(\\d+:\\d+)" | ||
content: "{{ vrf_item.export_rt_section.0.matches }}" | ||
match_all: true | ||
register: export_rt | ||
|
||
- name: match import route targets | ||
pattern_match: | ||
regex: "\\s+RT:(\\d+:\\d+)" | ||
content: "{{ vrf_item.import_rt_section.0.matches }}" | ||
match_all: true | ||
register: import_rt | ||
|
||
- name: match interfaces | ||
pattern_match: | ||
regex: "[\\s|\\\n]+(\\S*)[\\s|\\n]" | ||
content: "{{ vrf_item.interface_section.0.matches }}" | ||
match_all: true | ||
register: interface | ||
|
||
- name: build a dict for nested values with name as key | ||
register: vrf_nested_values | ||
export_as: dict | ||
loop: "{{ vrf_nested }}" | ||
loop_control: | ||
loop_var: vrf_nested_item | ||
json_template: | ||
template: | ||
- key: "{{ vrf_nested_item.name.0 }}" | ||
object: | ||
- key: export_rt | ||
elements: "{{ nested_item.matches }}" | ||
repeat_for: "{{ vrf_nested_item.export_rt }}" | ||
repeat_var: nested_item | ||
- key: import_rt | ||
elements: "{{ nested_item.matches }}" | ||
repeat_for: "{{ vrf_nested_item.import_rt }}" | ||
repeat_var: nested_item | ||
- key: interface | ||
elements: "{{ nested_item.matches }}" | ||
repeat_for: "{{ vrf_nested_item.interface }}" | ||
repeat_var: nested_item | ||
|
||
- name: ensure vrf_nested_values is a DICT | ||
set_vars: | ||
dict_vrf_nested_values: "{{ ({}| combine(*vrf_nested_values)) }}" | ||
|
||
- name: template export json object | ||
register: ip_vrf_detail | ||
loop: "{{ vrf }}" | ||
export: true | ||
export_as: dict | ||
extend: cisco_ios | ||
json_template: | ||
template: | ||
- key: "{{ item.name.matches.0 }}" | ||
object: | ||
- key: name | ||
value: "{{ item.name.matches.0 }}" | ||
- key: description | ||
value: "{{ item.description.matches.0 }}" | ||
- key: rd | ||
value: "{{ item.rd.matches.0 }}" | ||
- key: export_rt | ||
value: "{{ dict_vrf_nested_values[item.name.matches.0].export_rt }}" | ||
- key: import_rt | ||
value: "{{ dict_vrf_nested_values[item.name.matches.0].import_rt }}" | ||
- key: interfaces | ||
value: "{{ dict_vrf_nested_values[item.name.matches.0].interface }}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
BGP router identifier 172.16.32.1, local AS number 65123 | ||
BGP table version is 3317, main routing table version 3317 | ||
140 network entries using 16380 bytes of memory | ||
276 path entries using 14352 bytes of memory | ||
1184/12 BGP path/bestpath attribute entries using 165760 bytes of memory | ||
108 BGP AS-PATH entries using 2832 bytes of memory | ||
84 BGP community entries using 2016 bytes of memory | ||
74 BGP extended community entries using 1920 bytes of memory | ||
0 BGP route-map cache entries using 0 bytes of memory | ||
0 BGP filter-list cache entries using 0 bytes of memory | ||
BGP using 203260 total bytes of memory | ||
BGP activity 2362466/2358636 prefixes, 9381389/9370747 paths, scan interval 60 secs | ||
|
||
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd | ||
172.31.32.10 4 64910 5784429 5675902 3317 0 0 23w5d 114 | ||
172.16.32.1 4 65123 6281459 6288574 3317 0 0 28w5d 136 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
BGP router identifier 10.29.19.69, local AS number 65312 | ||
BGP table version is 8405, main routing table version 8405 | ||
1390 network entries using 189040 bytes of memory | ||
1390 path entries using 72280 bytes of memory | ||
1016/1016 BGP path/bestpath attribute entries using 125984 bytes of memory | ||
1008 BGP AS-PATH entries using 24516 bytes of memory | ||
2 BGP extended community entries using 48 bytes of memory | ||
0 BGP route-map cache entries using 0 bytes of memory | ||
0 BGP filter-list cache entries using 0 bytes of memory | ||
BGP using 411868 total bytes of memory | ||
BGP activity 3131/1741 prefixes, 4889/3499 paths, scan interval 60 secs | ||
|
||
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd | ||
10.29.19.70 4 7474 78662 72306 8405 0 0 4d22h 1385 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
% BGP not active |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
|
||
### 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 }}/output/show_ip_bgp_summary/bgp_not_active.txt') }}" | ||
register: result | ||
|
||
- name: not active - test `show ip bgp summary` parser | ||
assert: | ||
that: | ||
- "cisco_ios['ip_bgp_summary']['process_state'] == 'not active'" | ||
|
||
- 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 }}/output/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: | ||
- "'ip_bgp_summary' in cisco_ios" | ||
- "'10.15.17.2' in cisco_ios['ip_bgp_summary']" | ||
- "cisco_ios['ip_bgp_summary']['10.15.17.2']['state_pfxrcd'] == 1125" | ||
- "cisco_ios['ip_bgp_summary']['10.15.17.2']['asn'] == 64785" | ||
- "cisco_ios['ip_bgp_summary']['10.15.17.2']['ip_version'] == 4" | ||
- "cisco_ios['ip_bgp_summary']['10.15.17.2']['timer'] == '7w1d'" | ||
- "'10.1.19.2' in cisco_ios['ip_bgp_summary']" | ||
- "cisco_ios['ip_bgp_summary']['10.1.19.2']['state_pfxrcd'] == 'Active'" | ||
- "cisco_ios['ip_bgp_summary']['10.1.19.2']['asn'] == 1234" | ||
- "cisco_ios['ip_bgp_summary']['10.1.19.2']['ip_version'] == 4" | ||
- "'{{ cisco_ios['ip_bgp_summary']['10.1.19.2']['timer'] | string }}' == '00:00:30'" | ||
- "'72.31.0.13' in cisco_ios['ip_bgp_summary']" | ||
- "cisco_ios['ip_bgp_summary']['72.31.0.13']['state_pfxrcd'] == 'Idle'" | ||
- "cisco_ios['ip_bgp_summary']['72.31.0.13']['asn'] == 65004" | ||
- "cisco_ios['ip_bgp_summary']['72.31.0.13']['ip_version'] == 4" | ||
- "'{{ cisco_ios['ip_bgp_summary']['72.31.0.13']['timer'] | string }}' == '10:32:44'" | ||
|
||
### 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 }}/output/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: | ||
- "'ip_bgp_summary' in cisco_ios" | ||
- "'10.29.19.70' in cisco_ios['ip_bgp_summary']" | ||
- "cisco_ios['ip_bgp_summary']['10.29.19.70']['state_pfxrcd'] == 1385" | ||
- "cisco_ios['ip_bgp_summary']['10.29.19.70']['asn'] == 7474" | ||
- "cisco_ios['ip_bgp_summary']['10.29.19.70']['ip_version'] == 4" | ||
- "cisco_ios['ip_bgp_summary']['10.29.19.70']['timer'] == '4d22h'" | ||
|
||
### 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 }}/output/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: | ||
- "'ip_bgp_summary' in cisco_ios" | ||
- "'172.31.32.10' in cisco_ios['ip_bgp_summary']" | ||
- "cisco_ios['ip_bgp_summary']['172.31.32.10']['state_pfxrcd'] == 114" | ||
- "cisco_ios['ip_bgp_summary']['172.31.32.10']['asn'] == 64910" | ||
- "cisco_ios['ip_bgp_summary']['172.31.32.10']['ip_version'] == 4" | ||
- "cisco_ios['ip_bgp_summary']['172.31.32.10']['timer'] == '23w5d'" | ||
- "'172.16.32.1' in cisco_ios['ip_bgp_summary']" | ||
- "cisco_ios['ip_bgp_summary']['172.16.32.1']['state_pfxrcd'] == 136" | ||
- "cisco_ios['ip_bgp_summary']['172.16.32.1']['asn'] == 65123" | ||
- "cisco_ios['ip_bgp_summary']['172.16.32.1']['ip_version'] == 4" | ||
- "'{{ cisco_ios['ip_bgp_summary']['172.16.32.1']['timer'] | string }}' == '28w5d'" | ||
|
||
- name: all tests complete | ||
debug: | ||
msg: "All tests for `show ip bgp summary` passed" |
Oops, something went wrong.