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

Jsnapy is not executing #336

Open
Erdix opened this issue Apr 14, 2019 · 8 comments
Open

Jsnapy is not executing #336

Erdix opened this issue Apr 14, 2019 · 8 comments
Assignees
Labels

Comments

@Erdix
Copy link

Erdix commented Apr 14, 2019

Hi all,
There is the following issue that has been occurring on Win 10 and Python 3.7.3rc1. Any help please?

c:\Users\erix\jsnapy\snapshots>jsnapy --snap pre_snapfile.yml -f config_snap.yml
ERROR!! TypeError
Complete Message: 'NoneType' object is not subscriptable

Config_snap.yml file is:

hosts:  
-device: X.X.X.X
  username:demo
  passwd:demo
tests:
 -test_is_equal.yml

test_is_equal.yml file is:

test_command_version:
  - command: show interfaces terse lo* 
  - iterate:
      xpath: physical-interface
      id: './name'
      tests:
        - no-diff: oper-status       # element in which test is performed
          err: "Test Failed!! oper-status  got changed, before it was <{{pre['oper-status']}}>, now it is <{{post['oper-status']}}>"
          info: "Test Passed!! oper-status is same, before it is <{{pre['oper-status']}}> now it is <{{post['oper-status']}}> 

c:\Users\erix\jsnapy\snapshots>
c:\Users\erix\jsnapy\snapshots>jsnapy --version
JSNAPy version: 1.3.2

c:\Users\erix\jsnapy>dir
11/04/2019 02:43 PM

.
11/04/2019 02:43 PM ..
11/04/2019 02:22 PM 109 config_snap.yml
01/04/2019 11:43 AM 436 jsnapy.cfg
01/04/2019 11:43 AM 1,516 logging.yml
01/04/2019 11:43 AM snapshots
11/04/2019 02:43 PM testfiles
3 File(s) 2,061 bytes
4 Dir(s) 210,458,386,432 bytes free

c:\Users\erix\jsnapy>
c:\Users\erix\jsnapy>pip list
Package Version
asn1crypto 0.24.0
bcrypt 3.1.6
cffi 1.12.2
colorama 0.4.1
configparser 3.7.4
cryptography 2.6.1
future 0.17.1
icdiff 1.9.1
Jinja2 2.10
jsnapy 1.3.2
junos-eznc 2.2.1.dev0
lxml 4.3.2
MarkupSafe 1.1.1
ncclient 0.6.3
netaddr 0.7.19
paramiko 2.4.2
pip 19.0.3
pyasn1 0.4.5
pycparser 2.19
PyNaCl 1.3.0
pyparsing 2.3.1
pyserial 3.4
PyYAML 5.1
scp 0.13.2
selectors2 2.0.1
setuptools 40.8.0
six 1.12.0
c:\Users\erix\jsnapy>

H:>py
Python 3.7.3rc1 (tags/v3.7.3rc1:69785b2127, Mar 12 2019, 22:37:55) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Thanks for help.
Erix...

@Erdix
Copy link
Author

Erdix commented Apr 16, 2019

Any help please regarding my previous post? I really appreciate your assistance....Thx.

@mamathac
Copy link

@Erdix

I could get the snapshot without any issues for the same test file.(python3.4)
++++

(venv) user@host:~/venv/etc/jsnapy/snapshots# pip freeze
DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429).
asn1crypto==0.24.0
bcrypt==3.1.6
cffi==1.12.2
colorama==0.4.1
configparser==3.7.4
cryptography==2.6.1
future==0.17.1
icdiff==1.9.1
Jinja2==2.10.1
jsnapy==1.3.2
junos-eznc==2.2.0
lxml==4.3.3
MarkupSafe==1.1.1
ncclient==0.6.4
netaddr==0.7.19
paramiko==2.4.2
pyasn1==0.4.5
pycparser==2.19
PyNaCl==1.3.0
pyparsing==2.4.0
pyserial==3.4
PyYAML==5.1
scp==0.13.2
selectors2==2.0.1
six==1.12.0

(venv) user@host:~/venv/test_336# /root/venv/bin/jsnapy --snap snap.yml -f config.yml -v
jsnapy.cfg file location used : /root/venv/etc/jsnapy
Configuration file location used : /root/venv/etc/jsnapy
Connecting to device x.x.x.x ................
Tests Included: test_command_version
Taking snapshot of COMMAND: show interfaces terse lo*

(venv) user@host:~/venv/test_336# cat config.yml
hosts:

  • device: x.x.x.x
    username: user
    passwd: pwd
    tests:
  • test_336.yml

