]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
CG API should return volume type IDs
authorDeepti Ramakrishna <deepti.ramakrishna@intel.com>
Thu, 19 Nov 2015 08:43:49 +0000 (00:43 -0800)
committerDeepti Ramakrishna <deepti.ramakrishna@intel.com>
Tue, 24 Nov 2015 07:09:02 +0000 (23:09 -0800)
The create method of consistency group API requires a list of
volume type ids; volumes belonging to only these types can be added
to the consistency group. The get method of the consistency group API
does not, however, return the volume type id information.

Horizon needs this value for its "Add volumes to consistency group"
panel so that it can filter the "available volumes" list to only
show volumes that match the volume type associated with the consistency
group.

This was fixed by propagating the volume type id information in
the api layer (this information is stored in the db, it just wasn't
being propagated).

APIImpact
The get method of the consistency group API now returns the volume
type ids information.

DocImpact
The screenshots in the admin guide (see
http://docs.openstack.org/admin-guide-cloud/blockstorage-consistency-groups.html)
should be updated to show this new field.

Change-Id: Icc3206c67227af38a7bf89ea0145942f750b506b
Closes-Bug: #1489957

cinder/api/views/consistencygroups.py
cinder/tests/unit/api/contrib/test_consistencygroups.py

index 4337c1c8ee909f7fc61149ba33688e1498262ab4..306790032d19be32795b463e4bda82b6ce8c48ea 100644 (file)
@@ -49,6 +49,12 @@ class ViewBuilder(common.ViewBuilder):
 
     def detail(self, request, consistencygroup):
         """Detailed view of a single consistency group."""
+        if consistencygroup.volume_type_id:
+            volume_types = consistencygroup.volume_type_id.split(",")
+            volume_types = [type_id for type_id in volume_types if type_id]
+        else:
+            volume_types = []
+
         return {
             'consistencygroup': {
                 'id': consistencygroup.id,
@@ -56,7 +62,8 @@ class ViewBuilder(common.ViewBuilder):
                 'availability_zone': consistencygroup.availability_zone,
                 'created_at': consistencygroup.created_at,
                 'name': consistencygroup.name,
-                'description': consistencygroup.description
+                'description': consistencygroup.description,
+                'volume_types': volume_types,
             }
         }
 
index 2bb047f2ef44062892d13674721f7ecfe9783ed3..d723f03bbda6781df873cd30bb23b374eb07b571 100644 (file)
@@ -86,6 +86,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
                          res_dict['consistencygroup']['name'])
         self.assertEqual('creating',
                          res_dict['consistencygroup']['status'])
+        self.assertEqual(['123456'],
+                         res_dict['consistencygroup']['volume_types'])
 
         consistencygroup.destroy()
 
@@ -116,6 +118,28 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
         self.assertEqual('ConsistencyGroup 9999 could not be found.',
                          res_dict['itemNotFound']['message'])
 
+    def test_show_consistencygroup_with_null_volume_type(self):
+        consistencygroup = self._create_consistencygroup(volume_type_id=None)
+        req = webob.Request.blank('/v2/fake/consistencygroups/%s' %
+                                  consistencygroup.id)
+        req.method = 'GET'
+        req.headers['Content-Type'] = 'application/json'
+        res = req.get_response(fakes.wsgi_app())
+        res_dict = json.loads(res.body)
+
+        self.assertEqual(200, res.status_int)
+        self.assertEqual('az1',
+                         res_dict['consistencygroup']['availability_zone'])
+        self.assertEqual('this is a test consistency group',
+                         res_dict['consistencygroup']['description'])
+        self.assertEqual('test_consistencygroup',
+                         res_dict['consistencygroup']['name'])
+        self.assertEqual('creating',
+                         res_dict['consistencygroup']['status'])
+        self.assertEqual([], res_dict['consistencygroup']['volume_types'])
+
+        consistencygroup.destroy()
+
     def test_list_consistencygroups_json(self):
         consistencygroup1 = self._create_consistencygroup()
         consistencygroup2 = self._create_consistencygroup()
@@ -174,7 +198,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
     def test_list_consistencygroups_detail_json(self):
         consistencygroup1 = self._create_consistencygroup()
         consistencygroup2 = self._create_consistencygroup()
-        consistencygroup3 = self._create_consistencygroup()
+        consistencygroup3 = self._create_consistencygroup(volume_type_id=(
+                                                          'uuid1,uuid2'))
 
         req = webob.Request.blank('/v2/fake/consistencygroups/detail')
         req.method = 'GET'
@@ -194,6 +219,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
                          res_dict['consistencygroups'][0]['id'])
         self.assertEqual('creating',
                          res_dict['consistencygroups'][0]['status'])
+        self.assertEqual(['123456'],
+                         res_dict['consistencygroups'][0]['volume_types'])
 
         self.assertEqual('az1',
                          res_dict['consistencygroups'][1]['availability_zone'])
@@ -205,6 +232,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
                          res_dict['consistencygroups'][1]['id'])
         self.assertEqual('creating',
                          res_dict['consistencygroups'][1]['status'])
+        self.assertEqual(['123456'],
+                         res_dict['consistencygroups'][1]['volume_types'])
 
         self.assertEqual('az1',
                          res_dict['consistencygroups'][2]['availability_zone'])
@@ -216,6 +245,8 @@ class ConsistencyGroupsAPITestCase(test.TestCase):
                          res_dict['consistencygroups'][2]['id'])
         self.assertEqual('creating',
                          res_dict['consistencygroups'][2]['status'])
+        self.assertEqual(['uuid1', 'uuid2'],
+                         res_dict['consistencygroups'][2]['volume_types'])
 
         consistencygroup1.destroy()
         consistencygroup2.destroy()