]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Stop ignoring 400 errors returned by ODL
authorCédric Ollivier <ollivier.cedric@gmail.com>
Sun, 14 Sep 2014 11:04:21 +0000 (13:04 +0200)
committerCédric Ollivier <ollivier.cedric@gmail.com>
Tue, 11 Nov 2014 11:48:16 +0000 (11:48 +0000)
This commit stops ignoring 400 (Bad Request) HTTP codes returned by ODL
in create and update operations. It also modifies sendjson() because it
doesn't ignore any HTTP error code now.

Change-Id: Id0db2c0c1d8fddfbd16b3ce9476a2358e2ef1e49
Closes-Bug: #1369239
(cherry picked from commit f1507d080d9840e4cb6c1d5cfe5a4b6c1443bd8f)

neutron/plugins/ml2/drivers/mechanism_odl.py
neutron/tests/unit/ml2/test_mechanism_odl.py

index 05ca33bb7faff42e1405a8a8ff8c0c3bab572b10..e2fb229c6f3b0753e7968446abcd34025c4a3735 100644 (file)
@@ -218,10 +218,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
                         ctx.reraise = False
         key = collection_name[:-1] if len(to_be_synced) == 1 else (
             collection_name)
-
-        # 400 errors are returned if an object exists, which we ignore.
-        self.sendjson('post', collection_name, {key: to_be_synced},
-                      [requests.codes.bad_request])
+        self.sendjson('post', collection_name, {key: to_be_synced})
 
     @utils.synchronized('odl-sync-full')
     def sync_full(self, context):
@@ -276,9 +273,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
                     attr_filter = self.update_object_map[object_type]
                 resource = context.current.copy()
                 attr_filter(resource, context)
-                # 400 errors are returned if an object exists, which we ignore.
-                self.sendjson(method, urlpath, {object_type[:-1]: resource},
-                              [requests.codes.bad_request])
+                self.sendjson(method, urlpath, {object_type[:-1]: resource})
         except Exception:
             with excutils.save_and_reraise_exception():
                 self.out_of_sync = True
@@ -291,7 +286,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
                   for sg in port['security_groups']]
         port['security_groups'] = groups
 
-    def sendjson(self, method, urlpath, obj, ignorecodes=[]):
+    def sendjson(self, method, urlpath, obj):
         """Send json to the OpenDaylight controller."""
         headers = {'Content-Type': 'application/json'}
         data = jsonutils.dumps(obj, indent=2) if obj else None
@@ -301,10 +296,6 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
         r = requests.request(method, url=url,
                              headers=headers, data=data,
                              auth=self.auth, timeout=self.timeout)
-
-        # ignorecodes contains a list of HTTP error codes to ignore.
-        if r.status_code in ignorecodes:
-            return
         r.raise_for_status()
 
     def bind_port(self, context):
index 8d87eb5a6191981bd03306ec0231c9ee5ae514f5..5a93429f5a4507017627eeba881bdd64bf9363b8 100644 (file)
@@ -286,18 +286,17 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
                                     'delete', **kwargs)
 
     def test_create_network_postcommit(self):
-        for status_code in (requests.codes.created,
-                            requests.codes.bad_request):
-            self._test_create_resource_postcommit('network', status_code)
-        self._test_create_resource_postcommit(
-            'network', requests.codes.unauthorized,
-            requests.exceptions.HTTPError)
+        self._test_create_resource_postcommit('network',
+                                              requests.codes.created)
+        for status_code in (requests.codes.bad_request,
+                            requests.codes.unauthorized):
+            self._test_create_resource_postcommit(
+                'network', status_code, requests.exceptions.HTTPError)
 
     def test_create_subnet_postcommit(self):
-        for status_code in (requests.codes.created,
-                            requests.codes.bad_request):
-            self._test_create_resource_postcommit('subnet', status_code)
-        for status_code in (requests.codes.unauthorized,
+        self._test_create_resource_postcommit('subnet', requests.codes.created)
+        for status_code in (requests.codes.bad_request,
+                            requests.codes.unauthorized,
                             requests.codes.forbidden,
                             requests.codes.not_found,
                             requests.codes.conflict,
@@ -306,10 +305,9 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
                 'subnet', status_code, requests.exceptions.HTTPError)
 
     def test_create_port_postcommit(self):
-        for status_code in (requests.codes.created,
-                            requests.codes.bad_request):
-            self._test_create_resource_postcommit('port', status_code)
-        for status_code in (requests.codes.unauthorized,
+        self._test_create_resource_postcommit('port', requests.codes.created)
+        for status_code in (requests.codes.bad_request,
+                            requests.codes.unauthorized,
                             requests.codes.forbidden,
                             requests.codes.not_found,
                             requests.codes.conflict,
@@ -319,19 +317,17 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
                 'port', status_code, requests.exceptions.HTTPError)
 
     def test_update_network_postcommit(self):
-        for status_code in (requests.codes.ok,
-                            requests.codes.bad_request):
-            self._test_update_resource_postcommit('network', status_code)
-        for status_code in (requests.codes.forbidden,
+        self._test_update_resource_postcommit('network', requests.codes.ok)
+        for status_code in (requests.codes.bad_request,
+                            requests.codes.forbidden,
                             requests.codes.not_found):
             self._test_update_resource_postcommit(
                 'network', status_code, requests.exceptions.HTTPError)
 
     def test_update_subnet_postcommit(self):
-        for status_code in (requests.codes.ok,
-                            requests.codes.bad_request):
-            self._test_update_resource_postcommit('subnet', status_code)
-        for status_code in (requests.codes.unauthorized,
+        self._test_update_resource_postcommit('subnet', requests.codes.ok)
+        for status_code in (requests.codes.bad_request,
+                            requests.codes.unauthorized,
                             requests.codes.forbidden,
                             requests.codes.not_found,
                             requests.codes.not_implemented):
@@ -339,10 +335,9 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
                 'subnet', status_code, requests.exceptions.HTTPError)
 
     def test_update_port_postcommit(self):
-        for status_code in (requests.codes.ok,
-                            requests.codes.bad_request):
-            self._test_update_resource_postcommit('port', status_code)
-        for status_code in (requests.codes.unauthorized,
+        self._test_update_resource_postcommit('port', requests.codes.ok)
+        for status_code in (requests.codes.bad_request,
+                            requests.codes.unauthorized,
                             requests.codes.forbidden,
                             requests.codes.not_found,
                             requests.codes.conflict,