]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix QoS keys not being available to scheduler
authorAnthony Lee <anthony.mic.lee@hp.com>
Wed, 19 Aug 2015 22:48:33 +0000 (15:48 -0700)
committerAnthony Lee <anthony.mic.lee@hp.com>
Wed, 9 Sep 2015 16:40:24 +0000 (09:40 -0700)
There is a qos_specs property contained within the properties
passed to filters and weighers during volume placement decision
time. Currently qos_specs is always set to None even when a
QoS spec is associated with a volume type.

This patch exposes the QoS keys by placing them in the
qos_specs property. When no QoS spec is associated with a volume
the qos_specs property would still be set to None.

Change-Id: I5d5d36b56efeadd0884abc2f541ccf44b1010a2e
Closes-Bug: #1486286

cinder/tests/unit/volume/flows/test_create_volume_flow.py
cinder/volume/flows/api/create_volume.py

index 4cd1605a19d7e379854e08a6742d74db75ef7028..df820918ea0acc9d0e6a3b076bb4bbf55c8a0814 100644 (file)
@@ -279,6 +279,60 @@ class CreateVolumeFlowTestCase(test.TestCase):
                            'cgsnapshot_id': None, }
         self.assertEqual(expected_result, result)
 
+    @mock.patch('cinder.volume.volume_types.is_encrypted')
+    @mock.patch('cinder.volume.volume_types.get_volume_type_qos_specs')
+    @mock.patch('cinder.volume.flows.api.create_volume.'
+                'ExtractVolumeRequestTask.'
+                '_get_volume_type_id')
+    def test_extract_volume_request_from_image_with_qos_specs(
+            self,
+            fake_get_type_id,
+            fake_get_qos,
+            fake_is_encrypted):
+
+        fake_image_service = fake_image.FakeImageService()
+        image_id = 5
+        image_meta = {}
+        image_meta['id'] = image_id
+        image_meta['status'] = 'active'
+        image_meta['size'] = 1
+        fake_image_service.create(self.ctxt, image_meta)
+        fake_key_manager = mock_key_mgr.MockKeyManager()
+        volume_type = 'type1'
+
+        task = create_volume.ExtractVolumeRequestTask(
+            fake_image_service,
+            {'nova'})
+
+        fake_is_encrypted.return_value = False
+        fake_get_type_id.return_value = 1
+        fake_qos_spec = {'specs': {'fake_key': 'fake'}}
+        fake_get_qos.return_value = {'qos_specs': fake_qos_spec}
+        result = task.execute(self.ctxt,
+                              size=1,
+                              snapshot=None,
+                              image_id=image_id,
+                              source_volume=None,
+                              availability_zone='nova',
+                              volume_type=volume_type,
+                              metadata=None,
+                              key_manager=fake_key_manager,
+                              source_replica=None,
+                              consistencygroup=None,
+                              cgsnapshot=None)
+        expected_result = {'size': 1,
+                           'snapshot_id': None,
+                           'source_volid': None,
+                           'availability_zone': 'nova',
+                           'volume_type': volume_type,
+                           'volume_type_id': 1,
+                           'encryption_key_id': None,
+                           'qos_specs': {'fake_key': 'fake'},
+                           'source_replicaid': None,
+                           'consistencygroup_id': None,
+                           'cgsnapshot_id': None, }
+        self.assertEqual(expected_result, result)
+
 
 class CreateVolumeFlowManagerTestCase(test.TestCase):
 
index f1ab99d9de7f9d3d85676d81378c7228f3edc7fe..118c8b484d0484c510d799cbf5fe298f205045b1 100644 (file)
@@ -63,7 +63,8 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask):
     default_provides = set(['availability_zone', 'size', 'snapshot_id',
                             'source_volid', 'volume_type', 'volume_type_id',
                             'encryption_key_id', 'source_replicaid',
-                            'consistencygroup_id', 'cgsnapshot_id'])
+                            'consistencygroup_id', 'cgsnapshot_id',
+                            'qos_specs'])
 
     def __init__(self, image_service, availability_zones, **kwargs):
         super(ExtractVolumeRequestTask, self).__init__(addons=[ACTION],
@@ -409,7 +410,8 @@ class ExtractVolumeRequestTask(flow_utils.CinderTask):
         specs = {}
         if volume_type_id:
             qos_specs = volume_types.get_volume_type_qos_specs(volume_type_id)
-            specs = qos_specs['qos_specs']
+            if qos_specs['qos_specs']:
+                specs = qos_specs['qos_specs'].get('specs', {})
         if not specs:
             # to make sure we don't pass empty dict
             specs = None
@@ -444,7 +446,7 @@ class EntryCreateTask(flow_utils.CinderTask):
                     'name', 'reservations', 'size', 'snapshot_id',
                     'source_volid', 'volume_type_id', 'encryption_key_id',
                     'source_replicaid', 'consistencygroup_id',
-                    'cgsnapshot_id', 'multiattach']
+                    'cgsnapshot_id', 'multiattach', 'qos_specs']
         super(EntryCreateTask, self).__init__(addons=[ACTION],
                                               requires=requires)
         self.db = db