예제 #1
0
    def create(self, req, body):
        """Creates a new group type."""
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)

        grp_type = body['group_type']
        name = grp_type['name']
        description = grp_type.get('description')
        specs = grp_type.get('group_specs', {})
        is_public = strutils.bool_from_string(grp_type.get('is_public', True),
                                              strict=True)

        try:
            group_types.create(context,
                               name,
                               specs,
                               is_public,
                               description=description)
            grp_type = group_types.get_group_type_by_name(context, name)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(
                context, 'group_type.create', grp_type)

        except exception.GroupTypeExists as err:
            self._notify_group_type_error(
                context, 'group_type.create', err, group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeNotFoundByName as err:
            self._notify_group_type_error(
                context, 'group_type.create', err, name=name)
            raise webob.exc.HTTPNotFound(explanation=err.msg)

        return self._view_builder.show(req, grp_type)
예제 #2
0
 def test_delete_volume_of_group(self):
     group_type = group_types.create(
         self.context,
         'group',
         {'consistent_group_snapshot_enabled': '<is> True'}
     )
     group = test_utils.create_group(
         self.context,
         id=fake_constants.CONSISTENCY_GROUP_ID,
         host='host@backend#unit_test_pool',
         group_type_id=group_type.id)
     volume = test_utils.create_volume(
         self.context,
         id=DATA_IN_VOLUME_VG['id'],
         display_name=DATA_IN_VOLUME_VG['display_name'],
         size=DATA_IN_VOLUME_VG['size'],
         group_id=group.id,
         host=DATA_IN_VOLUME_VG['host'])
     self.DPL_MOCK.delete_vdev.return_value = DATA_OUTPUT
     self.DPL_MOCK.leave_vg.return_volume = DATA_OUTPUT
     self.dpldriver.delete_volume(volume)
     self.DPL_MOCK.leave_vg.assert_called_once_with(
         self._conver_uuid2hex(volume.id),
         self._conver_uuid2hex(volume.group_id)
     )
     self.DPL_MOCK.delete_vdev.assert_called_once_with(
         self._conver_uuid2hex(volume.id))
예제 #3
0
 def test_update_group_exception_leave(self):
     group_type = group_types.create(
         self.context,
         'group',
         {'consistent_group_snapshot_enabled': '<is> True'}
     )
     self.DPL_MOCK.get_vg.return_value = (0, DATA_OUT_CG)
     self.DPL_MOCK.leave_vg.return_value = -1, None
     volume = test_utils.create_volume(
         self.context,
         id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         display_name=DATA_IN_VOLUME_VG['display_name'],
         size=DATA_IN_VOLUME_VG['size'],
         host=DATA_IN_VOLUME_VG['host'])
     group = test_utils.create_group(
         self.context,
         id=fake_constants.CONSISTENCY_GROUP_ID,
         host='host@backend#unit_test_pool',
         group_type_id=group_type.id)
     self.assertRaises(exception.VolumeBackendAPIException,
                       self.dpldriver.update_group,
                       context=None,
                       group=group,
                       add_volumes=None,
                       remove_volumes=[volume])
예제 #4
0
 def create(self):
     if self.obj_attr_is_set("id"):
         raise exception.ObjectActionError(action="create", reason=_("already created"))
     db_group_type = group_types.create(
         self._context, self.name, self.group_specs, self.is_public, self.projects, self.description
     )
     self._from_db_object(self._context, self, db_group_type)
예제 #5
0
    def create(self, req, body):
        """Creates a new group type."""
        context = req.environ['cinder.context']
        self._check_policy(context)

        self.assert_valid_body(body, 'group_type')

        grp_type = body['group_type']
        name = grp_type.get('name', None)
        description = grp_type.get('description')
        specs = grp_type.get('group_specs', {})
        is_public = utils.get_bool_param('is_public', grp_type, True)

        if name is None or len(name.strip()) == 0:
            msg = _("Group type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        utils.check_string_length(name, 'Type name',
                                  min_length=1, max_length=255)

        if description is not None:
            utils.check_string_length(description, 'Type description',
                                      min_length=0, max_length=255)

        try:
            group_types.create(context,
                               name,
                               specs,
                               is_public,
                               description=description)
            grp_type = group_types.get_group_type_by_name(context, name)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(
                context, 'group_type.create', grp_type)

        except exception.GroupTypeExists as err:
            self._notify_group_type_error(
                context, 'group_type.create', err, group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeNotFoundByName as err:
            self._notify_group_type_error(
                context, 'group_type.create', err, name=name)
            raise webob.exc.HTTPNotFound(explanation=err.msg)

        return self._view_builder.show(req, grp_type)
예제 #6
0
    def create(self, req, body):
        """Creates a new group type."""
        context = req.environ['cinder.context']
        self._check_policy(context)

        self.assert_valid_body(body, 'group_type')

        grp_type = body['group_type']
        name = grp_type.get('name', None)
        description = grp_type.get('description')
        specs = grp_type.get('group_specs', {})
        is_public = grp_type.get('is_public', True)

        if name is None or len(name.strip()) == 0:
            msg = _("Group type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        utils.check_string_length(name, 'Type name',
                                  min_length=1, max_length=255)

        if description is not None:
            utils.check_string_length(description, 'Type description',
                                      min_length=0, max_length=255)

        try:
            group_types.create(context,
                               name,
                               specs,
                               is_public,
                               description=description)
            grp_type = group_types.get_group_type_by_name(context, name)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(
                context, 'group_type.create', grp_type)

        except exception.GroupTypeExists as err:
            self._notify_group_type_error(
                context, 'group_type.create', err, group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeNotFoundByName as err:
            self._notify_group_type_error(
                context, 'group_type.create', err, name=name)
            raise webob.exc.HTTPNotFound(explanation=err.msg)

        return self._view_builder.show(req, grp_type)
예제 #7
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason=_('already created'))
     db_group_type = group_types.create(self._context, self.name,
                                        self.group_specs,
                                        self.is_public, self.projects,
                                        self.description)
     self._from_db_object(self._context, self, db_group_type)
 def test_create_group_snapshot(self, get_all_for_group_snapshot):
     group_type = group_types.create(
         self.context, 'group',
         {'consistent_group_snapshot_enabled': '<is> True'})
     snapshot_obj = fake_snapshot.fake_snapshot_obj(self.context)
     snapshot_obj.group_id = \
         DATA_IN_CG_SNAPSHOT['group_id']
     snapshot_obj.group_type_id = group_type.id
     get_all_for_group_snapshot.return_value = [snapshot_obj]
     self.DPL_MOCK.create_vdev_snapshot.return_value = DATA_OUTPUT
     model_update, snapshots = self.dpldriver.create_group_snapshot(
         self.context, snapshot_obj, [])
     self.assertDictEqual({'status': 'available'}, model_update)
예제 #9
0
    def create(self, req, body):
        """Creates a new group type."""
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)

        grp_type = body['group_type']
        name = grp_type['name']
        description = grp_type.get('description')
        specs = grp_type.get('group_specs', {})
        is_public = strutils.bool_from_string(grp_type.get('is_public', True),
                                              strict=True)

        try:
            group_types.create(context,
                               name,
                               specs,
                               is_public,
                               description=description)
            grp_type = group_types.get_group_type_by_name(context, name)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(context, 'group_type.create',
                                         grp_type)

        except exception.GroupTypeExists as err:
            self._notify_group_type_error(context,
                                          'group_type.create',
                                          err,
                                          group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=str(err))
        except exception.GroupTypeNotFoundByName as err:
            self._notify_group_type_error(context,
                                          'group_type.create',
                                          err,
                                          name=name)
            raise webob.exc.HTTPNotFound(explanation=err.msg)

        return self._view_builder.show(req, grp_type)
예제 #10
0
 def test_create_group_snapshot(self, get_all_for_group_snapshot):
     group_type = group_types.create(
         self.context,
         'group',
         {'consistent_group_snapshot_enabled': '<is> True'}
     )
     snapshot_obj = fake_snapshot.fake_snapshot_obj(self.context)
     snapshot_obj.group_id = \
         DATA_IN_CG_SNAPSHOT['group_id']
     snapshot_obj.group_type_id = group_type.id
     get_all_for_group_snapshot.return_value = [snapshot_obj]
     self.DPL_MOCK.create_vdev_snapshot.return_value = DATA_OUTPUT
     model_update, snapshots = self.dpldriver.create_group_snapshot(
         self.context, snapshot_obj, [])
     self.assertDictEqual({'status': 'available'}, model_update)
 def test_create_group(self):
     group_type = group_types.create(
         self.context, 'group',
         {'consistent_group_snapshot_enabled': '<is> True'})
     group = test_utils.create_group(self.context,
                                     id=fake_constants.CONSISTENCY_GROUP_ID,
                                     host='host@backend#unit_test_pool',
                                     group_type_id=group_type.id)
     self.DPL_MOCK.create_vg.return_value = DATA_OUTPUT
     model_update = self.dpldriver.create_group(self.context, group)
     self.DPL_MOCK.create_vg.assert_called_once_with(
         self._conver_uuid2hex(fake_constants.CONSISTENCY_GROUP_ID),
         'test_group', 'this is a test group')
     self.assertDictEqual(
         {'status': (fields.ConsistencyGroupStatus.AVAILABLE)},
         model_update)
예제 #12
0
 def setUp(self,
           enforce_scope=False,
           enforce_new_defaults=False,
           *args,
           **kwargs):
     super().setUp(enforce_scope, enforce_new_defaults, *args, **kwargs)
     self.controller = groups.GroupsController()
     self.api_path = '/v3/%s/groups' % (self.project_id)
     self.api_version = mv.GROUP_REPLICATION
     self.group_type = group_types.create(self.project_admin_context,
                                          'group_type_name',
                                          {'key3': 'value3'},
                                          is_public=True)
     # not surprisingly, to do a group action you need to get a
     # group, so relax the group:get policy so that these tests
     # will check the group action policy we're interested in
     self.policy.set_rules({"group:get": ""}, overwrite=False)
예제 #13
0
 def test_create_group(self):
     group_type = group_types.create(
         self.context,
         'group',
         {'consistent_group_snapshot_enabled': '<is> True'}
     )
     group = test_utils.create_group(
         self.context,
         id=fake_constants.CONSISTENCY_GROUP_ID,
         host='host@backend#unit_test_pool',
         group_type_id=group_type.id)
     self.DPL_MOCK.create_vg.return_value = DATA_OUTPUT
     model_update = self.dpldriver.create_group(self.context, group)
     self.DPL_MOCK.create_vg.assert_called_once_with(
         self._conver_uuid2hex(fake_constants.CONSISTENCY_GROUP_ID),
         'test_group',
         'this is a test group')
     self.assertDictEqual({'status': (
         fields.ConsistencyGroupStatus.AVAILABLE)}, model_update)
예제 #14
0
    def test_update_group_type(self, body):
        req = fakes.HTTPRequest.blank('/v3/%s/types/%s' %
                                      (fake.PROJECT_ID, fake.GROUP_TYPE_ID),
                                      version=mv.GROUP_TYPE)

        group_type_1 = group_types.create(self.ctxt, 'group_type')

        req.environ['cinder.context'] = self.ctxt
        res = self.controller.update(req, group_type_1.get('id'), body=body)

        expected_name = body['group_type'].get('name')
        if expected_name is not None:
            self.assertEqual(expected_name, res['group_type']['name'])

        expected_is_public = body['group_type'].get('is_public')
        if expected_is_public is not None:
            self.assertEqual(expected_is_public,
                             res['group_type']['is_public'])

        self.assertEqual(body['group_type'].get('description'),
                         res['group_type']['description'])
예제 #15
0
    def test_update_group_type(self, body):
        req = fakes.HTTPRequest.blank(
            '/v3/%s/types/%s' % (fake.PROJECT_ID, fake.GROUP_TYPE_ID),
            version=mv.GROUP_TYPE)

        group_type_1 = group_types.create(self.ctxt, 'group_type')

        req.environ['cinder.context'] = self.ctxt
        res = self.controller.update(req, group_type_1.get('id'), body=body)

        expected_name = body['group_type'].get('name')
        if expected_name is not None:
            self.assertEqual(expected_name, res['group_type']['name'])

        expected_is_public = body['group_type'].get('is_public')
        if expected_is_public is not None:
            self.assertEqual(expected_is_public,
                             res['group_type']['is_public'])

        self.assertEqual(body['group_type'].get('description'),
                         res['group_type']['description'])
 def test_delete_group(self):
     group_type = group_types.create(
         self.context, 'group',
         {'consistent_group_snapshot_enabled': '<is> True'})
     group = test_utils.create_group(self.context,
                                     id=fake_constants.CONSISTENCY_GROUP_ID,
                                     host='host@backend#unit_test_pool',
                                     group_type_id=group_type.id)
     self.DB_MOCK.volume_get_all_by_group.return_value = ([
         DATA_IN_VOLUME_VG
     ])
     self.DPL_MOCK.delete_vdev.return_value = DATA_OUTPUT
     self.DPL_MOCK.delete_cg.return_value = DATA_OUTPUT
     model_update, volumes = self.dpldriver.delete_group(
         self.context, group, [])
     self.DPL_MOCK.delete_vg.assert_called_once_with(
         self._conver_uuid2hex(fake_constants.CONSISTENCY_GROUP_ID))
     self.DPL_MOCK.delete_vdev.assert_called_once_with(
         self._conver_uuid2hex((DATA_IN_VOLUME_VG['id'])))
     self.assertDictEqual(
         {'status': (fields.ConsistencyGroupStatus.DELETED)}, model_update)
예제 #17
0
 def test_update_group(self):
     group_type = group_types.create(
         self.context,
         'group',
         {'consistent_group_snapshot_enabled': '<is> True'}
     )
     self.DPL_MOCK.get_vg.return_value = (0, DATA_OUT_CG)
     self.DPL_MOCK.join_vg.return_value = DATA_OUTPUT
     self.DPL_MOCK.leave_vg.return_value = DATA_OUTPUT
     group = test_utils.create_group(
         self.context,
         id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         host='host@backend#unit_test_pool',
         group_type_id=group_type.id)
     vol_add = test_utils.create_volume(
         self.context,
         id=fake_constants.VOLUME2_ID,
         display_name=DATA_IN_VOLUME_VG['display_name'],
         size=DATA_IN_VOLUME_VG['size'],
         group_id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         host=DATA_IN_VOLUME_VG['host'])
     vol_del = test_utils.create_volume(
         self.context,
         id=DATA_IN_REMOVE_VOLUME_VG['id'],
         display_name=DATA_IN_REMOVE_VOLUME_VG['display_name'],
         size=DATA_IN_REMOVE_VOLUME_VG['size'],
         group_id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         host=DATA_IN_REMOVE_VOLUME_VG['host'])
     (model_update, add_vols, remove_vols) = (
         self.dpldriver.update_group(
             self.context, group, [vol_add], [vol_del]))
     self.DPL_MOCK.join_vg.assert_called_once_with(
         self._conver_uuid2hex(vol_add.id),
         self._conver_uuid2hex(group.id))
     self.DPL_MOCK.leave_vg.assert_called_once_with(
         self._conver_uuid2hex(vol_del.id),
         self._conver_uuid2hex(group.id))
     self.assertDictEqual({'status': (
         fields.ConsistencyGroupStatus.AVAILABLE)}, model_update)
 def test_update_group_exception_leave(self):
     group_type = group_types.create(
         self.context, 'group',
         {'consistent_group_snapshot_enabled': '<is> True'})
     self.DPL_MOCK.get_vg.return_value = (0, DATA_OUT_CG)
     self.DPL_MOCK.leave_vg.return_value = -1, None
     volume = test_utils.create_volume(
         self.context,
         id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         display_name=DATA_IN_VOLUME_VG['display_name'],
         size=DATA_IN_VOLUME_VG['size'],
         host=DATA_IN_VOLUME_VG['host'])
     group = test_utils.create_group(self.context,
                                     id=fake_constants.CONSISTENCY_GROUP_ID,
                                     host='host@backend#unit_test_pool',
                                     group_type_id=group_type.id)
     self.assertRaises(exception.VolumeBackendAPIException,
                       self.dpldriver.update_group,
                       context=None,
                       group=group,
                       add_volumes=None,
                       remove_volumes=[volume])
 def test_delete_volume_of_group(self):
     group_type = group_types.create(
         self.context, 'group',
         {'consistent_group_snapshot_enabled': '<is> True'})
     group = test_utils.create_group(self.context,
                                     id=fake_constants.CONSISTENCY_GROUP_ID,
                                     host='host@backend#unit_test_pool',
                                     group_type_id=group_type.id)
     volume = test_utils.create_volume(
         self.context,
         id=DATA_IN_VOLUME_VG['id'],
         display_name=DATA_IN_VOLUME_VG['display_name'],
         size=DATA_IN_VOLUME_VG['size'],
         group_id=group.id,
         host=DATA_IN_VOLUME_VG['host'])
     self.DPL_MOCK.delete_vdev.return_value = DATA_OUTPUT
     self.DPL_MOCK.leave_vg.return_volume = DATA_OUTPUT
     self.dpldriver.delete_volume(volume)
     self.DPL_MOCK.leave_vg.assert_called_once_with(
         self._conver_uuid2hex(volume.id),
         self._conver_uuid2hex(volume.group_id))
     self.DPL_MOCK.delete_vdev.assert_called_once_with(
         self._conver_uuid2hex(volume.id))
예제 #20
0
 def test_delete_group(self):
     group_type = group_types.create(
         self.context,
         'group',
         {'consistent_group_snapshot_enabled': '<is> True'}
     )
     group = test_utils.create_group(
         self.context,
         id=fake_constants.CONSISTENCY_GROUP_ID,
         host='host@backend#unit_test_pool',
         group_type_id=group_type.id)
     self.DB_MOCK.volume_get_all_by_group.return_value = (
         [DATA_IN_VOLUME_VG])
     self.DPL_MOCK.delete_vdev.return_value = DATA_OUTPUT
     self.DPL_MOCK.delete_cg.return_value = DATA_OUTPUT
     model_update, volumes = self.dpldriver.delete_group(
         self.context, group, [])
     self.DPL_MOCK.delete_vg.assert_called_once_with(
         self._conver_uuid2hex(fake_constants.CONSISTENCY_GROUP_ID))
     self.DPL_MOCK.delete_vdev.assert_called_once_with(
         self._conver_uuid2hex((DATA_IN_VOLUME_VG['id'])))
     self.assertDictEqual({'status': (
         fields.ConsistencyGroupStatus.DELETED)}, model_update)
 def test_update_group(self):
     group_type = group_types.create(
         self.context, 'group',
         {'consistent_group_snapshot_enabled': '<is> True'})
     self.DPL_MOCK.get_vg.return_value = (0, DATA_OUT_CG)
     self.DPL_MOCK.join_vg.return_value = DATA_OUTPUT
     self.DPL_MOCK.leave_vg.return_value = DATA_OUTPUT
     group = test_utils.create_group(
         self.context,
         id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         host='host@backend#unit_test_pool',
         group_type_id=group_type.id)
     vol_add = test_utils.create_volume(
         self.context,
         id=fake_constants.VOLUME2_ID,
         display_name=DATA_IN_VOLUME_VG['display_name'],
         size=DATA_IN_VOLUME_VG['size'],
         group_id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         host=DATA_IN_VOLUME_VG['host'])
     vol_del = test_utils.create_volume(
         self.context,
         id=DATA_IN_REMOVE_VOLUME_VG['id'],
         display_name=DATA_IN_REMOVE_VOLUME_VG['display_name'],
         size=DATA_IN_REMOVE_VOLUME_VG['size'],
         group_id='fe2dbc51-5810-451d-ab2f-8c8a48d15bee',
         host=DATA_IN_REMOVE_VOLUME_VG['host'])
     (model_update, add_vols,
      remove_vols) = (self.dpldriver.update_group(self.context, group,
                                                  [vol_add], [vol_del]))
     self.DPL_MOCK.join_vg.assert_called_once_with(
         self._conver_uuid2hex(vol_add.id), self._conver_uuid2hex(group.id))
     self.DPL_MOCK.leave_vg.assert_called_once_with(
         self._conver_uuid2hex(vol_del.id), self._conver_uuid2hex(group.id))
     self.assertDictEqual(
         {'status': (fields.ConsistencyGroupStatus.AVAILABLE)},
         model_update)
예제 #22
0
 def _create_group_type(self, group_type_name, group_specs=None, is_public=True, projects=None):
     return group_types.create(self.ctxt, group_type_name, group_specs, is_public, projects).get("id")
예제 #23
0
 def _create_group_type(self, group_type_name, group_specs=None,
                        is_public=True, projects=None):
     return group_types.create(self.ctxt, group_type_name, group_specs,
                               is_public, projects).get('id')