From: Dave Tucker Date: Wed, 23 Apr 2014 16:01:38 +0000 (+0100) Subject: Improve ODL ML2 Exception Handling X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7db44edd3c5ad4aea508c3cc74a8b0b8d785c26b;p=openstack-build%2Fneutron-build.git Improve ODL ML2 Exception Handling Raise a MechanismDriverError when authentication with ODL fails. Re-raise HTTPError in "sync_resources" for exceptions whose status code is not 404. Closes-Bug: #1311758 Change-Id: I99d2c4f270007c369024525ba4e6188d232a0b13 --- diff --git a/neutron/plugins/ml2/drivers/mechanism_odl.py b/neutron/plugins/ml2/drivers/mechanism_odl.py index cecc06c01..d4e92334f 100644 --- a/neutron/plugins/ml2/drivers/mechanism_odl.py +++ b/neutron/plugins/ml2/drivers/mechanism_odl.py @@ -68,6 +68,10 @@ def try_del(d, keys): pass +class OpendaylightAuthError(n_exc.NeutronException): + message = '%(msg)s' + + class JsessionId(requests.auth.AuthBase): """Attaches the JSESSIONID and JSESSIONIDSSO cookies to an HTTP Request. @@ -95,8 +99,16 @@ class JsessionId(requests.auth.AuthBase): def obtain_auth_cookies(self): """Make a REST call to obtain cookies for ODL authenticiation.""" - r = requests.get(self.url, auth=(self.username, self.password)) - r.raise_for_status() + try: + r = requests.get(self.url, auth=(self.username, self.password)) + r.raise_for_status() + except requests.exceptions.HTTPError as e: + raise OpendaylightAuthError(msg=_("Failed to authenticate with " + "OpenDaylight: %s") % e) + except requests.exceptions.Timeout as e: + raise OpendaylightAuthError(msg=_("Authentication Timed" + " Out: %s") % e) + jsessionid = r.cookies.get('JSESSIONID') jsessionidsso = r.cookies.get('JSESSIONIDSSO') if jsessionid and jsessionidsso: @@ -203,9 +215,11 @@ class OpenDaylightMechanismDriver(api.MechanismDriver): urlpath = collection_name + '/' + resource['id'] self.sendjson('get', urlpath, None) except requests.exceptions.HTTPError as e: - if e.response.status_code == 404: - attr_filter(resource, context, dbcontext) - to_be_synced.append(resource) + with excutils.save_and_reraise_exception() as ctx: + if e.response.status_code == 404: + attr_filter(resource, context, dbcontext) + to_be_synced.append(resource) + ctx.reraise = False key = resource_name if len(to_be_synced) == 1 else collection_name