Exemplo n.º 1
0
    def _from_db_object(context, group, db_group, expected_attrs=None):
        if expected_attrs is None:
            expected_attrs = []
        for name, field in group.fields.items():
            if name in Group.OPTIONAL_FIELDS:
                continue
            value = db_group.get(name)
            setattr(group, name, value)

        if 'volumes' in expected_attrs:
            volumes = base.obj_make_list(context, objects.VolumeList(context),
                                         objects.Volume, db_group['volumes'])
            group.volumes = volumes

        if 'volume_types' in expected_attrs:
            volume_types = base.obj_make_list(context,
                                              objects.VolumeTypeList(context),
                                              objects.VolumeType,
                                              db_group['volume_types'])
            group.volume_types = volume_types

        if 'group_snapshots' in expected_attrs:
            group_snapshots = base.obj_make_list(
                context, objects.GroupSnapshotList(context),
                objects.GroupSnapshot, db_group['group_snapshots'])
            group.group_snapshots = group_snapshots

        group._context = context
        group.obj_reset_changes()
        return group
Exemplo n.º 2
0
    def test_obj_make_compatible(self, version):
        extra_data = {'group_snapshot_id': fake.GROUP_SNAPSHOT_ID,
                      'source_group_id': fake.GROUP_ID,
                      'group_snapshots': objects.GroupSnapshotList()}
        group = objects.Group(self.context, name='name', **extra_data)

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

        converted_group = objects.Group.obj_from_primitive(primitive)
        is_set = version == '1.11'
        for key in extra_data:
            self.assertEqual(is_set, converted_group.obj_attr_is_set(key))
        self.assertEqual('name', converted_group.name)