Testfile:
(venv) user@host:~/venv/test_336# cat test_336.yml
test_command_version:

  • command: show interfaces terse lo*
  • iterate:
    xpath: physical-interface
    id: ./host-name
    tests:
    - no-diff: oper-status # element in which test is performed
    info: "Test Passed!! oper-status is same, before it is <{{pre['oper-status']}}> now it is <{{post['oper-status']}}>"
    err: "Test Failed!! oper-status got changed, before it was <{{pre['oper-status']}}>, now it is <{{post['oper-status']}}>"

NO changes made to the test file or config file <<<<

Snapshot created:

(venv) user@host:~/venv/etc/jsnapy/snapshots# ls -lrt
total 8
-rwxr-xr-x 1 root root 146 May 31 2018 README
-rw-r--r-- 1 root root 1930 Apr 16 18:26 x.x.x.x_snap.yml_show_interfaces_terse_lo_.xml

Could you run the same command with -v option and paste the result?

@Erdix
Copy link
Author

Erdix commented Apr 16, 2019

Hi Mamathac,

Thanks for help.
Firstly, I switched the Python version to 2.7. But it gives same error again...

C:\Users\erix\jsnapy\snapshots>jsnapy --snap snap.yml -f config_snap.yml -v
jsnapy.cfg file location used : C:\Users\erix\jsnapy
Configuration file location used : C:\Users\erix\jsnapy
ERROR!! TypeError
Complete Message: 'NoneType' object is not subscriptable
C:\Users\erix\jsnapy\snapshots>

When looking at the "Day One: Enabling Automated Network Verifications with JSNAPY". And the page of 12, under the "JSNAP and JSNAPy" it says that jsnapy is based on Python 2.7.... So I installed the Python version 2.7. And switched it to 2.7 as showing below. But not sure it was really switched or not! Another thing that I need to specify that there is no installed python virtual environment in my windows 10 systems.

C:>python
Python 3.7.3rc1 (tags/v3.7.3rc1:69785b2127, Mar 12 2019, 22:37:55) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

exit()

C:>
C:>py -2
Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

@mamathac
Copy link

Hi @Erdix ,

To make sure jsnapy used the correct python version , use virtualenv and install jsnapy from virtualenv.
Eg:
virtualenv -p <python path .2.7> venv
then source using command,
source venv/bin/activate.

after this, install JSNAPY which will install JSNAPY under /venv/etc/jsnapy

I see by default JSNAPY gets installed under /etc/jsnapy(even for mac), wonder how is it installed at /User/XXX.

Could you try once using virtualenv?

@Erdix
Copy link
Author

Erdix commented Apr 18, 2019

Hi Mamathac,
I installed the Python 3.4.4 and created its virtual environment on my system -64 bit Windows 10. I run it, but unfortunately , the same error occurs again -ERROR!! TypeError Complete Message: 'NoneType' object is not subscriptable.

Thanks for help again...I look forward to seeing your reply.......Here some outputs:

(venv) H:>py
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

C:\Users\erix\Envs\venv\etc\jsnapy

(venv) H:>jsnapy --snap pre_snapfile.yml -f config_snap.yml -v
c:\users\erix\envs\venv\lib\site-packages\jnpr\jsnapy\setup_logging.py:25: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
config = yaml.load(f.read())
jsnapy.cfg file location used : c:\users\erix\envs\venv\etc\jsnapy
Configuration file location used : c:\users\erix\envs\venv\etc\jsnapy
c:\users\erix\envs\venv\lib\site-packages\jnpr\jsnapy\jsnapy.py:334: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
self.main_file = yaml.load(config_file)
ERROR!! TypeError
Complete Message: 'NoneType' object is not subscriptable
(venv) H:>

(venv) H:>pip list
DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429).
Package Version


asn1crypto 0.24.0
bcrypt 3.1.6
cffi 1.12.2
colorama 0.4.1
configparser 3.7.4
cryptography 2.6.1
future 0.17.1
icdiff 1.9.1
Jinja2 2.10.1
jsnapy 1.3.2
junos-eznc 2.2.0
lxml 4.3.3
MarkupSafe 1.1.1
ncclient 0.6.4
netaddr 0.7.19
paramiko 2.4.2
pip 19.0.3
pyasn1 0.4.5
pycparser 2.19
PyNaCl 1.3.0
pyparsing 2.4.0
pyserial 3.4
PyYAML 5.1
scp 0.13.2
selectors2 2.0.1
setuptools 41.0.0
six 1.12.0
wheel 0.33.1

