예제 #1
0
    def test__get_snapshot_name(self):
        snapshot1 = objects.Snapshot(id=uuid.uuid4())
        snapshot1.update(
            {"provider_location": json.dumps({"name": "fake_name"})})
        snapshot2 = objects.Snapshot(id=uuid.uuid4())

        retval = self.fake_driver._get_snapshot_name(snapshot1)
        self.assertEqual("fake_name", retval)

        retval = self.fake_driver._get_snapshot_name(snapshot2)
        self.assertEqual(snapshot2.name, retval)
예제 #2
0
    def test_snapshot_reset_status(self):
        volume = db.volume_create(
            self.ctx, {
                'status': 'available',
                'host': 'test',
                'provider_location': '',
                'size': 1,
                'availability_zone': 'test',
                'attach_status': 'detached'
            })
        kwargs = {
            'volume_id': volume['id'],
            'cgsnapshot_id': None,
            'user_id': self.ctx.user_id,
            'project_id': self.ctx.project_id,
            'status': fields.SnapshotStatus.ERROR_DELETING,
            'progress': '0%',
            'volume_size': volume['size'],
            'metadata': {}
        }
        snapshot = objects.Snapshot(context=self.ctx, **kwargs)
        snapshot.create()
        self.addCleanup(snapshot.destroy)

        resp = self._issue_snapshot_reset(
            self.ctx, snapshot, {'status': fields.SnapshotStatus.ERROR})

        self.assertEqual(202, resp.status_int)
        snapshot = objects.Snapshot.get_by_id(self.ctx, snapshot['id'])
        self.assertEqual(fields.SnapshotStatus.ERROR, snapshot.status)
예제 #3
0
    def _create_snapshot_db_entry(self,
                                  display_name='test_snapshot',
                                  display_description='test snapshot',
                                  status='available',
                                  size=1,
                                  volume_id='1',
                                  provider_location=None):
        """Create a snapshot entry in the DB.

        Return the entry ID.
        """
        kwargs = {}
        kwargs['size'] = size
        kwargs['host'] = 'testhost'
        kwargs['user_id'] = 'fake'
        kwargs['project_id'] = 'fake'
        kwargs['status'] = status
        kwargs['display_name'] = display_name
        kwargs['display_description'] = display_description
        kwargs['volume_id'] = volume_id
        kwargs['cgsnapshot_id'] = None
        kwargs['volume_size'] = size
        kwargs['provider_location'] = provider_location
        snapshot_obj = objects.Snapshot(context=self.ctxt, **kwargs)
        snapshot_obj.create()
        return snapshot_obj
예제 #4
0
    def test_create_with_provider_id(self, snapshot_create):
        snapshot_create.return_value = copy.deepcopy(fake_db_snapshot)
        snapshot_create.return_value['provider_id'] = fake.PROVIDER_ID

        snapshot = objects.Snapshot(context=self.context)
        snapshot.create()
        self.assertEqual(fake.PROVIDER_ID, snapshot.provider_id)
예제 #5
0
 def test_save(self, snapshot_update):
     snapshot = objects.Snapshot._from_db_object(
         self.context, objects.Snapshot(), fake_db_snapshot)
     snapshot.display_name = 'foobar'
     snapshot.save()
     snapshot_update.assert_called_once_with(self.context, snapshot.id,
                                             {'display_name': 'foobar'})
예제 #6
0
 def test_obj_load_attr_group_not_exist(self, group_snapshot_get_by_id):
     fake_non_cg_db_snapshot = fake_snapshot.fake_db_snapshot(
         group_snapshot_id=None)
     snapshot = objects.Snapshot._from_db_object(
         self.context, objects.Snapshot(), fake_non_cg_db_snapshot)
     self.assertIsNone(snapshot.group_snapshot)
     group_snapshot_get_by_id.assert_not_called()
예제 #7
0
 def test_obj_fields(self):
     volume = objects.Volume(context=self.context, id=2, _name_id=2)
     snapshot = objects.Snapshot(context=self.context, id=1,
                                 volume=volume)
     self.assertEqual(['name', 'volume_name'], snapshot.obj_extra_fields)
     self.assertEqual('snapshot-1', snapshot.name)
     self.assertEqual('volume-2', snapshot.volume_name)
