def test_snapshot_metadata_update_delete(self):
        metadata1 = {'a': '1', 'c': '2'}
        metadata2 = {'a': '3', 'd': '5'}
        should_be = metadata2

        db.volume_create(self.ctxt, {'id': 1})
        db.snapshot_create(self.ctxt,
                           {'id': 1, 'volume_id': 1, 'metadata': metadata1})
        db.snapshot_metadata_update(self.ctxt, 1, metadata2, True)

        self.assertEquals(should_be, db.snapshot_metadata_get(self.ctxt, 1))
Beispiel #2
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'volume' in updates:
                raise exception.ObjectActionError(action='save',
                                                  reason=_('volume changed'))
            if 'cgsnapshot' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cgsnapshot changed'))

            if 'cluster' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cluster changed'))

            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.snapshot_metadata_update(self._context,
                                                            self.id, metadata,
                                                            True)

            db.snapshot_update(self._context, self.id, updates)

        self.obj_reset_changes()
Beispiel #3
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'volume' in updates:
                raise exception.ObjectActionError(action='save',
                                                  reason=_('volume changed'))
            if 'cgsnapshot' in updates:
                # NOTE(xyang): Allow this to pass if 'cgsnapshot' is
                # set to None. This is to support backward compatibility.
                if updates.get('cgsnapshot'):
                    raise exception.ObjectActionError(
                        action='save', reason=_('cgsnapshot changed'))
            if 'group_snapshot' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('group_snapshot changed'))

            if 'cluster' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cluster changed'))

            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.snapshot_metadata_update(self._context,
                                                            self.id, metadata,
                                                            True)

            db.snapshot_update(self._context, self.id, updates)

        self.obj_reset_changes()
Beispiel #4
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'volume' in updates:
                raise exception.ObjectActionError(action='save',
                                                  reason=_('volume changed'))
            if 'cgsnapshot' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cgsnapshot changed'))
            if 'group_snapshot' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('group_snapshot changed'))

            if 'cluster' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('cluster changed'))

            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.snapshot_metadata_update(self._context,
                                                            self.id, metadata,
                                                            True)

            db.snapshot_update(self._context, self.id, updates)

        self.obj_reset_changes()
Beispiel #5
0
    def save(self):
        updates = self.cinder_obj_get_changes()
        if updates:
            if 'volume' in updates:
                raise exception.ObjectActionError(action='save',
                                                  reason=_('volume changed'))
            if 'cgsnapshot' in updates:
                # NOTE(xyang): Allow this to pass if 'cgsnapshot' is
                # set to None. This is to support backward compatibility.
                if updates.get('cgsnapshot'):
                    raise exception.ObjectActionError(
                        action='save', reason=_('cgsnapshot changed'))
            if 'group_snapshot' in updates:
                raise exception.ObjectActionError(
                    action='save', reason=_('group_snapshot changed'))

            if 'cluster' in updates:
                raise exception.ObjectActionError(action='save',
                                                  reason=_('cluster changed'))

            if 'metadata' in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop('metadata', None)
                self.metadata = db.snapshot_metadata_update(
                    self._context, self.id, metadata, True)

            db.snapshot_update(self._context, self.id, updates)

        self.obj_reset_changes()
Beispiel #6
0
    def test_snapshot_metadata_update_delete(self):
        metadata1 = {"a": "1", "c": "2"}
        metadata2 = {"a": "3", "d": "5"}
        should_be = metadata2

        db.volume_create(self.ctxt, {"id": 1})
        db.snapshot_create(self.ctxt, {"id": 1, "volume_id": 1, "metadata": metadata1})
        db_meta = db.snapshot_metadata_update(self.ctxt, 1, metadata2, True)

        self.assertEqual(should_be, db_meta)
Beispiel #7
0
    def test_snapshot_metadata_update(self):
        metadata1 = {'a': '1', 'c': '2'}
        metadata2 = {'a': '3', 'd': '5'}
        should_be = {'a': '3', 'c': '2', 'd': '5'}

        db.volume_create(self.ctxt, {'id': 1})
        db.snapshot_create(self.ctxt,
                           {'id': 1, 'volume_id': 1, 'metadata': metadata1})
        db_meta = db.snapshot_metadata_update(self.ctxt, 1, metadata2, False)

        self.assertEqual(should_be, db_meta)
Beispiel #8
0
    def test_snapshot_metadata_update(self):
        metadata1 = {'a': '1', 'c': '2'}
        metadata2 = {'a': '3', 'd': '5'}
        should_be = {'a': '3', 'c': '2', 'd': '5'}

        db.volume_create(self.ctxt, {'id': 1})
        db.snapshot_create(self.ctxt, {
            'id': 1,
            'volume_id': 1,
            'metadata': metadata1
        })
        db_meta = db.snapshot_metadata_update(self.ctxt, 1, metadata2, False)

        self.assertEqual(should_be, db_meta)
Beispiel #9
0
    def save(self):
        updates = self.obj_get_changes()
        if updates:
            if "volume" in updates:
                raise exception.ObjectActionError(action="save", reason=_("volume changed"))

            if "metadata" in updates:
                # Metadata items that are not specified in the
                # self.metadata will be deleted
                metadata = updates.pop("metadata", None)
                self.metadata = db.snapshot_metadata_update(self._context, self.id, metadata, True)

            db.snapshot_update(self._context, self.id, updates)

        self.obj_reset_changes()