def get_all_for_volume(cls, context, volume_id): snapshots = db.snapshot_get_all_for_volume(context, volume_id) return base.obj_make_list(context, cls(context), objects.Snapshot, snapshots, expected_attrs=['metadata'])
def _fake_delete_gpfs_file(self, fchild): volume_path = fchild vol_name = os.path.basename(fchild) vol_id = vol_name.split('volume-').pop() utils.execute('rm', '-f', volume_path) utils.execute('rm', '-f', volume_path + '.snap') all_snaps = db.snapshot_get_all_for_volume(self.context, vol_id) for snap in all_snaps: snap_path = self.volumes_path + '/' + snap['name'] utils.execute('rm', '-f', snap_path)
def _fake_delete_gpfs_file(self, fchild): volume_path = fchild vol_name = os.path.basename(fchild) vol_id = vol_name.split('volume-').pop() utils.execute('rm', '-f', volume_path) utils.execute('rm', '-f', volume_path + '.snap') all_snaps = db.snapshot_get_all_for_volume(self.context, vol_id) for snap in all_snaps: snap_path = self.volumes_path + '/' + snap['name'] utils.execute('rm', '-f', snap_path)
def test_create_delete_snapshot(self): volume_src = test_utils.create_volume(self.context, host=CONF.host) self.volume.create_volume(self.context, volume_src['id']) snapCount = len(db.snapshot_get_all_for_volume(self.context, volume_src['id'])) self.assertEqual(snapCount, 0) snapshot = self._create_snapshot(volume_src['id']) snapshot_id = snapshot['id'] self.volume.create_snapshot(self.context, volume_src['id'], snapshot_id) self.assertTrue(os.path.exists(os.path.join(self.volumes_path, snapshot['name']))) snapCount = len(db.snapshot_get_all_for_volume(self.context, volume_src['id'])) self.assertEqual(snapCount, 1) self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume_src['id']) self.assertFalse(os.path.exists(os.path.join(self.volumes_path, snapshot['name']))) snapCount = len(db.snapshot_get_all_for_volume(self.context, volume_src['id'])) self.assertEqual(snapCount, 0)
def test_create_delete_snapshot(self): volume_src = test_utils.create_volume(self.context, host=CONF.host) self.volume.create_volume(self.context, volume_src['id']) snapCount = len( db.snapshot_get_all_for_volume(self.context, volume_src['id'])) self.assertTrue(snapCount == 0) snapshot = self._create_snapshot(volume_src['id']) snapshot_id = snapshot['id'] self.volume.create_snapshot(self.context, volume_src['id'], snapshot_id) self.assertTrue( os.path.exists(os.path.join(self.volumes_path, snapshot['name']))) snapCount = len( db.snapshot_get_all_for_volume(self.context, volume_src['id'])) self.assertTrue(snapCount == 1) self.volume.delete_volume(self.context, volume_src['id']) self.volume.delete_snapshot(self.context, snapshot_id) self.assertFalse( os.path.exists(os.path.join(self.volumes_path, snapshot['name']))) snapCount = len( db.snapshot_get_all_for_volume(self.context, volume_src['id'])) self.assertTrue(snapCount == 0)
def get_all_for_volume(cls, context, volume_id): snapshots = db.snapshot_get_all_for_volume(context, volume_id) expected_attrs = Snapshot._get_expected_attrs(context) return base.obj_make_list(context, cls(context), objects.Snapshot, snapshots, expected_attrs=expected_attrs)