Merge "Fix conflict exceptions handling in LB creation"
This commit is contained in:
commit
0113f1dc80
|
@ -678,16 +678,21 @@ class LBaaSv2Driver(base.LBaaSDriver):
|
|||
return member
|
||||
|
||||
def _ensure(self, obj, create, find):
|
||||
# TODO(yboaron): change the create/find order.
|
||||
okay_codes = (409, 500)
|
||||
try:
|
||||
result = create(obj)
|
||||
LOG.debug("Created %(obj)s", {'obj': result})
|
||||
return result
|
||||
except o_exc.HttpException as e:
|
||||
if e.status_code not in (409, 500):
|
||||
if e.status_code not in okay_codes:
|
||||
raise
|
||||
result = find(obj)
|
||||
if result:
|
||||
LOG.debug("Found %(obj)s", {'obj': result})
|
||||
except requests.exceptions.HTTPError as e:
|
||||
if e.response.status_code not in okay_codes:
|
||||
raise
|
||||
|
||||
result = find(obj)
|
||||
if result:
|
||||
LOG.debug("Found %(obj)s", {'obj': result})
|
||||
return result
|
||||
|
||||
def _ensure_provisioned(self, loadbalancer, obj, create, find,
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import mock
|
||||
import requests
|
||||
|
||||
from neutronclient.common import exceptions as n_exc
|
||||
from openstack import exceptions as o_exc
|
||||
|
@ -699,6 +700,15 @@ class TestLBaaSv2Driver(test_base.TestCase):
|
|||
self._verify_ensure_with_exception(
|
||||
o_exc.HttpException(http_status=500))
|
||||
|
||||
def test_ensure_with_httperrors(self):
|
||||
resp = requests.Response()
|
||||
resp.status_code = 409
|
||||
self._verify_ensure_with_exception(
|
||||
requests.exceptions.HTTPError(response=resp))
|
||||
resp.status_code = 500
|
||||
self._verify_ensure_with_exception(
|
||||
requests.exceptions.HTTPError(response=resp))
|
||||
|
||||
def test_request(self):
|
||||
cls = d_lbaasv2.LBaaSv2Driver
|
||||
m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
|
||||
|
|
Loading…
Reference in New Issue