Stop ignoring 400 errors returned by ODL
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
This commit is contained in:
parent
b01c6f56f2
commit
cc1e13b66d
@ -220,10 +220,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
|
|||||||
ctx.reraise = False
|
ctx.reraise = False
|
||||||
key = collection_name[:-1] if len(to_be_synced) == 1 else (
|
key = collection_name[:-1] if len(to_be_synced) == 1 else (
|
||||||
collection_name)
|
collection_name)
|
||||||
|
self.sendjson('post', collection_name, {key: to_be_synced})
|
||||||
# 400 errors are returned if an object exists, which we ignore.
|
|
||||||
self.sendjson('post', collection_name, {key: to_be_synced},
|
|
||||||
[requests.codes.bad_request])
|
|
||||||
|
|
||||||
@utils.synchronized('odl-sync-full')
|
@utils.synchronized('odl-sync-full')
|
||||||
def sync_full(self, context):
|
def sync_full(self, context):
|
||||||
@ -278,9 +275,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
|
|||||||
attr_filter = self.update_object_map[object_type]
|
attr_filter = self.update_object_map[object_type]
|
||||||
resource = context.current.copy()
|
resource = context.current.copy()
|
||||||
attr_filter(resource, context)
|
attr_filter(resource, context)
|
||||||
# 400 errors are returned if an object exists, which we ignore.
|
self.sendjson(method, urlpath, {object_type[:-1]: resource})
|
||||||
self.sendjson(method, urlpath, {object_type[:-1]: resource},
|
|
||||||
[requests.codes.bad_request])
|
|
||||||
except Exception:
|
except Exception:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
self.out_of_sync = True
|
self.out_of_sync = True
|
||||||
@ -293,7 +288,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
|
|||||||
for sg in port['security_groups']]
|
for sg in port['security_groups']]
|
||||||
port['security_groups'] = groups
|
port['security_groups'] = groups
|
||||||
|
|
||||||
def sendjson(self, method, urlpath, obj, ignorecodes=[]):
|
def sendjson(self, method, urlpath, obj):
|
||||||
"""Send json to the OpenDaylight controller."""
|
"""Send json to the OpenDaylight controller."""
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
data = jsonutils.dumps(obj, indent=2) if obj else None
|
data = jsonutils.dumps(obj, indent=2) if obj else None
|
||||||
@ -303,10 +298,6 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
|
|||||||
r = requests.request(method, url=url,
|
r = requests.request(method, url=url,
|
||||||
headers=headers, data=data,
|
headers=headers, data=data,
|
||||||
auth=self.auth, timeout=self.timeout)
|
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()
|
r.raise_for_status()
|
||||||
|
|
||||||
def bind_port(self, context):
|
def bind_port(self, context):
|
||||||
|
@ -287,18 +287,17 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
|
|||||||
'delete', **kwargs)
|
'delete', **kwargs)
|
||||||
|
|
||||||
def test_create_network_postcommit(self):
|
def test_create_network_postcommit(self):
|
||||||
for status_code in (requests.codes.created,
|
self._test_create_resource_postcommit('network',
|
||||||
requests.codes.bad_request):
|
requests.codes.created)
|
||||||
self._test_create_resource_postcommit('network', status_code)
|
for status_code in (requests.codes.bad_request,
|
||||||
self._test_create_resource_postcommit(
|
requests.codes.unauthorized):
|
||||||
'network', requests.codes.unauthorized,
|
self._test_create_resource_postcommit(
|
||||||
requests.exceptions.HTTPError)
|
'network', status_code, requests.exceptions.HTTPError)
|
||||||
|
|
||||||
def test_create_subnet_postcommit(self):
|
def test_create_subnet_postcommit(self):
|
||||||
for status_code in (requests.codes.created,
|
self._test_create_resource_postcommit('subnet', requests.codes.created)
|
||||||
requests.codes.bad_request):
|
for status_code in (requests.codes.bad_request,
|
||||||
self._test_create_resource_postcommit('subnet', status_code)
|
requests.codes.unauthorized,
|
||||||
for status_code in (requests.codes.unauthorized,
|
|
||||||
requests.codes.forbidden,
|
requests.codes.forbidden,
|
||||||
requests.codes.not_found,
|
requests.codes.not_found,
|
||||||
requests.codes.conflict,
|
requests.codes.conflict,
|
||||||
@ -307,10 +306,9 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
|
|||||||
'subnet', status_code, requests.exceptions.HTTPError)
|
'subnet', status_code, requests.exceptions.HTTPError)
|
||||||
|
|
||||||
def test_create_port_postcommit(self):
|
def test_create_port_postcommit(self):
|
||||||
for status_code in (requests.codes.created,
|
self._test_create_resource_postcommit('port', requests.codes.created)
|
||||||
requests.codes.bad_request):
|
for status_code in (requests.codes.bad_request,
|
||||||
self._test_create_resource_postcommit('port', status_code)
|
requests.codes.unauthorized,
|
||||||
for status_code in (requests.codes.unauthorized,
|
|
||||||
requests.codes.forbidden,
|
requests.codes.forbidden,
|
||||||
requests.codes.not_found,
|
requests.codes.not_found,
|
||||||
requests.codes.conflict,
|
requests.codes.conflict,
|
||||||
@ -320,19 +318,17 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
|
|||||||
'port', status_code, requests.exceptions.HTTPError)
|
'port', status_code, requests.exceptions.HTTPError)
|
||||||
|
|
||||||
def test_update_network_postcommit(self):
|
def test_update_network_postcommit(self):
|
||||||
for status_code in (requests.codes.ok,
|
self._test_update_resource_postcommit('network', requests.codes.ok)
|
||||||
requests.codes.bad_request):
|
for status_code in (requests.codes.bad_request,
|
||||||
self._test_update_resource_postcommit('network', status_code)
|
requests.codes.forbidden,
|
||||||
for status_code in (requests.codes.forbidden,
|
|
||||||
requests.codes.not_found):
|
requests.codes.not_found):
|
||||||
self._test_update_resource_postcommit(
|
self._test_update_resource_postcommit(
|
||||||
'network', status_code, requests.exceptions.HTTPError)
|
'network', status_code, requests.exceptions.HTTPError)
|
||||||
|
|
||||||
def test_update_subnet_postcommit(self):
|
def test_update_subnet_postcommit(self):
|
||||||
for status_code in (requests.codes.ok,
|
self._test_update_resource_postcommit('subnet', requests.codes.ok)
|
||||||
requests.codes.bad_request):
|
for status_code in (requests.codes.bad_request,
|
||||||
self._test_update_resource_postcommit('subnet', status_code)
|
requests.codes.unauthorized,
|
||||||
for status_code in (requests.codes.unauthorized,
|
|
||||||
requests.codes.forbidden,
|
requests.codes.forbidden,
|
||||||
requests.codes.not_found,
|
requests.codes.not_found,
|
||||||
requests.codes.not_implemented):
|
requests.codes.not_implemented):
|
||||||
@ -340,10 +336,9 @@ class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
|
|||||||
'subnet', status_code, requests.exceptions.HTTPError)
|
'subnet', status_code, requests.exceptions.HTTPError)
|
||||||
|
|
||||||
def test_update_port_postcommit(self):
|
def test_update_port_postcommit(self):
|
||||||
for status_code in (requests.codes.ok,
|
self._test_update_resource_postcommit('port', requests.codes.ok)
|
||||||
requests.codes.bad_request):
|
for status_code in (requests.codes.bad_request,
|
||||||
self._test_update_resource_postcommit('port', status_code)
|
requests.codes.unauthorized,
|
||||||
for status_code in (requests.codes.unauthorized,
|
|
||||||
requests.codes.forbidden,
|
requests.codes.forbidden,
|
||||||
requests.codes.not_found,
|
requests.codes.not_found,
|
||||||
requests.codes.conflict,
|
requests.codes.conflict,
|
||||||
|
Loading…
Reference in New Issue
Block a user