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:
parent
23e10121b0
commit
cbac15dfa1
|
@ -339,11 +339,11 @@ class OSDBInstance(resource.Resource):
|
||||||
nics=nics)
|
nics=nics)
|
||||||
self.resource_id_set(instance.id)
|
self.resource_id_set(instance.id)
|
||||||
|
|
||||||
return instance
|
return instance.id
|
||||||
|
|
||||||
def _refresh_instance(self, instance):
|
def _refresh_instance(self, instance_id):
|
||||||
try:
|
try:
|
||||||
instance = self.trove().instances.get(instance.id)
|
instance = self.trove().instances.get(instance_id)
|
||||||
return instance
|
return instance
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if self.client_plugin().is_over_limit(exc):
|
if self.client_plugin().is_over_limit(exc):
|
||||||
|
@ -353,15 +353,17 @@ class OSDBInstance(resource.Resource):
|
||||||
{'name': self.stack.name,
|
{'name': self.stack.name,
|
||||||
'id': self.stack.id,
|
'id': self.stack.id,
|
||||||
'exception': exc})
|
'exception': exc})
|
||||||
return instance
|
return None
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def check_create_complete(self, instance):
|
def check_create_complete(self, instance_id):
|
||||||
'''
|
'''
|
||||||
Check if cloud DB instance creation is complete.
|
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:
|
if instance.status in self.BAD_STATUSES:
|
||||||
raise resource.ResourceInError(
|
raise resource.ResourceInError(
|
||||||
resource_status=instance.status,
|
resource_status=instance.status,
|
||||||
|
@ -402,18 +404,18 @@ class OSDBInstance(resource.Resource):
|
||||||
self.client_plugin().ignore_not_found(ex)
|
self.client_plugin().ignore_not_found(ex)
|
||||||
else:
|
else:
|
||||||
instance.delete()
|
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
|
Check for completion of cloud DB instance deletion
|
||||||
'''
|
'''
|
||||||
if not instance:
|
if not instance_id:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# For some time trove instance may continue to live
|
# For some time trove instance may continue to live
|
||||||
self._refresh_instance(instance)
|
self._refresh_instance(instance_id)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self.client_plugin().ignore_not_found(ex)
|
self.client_plugin().ignore_not_found(ex)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -153,11 +153,11 @@ class TroveCluster(resource.Resource):
|
||||||
}
|
}
|
||||||
cluster = self.client().clusters.create(**args)
|
cluster = self.client().clusters.create(**args)
|
||||||
self.resource_id_set(cluster.id)
|
self.resource_id_set(cluster.id)
|
||||||
return cluster
|
return cluster.id
|
||||||
|
|
||||||
def _refresh_cluster(self, cluster):
|
def _refresh_cluster(self, cluster_id):
|
||||||
try:
|
try:
|
||||||
cluster = self.client().clusters.get(cluster.id)
|
cluster = self.client().clusters.get(cluster_id)
|
||||||
return cluster
|
return cluster
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if self.client_plugin().is_over_limit(exc):
|
if self.client_plugin().is_over_limit(exc):
|
||||||
|
@ -167,12 +167,15 @@ class TroveCluster(resource.Resource):
|
||||||
{'name': self.stack.name,
|
{'name': self.stack.name,
|
||||||
'id': self.stack.id,
|
'id': self.stack.id,
|
||||||
'exception': exc})
|
'exception': exc})
|
||||||
return cluster
|
return None
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def check_create_complete(self, cluster):
|
def check_create_complete(self, cluster_id):
|
||||||
cluster = self._refresh_cluster(cluster)
|
cluster = self._refresh_cluster(cluster_id)
|
||||||
|
|
||||||
|
if cluster is None:
|
||||||
|
return False
|
||||||
|
|
||||||
for instance in cluster.instances:
|
for instance in cluster.instances:
|
||||||
if instance['status'] in self.BAD_STATUSES:
|
if instance['status'] in self.BAD_STATUSES:
|
||||||
|
@ -197,15 +200,15 @@ class TroveCluster(resource.Resource):
|
||||||
self.client_plugin().ignore_not_found(ex)
|
self.client_plugin().ignore_not_found(ex)
|
||||||
else:
|
else:
|
||||||
cluster.delete()
|
cluster.delete()
|
||||||
return cluster
|
return cluster.id
|
||||||
|
|
||||||
def check_delete_complete(self, cluster):
|
def check_delete_complete(self, cluster_id):
|
||||||
if not cluster:
|
if not cluster_id:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# For some time trove cluster may continue to live
|
# For some time trove cluster may continue to live
|
||||||
self._refresh_cluster(cluster)
|
self._refresh_cluster(cluster_id)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self.client_plugin().ignore_not_found(ex)
|
self.client_plugin().ignore_not_found(ex)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -267,6 +267,9 @@ class OSDBInstanceTest(common.HeatTestCase):
|
||||||
self.fc.instances.get(fake_dbinstance.id).AndRaise(
|
self.fc.instances.get(fake_dbinstance.id).AndRaise(
|
||||||
troveexc.RequestEntityTooLarge)
|
troveexc.RequestEntityTooLarge)
|
||||||
|
|
||||||
|
self.fc.instances.get(fake_dbinstance.id).AndReturn(
|
||||||
|
fake_dbinstance)
|
||||||
|
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
scheduler.TaskRunner(instance.create)()
|
scheduler.TaskRunner(instance.create)()
|
||||||
|
|
Loading…
Reference in New Issue