def test_ignore_exception(self): class IgnoredException(Exception): pass def f(): raise IgnoredException('any exception') try: utils.ignore_exception(f) except IgnoredException: self.fail('should not raise any exception.')
def _dd_copy(self, vol_params, src_snap, src_lun=None): """Creates a volume via copying a Unity snapshot. It attaches the `volume` and `snap`, then use `dd` to copy the data from the Unity snapshot to the `volume`. """ dest_lun = self.client.create_lun( name=vol_params.name, size=vol_params.size, pool=vol_params.pool, description=vol_params.description, io_limit_policy=vol_params.io_limit_policy, is_thin=False if vol_params.is_thick else None, is_compressed=vol_params.is_compressed) src_id = src_snap.get_id() try: conn_props = cinder_utils.brick_get_connector_properties() with self._connect_resource(dest_lun, conn_props, vol_params.volume_id) as dest_info, \ self._connect_resource(src_snap, conn_props, src_id) as src_info: if src_lun is None: # If size is not specified, need to get the size from LUN # of snapshot. lun = self.client.get_lun( lun_id=src_snap.storage_resource.get_id()) size_in_m = utils.byte_to_mib(lun.size_total) else: size_in_m = utils.byte_to_mib(src_lun.size_total) vol_utils.copy_volume( src_info['device']['path'], dest_info['device']['path'], size_in_m, self.driver.configuration.volume_dd_blocksize, sparse=True) except Exception: with excutils.save_and_reraise_exception(): utils.ignore_exception(self.client.delete_lun, dest_lun.get_id()) LOG.error( 'Failed to create cloned volume: %(vol_id)s, ' 'from source unity snapshot: %(snap_name)s.', { 'vol_id': vol_params.volume_id, 'snap_name': src_snap.name }) return dest_lun
def _dd_copy(self, vol_params, src_snap, src_lun=None): """Creates a volume via copying a Unity snapshot. It attaches the `volume` and `snap`, then use `dd` to copy the data from the Unity snapshot to the `volume`. """ dest_lun = self.client.create_lun( name=vol_params.name, size=vol_params.size, pool=vol_params.pool, description=vol_params.description, io_limit_policy=vol_params.io_limit_policy) src_id = src_snap.get_id() try: conn_props = cinder_utils.brick_get_connector_properties() with self._connect_resource(dest_lun, conn_props, vol_params.volume_id) as dest_info, \ self._connect_resource(src_snap, conn_props, src_id) as src_info: if src_lun is None: # If size is not specified, need to get the size from LUN # of snapshot. lun = self.client.get_lun( lun_id=src_snap.storage_resource.get_id()) size_in_m = utils.byte_to_mib(lun.size_total) else: size_in_m = utils.byte_to_mib(src_lun.size_total) vol_utils.copy_volume( src_info['device']['path'], dest_info['device']['path'], size_in_m, self.driver.configuration.volume_dd_blocksize, sparse=True) except Exception: with excutils.save_and_reraise_exception(): utils.ignore_exception(self.client.delete_lun, dest_lun.get_id()) LOG.error('Failed to create cloned volume: %(vol_id)s, ' 'from source unity snapshot: %(snap_name)s.', {'vol_id': vol_params.volume_id, 'snap_name': src_snap.name}) return dest_lun
def _create_volume_from_snap(self, volume, snap, size_in_m=None): """Creates a volume from a Unity snapshot. It attaches the `volume` and `snap`, then use `dd` to copy the data from the Unity snapshot to the `volume`. """ model_update = self.create_volume(volume) # Update `provider_location` and `provider_id` of `volume` explicitly. volume.update(model_update) src_id = snap.get_id() dest_lun = self.client.get_lun(lun_id=self.get_lun_id(volume)) try: conn_props = cinder_utils.brick_get_connector_properties() with self._connect_resource(dest_lun, conn_props, volume.id) as dest_info, \ self._connect_resource(snap, conn_props, src_id) as src_info: if size_in_m is None: # If size is not specified, need to get the size from LUN # of snapshot. lun = self.client.get_lun( lun_id=snap.storage_resource.get_id()) size_in_m = utils.byte_to_mib(lun.size_total) vol_utils.copy_volume( src_info['device']['path'], dest_info['device']['path'], size_in_m, self.driver.configuration.volume_dd_blocksize, sparse=True) except Exception: with excutils.save_and_reraise_exception(): utils.ignore_exception(self.delete_volume, volume) LOG.error( 'Failed to create cloned volume: %(vol_id)s, ' 'from source unity snapshot: %(snap_name)s.', { 'vol_id': volume.id, 'snap_name': snap.name }) return model_update
def _create_volume_from_snap(self, volume, snap, size_in_m=None): """Creates a volume from a Unity snapshot. It attaches the `volume` and `snap`, then use `dd` to copy the data from the Unity snapshot to the `volume`. """ model_update = self.create_volume(volume) volume.provider_location = model_update['provider_location'] src_id = snap.get_id() dest_lun = self.client.get_lun(lun_id=self.get_lun_id(volume)) try: conn_props = cinder_utils.brick_get_connector_properties() with self._connect_resource(dest_lun, conn_props, volume.id) as dest_info, \ self._connect_resource(snap, conn_props, src_id) as src_info: if size_in_m is None: # If size is not specified, need to get the size from LUN # of snapshot. lun = self.client.get_lun( lun_id=snap.storage_resource.get_id()) size_in_m = utils.byte_to_mib(lun.size_total) vol_utils.copy_volume( src_info['device']['path'], dest_info['device']['path'], size_in_m, self.driver.configuration.volume_dd_blocksize, sparse=True) except Exception: with excutils.save_and_reraise_exception(): utils.ignore_exception(self.delete_volume, volume) LOG.error(_LE('Failed to create cloned volume: %(vol_id)s, ' 'from source unity snapshot: %(snap_name)s. '), {'vol_id': volume.id, 'snap_name': snap.name}) return model_update