예제 #8
0
    def test_snapshot_reset_status(self):
        ctx = context.RequestContext('admin', 'fake', True)
        volume = db.volume_create(
            ctx, {
                'status': 'available',
                'host': 'test',
                'provider_location': '',
                'size': 1,
                'availability_zone': 'test',
                'attach_status': 'detached'
            })
        kwargs = {
            'volume_id': volume['id'],
            'cgsnapshot_id': None,
            'user_id': ctx.user_id,
            'project_id': ctx.project_id,
            'status': 'error_deleting',
            'progress': '0%',
            'volume_size': volume['size'],
            'metadata': {}
        }
        snapshot = objects.Snapshot(context=ctx, **kwargs)
        snapshot.create()
        self.addCleanup(snapshot.destroy)

        resp = self._issue_snapshot_reset(ctx, snapshot, {'status': 'error'})

        self.assertEqual(202, resp.status_int)
        snapshot = objects.Snapshot.get_by_id(ctx, snapshot['id'])
        self.assertEqual('error', snapshot.status)
예제 #9
0
파일: utils.py 프로젝트: ashang/cinder-1
def create_snapshot(ctxt,
                    volume_id,
                    display_name='test_snapshot',
                    display_description='this is a test snapshot',
                    cgsnapshot_id=None,
                    status=fields.SnapshotStatus.CREATING,
                    testcase_instance=None,
                    **kwargs):
    vol = db.volume_get(ctxt, volume_id)
    snap = objects.Snapshot(ctxt)
    snap.volume_id = volume_id
    snap.user_id = ctxt.user_id or fake.USER_ID
    snap.project_id = ctxt.project_id or fake.PROJECT_ID
    snap.status = status
    snap.volume_size = vol['size']
    snap.display_name = display_name
    snap.display_description = display_description
    snap.cgsnapshot_id = cgsnapshot_id
    snap.create()
    # We do the update after creating the snapshot in case we want to set
    # deleted field
    snap.update(kwargs)
    snap.save()

    # If we get a TestCase instance we add cleanup
    if testcase_instance:
        testcase_instance.addCleanup(snap.destroy)
    return snap
 def test_volume_snapshot_glance_metadata_get_nonexistent(self):
     vol = db.volume_create(self.ctxt, {})
     snapshot = objects.Snapshot(self.ctxt, volume_id=vol['id'])
     snapshot.create()
     self.assertRaises(exception.GlanceMetadataNotFound,
                       db.volume_snapshot_glance_metadata_get, self.ctxt,
                       snapshot.id)
     snapshot.destroy()
예제 #11
0
 def test_migrate_volume_with_snap(self):
     expected_status = 400
     host = 'test2'
     volume = self._migrate_volume_prep()
     snap = objects.Snapshot(self.ctx, volume_id=volume['id'])
     snap.create()
     self.addCleanup(snap.destroy)
     self._migrate_volume_exec(self.ctx, volume, host, expected_status)
 def test_obj_load_attr(self, volume_get_by_id):
     snapshot = objects.Snapshot._from_db_object(
         self.context, objects.Snapshot(), fake_db_snapshot)
     volume = objects.Volume(context=self.context, id=2)
     volume_get_by_id.return_value = volume
     self.assertEqual(volume, snapshot.volume)
     volume_get_by_id.assert_called_once_with(self.context,
                                              snapshot.volume_id)
예제 #13
0
 def test_delete_metadata_key(self, snapshot_metadata_delete):
     snapshot = objects.Snapshot(self.context, id=1)
     snapshot.metadata = {'key1': 'value1', 'key2': 'value2'}
     self.assertEqual({}, snapshot._orig_metadata)
     snapshot.delete_metadata_key(self.context, 'key2')
     self.assertEqual({'key1': 'value1'}, snapshot.metadata)
     snapshot_metadata_delete.assert_called_once_with(
         self.context, '1', 'key2')
예제 #14
0
 def test__check_snapshot_exist(self, mock_query_snapshot_by_name):
     """Test snapshot exist or not."""
     volume = objects.Volume(_name_id=uuid.uuid4(), size=1)
     snapshot = objects.Snapshot(id=uuid.uuid4(),
                                 volume_size=2,
                                 volume=volume)
     mock_query_snapshot_by_name.return_value = {'success': 1}
     retval = self.fake_driver._check_snapshot_exist(snapshot)
     self.assertEqual({'success': 1}, retval)
예제 #15
0
 def _fake_create_snapshot(self, volume_id):
     snap = {
         'display_name': 'fake_snapshot1',
         'status': 'available',
         'volume_id': volume_id
     }
     snapshot = objects.Snapshot(context=self.ctxt, **snap)
     snapshot.create()
     return snapshot
예제 #16
0
 def test_migrate_volume_with_snap(self):
     expected_status = 400
     host = 'test2'
     ctx = context.RequestContext('admin', 'fake', True)
     volume = self._migrate_volume_prep()
     snap = objects.Snapshot(ctx, volume_id=volume['id'])
     snap.create()
     self.addCleanup(snap.destroy)
     self._migrate_volume_exec(ctx, volume, host, expected_status)
