Merge "Handle novaclient exception in delete_server wait"

This commit is contained in:
Jenkins 2015-05-28 03:46:54 +00:00 committed by Gerrit Code Review
commit a195993395
2 changed files with 35 additions and 8 deletions

View File

@ -1855,6 +1855,11 @@ class OpenStackCloud(object):
return
except nova_exceptions.NotFound:
return
except Exception as e:
self.log.debug("nova get server failed when waiting for "
"delete", exc_info=True)
raise OpenStackCloudException(
"Error in deleting server: {0}".format(e))
def get_container(self, name, skip_cache=False):
if skip_cache or name not in self._container_cache:

View File

@ -29,6 +29,14 @@ from shade.tests.unit import base
class TestDeleteServer(base.TestCase):
novaclient_exceptions = (nova_exc.BadRequest,
nova_exc.Unauthorized,
nova_exc.Forbidden,
nova_exc.MethodNotAllowed,
nova_exc.Conflict,
nova_exc.OverLimit,
nova_exc.RateLimit,
nova_exc.HTTPNotImplemented)
def setUp(self):
super(TestDeleteServer, self).setUp()
@ -89,14 +97,7 @@ class TestDeleteServer(base.TestCase):
nova_mock.servers.list.return_value = [fakes.FakeServer('1212',
'speedy',
'ACTIVE')]
for fail in (nova_exc.BadRequest,
nova_exc.Unauthorized,
nova_exc.Forbidden,
nova_exc.MethodNotAllowed,
nova_exc.Conflict,
nova_exc.OverLimit,
nova_exc.RateLimit,
nova_exc.HTTPNotImplemented):
for fail in self.novaclient_exceptions:
def _raise_fail(server):
raise fail(code=fail.http_status)
@ -108,3 +109,24 @@ class TestDeleteServer(base.TestCase):
# Note that message is deprecated from Exception, but not in
# the novaclient exceptions.
self.assertIn(fail.message, str(exc))
@mock.patch('shade.OpenStackCloud.nova_client')
def test_delete_server_get_fails(self, nova_mock):
"""
Test that delete_server wraps novaclient exceptions on wait fails
"""
nova_mock.servers.list.return_value = [fakes.FakeServer('2000',
'yosemite',
'ACTIVE')]
for fail in self.novaclient_exceptions:
def _raise_fail(server):
raise fail(code=fail.http_status)
nova_mock.servers.get.side_effect = _raise_fail
exc = self.assertRaises(shade_exc.OpenStackCloudException,
self.cloud.delete_server, 'yosemite',
wait=True)
# Note that message is deprecated from Exception, but not in
# the novaclient exceptions.
self.assertIn(fail.message, str(exc))