Ejemplo n.º 1
0
    def create(self, context, name, description, group_type,
               volume_types, availability_zone=None):
        check_policy(context, 'create')

        req_volume_types = []
        # NOTE: Admin context is required to get extra_specs of volume_types.
        req_volume_types = (self.db.volume_types_get_by_name_or_id(
            context.elevated(), volume_types))

        if not uuidutils.is_uuid_like(group_type):
            req_group_type = self.db.group_type_get_by_name(context,
                                                            group_type)
        else:
            req_group_type = self.db.group_type_get(context, group_type)

        availability_zone = self._extract_availability_zone(availability_zone)
        kwargs = {'user_id': context.user_id,
                  'project_id': context.project_id,
                  'availability_zone': availability_zone,
                  'status': c_fields.GroupStatus.CREATING,
                  'name': name,
                  'description': description,
                  'volume_type_ids': [t['id'] for t in req_volume_types],
                  'group_type_id': req_group_type['id'],
                  'replication_status': c_fields.ReplicationStatus.DISABLED}
        group = None
        try:
            group = objects.Group(context=context, **kwargs)
            group.create()
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error("Error occurred when creating group"
                          " %s.", name)

        request_spec_list = []
        filter_properties_list = []
        for req_volume_type in req_volume_types:
            request_spec = {'volume_type': req_volume_type.copy(),
                            'group_id': group.id}
            filter_properties = {}
            request_spec_list.append(request_spec)
            filter_properties_list.append(filter_properties)

        group_spec = {'group_type': req_group_type.copy(),
                      'group_id': group.id}
        group_filter_properties = {}

        # Update quota for groups
        self.update_quota(context, group, 1)

        self._cast_create_group(context, group,
                                group_spec,
                                request_spec_list,
                                group_filter_properties,
                                filter_properties_list)

        return group
Ejemplo n.º 2
0
    def test_obj_make_compatible_groups_added(self, version):
        extra_data = {'group_id': fake.GROUP_ID, 'group': objects.Group()}
        volume = objects.Volume(self.context, host='host', **extra_data)

        serializer = ovo_base.CinderObjectSerializer(version)
        primitive = serializer.serialize_entity(self.context, volume)

        converted_volume = objects.Volume.obj_from_primitive(primitive)
        is_set = version == '1.10'
        for key in extra_data:
            self.assertEqual(is_set, converted_volume.obj_attr_is_set(key))
        self.assertEqual('host', converted_volume.host)
Ejemplo n.º 3
0
 def test_save_with_group(self, group_snapshot_update,
                          group_snapshot_cg_update):
     group = objects.Group._from_db_object(
         self.context, objects.Group(), fake_group)
     group_snapshot = objects.GroupSnapshot._from_db_object(
         self.context, objects.GroupSnapshot(), fake_group_snapshot)
     group_snapshot.name = 'foobar'
     group_snapshot.group = group
     self.assertEqual({'name': 'foobar',
                       'group': group},
                      group_snapshot.obj_get_changes())
     self.assertRaises(exception.ObjectActionError, group_snapshot.save)
Ejemplo n.º 4
0
Archivo: api.py Proyecto: Jchuan/cinder
    def create_from_src(self, context, name, description=None,
                        group_snapshot_id=None, source_group_id=None):
        check_policy(context, 'create')

        kwargs = {
            'user_id': context.user_id,
            'project_id': context.project_id,
            'status': c_fields.GroupStatus.CREATING,
            'name': name,
            'description': description,
            'group_snapshot_id': group_snapshot_id,
            'source_group_id': source_group_id,
        }

        group = None
        try:
            group = objects.Group(context=context, **kwargs)
            group.create(group_snapshot_id=group_snapshot_id,
                         source_group_id=source_group_id)
        except exception.GroupNotFound:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Source Group %(source_group)s not found when "
                              "creating group %(group)s from "
                              "source."),
                          {'group': name, 'source_group': source_group_id})
        except exception.GroupSnapshotNotFound:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Group snapshot %(group_snap)s not found when "
                              "creating group %(group)s from source."),
                          {'group': name, 'group_snap': group_snapshot_id})
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Error occurred when creating group"
                              " %(group)s from group_snapshot %(grp_snap)s."),
                          {'group': name, 'grp_snap': group_snapshot_id})

        # Update quota for groups
        self.update_quota(context, group, 1)

        if not group.host:
            msg = _("No host to create group %s.") % group.id
            LOG.error(msg)
            raise exception.InvalidGroup(reason=msg)

        if group_snapshot_id:
            self._create_group_from_group_snapshot(context, group,
                                                   group_snapshot_id)
        elif source_group_id:
            self._create_group_from_source_group(context, group,
                                                 source_group_id)

        return group
Ejemplo n.º 5
0
    def test_populate_consistencygroup(self, mock_db_grp_create):
        db_volume = fake_volume.fake_db_volume()
        volume = objects.Volume._from_db_object(self.context,
                                                objects.Volume(), db_volume)

        fake_grp = fake_group.copy()
        del fake_grp['id']
        group = objects.Group(context=self.context,
                              **fake_grp)
        group.create()
        volume.group_id = group.id
        volume.group = group
        volume.populate_consistencygroup()
        self.assertEqual(volume.group_id, volume.consistencygroup_id)
        self.assertEqual(volume.group.id, volume.consistencygroup.id)
Ejemplo n.º 6
0
 def test_is_replicated_true(self, mock_get_specs):
     mock_get_specs.return_value = '<is> True'
     group = objects.Group(self.context, group_type_id=fake.GROUP_TYPE_ID)
     self.assertTrue(group.is_replicated)
Ejemplo n.º 7
0
def fake_group_obj(context, **updates):
    return objects.Group._from_db_object(
        context, objects.Group(), fake_db_group(**updates))