Fix Flake8 errors
[integration/test.git] / csit / libraries / XmlComparator.py
index 7bd8fff2fdf01835b5dd07721e1f7ca85e88371f..7c2617539ccf08e375055e2d52bc11204f7ab870 100644 (file)
@@ -176,10 +176,15 @@ class XMLtoDictParserTools():
                 diff[key] = (KEY_NOT_FOUND, key)
         return diff
 
+
 IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON = ['id', 'flow-name', 'barrier', 'cookie_mask', 'installHw', 'flags',
                                            'strict', 'byte-count', 'duration', 'packet-count', 'in-port',
                                            'vlan-id-present', 'out_group', 'out_port', 'hard-timeout', 'idle-timeout',
-                                           'flow-statistics', 'cookie', 'clear-actions']  # noqa
+                                           'flow-statistics', 'cookie', 'clear-actions',
+                                           'ipv4-source-address-no-mask', 'ipv4-source-arbitrary-bitmask',
+                                           'ipv4-destination-address-no-mask', 'ipv4-destination-arbitrary-bitmask',
+                                           'ipv6-source-address-no-mask', 'ipv6-source-arbitrary-bitmask',
+                                           'ipv6-destination-address-no-mask', 'ipv6-destination-arbitrary-bitmask']  # noqa
 
 IGNORED_PATHS_FOR_OC = [(['flow', 'instructions', 'instruction', 'apply-actions', 'action', 'controller-action'], True),  # noqa
                         (['flow', 'instructions', 'instruction', 'clear-actions', 'action'], False),
@@ -213,8 +218,6 @@ class XmlComparator:
             nodeDict = XMLtoDictParserTools.parseTreeToDict(node)
             XMLtoDictParserTools.addDictValue(reportDict, index, nodeDict)
             index += 1
-            # print nodeDict
-            # print origDict
             if nodeDict == origDict:
                 return True, ''
             if nodeDict['flow']['priority'] == origDict['flow']['priority']:
@@ -222,9 +225,8 @@ class XmlComparator:
                     XMLtoDictParserTools.getDifferenceDict(nodeDict, origDict))
         return False, ''
 
-    def is_flow_operational2(self, requested_flow, oper_resp):
+    def is_flow_operational2(self, requested_flow, oper_resp, check_id=False):
         def _rem_unimplemented_tags(tagpath, recurs, tdict):
-            # print "_rem_unimplemented_tags", tagpath, tdict
             if len(tagpath) > 1 and tagpath[0] in tdict:
                 _rem_unimplemented_tags(tagpath[1:], recurs, tdict[tagpath[0]])
 
@@ -241,11 +243,9 @@ class XmlComparator:
                 del tdict[tagpath[0]]
             if tdict.keys() == ['order']:
                 del tdict['order']
-            # print "leaving", tdict
 
         def _add_tags(tagpath, newtag, value, tdict):
             '''if whole tagpath exists and the tag is not present, it is added with given value'''
-            # print "_add_tags", tagpath, newtag, value, tdict
             if len(tagpath) > 0 and tagpath[0] in tdict:
                 _add_tags(tagpath[1:], newtag, value, tdict[tagpath[0]])
             elif len(tagpath) == 0 and newtag not in tdict:
@@ -253,19 +253,21 @@ class XmlComparator:
 
         def _to_be_modified_tags(tagpath, tag, related_tag, tdict):
             '''if whole tagpath exists and the tag is not present, it is added with given value'''
-            # print "_to_be_modified_tags", tagpath, tag, related_tag, tdict
             if len(tagpath) > 0 and tagpath[0] in tdict:
                 _to_be_modified_tags(tagpath[1:], tag, related_tag, tdict[tagpath[0]])
             elif len(tagpath) == 0 and tag in tdict and related_tag in tdict:
                 tdict[tag] = str(long(tdict[tag]) & long(tdict[related_tag]))
 
+        IGNORED_TAGS_LIST = list(IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON)
+        if check_id:
+            IGNORED_TAGS_LIST.remove('id')
         orig_tree = md.parseString(requested_flow)
         xml_resp_stream = oper_resp.encode('utf-8', 'ignore')
         xml_resp_tree = md.parseString(xml_resp_stream)
         nodeListOperFlows = xml_resp_tree.getElementsByTagNameNS("*", 'flow')
         origDict = XMLtoDictParserTools.parseTreeToDict(
             orig_tree._get_documentElement(),
-            ignoreList=IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON)
+            ignoreList=IGNORED_TAGS_LIST)
 
         # origDict['flow-statistics'] = origDict.pop( 'flow' )
         reportDict = {}
@@ -273,25 +275,20 @@ class XmlComparator:
         for node in nodeListOperFlows:
             nodeDict = XMLtoDictParserTools.parseTreeToDict(
                 node,
-                ignoreList=IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON)
+                ignoreList=IGNORED_TAGS_LIST)
             XMLtoDictParserTools.addDictValue(reportDict, index, nodeDict)
             index += 1
-            # print nodeDict
-            # print origDict
-            # print reportDict
             if nodeDict == origDict:
                 return True, ''
             if nodeDict['flow']['priority'] == origDict['flow']['priority']:
                 for p in IGNORED_PATHS_FOR_OC:
                     td = copy.copy(origDict)
-                    _rem_unimplemented_tags(p[0], p[1],  td)
+                    _rem_unimplemented_tags(p[0], p[1], td)
                     for (p, t, v) in TAGS_TO_ADD_FOR_OC:
                         _add_tags(p, t, v, td)
                     for (p, t, rt) in TAGS_TO_MODIFY_FOR_OC:
                         _to_be_modified_tags(p, t, rt, td)
 
-                    # print "comparing1", nodeDict
-                    # print "comparing2", td
                     if nodeDict == td:
                         return True, ''
                 if nodeDict == origDict: