diff options
author | Iccha Sethi <iccha.sethi@rackspace.com> | 2014-09-26 14:36:26 -0500 |
---|---|---|
committer | Iccha Sethi <iccha.sethi@rackspace.com> | 2014-09-29 11:38:28 -0500 |
commit | c3139485310893fd1ddd70633fb35cae544f7b6e (patch) | |
tree | 39d4eb878a0132a26f014a9308998b3e88ef84dd | |
parent | a5c515071174a494b1324147d4ac8f9aa8e650d4 (diff) | |
download | trove-c3139485310893fd1ddd70633fb35cae544f7b6e.tar.gz |
Mandate detach replicas before deleting replica source
If the user attempts to delete an instance which has
replicas attached to it, forbid the delete.
Closes bug: #1362299
Change-Id: I644243aef74d9a34b7726139f9fa5ca8bdb1452c
-rw-r--r-- | trove/common/exception.py | 5 | ||||
-rw-r--r-- | trove/common/wsgi.py | 3 | ||||
-rw-r--r-- | trove/instance/models.py | 5 | ||||
-rw-r--r-- | trove/tests/api/replication.py | 6 |
4 files changed, 19 insertions, 0 deletions
diff --git a/trove/common/exception.py b/trove/common/exception.py index c78b9ac9..820609cd 100644 --- a/trove/common/exception.py +++ b/trove/common/exception.py @@ -470,6 +470,11 @@ class InsufficientSpaceForReplica(TroveError): "of data.") +class ReplicaSourceDeleteForbidden(Forbidden): + message = _("The replica source cannot be deleted without detaching the " + "replicas.") + + class ClusterNotFound(NotFound): message = _("Cluster '%(cluster)s' cannot be found.") diff --git a/trove/common/wsgi.py b/trove/common/wsgi.py index 823df0d4..766d5960 100644 --- a/trove/common/wsgi.py +++ b/trove/common/wsgi.py @@ -317,6 +317,9 @@ class Controller(object): exception.Forbidden, exception.SwiftAuthError, ], + webob.exc.HTTPForbidden: [ + exception.ReplicaSourceDeleteForbidden, + ], webob.exc.HTTPBadRequest: [ exception.InvalidModelError, exception.BadRequest, diff --git a/trove/instance/models.py b/trove/instance/models.py index 2480f741..7dae8305 100644 --- a/trove/instance/models.py +++ b/trove/instance/models.py @@ -553,6 +553,11 @@ class BaseInstance(SimpleInstance): is_cluster_deleting(self.context, self.db_info.cluster_id)): raise exception.ClusterInstanceOperationNotSupported() + if self.slaves: + msg = _("Detach replicas before deleting replica source.") + LOG.warn(msg) + raise exception.ReplicaSourceDeleteForbidden(msg) + self.update_db(task_status=InstanceTasks.DELETING, configuration_id=None) task_api.API(self.context).delete_instance(self.id) diff --git a/trove/tests/api/replication.py b/trove/tests/api/replication.py index fd2a7657..da5165db 100644 --- a/trove/tests/api/replication.py +++ b/trove/tests/api/replication.py @@ -173,6 +173,12 @@ class TestInstanceListing(object): class DetachReplica(object): @test + def delete_before_detach_replica(self): + assert_raises(exceptions.Forbidden, + instance_info.dbaas.instances.delete, + instance_info.id) + + @test @time_out(5 * 60) def test_detach_replica(self): if CONFIG.fake_mode: |