diff --git a/manila/api/openstack/wsgi.py b/manila/api/openstack/wsgi.py index 6257eb586c..e12f2bcc5f 100644 --- a/manila/api/openstack/wsgi.py +++ b/manila/api/openstack/wsgi.py @@ -1260,6 +1260,12 @@ class AdminActionsMixin(object): resource = resource or self._get(context, id) except exception.NotFound as e: raise webob.exc.HTTPNotFound(e.message) + + if (status_attr == 'replica_state' and + resource.get('replica_state') == + constants.REPLICA_STATE_ACTIVE): + msg = _("Cannot reset replica_state of an active replica") + raise webob.exc.HTTPBadRequest(explanation=msg) try: policy.check_policy(context, self.resource_name, diff --git a/manila/tests/api/v2/test_share_replicas.py b/manila/tests/api/v2/test_share_replicas.py index fea87efe6f..fefe26d5d8 100644 --- a/manila/tests/api/v2/test_share_replicas.py +++ b/manila/tests/api/v2/test_share_replicas.py @@ -45,6 +45,7 @@ PROMOTE_QUIESCE_WAIT_VERSION = '2.75' @ddt.ddt class ShareReplicasApiTest(test.TestCase): """Share Replicas API Test Cases.""" + def setUp(self): super(ShareReplicasApiTest, self).setUp() self.controller = share_replicas.ShareReplicationController() @@ -822,6 +823,22 @@ class ShareReplicasApiTest(test.TestCase): valid_code=valid_code, status_attr='replica_state', valid_status=valid_status, body=body) + def test_reset_replica_with_active_state(self): + body = { + 'reset_replica_state': { + 'replica_state': constants.REPLICA_STATE_OUT_OF_SYNC, + } + } + + replica, action_req = self._create_replica_get_req( + replica_state=constants.REPLICA_STATE_ACTIVE) + + self._reset_status(self.admin_context, replica, action_req, + status_attr='replica_state', + valid_code=400, + valid_status=constants.REPLICA_STATE_ACTIVE, + body=body) + @ddt.data( {'os-reset_replica_state': {'x-replica_state': 'bad'}}, {'os-reset_replica_state': {'replica_state': constants.STATUS_ERROR}}, diff --git a/releasenotes/notes/bug-2015328-disallow-reset-replica-state-on-active-replicas-a3d4511ff1352d68.yaml b/releasenotes/notes/bug-2015328-disallow-reset-replica-state-on-active-replicas-a3d4511ff1352d68.yaml new file mode 100644 index 0000000000..51259beed0 --- /dev/null +++ b/releasenotes/notes/bug-2015328-disallow-reset-replica-state-on-active-replicas-a3d4511ff1352d68.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + The "replica_state" attribute of "active" replicas cannot be modified. + Please see `Launchpad bug 2015328 `_ + for more details.