(venv) H:>

(venv) H:>jsnapy
c:\users\erix\envs\venv\lib\site-packages\jnpr\jsnapy\setup_logging.py:25: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
config = yaml.load(f.read())
usage:
This tool enables you to capture and audit runtime environment of
networked devices running the Junos operating system (Junos OS)

Tool to capture snapshots and compare them
It supports four subcommands:
--snap, --check, --snapcheck, --diff

  1. Take snapshot:
    jsnapy --snap pre_snapfile -f main_configfile
  2. Compare snapshots:
    jsnapy --check post_snapfile pre_snapfile -f main_configfile
  3. Compare current configuration:
    jsnapy --snapcheck snapfile -f main_configfile
  4. Take diff without specifying test case:
    jsnapy --diff pre_snapfile post_snapfile -f main_configfile

positional arguments:
pre_snapfile pre snapshot filename
post_snapfile post snapshot filename

optional arguments:
-h, --help show this help message and exit
--snap take the snapshot for commands specified in test file
--check compare pre and post snapshots based on test operators specified in test file
--snapcheck check current snapshot based on test file
--diff display difference between two snapshots
-V, --version displays version
-T TESTFILES [TESTFILES ...], --testfiles TESTFILES [TESTFILES ...]
test file paths
-f FILE, --file FILE config file to take snapshot
--local whether to run snapcheck on local snapshot
--folder FOLDER custom directory path for lookup
-t HOSTNAME, --hostname HOSTNAME
hostname
-p PASSWD, --passwd PASSWD
password to login
-l LOGIN, --login LOGIN
username to login
-P PORT, --port PORT port no to connect to device
-v, --verbosity Set verbosity
-v: Debug level messages
-vv: Info level messages
-vvv: Warning level messages
-vvvv: Error level messages
-vvvvv: Critical level messages

(venv) H:>

C:\Users\erix\Envs\venv\etc\jsnapy>dir

Directory of C:\Users\erix\Envs\venv\etc\jsnapy

18/04/2019 02:39 PM

.
18/04/2019 02:39 PM ..
18/04/2019 01:28 PM 109 config_snap.yml
18/04/2019 01:04 PM 478 jsnapy.cfg
18/04/2019 01:04 PM 1,572 logging.yml
18/04/2019 01:04 PM snapshots
18/04/2019 01:34 PM testfiles
3 File(s) 2,159 bytes
4 Dir(s) 207,107,133,440 bytes free

C:\Users\erix\Envs\venv\etc\jsnapy>

C:\Users\erix\Envs\venv\etc\jsnapy\testfiles>dir

Directory of C:\Users\erix\Envs\venv\etc\jsnapy\testfiles

18/04/2019 01:34 PM

.
18/04/2019 01:34 PM ..
31/05/2018 10:29 PM 201 README
18/04/2019 01:34 PM 483 test_is_equal.yml
2 File(s) 684 bytes
2 Dir(s) 207,106,015,232 bytes free

C:\Users\erix\Envs\venv\etc\jsnapy\testfiles>

Jsnapy.cfg config is under the C:\Users\erix\Envs\venv\etc\jsnapy

[DEFAULT]
config_file_path = c:\users\erix\envs\venv\etc\jsnapy
snapshot_path = c:\users\erix\envs\venv\etc\jsnapy\snapshots
test_file_path = c:\users\erix\envs\venv\etc\jsnapy\testfiles

Thanks
Erix

@sidhujasminder
Copy link
Contributor

@Erdix Will get back to you, after trying on a windows machine. Till then please confirm that snapshots are being captured. And please place the content here, i will look further into it.

@sidhujasminder sidhujasminder self-assigned this Apr 21, 2019
@Erdix
Copy link
Author

Erdix commented Apr 23, 2019

I tried it again... The same error gives.... Can I ask you about how do you understand that there is a bug?

Thanks.
Erix

@sidhujasminder
Copy link
Contributor

sidhujasminder commented Apr 29, 2019

@Erdix I am able to get all the data proper. On windows laptop! Do you have ubuntu available? If yes, can you please verify over there?

Executing the following:
jsnapy --snap snap_pre.yml -f main.yml

I get the following response:

jsnapy.cfg file location used : /Users/xyz/env/etc/jsnapy/
Configuration file location used :
Connecting to device x.x.x.x ................
Tests Included: test_command_version 
Taking snapshot of COMMAND: show interfaces terse lo* 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants