Skip to content

Commit 76ffba7

Browse files
Merge pull request #18 from SWR-MoIP/PaulWinterstein-fix-ngraphelement-compare-ignore-rev-path
fix get_changed_ignore_rev, get_removed_ignore_rev and get_added_ignore_rev in topology_device_configuration_compare.py
2 parents 7b27a36 + 7fda6bd commit 76ffba7

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

src/videoipath_automation_tool/apps/topology/model/topology_device_configuration_compare.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
from videoipath_automation_tool.apps.topology.model.topology_device import TopologyDevice
1414

1515

16+
def is_revision_path(path: str) -> bool:
17+
"""
18+
Returns True if the given DeepDiff path refers to the 'rev' attribute directly under root.
19+
Examples that return True:
20+
- "root['rev']"
21+
- "root.rev"
22+
"""
23+
path = path.strip()
24+
if path.startswith("root"):
25+
path = path[4:].strip()
26+
return path in (".rev", "['rev']", '["rev"]')
27+
28+
1629
class NGraphElementConfigurationDiff(BaseModel):
1730
"""Class which contains the configuration differences on attribute level between two nGraphElements."""
1831

@@ -22,30 +35,15 @@ class NGraphElementConfigurationDiff(BaseModel):
2235

2336
def get_changed_ignore_rev(self) -> list:
2437
"""Method to get the changed values of the nGraphElement, ignoring the revision."""
25-
changed_list = []
26-
if len(self.changed) > 0:
27-
for change in self.changed:
28-
if change["path"] != "root.rev":
29-
changed_list.append(change)
30-
return changed_list
38+
return [change for change in self.changed if not is_revision_path(change["path"])]
3139

3240
def get_removed_ignore_rev(self) -> list:
3341
"""Method to get the removed values of the nGraphElement, ignoring the revision."""
34-
removed_list = []
35-
if len(self.removed) > 0:
36-
for remove in self.removed:
37-
if remove["path"] != "root.rev":
38-
removed_list.append(remove)
39-
return removed_list
42+
return [remove for remove in self.removed if not is_revision_path(remove["path"])]
4043

4144
def get_added_ignore_rev(self) -> list:
4245
"""Method to get the added values of the nGraphElement, ignoring the revision."""
43-
added_list = []
44-
if len(self.added) > 0:
45-
for add in self.added:
46-
if add["path"] != "root.rev":
47-
added_list.append(add)
48-
return added_list
46+
return [add for add in self.added if not is_revision_path(add["path"])]
4947

5048

5149
class NGraphElementDiff(BaseModel):

0 commit comments

Comments
 (0)