Merge "Ignore 404 amphora error when deleting resources"

This commit is contained in:
Jenkins 2017-08-10 20:10:00 +00:00 committed by Gerrit Code Review
commit 283ff4b754
5 changed files with 20 additions and 26 deletions

View File

@ -265,7 +265,10 @@ class Listener(object):
status=202)
def delete_listener(self, listener_id):
self._check_listener_exists(listener_id)
try:
self._check_listener_exists(listener_id)
except exceptions.HTTPException:
return webob.Response(json={'message': 'OK'})
# check if that haproxy is still running and if stop it
if os.path.exists(util.pid_path(listener_id)) and os.path.exists(
@ -433,13 +436,8 @@ class Listener(object):
def delete_certificate(self, listener_id, filename):
self._check_ssl_filename_format(filename)
if not os.path.exists(self._cert_file_path(listener_id, filename)):
return webob.Response(json=dict(
message='Certificate Not Found',
details="No certificate with filename: {f}".format(
f=filename)), status=404)
os.remove(self._cert_file_path(listener_id, filename))
if os.path.exists(self._cert_file_path(listener_id, filename)):
os.remove(self._cert_file_path(listener_id, filename))
return webob.Response(json=dict(message='OK'))
def _check_listener_status(self, listener_id):

View File

@ -16,7 +16,7 @@
from webob import exc
def check_exception(response):
def check_exception(response, ignore=tuple()):
status_code = response.status_code
responses = {
400: InvalidRequest,
@ -28,7 +28,7 @@ def check_exception(response):
500: InternalServerError,
503: ServiceUnavailable
}
if status_code in responses:
if (status_code not in ignore) and (status_code in responses):
raise responses[status_code]()
return response

View File

@ -353,7 +353,8 @@ class AmphoraAPIClient(object):
def delete_listener(self, amp, listener_id):
r = self.delete(
amp, 'listeners/{listener_id}'.format(listener_id=listener_id))
return exc.check_exception(r)
return exc.check_exception(r, (404,))
def get_info(self, amp):
r = self.get(amp, "info")
@ -375,7 +376,7 @@ class AmphoraAPIClient(object):
amp,
'listeners/{listener_id}/certificates/{filename}'.format(
listener_id=listener_id, filename=pem_filename))
return exc.check_exception(r)
return exc.check_exception(r, (404,))
def plug_network(self, amp, port):
r = self.post(amp, 'plug/network',

View File

@ -442,11 +442,8 @@ class TestServerTestCase(base.TestCase):
elif distro == consts.CENTOS:
rv = self.centos_app.delete('/' + api_server.VERSION +
'/listeners/123')
self.assertEqual(404, rv.status_code)
self.assertEqual(
{'message': 'Listener Not Found',
'details': 'No listener with UUID: 123'},
json.loads(rv.data.decode('utf-8')))
self.assertEqual(200, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
mock_exists.assert_called_with('/var/lib/octavia/123/haproxy.cfg')
# service is stopped + no upstart script + no vrrp
@ -814,11 +811,8 @@ class TestServerTestCase(base.TestCase):
elif distro == consts.CENTOS:
rv = self.centos_app.delete('/' + api_server.VERSION +
'/listeners/123/certificates/test.pem')
self.assertEqual(404, rv.status_code)
self.assertEqual(dict(
details='No certificate with filename: test.pem',
message='Certificate Not Found'),
json.loads(rv.data.decode('utf-8')))
self.assertEqual(200, rv.status_code)
self.assertEqual(OK, json.loads(rv.data.decode('utf-8')))
mock_exists.assert_called_once_with(
'/var/lib/octavia/certs/123/test.pem')

View File

@ -529,8 +529,8 @@ class TestAmphoraAPIClientTest(base.TestCase):
base=self.base_url, listener_id=FAKE_UUID_1),
status_code=404,
headers={'content-type': 'application/json'})
self.assertRaises(exc.NotFound, self.driver.delete_listener,
self.amp, FAKE_UUID_1)
self.driver.delete_listener(self.amp, FAKE_UUID_1)
self.assertTrue(m.called)
@requests_mock.mock()
def test_delete_listener_unauthorized(self, m):
@ -697,8 +697,9 @@ class TestAmphoraAPIClientTest(base.TestCase):
base=self.base_url, listener_id=FAKE_UUID_1,
filename=FAKE_PEM_FILENAME), status_code=404,
headers={'content-type': 'application/json'})
self.assertRaises(exc.NotFound, self.driver.delete_cert_pem, self.amp,
FAKE_UUID_1, FAKE_PEM_FILENAME)
self.driver.delete_cert_pem(self.amp, FAKE_UUID_1,
FAKE_PEM_FILENAME)
self.assertTrue(m.called)
@requests_mock.mock()
def test_delete_cert_pem_unauthorized(self, m):