Merge "Handle API limit exception in OS::Trove::Instance"

This commit is contained in:
Jenkins 2014-02-17 17:59:15 +00:00 committed by Gerrit Code Review
commit 19a06cd6c3
2 changed files with 62 additions and 13 deletions

View File

@ -13,19 +13,14 @@
# License for the specific language governing permissions and limitations
# under the License.
try:
from troveclient.openstack.common.apiclient.exceptions import NotFound
except ImportError:
#Setup fake exception for unit testing without troveclient
class NotFound(Exception):
pass
from heat.common import exception
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine.clients import troveclient
from heat.engine.resources import nova_utils
from heat.openstack.common import log as logging
from heat.openstack.common.gettextutils import _
logger = logging.getLogger(__name__)
@ -226,11 +221,22 @@ class OSDBInstance(resource.Resource):
return instance
def _refresh_instance(self, instance):
try:
instance.get()
except troveclient.exceptions.RequestEntityTooLarge as exc:
msg = _("Stack %(name)s (%(id)s) received an OverLimit "
"response during instance.get(): %(exception)s")
logger.warning(msg % {'name': self.stack.name,
'id': self.stack.id,
'exception': str(exc)})
def check_create_complete(self, instance):
'''
Check if cloud DB instance creation is complete.
'''
instance.get() # get updated attributes
self._refresh_instance(instance)
if instance.status == 'ERROR':
raise exception.Error(_("Database instance creation failed."))
@ -254,7 +260,7 @@ class OSDBInstance(resource.Resource):
instance = None
try:
instance = self.trove().instances.get(self.resource_id)
except NotFound:
except troveclient.exceptions.NotFound:
logger.debug(_("Database instance %s not found.") %
self.resource_id)
self.resource_id_set(None)
@ -270,8 +276,8 @@ class OSDBInstance(resource.Resource):
return True
try:
instance.get()
except NotFound:
self._refresh_instance(instance)
except troveclient.exceptions.NotFound:
self.resource_id_set(None)
return True

View File

@ -19,6 +19,7 @@ from heat.common import template_format
from heat.engine import environment
from heat.engine import parser
from heat.engine import scheduler
from heat.engine.clients import troveclient
from heat.engine.resources import os_database
from heat.tests.common import HeatTestCase
from heat.tests import utils
@ -140,6 +141,24 @@ class OSDBInstanceTest(HeatTestCase):
self.assertEqual((instance.CREATE, instance.COMPLETE), instance.state)
self.m.VerifyAll()
def test_osdatabase_create_overlimit(self):
fake_dbinstance = FakeDBInstance()
t = template_format.parse(wp_template)
instance = self._setup_test_clouddbinstance('dbinstance_create', t)
self._stubout_create(instance, fake_dbinstance)
# Simulate an OverLimit exception
self.m.StubOutWithMock(fake_dbinstance, 'get')
fake_dbinstance.get().AndRaise(
troveclient.exceptions.RequestEntityTooLarge)
self.m.ReplayAll()
scheduler.TaskRunner(instance.create)()
self.assertEqual((instance.CREATE, instance.COMPLETE), instance.state)
self.m.VerifyAll()
def test_osdatabase_create_fails(self):
fake_dbinstance = FakeDBInstance()
fake_dbinstance.status = 'ERROR'
@ -162,7 +181,30 @@ class OSDBInstanceTest(HeatTestCase):
fake_dbinstance.delete().AndReturn(None)
self.m.StubOutWithMock(fake_dbinstance, 'get')
fake_dbinstance.get().AndReturn(None)
fake_dbinstance.get().AndRaise(os_database.NotFound(404))
fake_dbinstance.get().AndRaise(troveclient.exceptions.NotFound(404))
self.m.ReplayAll()
scheduler.TaskRunner(instance.delete)()
self.assertIsNone(instance.resource_id)
self.m.VerifyAll()
def test_osdatabase_delete_overlimit(self):
fake_dbinstance = FakeDBInstance()
t = template_format.parse(wp_template)
instance = self._setup_test_clouddbinstance('dbinstance_del', t)
self._stubout_create(instance, fake_dbinstance)
scheduler.TaskRunner(instance.create)()
self.m.StubOutWithMock(self.fc.instances, 'get')
self.fc.instances.get(12345).AndReturn(fake_dbinstance)
self.m.StubOutWithMock(fake_dbinstance, 'delete')
fake_dbinstance.delete().AndReturn(None)
# Simulate an OverLimit exception
self.m.StubOutWithMock(fake_dbinstance, 'get')
fake_dbinstance.get().AndRaise(
troveclient.exceptions.RequestEntityTooLarge)
fake_dbinstance.get().AndReturn(None)
fake_dbinstance.get().AndRaise(troveclient.exceptions.NotFound(404))
self.m.ReplayAll()
scheduler.TaskRunner(instance.delete)()
@ -189,7 +231,8 @@ class OSDBInstanceTest(HeatTestCase):
self._stubout_create(instance, fake_dbinstance)
scheduler.TaskRunner(instance.create)()
self.m.StubOutWithMock(self.fc.instances, 'get')
self.fc.instances.get(12345).AndRaise(os_database.NotFound(404))
self.fc.instances.get(12345).AndRaise(
troveclient.exceptions.NotFound(404))
self.m.ReplayAll()
scheduler.TaskRunner(instance.delete)()