예제 #17
0
 def test_create_snapshot(self, mock_create_snapshot):
     """Test create snapshot of volume."""
     volume = objects.Volume(_name_id=uuid.uuid4(), size=1)
     snapshot = objects.Snapshot(id=uuid.uuid4(),
                                 volume_size=2,
                                 volume=volume)
     mock_create_snapshot.return_value = {'success': 1}
     retval = self.fake_driver.create_snapshot(snapshot)
     self.assertIsNone(retval)
예제 #18
0
    def test_obj_make_compatible_use_quota_added(self, version):
        snapshot = objects.Snapshot(self.context, use_quota=False)

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

        converted_snapshot = objects.Snapshot.obj_from_primitive(primitive)
        expected = version != '1.39'
        self.assertIs(expected, converted_snapshot.use_quota)
예제 #19
0
 def test_obj_fields(self):
     volume = objects.Volume(context=self.context, id=fake.VOLUME_ID,
                             _name_id=fake.VOLUME_NAME_ID)
     snapshot = objects.Snapshot(context=self.context, id=fake.VOLUME_ID,
                                 volume=volume)
     self.assertEqual(['name', 'volume_name'], snapshot.obj_extra_fields)
     self.assertEqual('snapshot-%s' % fake.VOLUME_ID, snapshot.name)
     self.assertEqual('volume-%s' % fake.VOLUME_NAME_ID,
                      snapshot.volume_name)
예제 #20
0
    def test_snapshot_get_all_active_by_window(self):
        # Find all all snapshots valid within a timeframe window.
        db.volume_create(self.context, {
            'id': fake.VOLUME_ID,
            'volume_type_id': fake.VOLUME_TYPE_ID
        })
        for i in range(5):
            self.db_vol_attrs[i]['volume_id'] = fake.VOLUME_ID

        # Not in window
        del self.db_snap_attrs[0]['id']
        snap1 = objects.Snapshot(self.ctx, **self.db_snap_attrs[0])
        snap1.create()

        # In - deleted in window
        del self.db_snap_attrs[1]['id']
        snap2 = objects.Snapshot(self.ctx, **self.db_snap_attrs[1])
        snap2.create()

        # In - deleted after window
        del self.db_snap_attrs[2]['id']
        snap3 = objects.Snapshot(self.ctx, **self.db_snap_attrs[2])
        snap3.create()

        # In - created in window
        del self.db_snap_attrs[3]['id']
        snap4 = objects.Snapshot(self.ctx, **self.db_snap_attrs[3])
        snap4.create()

        # Not of window.
        del self.db_snap_attrs[4]['id']
        snap5 = objects.Snapshot(self.ctx, **self.db_snap_attrs[4])
        snap5.create()

        snapshots = objects.SnapshotList.get_all_active_by_window(
            self.context, datetime.datetime(1, 3, 1, 1, 1, 1),
            datetime.datetime(1, 4, 1, 1, 1, 1)).objects
        self.assertEqual(3, len(snapshots))
        self.assertEqual(snap2.id, snapshots[0].id)
        self.assertEqual(fake.VOLUME_ID, snapshots[0].volume_id)
        self.assertEqual(snap3.id, snapshots[1].id)
        self.assertEqual(fake.VOLUME_ID, snapshots[1].volume_id)
        self.assertEqual(snap4.id, snapshots[2].id)
        self.assertEqual(fake.VOLUME_ID, snapshots[2].volume_id)
예제 #21
0
 def test_obj_make_compatible_1_4(self, version):
     snapshot = objects.Snapshot(context=self.context)
     snapshot.status = fields.SnapshotStatus.BACKING_UP
     primitive = snapshot.obj_to_primitive(version)
     snapshot = objects.Snapshot.obj_from_primitive(primitive)
     if version == '1.4':
         status = fields.SnapshotStatus.BACKING_UP
     else:
         status = fields.SnapshotStatus.AVAILABLE
     self.assertEqual(status, snapshot.status)
예제 #22
0
 def test_snapshot_data_get_for_project(self, snapshot_data_get):
     snapshot = objects.Snapshot._from_db_object(self.context,
                                                 objects.Snapshot(),
                                                 fake_snapshot)
     volume_type_id = mock.sentinel.volume_type_id
     snapshot.snapshot_data_get_for_project(self.context, self.project_id,
                                            volume_type_id)
     snapshot_data_get.assert_called_once_with(self.context,
                                               self.project_id,
                                               volume_type_id)
예제 #23
0
 def test_obj_make_compatible_1_3(self, version):
     snapshot = objects.Snapshot(context=self.context)
     snapshot.status = fields.SnapshotStatus.UNMANAGING
     primitive = snapshot.obj_to_primitive(version)
     snapshot = objects.Snapshot.obj_from_primitive(primitive)
     if version == '1.3':
         status = fields.SnapshotStatus.UNMANAGING
     else:
         status = fields.SnapshotStatus.DELETING
     self.assertEqual(status, snapshot.status)
