Python version of Junos Snapshot Administrator
APACHE-2.0 License
Bot releases are hidden (Show)
Published by chidanandpujar 2 months ago
Published by rahkumar651991 over 3 years ago
Published by rahkumar651991 almost 4 years ago
Published by rahkumar651991 over 4 years ago
Bug Fixes
no-diff command fixed in the code. #366
Published by rahkumar651991 over 4 years ago
Published by sidhujasminder over 6 years ago
Published by vnitinv over 6 years ago
Minor bug fixes
Published by sidhujasminder over 6 years ago
The /etc folder will from version >= 1.3
contain-
a) jsnapy.cfg: JSNAPy configparser file containing file paths, modify this file to change file paths
b) logging.yml: File describing loggging settings. Modify this file if you want to change logging levels or
output format
And the Testfiles and Snapshots stored in ~/jsnapy folder.
Testfiles and Snapshots stored in ~/jsnapy folder.
The testfiles and snapshots will now get stored in the home folder of the user.
User will have to create the path to ~/jsnapy/snapshots and ~/jsnapy/testfiles
if they do not exist.
These changes are necessary with respect to security and user permission in /etc folder
Published by sidhujasminder almost 7 years ago
Published by sidhujasminder almost 7 years ago
Published by sidhujasminder over 7 years ago
Compatibility to Windows and Python Virtual Environment.#252
pip install jsnapy
. For Documentation related to Windows referpip install jsnapy
. For Documentation related to Python virtual environment refer Virtual Environment support
JSNAPy Compatible to Python 3.4+
jsnapy --snapcheck <snap_name> --testfiles <test_file1> --hostname <host_name> --login <login> --passwd <passwd>
jsnapy --snapcheck <snap_name> --testfiles <test_file1> <test_file2> <test_file3> --hostname <host_name> --login <login> --passwd <passwd>
For more Reference, see how to use optional arguments in jsnapy through cli
from jnpr.jsnapy import SnapAdmin
from pprint import pprint
js = SnapAdmin()
pre_pass = js.snap('config.yml', 'pre_check')
post_pass = js.snap('config.yml', 'post_check')
snapval = js.check('config.yml', 'pre_check', 'post_check')
for item in snapval:
print("\n -----------check----------")
print("Tested on", item.device)
print("Final result: ", item.result)
print("Total passed: ", item.no_passed)
print("Total failed:", item.no_failed)
pprint(item.test_results)
config.yml
hosts:
- device: 1.1.1.1
username: abc
passwd: xyz
tests:
- test_in_range.yml
test_in_range.yml
check_chassis_fpc:
- command: show chassis fpc
- iterate:
xpath: fpc[normalize-space(slot) = "0"]
tests:
- in-range: memory-heap-utilization, 5, 40
info: "Test Succeeded!! memory heap utilisation of the FPCs is within the range of 5-40, it is <{{post['memory-heap-utilization']}}> with temperature: <{{post['temperature']}}>"
err: "Test Failed!! memory heap utilisation of the FPCs is not in range of 5-40, it is <{{post['memory-heap-utilization']}}> with temperature: <{{post['temperature']}}>"
Output
-----------check----------
('Tested on', '1.1.1.1')
('Final result: ', 'Passed')
('Total passed: ', 1)
('Total failed:', 0)
{'show chassis fpc': [{'count': {'fail': 0, 'pass': 1},
'expected_node_value': [5.0, 40.0],
'failed': [],
'node_name': 'memory-heap-utilization',
'passed': [{'actual_node_value': '20',
'id': {},
'message': 'Test Succeeded!! memory heap utilisation of the FPCs is within the range of 5-40, it is <20> with temperature: <Testing>',
'post': {'memory-heap-utilization': '20',
'temperature': 'Testing'},
'pre': {'memory-heap-utilization': '20'}}],
'result': True,
'test_name': 'check_chassis_fpc',
'testoperation': 'in-range',
'xpath': 'fpc[normalize-space(slot) = "0"]'}]}
from pprint import pprint
js = SnapAdmin()
pre_pass = js.snap('config.yml', 'pre_check')
post_pass = js.snap('config.yml', 'post_check')
snapval = js.check('config.yml', 'pre_check', 'post_check')
for item in snapval:
print("\n -----------check----------")
print("Tested on", item.device)
print("Final result: ", item.result)
print("Total passed: ", item.no_passed)
print("Total failed:", item.no_failed)
pprint(item.testname_results)
-----------check----------
('Tested on', '1.1.1.1')
('Final result: ', 'Passed')
('Total passed: ', 1)
('Total failed:', 0)
{'check_chassis_fpc': [{'command': 'show chassis fpc',
'count': {'fail': 0, 'pass': 1},
'expected_node_value': [5.0, 40.0],
'failed': [],
'node_name': 'memory-heap-utilization',
'passed': [{'actual_node_value': '20',
'id': {},
'message': 'Test Succeeded!! memory heap utilisation of the FPCs is within the range of 5-40, it is <20> with temperature: <Testing>',
'post': {'memory-heap-utilization': '20',
'temperature': 'Testing'},
'pre': {'memory-heap-utilization': '20'}}],
'result': True,
'testoperation': 'in-range',
'xpath': 'fpc[normalize-space(slot) = "0"]'}]}
NOTE
Published by vnitinv almost 8 years ago
ignore-null attribute support via #170
Sample Output
stored snapshots can be used with snapcheck using --local
option #172
Example:
jsnapy --snapcheck STORED -f config.yml --local
Where STORED might have already been used by snap function to fetch snapshots
jsnapy --snap STORED -f config.yml
Operators for chained tests #178
Now user can use AND
, OR
and NOT
operators to chain their test cases. Final result will be decided depending on the mathematical calculation based on operators used. For more details refer: PR or wiki
Docker image for JSNAPy
Added test based mail support #149
Depending on test results user can decide on which condition of overall test result mail to be sent.
mail:
pass: <filename>
fail: <filename>
all: <filename>
User defined path for jsnapy.cfg
JSNAPY_HOME -> ~/.jsnapy -> /etc/jsnapy
sudo pip install jsnapy --install-option="--install-data=~/Desktop/test_inst"
Note User still need to use sudo to do the installation as we still create different config file at /etc/jsnapy
Published by vnitinv about 8 years ago
Junos® Snapshot Administrator in Python (jsnapy) enables you to capture and audit
runtime environment snapshots of your networked devices running the Junos OS. You
can capture and validate the operational status of a device and review operational
changes to a device. You create configuration files that define the scope of snapshots
and customize the test criteria for the snapshot data.
You can use Junos Snapshot Administrator in Python to perform the following functions
on either a single device or list of devices running Junos OS:
• Take a snapshot of the runtime environment on a device.
• Compare two snapshots.
• Audit a device’s runtime environment against pre-defined criteria.
• Use as a module in other Python programs.
• Send e-mail alerts that include test results.
• Store and compare snapshots in an SQLite database.
Published by Jainpriyal over 8 years ago
Published by Jainpriyal over 8 years ago
Published by Jainpriyal over 8 years ago
Feature Enhancement:
1] Modifying output in case of module
test_command_version:
- command: show interfaces terse
- iterate:
xpath: physical-interface
id: ['./name', 'admin-status']
tests:
- no-diff: oper-status
err: "Test Failed!! oper-status got changed, before it was <{{pre['oper-status']}}>, now it is <{{post['oper-status']}}> with name <{{id_0}}> and admin status <{{post['admin-status']}}>"
info: "Test Passed! oper-status is same with value, before it is <{{pre['oper-status']}}> now it is <{{post['oper-status']}}> with admin status <{{post['admin-status']}}> "
Below is the output of “no-diff” test operation.
Tested on adora
Final result: Passed
Total passed: 1
Total failed: 0
{'show interfaces terse': [{'count': {'fail': 0, 'pass': 59},
'failed': [],
'node_name': 'oper-status',
'passed': [[{'id': {'./name': 'tap',
'admin-status': 'up'},
'post': {'admin-status': 'up',
'oper-status': ['up']},
'post_node_value': ['up'],
'pre': {'oper-status': ['up']},
'pre_node_value': ['up']}],
[{'id': {'./name': 'pimd',
'admin-status': 'up'},
'post': {'admin-status': 'up',
'oper-status': ['up']},
'post_node_value': ['up'],
'pre': {'oper-status': ['up']},
'pre_node_value': ['up']}]],
'post_xml': <lxml.etree._ElementTree object at 0x10d958f80>,
'pre_xml': <lxml.etree._ElementTree object at 0x10d958ef0>,
'result': True,
'testoperation': 'no-diff',
'xpath': 'physical-interface'}]}
2] Added verbosity:
-v, --verbosity Set verbosity
-v: Debug level messages
-vv: Info level messages
-vvv: Warning level messages
-vvvv: Error level messages
-vvvvv: Critical level messages
Bug Fixes:
1] Making error messages more precise for better understanding.
Published by Jainpriyal over 8 years ago
1] Added functionality to pass port number:
hosts:
- device: 100.219.16.204
username : foo
passwd: baar
port: 830
tests:
- test_is_gt.yml
From command line
-P PORT, --port PORT port no to connect to device
(venv)sh-3.2# jsnapy --snap pre -l foo -p bar -t 10.209.16.204 -P 830 -f config_single_snapcheck.yml
Connecting to device 10.209.16.204 ................
Taking snapshot for show interfaces terse ................
2] Added new test operator
It can be used to compare node values using regular expression:
(venv)sh-3.2# cat test_regx.yml
test_interfaces_terse:
- command: show interfaces terse
- iterate:
xpath: //physical-interface/name[starts-with(normalize-space(text()),'ge-')]
tests:
- regex: ../name , ge-\d/\d/\d
info: "Test Succeeded !! name is equal to <{{post['../name']}}> "
err: "Test Failed !! name is equal to <{{post['../name']}}> "
Output:
(venv)sh-3.2# jsnapy --snapcheck -f config_single_snapcheck.yml
Connecting to device adora ................
Taking snapshot for show interfaces terse ................
******************************* Device: adora *******************************
Tests Included: test_interfaces_terse
*********************** Command: show interfaces terse ***********************
-----------------------Performing regex Test Operation-----------------------
Test Succeeded !! name is equal to <ge-1/0/0>
Test Succeeded !! name is equal to <ge-1/0/1>
Test Succeeded !! name is equal to <ge-1/0/2>
Test Succeeded !! name is equal to <ge-1/0/3>
Test Succeeded !! name is equal to <ge-1/0/4>
Test Succeeded !! name is equal to <ge-1/0/5>
Test Succeeded !! name is equal to <ge-1/0/6>
Test Succeeded !! name is equal to <ge-1/0/7>
Test Succeeded !! name is equal to <ge-1/0/8>
Test Succeeded !! name is equal to <ge-1/0/9>
Test Succeeded !! name is equal to <ge-1/1/0>
Test Succeeded !! name is equal to <ge-1/1/1>
Test Succeeded !! name is equal to <ge-1/1/2>
Test Succeeded !! name is equal to <ge-1/1/3>
Test Succeeded !! name is equal to <ge-1/1/4>
Test Succeeded !! name is equal to <ge-1/1/5>
Test Succeeded !! name is equal to <ge-1/1/6>
Test Succeeded !! name is equal to <ge-1/1/7>
Test Succeeded !! name is equal to <ge-1/1/8>
Test Succeeded !! name is equal to <ge-1/1/9>
PASS | All "../name" matches with regex "ge-\d/\d/\d" [ 20 matched ]
------------------------------- Final Result!! -------------------------------
Total No of tests passed: 1
Total No of tests failed: 0
Overall Tests passed!!!
Published by Jainpriyal over 8 years ago
1] Functionality to pass id as a list.
Now IDs can be passed both as string or list.
For Example
One way:
test_command_bgp_neighbor:
- command: show bgp neighbor
- iterate:
xpath: bgp-peer
id: [ ./peer-address, ./peer-as ]
........
Second way:
test_command_bgp_neighbor:
- command: show bgp neighbor
- iterate:
xpath: bgp-peer
id: ./peer-address, ./peer-as
.....
2] Modified test cases to compare attribute values.
Can compare attributes via:
check_int_ext:
- command: show interfaces extensive
- iterate:
xpath: //interface-information/physical-interface[normalize-space(admin-status)="up" and logical-interface/address-family/address-family-name and interface-flapped[@seconds]]
tests:
- is-gt: interface-flapped/@seconds, 600
info: Interfaces {{post['name']}} with family defined is UP for more than 10 min
err: Interface {{post['name']}} is Up since XX seconds
3] Less verbose CLI output.
Modified info and debug level messages in case of test pass and fail.
4] Changes for module feature.
5] JSNAPy can also take test file from present working directory.
Now user can give test files by:
1. giving complete path
2. it is present in current working directory
3. it looks in default directory mentioned in jsnapy.cfg (/etc/jsnapy/testfiles)
6] More verbose error message.
Now error message is also printing xpath and id details when no node is found.
Published by Jainpriyal over 8 years ago
check_certificate:
- command: show configuration security certificates | display xml
- iterate:
xpath: //configuration/security/certificates
tests:
- is-equal: local/name, mycert
info: "Name matches .. PASS...NAME - <{{pre['local/name']}}>"
err: "Name Not matching.. FAIL...NAME - <{{pre['local/name']}}>"