Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ping template for Cisco IOS XR devices #1564

Merged
merged 40 commits into from
Jan 10, 2024

Conversation

jorlandobr
Copy link
Contributor

@jorlandobr jorlandobr commented Nov 17, 2023

Added a ping template for Cisco IOS XR devices. These devices begin the ping output with an extra line with a timestamp. That line would fail if tested against the cisco_ios_ping.textfsm template

Added a ping template for Cisco IOS XR devices. These devices begin the ping output with an extra line with a timestamp. That line would fail if testes against the cisco_ios_ping.textfsm template
@jorlandobr jorlandobr changed the title Add files via upload ping template for Cisco IOS XR devices Nov 17, 2023
@jvanderaa
Copy link
Contributor

Please add test cases and update the index.

@jorlandobr jorlandobr mentioned this pull request Nov 17, 2023
@jorlandobr
Copy link
Contributor Author

jorlandobr commented Nov 17, 2023

I don't know how to properly test the templates, I apprecciate any directions.

What I did was validating against https://textfsm.nornir.tech/

Also I did a collection of input files with ping outputs for each case (success, fail, unreachable, quench and mix) and a small program that test these inputs against a given template,

The ping output command in Cisco IOS XR devices starts with a timestamp on the first line, so cisco_ios_ping.textfsm would fail to test these outputs, like this:

PS C:\python> python .\test_template.py
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:28:01.206 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:29:18.710 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:29:18.710 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:29:18.710 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Tue Nov 14 11:03:09.626 BRA.
PS C:\python>

I modified slightly the template to use with IOS XR devices.

below are the bodies of the input files, the program and the outputs, first with the unmodified template cisco_xr_ping.textfsm and next with the modified template cisco_xr_ping_xr_mod.textfsm.

Let me know if this is enough.

ping_xr_success.txt:
Fri Nov 17 16:28:01.206 BRA
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 7/7/7 ms

ping_xr_fail.txt:
Fri Nov 17 16:29:18.710 BRA
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.27.18.2, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)

ping_xr_unreachable.txt:
Fri Nov 17 16:29:18.710 BRA
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.227.128.2, timeout is 2 seconds:
U.U.U
Success rate is 0 percent (0/5)

ping_xr_quench.txt:
Fri Nov 17 16:29:18.710 BRA
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.27.18.2, timeout is 2 seconds:
QQQQQ
Success rate is 0 percent (0/5)

ping_xr_mix.txt:
Tue Nov 14 11:03:09.626 BRA
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.44.222.174, timeout is 2 seconds:
U.U!Q
Success rate is 20 percent (1/5), round-trip min/avg/max = 10/10/10 ms

import textfsm
# Load the input file to a variable
input_file = open("ping_xr_success.txt", encoding='utf-8')
raw_text_data = input_file.read()
input_file.close()

#template = open("cisco_asa_ping.textfsm")
#template = open("cisco_asa_ping_mod.textfsm")
template = open("cisco_xr_ping.textfsm")
#template = open("cisco_xr_ping_mod.textfsm")
#template = open("cisco_ios_ping.textfsm")
#template = open("cisco_ios_ping_mod.textfsm")
re_table = textfsm.TextFSM(template)

fsm_results = re_table.ParseText(raw_text_data)
print ("Printing input file ping_xr_succcess.txt" +  '\n' + str(fsm_results) + '\n' + '\n')

try:

    re_table = ''
    re_table = textfsm.TextFSM(template)
    # Load the input file to a variable
    input_file = open("ping_xr_fail.txt", encoding='utf-8')
    raw_text_data = input_file.read()
    input_file.close()
    fsm_results = re_table.ParseText(raw_text_data)
    print ("Printing input file ping_xr_fail.txt" +  '\n' + str(fsm_results) + '\n' + '\n')

except Exception as e:
    print(e)
    
try:
    
    re_table = ''
    re_table = textfsm.TextFSM(template)
    # Load the input file to a variable
    input_file = open("ping_xr_unreachable.txt", encoding='utf-8')
    raw_text_data = input_file.read()
    input_file.close()

    fsm_results = re_table.ParseText(raw_text_data)
    print ("Printing input file ping_xr_unreachable.txt" + '\n' + str(fsm_results) + '\n' + '\n')

except Exception as e:
    print(e)


try:
    
    re_table = ''
    re_table = textfsm.TextFSM(template)
    # Load the input file to a variable
    input_file = open("ping_xr_quench.txt", encoding='utf-8')
    raw_text_data = input_file.read()
    input_file.close()

    fsm_results = re_table.ParseText(raw_text_data)
    print ("Printing input file ping_xr_quench.txt" +  '\n' + str(fsm_results) + '\n' + '\n')

except Exception as e:
    print(e)

try:
    
    re_table = ''
    re_table = textfsm.TextFSM(template)
    # Load the input file to a variable
    input_file = open("ping_xr_mix.txt", encoding='utf-8')
    raw_text_data = input_file.read()
    input_file.close()

    fsm_results = re_table.ParseText(raw_text_data)
    print ("Printing input file ping_xr_mix.txt" +  '\n' + str(fsm_results) + '\n' + '\n')

except Exception as e:
    print(e)

Testing with the original template:

PS C:\python> python .\test_template.py
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:28:01.206 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:29:18.710 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:29:18.710 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Fri Nov 17 16:29:18.710 BRA.
Error: "Could not parse line:". Rule Line: 23. Input Line: Tue Nov 14 11:03:09.626 BRA.
PS C:\python>

Testing with the modified template:

PS C:\python> python .\test_template.py
Printing input file ping_xr_succcess.txt
[['5', '100-byte ICMP Echos', '8.8.8.8', '2', '', ['!!!!!'], '100', '5', '7', '7', '7']]

Printing input file ping_xr_fail.txt
[['5', '100-byte ICMP Echos', '10.27.18.2', '2', '', ['.....'], '0', '0', '', '', '']]

Printing input file ping_xr_unreachable.txt
[['5', '100-byte ICMP Echos', '10.227.128.2', '2', '', ['U.U.U'], '0', '0', '', '', '']]

Printing input file ping_xr_quench.txt
[['5', '100-byte ICMP Echos', '10.27.18.2', '2', '', ['QQQQQ'], '0', '0', '', '', '']]

Printing input file ping_xr_mix.txt
[['5', '100-byte ICMP Echos', '10.44.222.174', '2', '', ['U.U!Q'], '20', '1', '10', '10', '10']]

PS C:\python>

Added U and Q response to RESPONSE STREAM

Cisco has four valid outputs for ping: . (fail) ! (success) U (unreachable) Q (quench)

U and Q where missing. Testing an output that carried these values would generate an error.
Added a ping template for Cisco IOS XR devices. These devices begin the ping output with an extra line with a timestamp. That line would fail if tested against the cisco_ios_ping.textfsm template
@jorlandobr
Copy link
Contributor Author

Added test cases (yml and raw fles) and updated index in jorlandobr-patch-3

Added U and Q response to RESPONSE STREAM

Cisco has four valid outputs for ping: . (fail) ! (success) U (unreachable) Q (quench)

U and Q were missing. Testing an output that carried these values would generate an error.
Added U and Q response to RESPONSE STREAM

Cisco has four valid outputs for ping: . (fail) ! (success) U (unreachable) Q (quench)

U and Q were missing. Testing an output that carried these values would generate an error.
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@jorlandobr jorlandobr closed this Dec 26, 2023
@jorlandobr jorlandobr deleted the jorlandobr-patch-3 branch December 26, 2023 17:03
@jorlandobr jorlandobr restored the jorlandobr-patch-3 branch December 26, 2023 17:11
@jorlandobr jorlandobr reopened this Dec 26, 2023
@jorlandobr jorlandobr requested a review from jvanderaa December 28, 2023 20:56
Copy link
Contributor Author

@jorlandobr jorlandobr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes applied.

@jvanderaa
Copy link
Contributor

LGTM ,TY

@jvanderaa jvanderaa merged commit 211ecf4 into networktocode:master Jan 10, 2024
14 checks passed
@jorlandobr jorlandobr deleted the jorlandobr-patch-3 branch February 14, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants