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

Port included in filename during snapcheck, but not during snap #374

Closed
dangerChef opened this issue Jun 22, 2020 · 3 comments
Closed

Port included in filename during snapcheck, but not during snap #374

dangerChef opened this issue Jun 22, 2020 · 3 comments
Assignees

Comments

@dangerChef
Copy link

dangerChef commented Jun 22, 2020

When running jsnapy as a module, if a port is specified in the configuration but the pre-connected device object is passed to SnapAdmin(), the snapshot filename from the snap action does not contain the port number but snapcheck does expect the port number to be in the filename.

Tests Included: test_route_summary
*************************RPC is get-route-summary-information*************************
ERROR, Snapshot file /tmp/snapshots/192.168.0.1_22_pre_get_route_summary_information.xml is not present in given path !!

Setup

Jsnapy is being run as a module from within a pyez script and connecting to a specific port (ie: port 22) - the device object connection is already established before passing the device object to SnapAdmin() - the jsnapy config file references port 22

Steps to Reproduce Issue

First, the config file needs to contain the port number:

hosts:
   - device: {router}
     port: 22
     username: {user}
 tests:
   - test_route_summary.yaml

Second, jsnapy must be running as a module in a pyez script:

from jnpr.jsnapy import SnapAdmin
from jnpr.junos import Device

Third, you must connect to the device outside of jsnapy and pass the device object to SnapAdmin():

dev = Device( host=rtr_ip, port='22')
dev.open()

js = SnapAdmin()
js.snap(config_data, "pre", dev)

Then you do the snapcheck in a similar manner (connect prior and pass the object)

js.snap(config_data, "post", dev)
Then do the comparison:

chk = js.check(config_data, "pre", "post")

Versions Report

[aelliott]$ jsnapy --version
JSNAPy version: 1.3.2
[aelliott]$ python3 -V
Python 3.6.8

@dangerChef
Copy link
Author

The workaround was to remove the port configuration from the config file, but I believe you should not be constructing the filenames differently in snap or snapcheck

@rahkumar651991 rahkumar651991 self-assigned this Jun 22, 2020
@chidanandpujar
Copy link
Collaborator

Hi @dangerChef
Issue is not reproducible in the latest jsnapy 1.3.8.dev0, we will close this issue as fixed.
Please refer the following pass logs, port number is not part of the snap and snapcheck snapfile names.

# rm ~/ansible_release_v105_final/venv/etc/jsnapy/snapshots/10.220.1.222_*
# ls ~/ansible_release_v105_final/venv/etc/jsnapy/snapshots/
README
# ls ~/ansible_release_v105_final/venv/etc/jsnapy/snapshots/
README
# cat issue_374_dev_port_config.py 
from jnpr.jsnapy import SnapAdmin
from pprint import pprint
from jnpr.junos import Device

config_data = """
hosts:
  - device: x.x.x.x
    username : xyz
    port : 22
    passwd: xyz
tests:
  - test_show_chassis_hardware_no_diff.yml 
"""

dev = Device(host='x.x.x.x', user='xyz', password='xyz', port=22)
dev.open()

js = SnapAdmin()
js.snap(config_data, "pre", dev)

js.snap(config_data, "post", dev)

snapvalue = js.check(config_data, "pre", "post", dev)


for snapcheck in snapvalue:
    print ("\n -----------snapcheck----------")
    print ("Tested on", snapcheck.device)
    print ("Final result: ", snapcheck.result)
    print ("Total passed: ", snapcheck.no_passed)
    print ("Total failed:", snapcheck.no_failed)
    pprint(snapcheck.test_results) 

# python issue_374_dev_port_config.py 
Taking snapshot of COMMAND: show chassis hardware 
Taking snapshot of COMMAND: show chassis hardware 
**************************** Device: x.x.x.x ****************************
Tests Included: test_chassis_hardware 
*********************** Command: show chassis hardware ***********************
PASS | All "serial-number" is same in pre and post snapshot [ 1 value matched ]
------------------------------- Final Result!! -------------------------------
test_chassis_hardware : Passed
Total No of tests passed: 1
Total No of tests failed: 0 
Overall Tests passed!!! 

 -----------snapcheck----------
Tested on x.x.x.x
Final result:  Passed
Total passed:  1
Total failed: 0
{'show chassis hardware': [{'count': {'fail': 0, 'pass': 1},
                            'failed': [],
                            'node_name': 'serial-number',
                            'passed': [{'id': {'serial-number': 'VM663B0192BF'},
                                        'message': 'Test Pass: Serial number '
                                                   'is same PRE '
                                                   "['VM663B0192BF']  and POST "
                                                   "['VM663B0192BF']",
                                        'post': {'serial-number': ['VM663B0192BF']},
                                        'post_node_value': ['VM663B0192BF'],
                                        'pre': {'serial-number': ['VM663B0192BF']},
                                        'pre_node_value': ['VM663B0192BF']}],
                            'result': True,
                            'test_name': 'test_chassis_hardware',
                            'testoperation': 'no-diff',
                            'xpath': '//chassis'}]}
# ls ~/ansible_release_v105_final/venv/etc/jsnapy/snapshots/
10.220.1.222_post_show_chassis_hardware.xml  10.220.1.222_pre_show_chassis_hardware.xml  README


# rm ~/ansible_release_v105_final/venv/etc/jsnapy/snapshots/10.220.1.222_*
# ls ~/ansible_release_v105_final/venv/etc/jsnapy/snapshots/
README
# cat issue_374_dev_port_snapcheck_config.py 
from jnpr.jsnapy import SnapAdmin
from pprint import pprint
from jnpr.junos import Device

config_data = """
hosts:
  - device: x.x.x.x 
    username : xyz
    port : 22
    passwd: xyz
tests:
  - test_snmp.yml 
"""

dev = Device(host='x.x.x.x', user='xyz', password='xyz', port=22)
dev.open()

js = SnapAdmin()
snapvalue = js.snapcheck(config_data, "pre", dev)
for snapcheck in snapvalue:
    print ("\n -----------snapcheck----------")
    print ("Tested on", snapcheck.device)
    print ("Final result: ", snapcheck.result)
    print ("Total passed: ", snapcheck.no_passed)
    print ("Total failed:", snapcheck.no_failed)
    pprint(snapcheck.test_results) 

# python issue_374_dev_port_snapcheck_config.py 
Taking snapshot of RPC: get-configuration
**************************** Device: 10.220.1.222 ****************************
Tests Included: test_snmp_config 
*************************RPC is get-configuration*************************
ERROR!! Nodes are not present in given <Xpath> : </configuration/snmp>
FAIL | All "community[name='mycommunity']" do not exists at xpath "/configuration/snmp" [ 0 value matched / 1 value failed ]
FAIL | SNMP community ''mycommunity' is not configured!
------------------------------- Final Result!! -------------------------------
test_snmp_config : Failed
Total No of tests passed: 0
Total No of tests failed: 1 
Overall Tests failed!!! 

 -----------snapcheck----------
Tested on 10.220.1.222
Final result:  Failed
Total passed:  0
Total failed: 1
{'get-configuration': [{'count': {'fail': 1, 'pass': 0},
                        'err': "SNMP community ''mycommunity' is not "
                               'configured!',
                        'failed': [{'actual_node_value': None,
                                    'id': {},
                                    'post': {},
                                    'pre': {},
                                    'xpath_error': True}],
                        'node_name': "community[name='mycommunity']",
                        'passed': [],
                        'result': False,
                        'test_name': 'test_snmp_config',
                        'testoperation': 'exists',
                        'xpath': '/configuration/snmp'}]}
# ls ~/ansible_release_v105_final/venv/etc/jsnapy/snapshots/
10.220.1.222_pre_get_configuration.xml  README

Thanks
Chidanand

@chidanandpujar
Copy link
Collaborator

I have provided the pass log in the above comment, closing this issue..

Thanks
Chidanand

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

No branches or pull requests

3 participants