Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ develop-eggs
.installed.cfg
lib64
env
venv*

# Documentation
docs/_build
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ sudo: true

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"

addons:
apt:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ jsnap2py -i test_interface.conf -o interface.yml
```
For more information please refer [jsnap2py-wiki] (https://github.com/Juniper/jsnapy/wiki/7.-jsnap2py)


Logging:
--------
Log related details will be extracted from "logging.yml" in jsnapy.cfg file.
Default path is "/etc/jsnapy/logging.yml"

CONTRIBUTORS
-------------

Expand Down
2 changes: 1 addition & 1 deletion development.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r requirements.txt

coverage==4.0.0 # http://nedbatchelder.com/code/coverage/
coverage # http://nedbatchelder.com/code/coverage/
mock==1.0.1 # http://www.voidspace.org.uk/python/mock/
nose # http://nose.readthedocs.org/en/latest/
pep8 # https://github.com/jcrocholl/pep8
Expand Down
11 changes: 10 additions & 1 deletion lib/jnpr/jsnapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@
class DirStore:
custom_dir = None

# Function added by @gcasella
# To check if the user is currently running the installation inside of a virtual environment that was installed using the `python3 -m venv venv` command.
def venv_check():

if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
return True
else:
return False

def get_config_location(file='jsnapy.cfg'):
p_locations = []
if 'JSNAPY_HOME' in os.environ:
p_locations = [os.environ['JSNAPY_HOME']]

if hasattr(sys, 'real_prefix'):
# Modified by @gcasella to use the function created on lines 22-29.
if venv_check() is True:
p_locations.extend([os.path.join(os.path.expanduser("~"), '.jsnapy'),
os.path.join(sys.prefix, 'etc', 'jsnapy')])
elif 'win32' in sys.platform:
Expand Down
25 changes: 16 additions & 9 deletions lib/jnpr/jsnapy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@

class Comparator:

def __init__(self):
def __init__(self, **kwargs):
"""
Comparator object constructor.
:param int port.

"""
self.logger_check = logging.getLogger(__name__)
self.log_detail = {'hostname': None}

self.port = kwargs.get('port', None)

def is_op(self, op):
"""
Expand Down Expand Up @@ -63,6 +68,8 @@ def generate_snap_file(self, device, prefix, name, reply_format):
"""
This function generates name of snapshot files
"""
if self.port is not None:
device = "{}_{}".format(device, self.port)
if os.path.isfile(prefix):
return prefix
else:
Expand Down Expand Up @@ -209,7 +216,7 @@ def expression_evaluator(self, elem_test, op, x_path, id_list, iter, teston,
ele_list = ele_list + [elements.strip()
for elements
in xml_paras.split(',') if
elements.strip() is not '']
elements.strip() != '']
else:
ele_list = [elements.strip()
for elements in ele.split(',')]
Expand All @@ -226,7 +233,7 @@ def expression_evaluator(self, elem_test, op, x_path, id_list, iter, teston,
is_skipped = False
if testop in [
'no-diff', 'list-not-less', 'list-not-more', 'delta']:
if check is True or action is "check":
if check is True or action == "check":
xml1 = self.get_xml_reply(db, snap1)
xml2 = self.get_xml_reply(db, snap2)
if xml2 is None:
Expand Down Expand Up @@ -255,7 +262,7 @@ def expression_evaluator(self, elem_test, op, x_path, id_list, iter, teston,
else:
# if check is used with uni operand test operator then use
# second snapshot file
if check is True or action is "check":
if check is True or action == "check":
pre_snap = self.get_xml_reply(db, snap1)
post_snap = self.get_xml_reply(db, snap2)
else:
Expand Down Expand Up @@ -353,7 +360,7 @@ def expression_builder(self, sub_expr, parent_op=None, **kwargs):
expr = '{0} {1}'.format(parent_op,ret_expr[0])
elif len(ret_expr) >= 1 :
expr = ' {0} '.format(parent_op).join(ret_expr)
if expr is not '':
if expr != '':
expr = '(' +expr+ ')'
return expr

Expand Down Expand Up @@ -383,7 +390,7 @@ def compare_reply(
top_ignore_null = ignore_null_list[0].get('ignore-null')
#### extract all test cases in given test file ####
tests = [t for t in tests if ('iterate' in t or 'item' in t)]
if not len(tests) and (check is True or action is "check"):
if not len(tests) and (check is True or action == "check"):
res = self.compare_xml(op, db, teston, snap1, snap2)
if res is False:
op.no_failed = op.no_failed + 1
Expand Down Expand Up @@ -436,7 +443,7 @@ def compare_reply(
}
final_boolean_expr = self.expression_builder(testcases, None, **kwargs)
#for cases where skip was encountered due to ignore-null
if final_boolean_expr is '' or final_boolean_expr is None or final_boolean_expr == str(None):
if final_boolean_expr == '' or final_boolean_expr is None or final_boolean_expr == str(None):
continue

result = eval(final_boolean_expr)
Expand Down Expand Up @@ -752,7 +759,7 @@ def generate_test_files(

# if check is true then call function to compare two
# snapshots ####
if (check is True or action is "check") and reply_format == 'xml':
if (check is True or action == "check") and reply_format == 'xml':
if db.get('check_from_sqlite') is False:
snapfile2 = self.generate_snap_file(
device,
Expand Down
Loading