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_name = 'test_grp_type' grp_type = db.group_type_create(self.ctxt, { '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, "description": "Group 1", } } req = fakes.HTTPRequest.blank('/v3/%s/groups' % fake.PROJECT_ID, version=GROUP_MICRO_VERSION) res_dict = self.controller.create(req, body) self.assertEqual(1, len(res_dict)) self.assertIn('id', res_dict['group']) self.assertTrue(mock_validate.called) group_id = res_dict['group']['id'] objects.Group.get_by_id(self.ctxt, group_id)
def test_create_group_json(self, 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( self.ctxt, {'name': grp_type, 'group_specs': {}}).get('id') body = {"group": {"name": "group1", "volume_types": [vol_type_id], "group_type": grp_type_id, "description": "Group 1", }} req = fakes.HTTPRequest.blank('/v3/%s/groups' % fake.PROJECT_ID, version=GROUP_MICRO_VERSION) res_dict = self.controller.create(req, body) self.assertEqual(1, len(res_dict)) self.assertIn('id', res_dict['group']) self.assertTrue(mock_validate.called) group_id = res_dict['group']['id'] objects.Group.get_by_id(self.ctxt, group_id)
def create(context, name, group_specs=None, is_public=True, projects=None, description=None): """Creates group types.""" group_specs = group_specs or {} projects = projects or [] elevated = context if context.is_admin else context.elevated() try: type_ref = db.group_type_create( elevated, dict(name=name, group_specs=group_specs, is_public=is_public, description=description), projects=projects, ) except db_exc.DBError: LOG.exception(_LE("DB error:")) raise exception.GroupTypeCreateFailed(name=name, group_specs=group_specs) return type_ref
def create(context, name, group_specs=None, is_public=True, projects=None, description=None): """Creates group types.""" group_specs = group_specs or {} projects = projects or [] elevated = context if context.is_admin else context.elevated() try: type_ref = db.group_type_create(elevated, dict(name=name, group_specs=group_specs, is_public=is_public, description=description), projects=projects) except db_exc.DBError: LOG.exception('DB error:') raise exception.GroupTypeCreateFailed(name=name, group_specs=group_specs) return type_ref