Do not pass around rich objects in Trove resources

As described by the ref'd bug, handle_* methods should not return rich
objects to check_*_complete. This patch fixed such violations in Trove
Istance and Trove Cluster resources.

Change-Id: I65b317a17827258acd11ffc08dc4f2fd5cca517c
Partial-Bug: #1393268
This commit is contained in:
Pavlo Shchelokovskyy 2015-04-23 16:50:48 -07:00
parent 23e10121b0
commit cbac15dfa1
3 changed files with 28 additions and 20 deletions

View File

@ -339,11 +339,11 @@ class OSDBInstance(resource.Resource):
nics=nics)
self.resource_id_set(instance.id)
return instance
return instance.id
def _refresh_instance(self, instance):
def _refresh_instance(self, instance_id):
try:
instance = self.trove().instances.get(instance.id)
instance = self.trove().instances.get(instance_id)
return instance
except Exception as exc:
if self.client_plugin().is_over_limit(exc):
@ -353,15 +353,17 @@ class OSDBInstance(resource.Resource):
{'name': self.stack.name,
'id': self.stack.id,
'exception': exc})
return instance
return None
else:
raise
def check_create_complete(self, instance):
def check_create_complete(self, instance_id):
'''
Check if cloud DB instance creation is complete.
'''
instance = self._refresh_instance(instance) # get updated attributes
instance = self._refresh_instance(instance_id) # refresh attributes
if instance is None:
return False
if instance.status in self.BAD_STATUSES:
raise resource.ResourceInError(
resource_status=instance.status,
@ -402,18 +404,18 @@ class OSDBInstance(resource.Resource):
self.client_plugin().ignore_not_found(ex)
else:
instance.delete()
return instance
return instance.id
def check_delete_complete(self, instance):
def check_delete_complete(self, instance_id):
'''
Check for completion of cloud DB instance deletion
'''
if not instance:
if not instance_id:
return True
try:
# For some time trove instance may continue to live
self._refresh_instance(instance)
self._refresh_instance(instance_id)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
return True

View File

@ -153,11 +153,11 @@ class TroveCluster(resource.Resource):
}
cluster = self.client().clusters.create(**args)
self.resource_id_set(cluster.id)
return cluster
return cluster.id
def _refresh_cluster(self, cluster):
def _refresh_cluster(self, cluster_id):
try:
cluster = self.client().clusters.get(cluster.id)
cluster = self.client().clusters.get(cluster_id)
return cluster
except Exception as exc:
if self.client_plugin().is_over_limit(exc):
@ -167,12 +167,15 @@ class TroveCluster(resource.Resource):
{'name': self.stack.name,
'id': self.stack.id,
'exception': exc})
return cluster
return None
else:
raise
def check_create_complete(self, cluster):
cluster = self._refresh_cluster(cluster)
def check_create_complete(self, cluster_id):
cluster = self._refresh_cluster(cluster_id)
if cluster is None:
return False
for instance in cluster.instances:
if instance['status'] in self.BAD_STATUSES:
@ -197,15 +200,15 @@ class TroveCluster(resource.Resource):
self.client_plugin().ignore_not_found(ex)
else:
cluster.delete()
return cluster
return cluster.id
def check_delete_complete(self, cluster):
if not cluster:
def check_delete_complete(self, cluster_id):
if not cluster_id:
return True
try:
# For some time trove cluster may continue to live
self._refresh_cluster(cluster)
self._refresh_cluster(cluster_id)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
return True

View File

@ -267,6 +267,9 @@ class OSDBInstanceTest(common.HeatTestCase):
self.fc.instances.get(fake_dbinstance.id).AndRaise(
troveexc.RequestEntityTooLarge)
self.fc.instances.get(fake_dbinstance.id).AndReturn(
fake_dbinstance)
self.m.ReplayAll()
scheduler.TaskRunner(instance.create)()