Skip to content

Commit bc56426

Browse files
authored
Merge pull request Juniper#206 from eeishaan/ignore-null-id-bug
Fix Juniper#184 -- ignore-null functionality with `id` field in check operators
2 parents ca71e53 + fbb32f4 commit bc56426

12 files changed

+294
-50
lines changed

lib/jnpr/jsnapy/check.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,19 @@ def expression_builder(self, sub_expr, parent_op=None, **kwargs):
253253
#this should be guaranteed by the operator function, never use try-catch here
254254
last_test_instance = kwargs['op'].test_details[kwargs['teston']][-1]
255255
res = last_test_instance['result']
256-
256+
257+
values = ['err', 'info']
258+
testvalues = elem.keys()
259+
testop1 = [
260+
tvalue for tvalue in testvalues if tvalue not in values]
261+
testop = testop1[0] if testop1 else "Define test operator"
257262
#for skipping cases
258-
if res is None or ( last_test_instance['count']['pass'] == 0 \
259-
and last_test_instance['count']['fail'] == 0 ):
263+
if res is None or (last_test_instance['count']['pass'] == 0 and
264+
last_test_instance['count']['fail'] == 0 and
265+
testop not in ['no-diff',
266+
'list-not-less',
267+
'list-not-more'
268+
]):
260269
continue
261270

262271
ret_expr.append(str(res))

lib/jnpr/jsnapy/operator.py

Lines changed: 77 additions & 41 deletions
Large diffs are not rendered by default.

samples/test_no_diff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ test_command_version:
1414
- no-diff: oper-status # element in which test is performed
1515
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']}}>"
1616
info: "Test succeeded!! oper-status is same with value, before it is <{{pre['oper-status']}}> now it is <{{post['oper-status']}}> with admin status <{{post['admin-status']}}> "
17-
17+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
check_chassis_fpc:
2+
- command: show chassis fpc
3+
- item:
4+
xpath: //fpc
5+
id: bogus-slot
6+
tests:
7+
- delta: memory-heap-utilization, 50%
8+
info: "Test Succeeded!! Memory heap utilisation of the FPC {{id_0}} has changed less than 50%"
9+
err: "Test Failed!!! Memory heap utilisation of the FPC {{id_0}} has changed less than 50%"
10+
ignore-null: True
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
# use '/' in your test cases apart from xpath if u want to search all elements irrespective of hierarchy, ex: in id if u use /name instead of name
4+
# then it will search in all the names in given xpath irrespective of their position
5+
# for simple, one test using command
6+
7+
test_command_version1:
8+
- command: show interfaces terse ge-*
9+
- iterate:
10+
xpath: physical-interface
11+
id: bogus-name
12+
tests:
13+
- list-not-less: name
14+
err: "Interface {{pre['name']}} is missing in post snapshot"
15+
info: "Interface {{pre['name']}} is present in post snapshot"
16+
ignore-null: True
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tests_include:
2+
- test_command_version
3+
4+
# use '/' in your test cases apart from xpath if u want to search all elements irrespective of hierarchy, ex: in id if u use /name instead of name
5+
# then it will search in all the names in given xpath irrespective of their position
6+
# for simple, one test using command
7+
8+
test_command_version:
9+
- command: show interfaces terse ge-*
10+
- iterate:
11+
xpath: physical-interface
12+
id: bogus-name
13+
tests:
14+
- list-not-more: name
15+
err: "Interface {{post['name']}} has been added in post snapshot"
16+
info: "Interface {{post['name']}} was present in pre snapshot"
17+
ignore-null: True
18+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# for one device, can be given like this:
3+
hosts:
4+
- device: 10.216.193.114
5+
username : abc
6+
passwd: xyz
7+
tests:
8+
- delta_ignore-null_id_skip.yml
9+
10+
sqlite:
11+
- store_in_sqlite: yes
12+
check_from_sqlite: no
13+
database_name: jbb.db
14+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# for one device, can be given like this:
3+
hosts:
4+
- device: 10.216.193.114
5+
username : abc
6+
passwd: xyz
7+
tests:
8+
- list-not-less_ignore-null_id_skip.yml
9+
10+
11+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# for one device, can be given like this:
3+
hosts:
4+
- device: 10.216.193.114
5+
username : abc
6+
passwd: xyz
7+
tests:
8+
- list-not-more_ignore-null_id_skip.yml
9+
10+
sqlite:
11+
- store_in_sqlite: yes
12+
check_from_sqlite: no
13+
database_name: jbb.db
14+
15+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# for one device, can be given like this:
3+
hosts:
4+
- device: 10.216.193.114
5+
username : abc
6+
passwd: xyz
7+
tests:
8+
- no-diff_ignore-null_id_skip.yml
9+
10+
# sqlite:
11+
# - store_in_sqlite: yes
12+
# check_from_sqlite: no
13+
# database_name: jbb.db
14+

0 commit comments

Comments
 (0)