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:
parent
9f00487d79
commit
21365abd52
|
@ -207,7 +207,7 @@ class GroupsController(wsgi.Controller):
|
||||||
if not uuidutils.is_uuid_like(group_type):
|
if not uuidutils.is_uuid_like(group_type):
|
||||||
req_group_type = group_types.get_group_type_by_name(context,
|
req_group_type = group_types.get_group_type_by_name(context,
|
||||||
group_type)
|
group_type)
|
||||||
group_type = req_group_type.id
|
group_type = req_group_type['id']
|
||||||
self._check_default_cgsnapshot_type(group_type)
|
self._check_default_cgsnapshot_type(group_type)
|
||||||
volume_types = group.get('volume_types')
|
volume_types = group.get('volume_types')
|
||||||
if not volume_types:
|
if not volume_types:
|
||||||
|
|
|
@ -340,21 +340,24 @@ class GroupsAPITestCase(test.TestCase):
|
||||||
self.assertEqual([fake.VOLUME_TYPE_ID, fake.VOLUME_TYPE2_ID],
|
self.assertEqual([fake.VOLUME_TYPE_ID, fake.VOLUME_TYPE2_ID],
|
||||||
res_dict['groups'][2]['volume_types'])
|
res_dict['groups'][2]['volume_types'])
|
||||||
|
|
||||||
|
@ddt.data(False, True)
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
'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
|
# Create volume types and group type
|
||||||
vol_type = 'test'
|
vol_type = 'test'
|
||||||
vol_type_id = db.volume_type_create(
|
vol_type_id = db.volume_type_create(
|
||||||
self.ctxt,
|
self.ctxt,
|
||||||
{'name': vol_type, 'extra_specs': {}}).get('id')
|
{'name': vol_type, 'extra_specs': {}}).get('id')
|
||||||
grp_type = 'grp_type'
|
grp_type_name = 'test_grp_type'
|
||||||
grp_type_id = db.group_type_create(
|
grp_type = db.group_type_create(
|
||||||
self.ctxt,
|
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",
|
body = {"group": {"name": "group1",
|
||||||
"volume_types": [vol_type_id],
|
"volume_types": [vol_type_id],
|
||||||
"group_type": grp_type_id,
|
"group_type": grp_type,
|
||||||
"description":
|
"description":
|
||||||
"Group 1", }}
|
"Group 1", }}
|
||||||
req = fakes.HTTPRequest.blank('/v3/%s/groups' % fake.PROJECT_ID,
|
req = fakes.HTTPRequest.blank('/v3/%s/groups' % fake.PROJECT_ID,
|
||||||
|
|
Loading…
Reference in New Issue