test fix 45/4345/1
authorJuraj Sebin <jsebin@cisco.com>
Fri, 17 Jan 2014 09:41:24 +0000 (10:41 +0100)
committerJuraj Sebin <jsebin@cisco.com>
Fri, 17 Jan 2014 09:41:24 +0000 (10:41 +0100)
delete flow after test

Change-Id: Ia6920b25a8c22fdf843e18d6cee01cfbf3691cfb
Signed-off-by: Juraj Sebin <jsebin@cisco.com>
test-scripts/odl_tests.py
test-scripts/odl_tests_new.py

index a8639cb51d7993b030e165bfd8743c0b2ad06174..2b6f1d913c76f6a025bd2b8d9077ab7edb1bc6d7 100755 (executable)
@@ -517,6 +517,13 @@ def get_values(node, *tags):
         if node.nodeName in result and len(node.childNodes) > 0:
             result[node.nodeName] = node.childNodes[0].nodeValue
     return result
+    
+    
+class BadResponseCodeError(Exception):
+    def __init__(self, value):
+        self.value = value
+    def __str__(self):
+        return repr('BadResponseCodeError: %s' % self.value)    
 
 
 def generate_tests_from_xmls(path, xmls=None):
@@ -541,33 +548,41 @@ def generate_tests_from_xmls(path, xmls=None):
             }
             log.info('sending request to url: {}'.format(url))
             rsp = requests.put(url, auth=('admin', 'admin'), data=xml_string,
-                               headers=headers)
+                               headers=headers)                               
             log.info('received status code: {}'.format(rsp.status_code))
             log.debug('received content: {}'.format(rsp.text))
             assert rsp.status_code == 204 or rsp.status_code == 200, 'Status' \
                     ' code returned %d' % rsp.status_code
 
-            # check request content against restconf's datastore
-            response = requests.get(url, auth=('admin', 'admin'),
+            try:        
+                # check request content against restconf's datastore
+                response = requests.get(url, auth=('admin', 'admin'),
+                                        headers={'Accept': 'application/xml'})
+                if response.status_code != 200:
+                    raise BadResponseCodeError('response: {}'.format(response))
+                    
+                req = xmltodict.parse(ET.tostring(ET.fromstring(xml_string)))
+                res = xmltodict.parse(ET.tostring(ET.fromstring(response.text)))
+                assert req == res, 'uploaded and stored xml, are not the same\n' \
+                    'uploaded: %s\nstored:%s' % (req, res)
+
+                # collect flow table state on switch
+                switch_flows = get_flows(self.net)
+                assert len(switch_flows) > 0
+
+                # compare requested object and flow table state
+                for important_element in check_elements(xml_string, keywords):
+                    # log.info('important element: {}'.format(important_element.nodeName))
+                    comparator = COMPARATORS.get(important_element.nodeName,
+                                                 COMPARATORS['default'])
+
+                    comparator(important_element, switch_flows[0])                    
+            finally:    
+                response = requests.delete(url, auth=('admin', 'admin'),
                                     headers={'Accept': 'application/xml'})
-            assert response.status_code == 200
-            req = xmltodict.parse(ET.tostring(ET.fromstring(xml_string)))
-            res = xmltodict.parse(ET.tostring(ET.fromstring(response.text)))
-            assert req == res, 'uploaded and stored xml, are not the same\n' \
-                'uploaded: %s\nstored:%s' % (req, res)
-
-            # collect flow table state on switch
-            switch_flows = get_flows(self.net)
-            assert len(switch_flows) > 0
-
-            # compare requested object and flow table state
-            for important_element in check_elements(xml_string, keywords):
-                # log.info('important element: {}'.format(important_element.nodeName))
-                comparator = COMPARATORS.get(important_element.nodeName,
-                                             COMPARATORS['default'])
-
-                comparator(important_element, switch_flows[0])
-
+                assert response.status_code == 200
+                print '\n\n\n'
+                
         return new_test
 
     # generate list of available xml requests
index 45843a6323a5c6e066ed735d4fbbd6bc888d55c0..24dbadb46c1d0562eb88996d29cd2a41d77119b2 100644 (file)
@@ -254,26 +254,31 @@ def generate_tests_from_xmls(path, xmls=None):
             log.debug('received content: {}'.format(rsp.text))
             assert rsp.status_code == 204 or rsp.status_code == 200, 'Status' \
                     ' code returned %d' % rsp.status_code
-
-            # check request content against restconf's datastore
-            response = requests.get(url, auth=('admin', 'admin'),
+            try:
+                # check request content against restconf's datastore
+                response = requests.get(url, auth=('admin', 'admin'),
+                                        headers={'Accept': 'application/xml'})
+                assert response.status_code == 200
+                req = (xmltodict.parse(ET.tostring(ET.fromstring(xml_string))))
+                res = (xmltodict.parse(ET.tostring(ET.fromstring(response.text))))
+                assert req == res, 'uploaded and stored xml, are not the same\n' \
+                    'uploaded: %s\nstored:%s' % (req, res)
+
+                # collect flow table state on switch
+                switch_flows = MininetTools.get_flows(self.net)
+                assert len(switch_flows) > 0
+
+                # compare requested object and flow table state
+                if mn_string is not None:
+                    #log.info('running tests')
+                    Comparator.compare_results(switch_flows[0], ParseTools.dump_string_to_dict(mn_string))
+                else:
+                    log.error('cannot find test results - comparison skipped')
+            finally:    
+                response = requests.delete(url, auth=('admin', 'admin'),
                                     headers={'Accept': 'application/xml'})
-            assert response.status_code == 200
-            req = (xmltodict.parse(ET.tostring(ET.fromstring(xml_string))))
-            res = (xmltodict.parse(ET.tostring(ET.fromstring(response.text))))
-            assert req == res, 'uploaded and stored xml, are not the same\n' \
-                'uploaded: %s\nstored:%s' % (req, res)
-
-            # collect flow table state on switch
-            switch_flows = MininetTools.get_flows(self.net)
-            assert len(switch_flows) > 0
-
-            # compare requested object and flow table state
-            if mn_string is not None:
-                #log.info('running tests')
-                Comparator.compare_results(switch_flows[0], ParseTools.dump_string_to_dict(mn_string))
-            else:
-                log.error('cannot find test results - comparison skipped')
+                assert response.status_code == 200
+                print '\n\n\n'    
 
         return new_test