def test_create_delete_snapshot(self): """Test snapshot can be created and deleted.""" volume = self._create_volume() self.volume.create_volume(self.context, volume["id"]) snapshot_id = self._create_snapshot(volume["id"]) self.volume.create_snapshot(self.context, volume["id"], snapshot_id) self.assertEqual(snapshot_id, db.snapshot_get(context.get_admin_context(), snapshot_id).id) self.volume.delete_snapshot(self.context, snapshot_id) self.assertRaises(exception.NotFound, db.snapshot_get, self.context, snapshot_id) self.volume.delete_volume(self.context, volume["id"])
def test_create_delete_snapshot(self): """Test snapshot can be created and deleted.""" volume_id = self._create_volume() self.volume.create_volume(self.context, volume_id) snapshot_id = self._create_snapshot(volume_id) self.volume.create_snapshot(self.context, volume_id, snapshot_id) self.assertEqual( snapshot_id, db.snapshot_get(context.get_admin_context(), snapshot_id).id) self.volume.delete_snapshot(self.context, snapshot_id) self.assertRaises(exception.NotFound, db.snapshot_get, self.context, snapshot_id) self.volume.delete_volume(self.context, volume_id)
def test_can_delete_errored_snapshot(self): """Test snapshot can be created and deleted.""" volume = self._create_volume() self.volume.create_volume(self.context, volume["id"]) snapshot_id = self._create_snapshot(volume["id"]) self.volume.create_snapshot(self.context, volume["id"], snapshot_id) snapshot = db.snapshot_get(context.get_admin_context(), snapshot_id) volume_api = nova.volume.api.API() snapshot["status"] = "badstatus" self.assertRaises(exception.InvalidVolume, volume_api.delete_snapshot, self.context, snapshot) snapshot["status"] = "error" self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume["id"])
def test_cant_delete_volume_with_snapshots(self): """Test snapshot can be created and deleted.""" volume = self._create_volume() self.volume.create_volume(self.context, volume["id"]) snapshot_id = self._create_snapshot(volume["id"]) self.volume.create_snapshot(self.context, volume["id"], snapshot_id) self.assertEqual(snapshot_id, db.snapshot_get(context.get_admin_context(), snapshot_id).id) volume["status"] = "available" volume["host"] = "fakehost" volume_api = nova.volume.api.API() self.assertRaises(exception.InvalidVolume, volume_api.delete, self.context, volume) self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume["id"])
def test_can_delete_errored_snapshot(self): """Test snapshot can be created and deleted.""" volume = self._create_volume() self.volume.create_volume(self.context, volume['id']) snapshot_id = self._create_snapshot(volume['id']) self.volume.create_snapshot(self.context, volume['id'], snapshot_id) snapshot = db.snapshot_get(context.get_admin_context(), snapshot_id) volume_api = nova.volume.api.API() snapshot['status'] = 'badstatus' self.assertRaises(exception.InvalidVolume, volume_api.delete_snapshot, self.context, snapshot) snapshot['status'] = 'error' self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume['id'])
def test_cant_delete_volume_with_snapshots(self): """Test snapshot can be created and deleted.""" volume = self._create_volume() self.volume.create_volume(self.context, volume['id']) snapshot_id = self._create_snapshot(volume['id']) self.volume.create_snapshot(self.context, volume['id'], snapshot_id) self.assertEqual( snapshot_id, db.snapshot_get(context.get_admin_context(), snapshot_id).id) volume['status'] = 'available' volume['host'] = 'fakehost' volume_api = nova.volume.api.API() self.assertRaises(exception.InvalidVolume, volume_api.delete, self.context, volume) self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume['id'])
def test_delete_busy_snapshot(self): """Test snapshot can be created and deleted.""" volume = self._create_volume() volume_id = volume["id"] self.volume.create_volume(self.context, volume_id) snapshot_id = self._create_snapshot(volume_id) self.volume.create_snapshot(self.context, volume_id, snapshot_id) self.mox.StubOutWithMock(self.volume.driver, "delete_snapshot") self.volume.driver.delete_snapshot(mox.IgnoreArg()).AndRaise(exception.SnapshotIsBusy) self.mox.ReplayAll() self.volume.delete_snapshot(self.context, snapshot_id) snapshot_ref = db.snapshot_get(self.context, snapshot_id) self.assertEqual(snapshot_id, snapshot_ref.id) self.assertEqual("available", snapshot_ref.status) self.mox.UnsetStubs() self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume_id)
def test_delete_busy_snapshot(self): """Test snapshot can be created and deleted.""" volume = self._create_volume() volume_id = volume['id'] self.volume.create_volume(self.context, volume_id) snapshot_id = self._create_snapshot(volume_id) self.volume.create_snapshot(self.context, volume_id, snapshot_id) self.mox.StubOutWithMock(self.volume.driver, 'delete_snapshot') self.volume.driver.delete_snapshot(mox.IgnoreArg()).AndRaise( exception.SnapshotIsBusy) self.mox.ReplayAll() self.volume.delete_snapshot(self.context, snapshot_id) snapshot_ref = db.snapshot_get(self.context, snapshot_id) self.assertEqual(snapshot_id, snapshot_ref.id) self.assertEqual("available", snapshot_ref.status) self.mox.UnsetStubs() self.volume.delete_snapshot(self.context, snapshot_id) self.volume.delete_volume(self.context, volume_id)
def test_snapshot_reset_status(self): # admin context ctx = context.RequestContext('admin', 'fake', is_admin=True) ctx.elevated() # add roles # snapshot in 'error_deleting' volume = db.volume_create(ctx, {}) snapshot = db.snapshot_create(ctx, {'status': 'error_deleting', 'volume_id': volume['id']}) req = webob.Request.blank('/v1/fake/snapshots/%s/action' % snapshot['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' # request status of 'error' req.body = jsonutils.dumps({'os-reset_status': {'status': 'error'}}) # attach admin context to request req.environ['nova.context'] = ctx resp = req.get_response(app()) # request is accepted self.assertEquals(resp.status_int, 202) snapshot = db.snapshot_get(ctx, snapshot['id']) # status changed to 'error' self.assertEquals(snapshot['status'], 'error')
def test_invalid_status_for_snapshot(self): # admin context ctx = context.RequestContext('admin', 'fake', is_admin=True) ctx.elevated() # add roles # snapshot in 'available' volume = db.volume_create(ctx, {}) snapshot = db.snapshot_create(ctx, {'status': 'available', 'volume_id': volume['id']}) req = webob.Request.blank('/v1/fake/snapshots/%s/action' % snapshot['id']) req.method = 'POST' req.headers['content-type'] = 'application/json' # 'attaching' is not a valid status for snapshots req.body = jsonutils.dumps({'os-reset_status': {'status': 'attaching'}}) # attach admin context to request req.environ['nova.context'] = ctx resp = req.get_response(app()) # request is accepted print resp self.assertEquals(resp.status_int, 400) snapshot = db.snapshot_get(ctx, snapshot['id']) # status is still 'available' self.assertEquals(snapshot['status'], 'available')