# under the License.
""" Tests for Ceph backup service."""
-import contextlib
import hashlib
import os
import tempfile
self.mock_rbd.RBD.list = mock.Mock()
self.mock_rbd.RBD.list.return_value = [backup_name]
- with contextlib.nested(
- mock.patch.object(self.service, 'get_backup_snaps'),
- mock.patch.object(self.service, '_rbd_diff_transfer')
- ) as (_unused, mock_rbd_diff_transfer):
+ with mock.patch.object(self.service, 'get_backup_snaps'), \
+ mock.patch.object(self.service, '_rbd_diff_transfer') as \
+ mock_rbd_diff_transfer:
def mock_rbd_diff_transfer_side_effect(src_name, src_pool,
dest_name, dest_pool,
src_user, src_conf,
# Raise a pseudo exception.BackupRBDOperationFailed.
mock_rbd_diff_transfer.side_effect \
= mock_rbd_diff_transfer_side_effect
- with contextlib.nested(
- mock.patch.object(self.service, '_full_backup'),
- mock.patch.object(self.service, '_try_delete_base_image')
- ) as (_unused, mock_try_delete_base_image):
+
+ with mock.patch.object(self.service, '_full_backup'), \
+ mock.patch.object(self.service,
+ '_try_delete_base_image') as \
+ mock_try_delete_base_image:
def mock_try_delete_base_image_side_effect(backup_id,
volume_id,
base_name):
self.mock_rbd.RBD.list = mock.Mock()
self.mock_rbd.RBD.list.return_value = [backup_name]
- with contextlib.nested(
- mock.patch.object(self.service, 'get_backup_snaps'),
- mock.patch.object(self.service, '_rbd_diff_transfer'),
- mock.patch.object(self.service, '_full_backup'),
- mock.patch.object(self.service, '_backup_metadata')
- ) as (_unused1, _u2, _u3, mock_backup_metadata):
+ with mock.patch.object(self.service, 'get_backup_snaps'), \
+ mock.patch.object(self.service, '_rbd_diff_transfer'), \
+ mock.patch.object(self.service, '_full_backup'), \
+ mock.patch.object(self.service, '_backup_metadata') as \
+ mock_backup_metadata:
def mock_backup_metadata_side_effect(backup):
raise exception.BackupOperationError(_('mock'))
# License for the specific language governing permissions and limitations
# under the License.
-import contextlib
import datetime
import StringIO
import sys
mock.sentinel.iser_enabled)
def _test_create_rtslib_error_network_portal(self, ip):
- with contextlib.nested(
- mock.patch('rtslib.NetworkPortal'),
- mock.patch('rtslib.LUN'),
- mock.patch('rtslib.TPG'),
- mock.patch('rtslib.FabricModule'),
- mock.patch('rtslib.Target'),
- mock.patch('rtslib.BlockStorageObject'),
- mock.patch('rtslib.root.RTSRoot')
- ) as (network_portal, lun, tpg, fabric_module, target,
- block_storage_object, rts_root):
+ with mock.patch('rtslib.NetworkPortal') as network_portal, \
+ mock.patch('rtslib.LUN') as lun, \
+ mock.patch('rtslib.TPG') as tpg, \
+ mock.patch('rtslib.FabricModule') as fabric_module, \
+ mock.patch('rtslib.Target') as target, \
+ mock.patch('rtslib.BlockStorageObject') as \
+ block_storage_object, \
+ mock.patch('rtslib.root.RTSRoot') as rts_root:
root_new = mock.MagicMock(storage_objects=mock.MagicMock())
rts_root.return_value = root_new
block_storage_object.return_value = mock.sentinel.so_new
self._test_create_rtslib_error_network_portal('::0')
def _test_create(self, ip):
- with contextlib.nested(
- mock.patch('rtslib.NetworkPortal'),
- mock.patch('rtslib.LUN'),
- mock.patch('rtslib.TPG'),
- mock.patch('rtslib.FabricModule'),
- mock.patch('rtslib.Target'),
- mock.patch('rtslib.BlockStorageObject'),
- mock.patch('rtslib.root.RTSRoot')
- ) as (network_portal, lun, tpg, fabric_module, target,
- block_storage_object, rts_root):
+ with mock.patch('rtslib.NetworkPortal') as network_portal, \
+ mock.patch('rtslib.LUN') as lun, \
+ mock.patch('rtslib.TPG') as tpg, \
+ mock.patch('rtslib.FabricModule') as fabric_module, \
+ mock.patch('rtslib.Target') as target, \
+ mock.patch('rtslib.BlockStorageObject') as \
+ block_storage_object, \
+ mock.patch('rtslib.root.RTSRoot') as rts_root:
root_new = mock.MagicMock(storage_objects=mock.MagicMock())
rts_root.return_value = root_new
block_storage_object.return_value = mock.sentinel.so_new
# under the License.
"""Unit tests for the Quobyte driver module."""
-import contextlib
import errno
import os
import StringIO
drv.local_path(volume))
def test_mount_quobyte_should_mount_correctly(self):
- with contextlib.nested(
- mock.patch.object(self._driver, '_execute'),
+ with mock.patch.object(self._driver, '_execute') as mock_execute, \
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
- '.read_proc_mount'),
- ) as (mock_execute, mock_open):
+ '.read_proc_mount') as mock_open:
# Content of /proc/mount (not mounted yet).
mock_open.return_value = StringIO.StringIO(
"/dev/sda5 / ext4 rw,relatime,data=ordered 0 0")
[mkdir_call, mount_call, getfattr_call], any_order=False)
def test_mount_quobyte_already_mounted_detected_seen_in_proc_mount(self):
- with contextlib.nested(
- mock.patch.object(self._driver, '_execute'),
+ with mock.patch.object(self._driver, '_execute') as mock_execute, \
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
- '.read_proc_mount'),
- ) as (mock_execute, mock_open):
+ '.read_proc_mount') as mock_open:
# Content of /proc/mount (already mounted).
mock_open.return_value = StringIO.StringIO(
"quobyte@%s %s fuse rw,nosuid,nodev,noatime,user_id=1000"
Because _mount_quobyte gets called with ensure=True, the error will
be suppressed and logged instead.
"""
- with contextlib.nested(
- mock.patch.object(self._driver, '_execute'),
+ with mock.patch.object(self._driver, '_execute') as mock_execute, \
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
- '.read_proc_mount'),
- mock.patch('cinder.volume.drivers.quobyte.LOG')
- ) as (mock_execute, mock_open, mock_LOG):
+ '.read_proc_mount') as mock_open, \
+ mock.patch('cinder.volume.drivers.quobyte.LOG') as mock_LOG:
# Content of /proc/mount (empty).
mock_open.return_value = StringIO.StringIO()
mock_execute.side_effect = [None, putils.ProcessExecutionError(
test_mount_quobyte_should_suppress_and_log_already_mounted_error
but with ensure=False.
"""
- with contextlib.nested(
- mock.patch.object(self._driver, '_execute'),
+ with mock.patch.object(self._driver, '_execute') as mock_execute, \
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
- '.read_proc_mount')
- ) as (mock_execute, mock_open):
+ '.read_proc_mount') as mock_open:
mock_open.return_value = StringIO.StringIO()
mock_execute.side_effect = [
None, # mkdir
def test_ensure_share_mounted(self):
"""_ensure_share_mounted simple use case."""
- with contextlib.nested(
- mock.patch.object(self._driver, '_get_mount_point_for_share'),
- mock.patch.object(self._driver, '_mount_quobyte')
- ) as (mock_get_mount_point, mock_mount):
+ with mock.patch.object(self._driver, '_get_mount_point_for_share') as \
+ mock_get_mount_point, \
+ mock.patch.object(self._driver, '_mount_quobyte') as \
+ mock_mount:
drv = self._driver
drv._ensure_share_mounted(self.TEST_QUOBYTE_VOLUME)
volume_path = '%s/%s' % (self.TEST_MNT_POINT, volume_filename)
info_file = volume_path + '.info'
- with contextlib.nested(
- mock.patch.object(self._driver, '_ensure_share_mounted'),
- mock.patch.object(self._driver, '_local_volume_dir'),
- mock.patch.object(self._driver, 'get_active_image_from_info'),
- mock.patch.object(self._driver, '_execute'),
- mock.patch.object(self._driver, '_local_path_volume'),
- mock.patch.object(self._driver, '_local_path_volume_info')
- ) as (mock_ensure_share_mounted, mock_local_volume_dir,
- mock_active_image_from_info, mock_execute,
- mock_local_path_volume, mock_local_path_volume_info):
+ with mock.patch.object(self._driver, '_ensure_share_mounted') as \
+ mock_ensure_share_mounted, \
+ mock.patch.object(self._driver, '_local_volume_dir') as \
+ mock_local_volume_dir, \
+ mock.patch.object(self._driver,
+ 'get_active_image_from_info') as \
+ mock_active_image_from_info, \
+ mock.patch.object(self._driver, '_execute') as \
+ mock_execute, \
+ mock.patch.object(self._driver, '_local_path_volume') as \
+ mock_local_path_volume, \
+ mock.patch.object(self._driver, '_local_path_volume_info') as \
+ mock_local_path_volume_info:
mock_local_volume_dir.return_value = self.TEST_MNT_POINT
mock_active_image_from_info.return_value = volume_filename
mock_local_path_volume.return_value = volume_path
volume_path = '%s/%s' % (self.TEST_MNT_POINT, volume['name'])
image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
- with contextlib.nested(
- mock.patch.object(drv, 'get_active_image_from_info'),
- mock.patch.object(drv, '_local_volume_dir'),
- mock.patch.object(image_utils, 'qemu_img_info'),
- mock.patch.object(image_utils, 'upload_volume'),
- mock.patch.object(image_utils, 'create_temporary_file')
- ) as (mock_get_active_image_from_info, mock_local_volume_dir,
- mock_qemu_img_info, mock_upload_volume,
- mock_create_temporary_file):
+ with mock.patch.object(drv, 'get_active_image_from_info') as \
+ mock_get_active_image_from_info, \
+ mock.patch.object(drv, '_local_volume_dir') as \
+ mock_local_volume_dir, \
+ mock.patch.object(image_utils, 'qemu_img_info') as \
+ mock_qemu_img_info, \
+ mock.patch.object(image_utils, 'upload_volume') as \
+ mock_upload_volume, \
+ mock.patch.object(image_utils, 'create_temporary_file') as \
+ mock_create_temporary_file:
mock_get_active_image_from_info.return_value = volume['name']
mock_local_volume_dir.return_value = self.TEST_MNT_POINT
volume_path = '%s/%s' % (self.TEST_MNT_POINT, volume['name'])
image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
- with contextlib.nested(
- mock.patch.object(drv, 'get_active_image_from_info'),
- mock.patch.object(drv, '_local_volume_dir'),
- mock.patch.object(image_utils, 'qemu_img_info'),
- mock.patch.object(image_utils, 'convert_image'),
- mock.patch.object(image_utils, 'upload_volume'),
- mock.patch.object(image_utils, 'create_temporary_file')
- ) as (mock_get_active_image_from_info, mock_local_volume_dir,
- mock_qemu_img_info, mock_convert_image, mock_upload_volume,
- mock_create_temporary_file):
+ with mock.patch.object(drv, 'get_active_image_from_info') as \
+ mock_get_active_image_from_info, \
+ mock.patch.object(drv, '_local_volume_dir') as \
+ mock_local_volume_dir, \
+ mock.patch.object(image_utils, 'qemu_img_info') as \
+ mock_qemu_img_info, \
+ mock.patch.object(image_utils, 'convert_image') as \
+ mock_convert_image, \
+ mock.patch.object(image_utils, 'upload_volume') as \
+ mock_upload_volume, \
+ mock.patch.object(image_utils, 'create_temporary_file') as \
+ mock_create_temporary_file:
mock_get_active_image_from_info.return_value = volume['name']
mock_local_volume_dir.return_value = self.TEST_MNT_POINT
volume_filename = 'volume-%s' % self.VOLUME_UUID
image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}
- with contextlib.nested(
- mock.patch.object(drv, 'get_active_image_from_info'),
- mock.patch.object(drv, '_local_volume_dir'),
- mock.patch.object(image_utils, 'qemu_img_info'),
- mock.patch.object(image_utils, 'convert_image'),
- mock.patch.object(image_utils, 'upload_volume'),
- mock.patch.object(image_utils, 'create_temporary_file')
- ) as (mock_get_active_image_from_info, mock_local_volume_dir,
- mock_qemu_img_info, mock_convert_image, mock_upload_volume,
- mock_create_temporary_file):
+ with mock.patch.object(drv, 'get_active_image_from_info') as \
+ mock_get_active_image_from_info, \
+ mock.patch.object(drv, '_local_volume_dir') as \
+ mock_local_volume_dir, \
+ mock.patch.object(image_utils, 'qemu_img_info') as \
+ mock_qemu_img_info, \
+ mock.patch.object(image_utils, 'convert_image') as \
+ mock_convert_image, \
+ mock.patch.object(image_utils, 'upload_volume') as \
+ mock_upload_volume, \
+ mock.patch.object(image_utils, 'create_temporary_file') as \
+ mock_create_temporary_file:
mock_get_active_image_from_info.return_value = volume['name']
mock_local_volume_dir.return_value = self.TEST_MNT_POINT