self.volume.driver.migrate_volume, self.context,
vol, host)
+ @mock.patch.object(lvm.LVMVolumeDriver, '_create_volume')
+ @mock.patch.object(brick_lvm.LVM, 'get_all_physical_volumes')
+ @mock.patch.object(brick_lvm.LVM, 'delete')
+ @mock.patch.object(volutils, 'copy_volume',
+ side_effect=processutils.ProcessExecutionError)
+ @mock.patch.object(volutils, 'get_all_volume_groups',
+ return_value=[{'name': 'cinder-volumes'}])
+ def test_lvm_migrate_volume_volume_copy_error(self, vgs, copy_volume,
+ mock_delete, mock_pvs,
+ mock_create):
+
+ hostname = socket.gethostname()
+ capabilities = {'location_info': 'LVMVolumeDriver:%s:'
+ 'cinder-volumes:default:0' % hostname}
+ host = {'capabilities': capabilities}
+ vol = {'name': 'test', 'id': 1, 'size': 1, 'status': 'available'}
+ self.volume.driver.vg = fake_lvm.FakeBrickLVM('cinder-volumes-old',
+ False, None, 'default')
+ self.assertRaises(processutils.ProcessExecutionError,
+ self.volume.driver.migrate_volume, self.context,
+ vol, host)
+ mock_delete.assert_called_once_with(vol)
+
def test_lvm_volume_group_missing(self):
hostname = socket.gethostname()
capabilities = {'location_info': 'LVMVolumeDriver:%s:'
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_log import log as logging
+from oslo_utils import excutils
from oslo_utils import importutils
from oslo_utils import units
import six
# copy_volume expects sizes in MiB, we store integer GiB
# be sure to convert before passing in
size_in_mb = int(volume['size']) * units.Ki
- volutils.copy_volume(self.local_path(volume),
- self.local_path(volume, vg=dest_vg),
- size_in_mb,
- self.configuration.volume_dd_blocksize,
- execute=self._execute,
- sparse=self.sparse_copy_volume)
+ try:
+ volutils.copy_volume(self.local_path(volume),
+ self.local_path(volume, vg=dest_vg),
+ size_in_mb,
+ self.configuration.volume_dd_blocksize,
+ execute=self._execute,
+ sparse=self.sparse_copy_volume)
+ except Exception as e:
+ with excutils.save_and_reraise_exception():
+ LOG.error(_LE("Volume migration failed due to "
+ "exception: %(reason)s."),
+ {'reason': six.text_type(e)}, resource=volume)
+ dest_vg_ref.delete(volume)
self._delete_volume(volume)
return (True, None)