예제 #24
0
    def test_create_snapshot(self, mock_create_snapshot):
        self.fake_driver.client = fs_client.RestCommon(
            'https://fake_rest_site', 'user', 'password')
        volume = objects.Volume(_name_id=uuid.uuid4())
        snapshot = objects.Snapshot(id=uuid.uuid4(),
                                    volume_id=uuid.uuid4(), volume=volume)

        retval = self.fake_driver.create_snapshot(snapshot)
        self.assertIsNone(retval)
        mock_create_snapshot.assert_called_once_with(
            snapshot_name=snapshot.name, vol_name=volume.name)
예제 #25
0
 def test_create_volume_from_snapshot(self, mock_lun_from_snapshot,
                                      mock_extend_lun):
     """Test create new volume from snapshot of src volume."""
     volume = objects.Volume(_name_id=uuid.uuid4(), size=1)
     snapshot = objects.Snapshot(id=uuid.uuid4(),
                                 volume_size=2,
                                 volume=volume)
     mock_lun_from_snapshot.return_value = {'success': 1}
     mock_extend_lun.return_value = {'success': 1}
     retval = self.fake_driver.create_volume_from_snapshot(volume, snapshot)
     self.assertIsNone(retval)
예제 #26
0
 def test_delete_snapshot(self, mock__check_snapshot_exist,
                          mock_delete_snapshot):
     """Test delete snapshot."""
     volume = objects.Volume(_name_id=uuid.uuid4(), size=1)
     snapshot = objects.Snapshot(id=uuid.uuid4(),
                                 volume_size=2,
                                 volume=volume)
     mock__check_snapshot_exist.return_value = True
     mock_delete_snapshot.return_value = {'success': 1}
     retval = self.fake_driver.delete_snapshot(snapshot)
     self.assertIsNone(retval)
 def test_volume_glance_metadata_copy_to_volume(self):
     vol1 = db.volume_create(self.ctxt, {})
     vol2 = db.volume_create(self.ctxt, {})
     db.volume_glance_metadata_create(self.ctxt, vol1['id'], 'm1', 'v1')
     snapshot = objects.Snapshot(self.ctxt, volume_id=vol1['id'])
     snapshot.create()
     db.volume_glance_metadata_copy_to_snapshot(self.ctxt, snapshot.id,
                                                vol1['id'])
     db.volume_glance_metadata_copy_to_volume(self.ctxt, vol2['id'],
                                              snapshot.id)
     metadata = db.volume_glance_metadata_get(self.ctxt, vol2['id'])
     metadata = {m['key']: m['value'] for m in metadata}
     self.assertEqual({'m1': 'v1'}, metadata)
예제 #28
0
 def test_destroy(self, snapshot_destroy, utcnow_mock):
     snapshot_destroy.return_value = {
         'status': 'deleted',
         'deleted': True,
         'deleted_at': utcnow_mock.return_value}
     snapshot = objects.Snapshot(context=self.context, id=fake.SNAPSHOT_ID)
     snapshot.destroy()
     snapshot_destroy.assert_called_once_with(self.context,
                                              fake.SNAPSHOT_ID)
     self.assertTrue(snapshot.deleted)
     self.assertEqual('deleted', snapshot.status)
     self.assertEqual(utcnow_mock.return_value.replace(tzinfo=pytz.UTC),
                      snapshot.deleted_at)
예제 #29
0
    def test_invalid_status_for_snapshot(self):
        volume = db.volume_create(self.ctx,
                                  {'status': 'available', 'host': 'test',
                                   'provider_location': '', 'size': 1})
        snapshot = objects.Snapshot(self.ctx, status='available',
                                    volume_id=volume['id'])
        snapshot.create()
        self.addCleanup(snapshot.destroy)

        resp = self._issue_snapshot_reset(self.ctx, snapshot,
                                          {'status': 'attaching'})

        self.assertEqual(400, resp.status_int)
        self.assertEqual('available', snapshot.status)
예제 #30
0
def create_snapshot(volume_id, size=1, metadata=None, ctxt=None, **kwargs):
    """Create a snapshot object."""
    metadata = metadata or {}
    snap = objects.Snapshot(ctxt or context.get_admin_context())
    snap.volume_size = size
    snap.user_id = fake.USER_ID
    snap.project_id = fake.PROJECT_ID
    snap.volume_id = volume_id
    snap.status = "creating"
    if metadata is not None:
        snap.metadata = metadata
    snap.update(kwargs)

    snap.create()
    return snap