Fix create_group with group type name

When creating a group with a group type name, an exception
was raised: AttributeError: 'dict' object has no attribute 'id'
This is because group_types.get_group_type_by_name returns a
dictionary of a group type, not an object. This patch fixes it.

Change-Id: I36c0ccd6262dfb392241b2898f57ecaef5dc5162
Closes-Bug: #1654098
This commit is contained in:
xing-yang 2016-11-24 07:08:01 -05:00
parent 9f00487d79
commit 21365abd52
2 changed files with 9 additions and 6 deletions

View File

@ -207,7 +207,7 @@ class GroupsController(wsgi.Controller):
if not uuidutils.is_uuid_like(group_type):
req_group_type = group_types.get_group_type_by_name(context,
group_type)
group_type = req_group_type.id
group_type = req_group_type['id']
self._check_default_cgsnapshot_type(group_type)
volume_types = group.get('volume_types')
if not volume_types:

View File

@ -340,21 +340,24 @@ class GroupsAPITestCase(test.TestCase):
self.assertEqual([fake.VOLUME_TYPE_ID, fake.VOLUME_TYPE2_ID],
res_dict['groups'][2]['volume_types'])
@ddt.data(False, True)
@mock.patch(
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
def test_create_group_json(self, mock_validate):
def test_create_group_json(self, use_group_type_name, mock_validate):
# Create volume types and group type
vol_type = 'test'
vol_type_id = db.volume_type_create(
self.ctxt,
{'name': vol_type, 'extra_specs': {}}).get('id')
grp_type = 'grp_type'
grp_type_id = db.group_type_create(
grp_type_name = 'test_grp_type'
grp_type = db.group_type_create(
self.ctxt,
{'name': grp_type, 'group_specs': {}}).get('id')
{'name': grp_type_name, 'group_specs': {}}).get('id')
if use_group_type_name:
grp_type = grp_type_name
body = {"group": {"name": "group1",
"volume_types": [vol_type_id],
"group_type": grp_type_id,
"group_type": grp_type,
"description":
"Group 1", }}
req = fakes.HTTPRequest.blank('/v3/%s/groups' % fake.PROJECT_ID,