def return_volume_types_get_volume_type(context, id): if id == fake.WILL_NOT_BE_FOUND_ID: raise exception.VolumeTypeNotFound(volume_type_id=id) return stub_volume_type(id)
def return_volume_types_get_volume_type(context, id): if id == "777": raise exception.VolumeTypeNotFound(volume_type_id=id) return stub_volume_type(int(id))
def fake_db_disassociate(context, id, type_id): if id == 'Trouble': raise db_exc.DBError() elif type_id == 'NotFound': raise exception.VolumeTypeNotFound(volume_type_id=type_id) pass
def test_retype_type_no_exist(self): # Should fail if new type does not exist exc = exception.VolumeTypeNotFound('exc') self.retype_mocks['get_volume_type'].side_effect = exc self._retype_volume_exec(404)
def return_volume_types_get_volume_type(context, id): if id == fake.will_not_be_found_id: raise exception.VolumeTypeNotFound(volume_type_id=id) return stub_volume_type(id)
def execute(self, context, volume_ref, volume_spec): volume_spec = dict(volume_spec) volume_id = volume_spec.pop('volume_id', None) if not volume_id: volume_id = volume_ref['id'] # we can't do anything if the driver didn't init if not self.driver.initialized: driver_name = self.driver.__class__.__name__ LOG.exception( _LE("Unable to create volume. " "Volume driver %s not initialized"), driver_name) # NOTE(flaper87): Set the error status before # raising any exception. self.db.volume_update(context, volume_id, dict(status='error')) raise exception.DriverNotInitialized() create_type = volume_spec.pop('type', None) LOG.info( _LI("Volume %(volume_id)s: being created as %(create_type)s " "with specification: %(volume_spec)s"), { 'volume_spec': volume_spec, 'volume_id': volume_id, 'create_type': create_type }) if create_type == 'raw': model_update = self._create_raw_volume(context, volume_ref=volume_ref, **volume_spec) elif create_type == 'snap': model_update = self._create_from_snapshot(context, volume_ref=volume_ref, **volume_spec) elif create_type == 'source_vol': model_update = self._create_from_source_volume( context, volume_ref=volume_ref, **volume_spec) elif create_type == 'source_replica': model_update = self._create_from_source_replica( context, volume_ref=volume_ref, **volume_spec) elif create_type == 'image': model_update = self._create_from_image(context, volume_ref=volume_ref, **volume_spec) else: raise exception.VolumeTypeNotFound(volume_type_id=create_type) # Persist any model information provided on creation. try: if model_update: volume_ref = self.db.volume_update(context, volume_ref['id'], model_update) except exception.CinderException: # If somehow the update failed we want to ensure that the # failure is logged (but not try rescheduling since the volume at # this point has been created). LOG.exception( _LE("Failed updating model of volume %(volume_id)s " "with creation provided model %(model)s"), { 'volume_id': volume_id, 'model': model_update }) raise return volume_ref
def execute(self, context, volume, volume_spec): volume_spec = dict(volume_spec) volume_id = volume_spec.pop('volume_id', None) if not volume_id: volume_id = volume.id # we can't do anything if the driver didn't init if not self.driver.initialized: driver_name = self.driver.__class__.__name__ LOG.error("Unable to create volume. " "Volume driver %s not initialized", driver_name) raise exception.DriverNotInitialized() # NOTE(xyang): Populate consistencygroup_id and consistencygroup # fields before passing to the driver. This is to support backward # compatibility of consistencygroup. if volume.group_id: volume.consistencygroup_id = volume.group_id cg = consistencygroup.ConsistencyGroup() cg.from_group(volume.group) volume.consistencygroup = cg create_type = volume_spec.pop('type', None) LOG.info("Volume %(volume_id)s: being created as %(create_type)s " "with specification: %(volume_spec)s", {'volume_spec': volume_spec, 'volume_id': volume_id, 'create_type': create_type}) if create_type == 'raw': model_update = self._create_raw_volume(volume, **volume_spec) elif create_type == 'snap': model_update = self._create_from_snapshot(context, volume, **volume_spec) elif create_type == 'source_vol': model_update = self._create_from_source_volume( context, volume, **volume_spec) elif create_type == 'image': model_update = self._create_from_image(context, volume, **volume_spec) elif create_type == 'backup': model_update, need_update_volume = self._create_from_backup( context, volume, **volume_spec) volume_spec.update({'need_update_volume': need_update_volume}) else: raise exception.VolumeTypeNotFound(volume_type_id=create_type) # Persist any model information provided on creation. try: if model_update: with volume.obj_as_admin(): volume.update(model_update) volume.save() except exception.CinderException: # If somehow the update failed we want to ensure that the # failure is logged (but not try rescheduling since the volume at # this point has been created). LOG.exception("Failed updating model of volume %(volume_id)s " "with creation provided model %(model)s", {'volume_id': volume_id, 'model': model_update}) raise return volume_spec