From: Vincent Hou Date: Tue, 25 Nov 2014 07:36:07 +0000 (-0800) Subject: Get the 'consumer' in a correct way for retyping with qos-specs X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ef59e5f8c42365f7d55ea84d4afb364241a388c3;p=openstack-build%2Fcinder-build.git Get the 'consumer' in a correct way for retyping with qos-specs The qos specs returned from the database does not contain the property "qos-specs". Intead, the property "consumer" can be accessed directly. Change-Id: I3fe57e5cc20a97d32c8b8c6089ab1e812257da45 closes-bug: #1389519 --- diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py index a8c0cecd9..a3e1113a4 100644 --- a/cinder/tests/api/contrib/test_volume_actions.py +++ b/cinder/tests/api/contrib/test_volume_actions.py @@ -357,7 +357,8 @@ class VolumeRetypeActionsTest(VolumeActionsTest): # Test that the retype API works for both available and in-use self._retype_volume_exec(202) self.mock_volume_get.return_value['status'] = 'in-use' - specs = {'qos_specs': {'id': 'fakeqid1', 'consumer': 'back-end'}} + specs = {'id': 'fakeqid1', 'name': 'fake_name1', + 'consumer': 'back-end', 'specs': {'key1': 'value1'}} _mock_get_qspecs.return_value = specs self._retype_volume_exec(202) @@ -408,9 +409,11 @@ class VolumeRetypeActionsTest(VolumeActionsTest): def _retype_volume_diff_qos(self, vol_status, consumer, expected_status, _mock_get_qspecs): def fake_get_qos(ctxt, qos_id): - d1 = {'qos_specs': {'id': 'fakeqid1', 'consumer': consumer}} - d2 = {'qos_specs': {'id': 'fakeqid2', 'consumer': consumer}} - return d1 if d1['qos_specs']['id'] == qos_id else d2 + d1 = {'id': 'fakeqid1', 'name': 'fake_name1', + 'consumer': consumer, 'specs': {'key1': 'value1'}} + d2 = {'id': 'fakeqid2', 'name': 'fake_name2', + 'consumer': consumer, 'specs': {'key1': 'value1'}} + return d1 if d1['id'] == qos_id else d2 self.mock_volume_get.return_value['status'] = vol_status _mock_get_qspecs.side_effect = fake_get_qos diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 1f2ab593c..237e07c34 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -1202,7 +1202,7 @@ class API(base.Base): for qos_id in [old_vol_type_qos_id, vol_type_qos_id]: if qos_id: specs = qos_specs.get_qos_specs(context.elevated(), qos_id) - if specs['qos_specs']['consumer'] != 'back-end': + if specs['consumer'] != 'back-end': msg = _('Retype cannot change front-end qos specs for ' 'in-use volumes') raise exception.InvalidInput(reason=msg)