Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
fix: intent comparison name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeff07 committed Dec 20, 2021
1 parent af73042 commit 7439482
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions examples/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"""
print()

compare = ipf.intent.compare_snapshot('$lastLocked', reverse=False)
compare = ipf.intent.compare_snapshot('$lastLocked', reverse=True)
print(tabulate(compare, headers="keys"))
"""
Current: The snapshot loaded into the intent class:
Expand All @@ -88,13 +88,13 @@
ipf.intent.compare_snapshot('$prev', reverse=True)
Reverse (Default: False): Will flip current and other. Use when class is newest date and compare is an older date.
name id check current other diff
-------------------------------------------- ---------- ------- --------- ------- ------
CDP/LLDP unidirectional 320633253 total 21 25 4
CDP/LLDP unidirectional 320633253 blue 21 25 4
BGP Session Age 322316677 total 344 367 23
BGP Session Age 322316677 green 254 309 55
BGP Session Age 322316677 blue 56 22 -34
BGP Session Age 322316677 amber 0 3 3
BGP Session Age 322316677 red 34 33 -1
name id check loaded_snapshot compare_snapshot diff
-------------------------------------------- ---------- ------- ----------------- ------------------ ------
CDP/LLDP unidirectional 320633253 total 25 18 -7
CDP/LLDP unidirectional 320633253 blue 25 18 -7
BGP Session Age 322316677 total 367 358 -9
BGP Session Age 322316677 green 309 305 -4
BGP Session Age 322316677 blue 22 19 -3
BGP Session Age 322316677 amber 3 0 -3
BGP Session Age 322316677 red 33 33 0
"""
4 changes: 2 additions & 2 deletions ipfabric/intent_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def compare(self, other):
new = other.checks
data = dict()
if self.count is not None or other.count is not None:
data['count'] = dict(current=self.count or 0, other=other.count or 0,
data['count'] = dict(loaded_snapshot=self.count or 0, compare_snapshot=other.count or 0,
diff=(other.count or 0) - (self.count or 0))

for value in ['green', 'blue', 'amber', 'red']:
if getattr(old, value) is not None or getattr(new, value) is not None:
o = self.get_value(old, value)
n = self.get_value(new, value)
data[value] = dict(current=o, other=n, diff=(n - o))
data[value] = dict(loaded_snapshot=o, compare_snapshot=n, diff=(n - o))
return data

@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions tests/unittests/test_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def test_compare(self, mock_i):
self.i_json["result"]["checks"]["30"] = 100
mock_i.return_value = [imodels.IntentCheck(**self.i_json)]
comp = self.i.compare_snapshot('$last')
data = [{'name': 'CDP/LLDP unidirectional', 'id': '320633253', 'check': 'total', 'current': 21, 'other': 21,
'diff': 0}, {'name': 'CDP/LLDP unidirectional', 'id': '320633253', 'check': 'blue', 'current': 21,
'other': 22, 'diff': 1}, {'name': 'CDP/LLDP unidirectional', 'id': '320633253',
'check': 'amber', 'current': 10, 'other': 5, 'diff': -5},
{'name': 'CDP/LLDP unidirectional', 'id': '320633253', 'check': 'red', 'current': 0, 'other': 100,
data = [{'name': 'CDP/LLDP unidirectional', 'id': '320633253', 'check': 'total', 'loaded_snapshot': 21, 'compare_snapshot': 21,
'diff': 0}, {'name': 'CDP/LLDP unidirectional', 'id': '320633253', 'check': 'blue', 'loaded_snapshot': 21,
'compare_snapshot': 22, 'diff': 1}, {'name': 'CDP/LLDP unidirectional', 'id': '320633253',
'check': 'amber', 'loaded_snapshot': 10, 'compare_snapshot': 5, 'diff': -5},
{'name': 'CDP/LLDP unidirectional', 'id': '320633253', 'check': 'red', 'loaded_snapshot': 0, 'compare_snapshot': 100,
'diff': 100}]

self.assertEqual(comp, data)
8 changes: 4 additions & 4 deletions tests/unittests/test_intent_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def test_result_compare(self):
result = imodels.Result(count=100, checks={'0': 1, '20': 5})
result2 = imodels.Result(count=80, checks={'0': 2, '20': 1, '30': 10})
comp = result.compare(result2)
self.assertEqual(comp['count'], {'current': 100, 'other': 80, 'diff': -20})
self.assertEqual(comp['green'], {'current': 1, 'other': 2, 'diff': 1})
self.assertEqual(comp['amber'], {'current': 5, 'other': 1, 'diff': -4})
self.assertEqual(comp['red'], {'current': 0, 'other': 10, 'diff': 10})
self.assertEqual(comp['count'], {'loaded_snapshot': 100, 'compare_snapshot': 80, 'diff': -20})
self.assertEqual(comp['green'], {'loaded_snapshot': 1, 'compare_snapshot': 2, 'diff': 1})
self.assertEqual(comp['amber'], {'loaded_snapshot': 5, 'compare_snapshot': 1, 'diff': -4})
self.assertEqual(comp['red'], {'loaded_snapshot': 0, 'compare_snapshot': 10, 'diff': 10})

def test_child(self):
child = imodels.Child(weight=10, id='TEST')
Expand Down

0 comments on commit 7439482

Please sign in to comment.