def test_too_many_gigabytes(self): volume_ids = [] volume_id = self._create_volume(size=20) volume_ids.append(volume_id) self.assertRaises(exception.QuotaError, volume.API().create, self.context, size=10, snapshot_id=None, name='', description='') for volume_id in volume_ids: db.volume_destroy(self.context, volume_id)
def test_parse_volume_info_raise_exception(self): """This shows how to test helper classes' methods.""" stubs.stubout_session(self.stubs, stubs.FakeSessionForVolumeTests) session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass') helper = volume_utils.VolumeHelper helper.XenAPI = session.get_imported_xenapi() vol = self._create_volume() # oops, wrong mount point! self.assertRaises(volume_utils.StorageError, helper.parse_volume_info, self._make_info(), 'dev/sd' ) db.volume_destroy(context.get_admin_context(), vol['id'])
def test_too_many_volumes(self): """Ensure that NoMoreTargets is raised when we run out of volumes.""" vols = [] total_slots = FLAGS.iscsi_num_targets for _index in xrange(total_slots): volume_id = self._create_volume() self.volume.create_volume(self.context, volume_id) vols.append(volume_id) volume_id = self._create_volume() self.assertRaises(db.NoMoreTargets, self.volume.create_volume, self.context, volume_id) db.volume_destroy(context.get_admin_context(), volume_id) for volume_id in vols: self.volume.delete_volume(self.context, volume_id)
def test_create_snapshot_force(self): """Test snapshot in use can be created forcibly.""" def fake_cast(ctxt, topic, msg): pass self.stubs.Set(rpc, 'cast', fake_cast) volume_id = self._create_volume() self.volume.create_volume(self.context, volume_id) db.volume_attached(self.context, volume_id, self.instance_id, '/dev/sda1') volume_api = volume.api.API() self.assertRaises(exception.ApiError, volume_api.create_snapshot, self.context, volume_id, 'fake_name', 'fake_description') snapshot_ref = volume_api.create_snapshot_force( self.context, volume_id, 'fake_name', 'fake_description') db.snapshot_destroy(self.context, snapshot_ref['id']) db.volume_destroy(self.context, volume_id)
def test_create_snapshot_force(self): """Test snapshot in use can be created forcibly.""" def fake_cast(ctxt, topic, msg): pass self.stubs.Set(rpc, 'cast', fake_cast) volume_id = self._create_volume() self.volume.create_volume(self.context, volume_id) db.volume_attached(self.context, volume_id, self.instance_id, '/dev/sda1') volume_api = volume.api.API() self.assertRaises(exception.ApiError, volume_api.create_snapshot, self.context, volume_id, 'fake_name', 'fake_description') snapshot_ref = volume_api.create_snapshot_force(self.context, volume_id, 'fake_name', 'fake_description') db.snapshot_destroy(self.context, snapshot_ref['id']) db.volume_destroy(self.context, volume_id)