'features': self.mock_rbd.RBD_FEATURE_LAYERING}
self.mock_rbd.RBD.return_value.create.assert_called_once_with(
*args, **kwargs)
- client.__enter__.assert_called_once()
- client.__exit__.assert_called_once()
- mock_supports_layering.assert_called_once()
+ client.__enter__.assert_called_once_with()
+ client.__exit__.assert_called_once_with(None, None, None)
+ mock_supports_layering.assert_called_once_with()
@common_mocks
def test_manage_existing_get_size(self):
'features': 0}
self.mock_rbd.RBD.return_value.create.assert_called_once_with(
*args, **kwargs)
- client.__enter__.assert_called_once()
- client.__exit__.assert_called_once()
- mock_supports_layering.assert_called_once()
+ client.__enter__.assert_called_once_with()
+ client.__exit__.assert_called_once_with(None, None, None)
+ mock_supports_layering.assert_called_once_with()
@common_mocks
def test_delete_backup_snaps(self):
self.driver.delete_volume(self.volume)
- mock_get_clone_info.assert_called_once()
+ mock_get_clone_info.assert_called_once_with(
+ self.mock_rbd.Image.return_value,
+ self.volume_name,
+ None)
(self.driver.rbd.Image.return_value
- .list_snaps.assert_called_once())
- client.__enter__.assert_called_once()
- client.__exit__.assert_called_once()
- mock_delete_backup_snaps.assert_called_once()
+ .list_snaps.assert_called_once_with())
+ client.__enter__.assert_called_once_with()
+ client.__exit__.assert_called_once_with(None, None, None)
+ mock_delete_backup_snaps.assert_called_once_with(
+ self.mock_rbd.Image.return_value)
self.assertFalse(
self.driver.rbd.Image.return_value.unprotect_snap.called)
- self.driver.rbd.RBD.return_value.remove.assert_called_once()
+ self.assertEqual(
+ 1, self.driver.rbd.RBD.return_value.remove.call_count)
@common_mocks
def delete_volume_not_found(self):
self.mock_rbd.Image.side_effect = self.mock_rbd.ImageNotFound
self.assertIsNone(self.driver.delete_volume(self.volume))
- self.mock_rbd.Image.assert_called_once()
+ self.mock_rbd.Image.assert_called_once_with()
# Make sure the exception was raised
self.assertEqual(RAISED_EXCEPTIONS, [self.mock_rbd.ImageNotFound])
self.assertRaises(exception.VolumeIsBusy,
self.driver.delete_volume, self.volume)
- mock_get_clone_info.assert_called_once()
+ mock_get_clone_info.assert_called_once_with(
+ self.mock_rbd.Image.return_value,
+ self.volume_name,
+ None)
(self.mock_rbd.Image.return_value.list_snaps
- .assert_called_once())
- mock_rados_client.assert_called_once()
- mock_delete_backup_snaps.assert_called_once()
+ .assert_called_once_with())
+ mock_rados_client.assert_called_once_with(self.driver)
+ mock_delete_backup_snaps.assert_called_once_with(
+ self.mock_rbd.Image.return_value)
self.assertFalse(
self.mock_rbd.Image.return_value.unprotect_snap.called)
- self.mock_rbd.RBD.return_value.remove.assert_called_once()
+ self.assertEqual(
+ 1, self.mock_rbd.RBD.return_value.remove.call_count)
# Make sure the exception was raised
self.assertEqual(RAISED_EXCEPTIONS,
[self.mock_rbd.ImageBusy])
self.assertEqual(info, parent_info)
self.assertFalse(volume.set_snap.called)
- volume.parent_info.assert_called_once()
+ volume.parent_info.assert_called_once_with()
@common_mocks
def test_get_clone_info_w_snap(self):
self.assertEqual(info, parent_info)
- volume.set_snap.assert_called_once()
self.assertEqual(volume.set_snap.call_count, 2)
- volume.parent_info.assert_called_once()
+ volume.parent_info.assert_called_once_with()
@common_mocks
def test_get_clone_info_w_exception(self):
self.assertEqual(info, (None, None, None))
- volume.set_snap.assert_called_once()
self.assertEqual(volume.set_snap.call_count, 2)
- volume.parent_info.assert_called_once()
+ volume.parent_info.assert_called_once_with()
# Make sure the exception was raised
self.assertEqual(RAISED_EXCEPTIONS, [self.mock_rbd.ImageNotFound])
self.assertEqual(info, parent_info)
self.assertFalse(volume.set_snap.called)
- volume.parent_info.assert_called_once()
+ volume.parent_info.assert_called_once_with()
@common_mocks
def test_create_cloned_volume(self):
dst_name = u'volume-00000002'
self.cfg.rbd_max_clone_depth = 2
- self.mock_rbd.RBD.clone = mock.Mock()
with mock.patch.object(self.driver, '_get_clone_depth') as \
mock_get_clone_depth:
# Try with no flatten required
mock_get_clone_depth.return_value = 1
- self.mock_rbd.Image.create_snap = mock.Mock()
- self.mock_rbd.Image.protect_snap = mock.Mock()
- self.mock_rbd.Image.close = mock.Mock()
+ self.driver.create_cloned_volume({'name': dst_name},
+ {'name': src_name})
- self.driver.create_cloned_volume(dict(name=dst_name),
- dict(name=src_name))
-
- self.mock_rbd.Image.create_snap.assert_called_once()
- self.mock_rbd.Image.protect_snap.assert_called_once()
- self.mock_rbd.RBD.clone.assert_called_once()
- self.mock_rbd.Image.close.assert_called_once()
+ (self.mock_rbd.Image.return_value.create_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ (self.mock_rbd.Image.return_value.protect_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ self.assertEqual(
+ 1, self.mock_rbd.RBD.return_value.clone.call_count)
+ self.mock_rbd.Image.return_value.close.assert_called_once_with()
self.assertTrue(mock_get_clone_depth.called)
@common_mocks
self.driver.create_cloned_volume,
dict(name=dst_name), dict(name=src_name))
- self.mock_rbd.Image.return_value.create_snap.assert_called_once()
- self.mock_rbd.Image.return_value.protect_snap.assert_called_once()
- self.mock_rbd.RBD.return_value.clone.assert_called_once()
- (self.mock_rbd.Image.return_value
- .unprotect_snap.assert_called_once())
- self.mock_rbd.Image.return_value.remove_snap.assert_called_once()
- self.mock_rbd.Image.return_value.close.assert_called_once()
+ (self.mock_rbd.Image.return_value.create_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ (self.mock_rbd.Image.return_value.protect_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ self.assertEqual(
+ 1, self.mock_rbd.RBD.return_value.clone.call_count)
+ (self.mock_rbd.Image.return_value.unprotect_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ (self.mock_rbd.Image.return_value.remove_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ self.mock_rbd.Image.return_value.close.assert_called_once_with()
self.assertTrue(mock_get_clone_depth.called)
@common_mocks
self.assertRaises(self.mock_rbd.RBD.Error,
self.driver.create_cloned_volume,
- dict(name=dst_name), dict(name=src_name))
-
- self.mock_rbd.Image.create_snap.assert_called_once()
- self.mock_rbd.Image.protect_snap.assert_called_once()
- self.mock_rbd.RBD.clone.assert_called_once()
- self.mock_rbd.Image.unprotect_snap.assert_called_once()
- self.mock_rbd.Image.remove_snap.assert_called_once()
- self.mock_rbd.Image.close.assert_called_once()
+ {'name': dst_name}, {'name': src_name})
+
+ (self.mock_rbd.Image.return_value.create_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ (self.mock_rbd.Image.return_value.protect_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ self.assertEqual(
+ 1, self.mock_rbd.RBD.return_value.clone.call_count)
+ (self.mock_rbd.Image.return_value.unprotect_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ (self.mock_rbd.Image.return_value.remove_snap
+ .assert_called_once_with('.'.join((dst_name, 'clone_snap'))))
+ self.mock_rbd.Image.return_value.close.assert_called_once_with()
@common_mocks
def test_good_locations(self):
args = [location, {'disk_format': 'raw'}]
self.assertFalse(self.driver._is_cloneable(*args))
- self.mock_proxy.assert_called_once()
+ self.assertEqual(1, self.mock_proxy.call_count)
self.assertTrue(mock_get_fsid.called)
@common_mocks
reserved_percentage=0)
actual = self.driver.get_volume_stats(True)
- client.cluster.get_cluster_stats.assert_called_once()
+ client.cluster.get_cluster_stats.assert_called_once_with()
self.assertDictMatch(expected, actual)
@common_mocks
reserved_percentage=0)
actual = self.driver.get_volume_stats(True)
- client.cluster.get_cluster_stats.assert_called_once()
+ client.cluster.get_cluster_stats.assert_called_once_with()
self.assertDictMatch(expected, actual)
@common_mocks
self.mox.VerifyAll()
- @common_mocks
def test_rbd_volume_proxy_init(self):
- snap = u'snapshot-name'
-
- client = self.mock_client.return_value
- client.__enter__.return_value = client
-
- with mock.patch.object(self.driver, '_connect_to_rados') as \
- mock_connect_from_rados:
- with mock.patch.object(self.driver, '_disconnect_from_rados') as \
- mock_disconnect_from_rados:
- mock_connect_from_rados.return_value = (None, None)
- mock_disconnect_from_rados.return_value = (None, None)
+ mock_driver = mock.Mock(name='driver')
+ mock_driver._connect_to_rados.return_value = (None, None)
+ with driver.RBDVolumeProxy(mock_driver, self.volume_name):
+ self.assertEqual(1, mock_driver._connect_to_rados.call_count)
+ self.assertFalse(mock_driver._disconnect_from_rados.called)
- with driver.RBDVolumeProxy(self.driver, self.volume_name):
- mock_connect_from_rados.assert_called_once()
- self.assertFalse(mock_disconnect_from_rados.called)
+ self.assertEqual(1, mock_driver._disconnect_from_rados.call_count)
- mock_disconnect_from_rados.assert_called_once()
+ mock_driver.reset_mock()
- mock_connect_from_rados.reset_mock()
- mock_disconnect_from_rados.reset_mock()
-
- with driver.RBDVolumeProxy(self.driver, self.volume_name,
- snapshot=snap):
- mock_connect_from_rados.assert_called_once()
- self.assertFalse(mock_disconnect_from_rados.called)
+ snap = u'snapshot-name'
+ with driver.RBDVolumeProxy(mock_driver, self.volume_name,
+ snapshot=snap):
+ self.assertEqual(1, mock_driver._connect_to_rados.call_count)
+ self.assertFalse(mock_driver._disconnect_from_rados.called)
- mock_disconnect_from_rados.assert_called_once()
+ self.assertEqual(1, mock_driver._disconnect_from_rados.call_count)
@common_mocks
def test_connect_to_rados(self):
self.mock_rados.Error)
self.assertRaises(exception.VolumeBackendAPIException,
self.driver._connect_to_rados)
- self.mock_rados.Rados.return_value.open_ioctx.assert_called_once()
- self.mock_rados.Rados.return_value.shutdown.assert_called_once()
+ self.assertTrue(self.mock_rados.Rados.return_value.open_ioctx.called)
+ self.mock_rados.Rados.return_value.shutdown.assert_called_once_with()
class RBDImageIOWrapperTestCase(test.TestCase):
with mock.patch.object(driver, 'LOG') as mock_logger:
self.meta.image.flush = mock.Mock()
self.mock_rbd_wrapper.flush()
- self.meta.image.flush.assert_called_once()
+ self.meta.image.flush.assert_called_once_with()
self.meta.image.flush.reset_mock()
# this should be caught and logged silently.
self.meta.image.flush.side_effect = AttributeError
self.mock_rbd_wrapper.flush()
- self.meta.image.flush.assert_called_once()
+ self.meta.image.flush.assert_called_once_with()
msg = _("flush() not supported in this version of librbd")
mock_logger.warning.assert_called_with(msg)
self._create_volume_from_image('available', raw=True)
self.assertFalse(mock_copy.called)
- mock_clone_image.assert_called_once()
+ self.assertTrue(mock_clone_image.called)
self.assertFalse(mock_create.called)
def test_create_vol_from_non_raw_image_status_available(self):
with mock.patch.object(create_volume.CreateVolumeFromSpecTask,
'_copy_image_to_volume') as mock_copy:
self._create_volume_from_image('available', raw=False)
- mock_copy.assert_called_once()
+ self.assertTrue(mock_copy.called)
- mock_clone_image.assert_called_once()
- mock_create.assert_called_once()
+ self.assertTrue(mock_clone_image.called)
+ self.assertTrue(mock_create.called)
def test_create_vol_from_image_status_error(self):
"""Fail to clone raw image then verify volume is in error state."""
clone_error=True)
self.assertFalse(mock_copy.called)
- mock_clone_image.assert_called_once()
+ self.assertTrue(mock_clone_image.called)
self.assertFalse(self.volume.driver.create_volume.called)
def test_clone_failure(self):
mock_resize:
image_loc = ('rbd://fee/fi/fo/fum', None)
- actual = driver.clone_image({'name': 'vol1'}, image_loc,
+ volume = {'name': 'vol1'}
+ actual = driver.clone_image(volume, image_loc,
'id.foo',
{'disk_format': 'raw'})
self.assertEqual(expected, actual)
- mock_clone.assert_called_once()
- mock_resize.assert_called_once()
+ mock_clone.assert_called_once_with(volume,
+ 'fi', 'fo', 'fum')
+ mock_resize.assert_called_once_with(volume)
@mock.patch.object(BrcdFCZoneClientCLI, 'get_active_zone_set')
@mock.patch.object(BrcdFCZoneClientCLI, 'apply_zone_change')
@mock.patch.object(BrcdFCZoneClientCLI, '_cfg_save')
- def test_add_zones_new_zone_no_activate(self, get_active_zs_mock,
+ def test_add_zones_new_zone_no_activate(self, cfg_save_mock,
apply_zone_change_mock,
- cfg_save_mock):
+ get_active_zs_mock):
get_active_zs_mock.return_value = active_zoneset
self.add_zones(new_zones, False, None)
- get_active_zs_mock.assert_called_once()
- apply_zone_change_mock.assert_called_twice()
- cfg_save_mock.assert_called_once()
+ get_active_zs_mock.assert_called_once_with()
+ self.assertEqual(3, apply_zone_change_mock.call_count)
+ cfg_save_mock.assert_called_once_with()
@mock.patch.object(BrcdFCZoneClientCLI, 'get_active_zone_set')
@mock.patch.object(BrcdFCZoneClientCLI, 'apply_zone_change')
@mock.patch.object(BrcdFCZoneClientCLI, 'activate_zoneset')
- def test_add_zones_new_zone_activate(self, get_active_zs_mock,
+ def test_add_zones_new_zone_activate(self, activate_zoneset_mock,
apply_zone_change_mock,
- activate_zoneset_mock):
+ get_active_zs_mock):
get_active_zs_mock.return_value = active_zoneset
self.add_zones(new_zone, True, active_zoneset)
- apply_zone_change_mock.assert_called_once()
- activate_zoneset_mock.assert_called_once()
+ self.assertEqual(2, apply_zone_change_mock.call_count)
+ activate_zoneset_mock.assert_called_once_with(
+ active_zoneset['active_zone_config'])
@mock.patch.object(BrcdFCZoneClientCLI, '_ssh_execute')
def test_activate_zoneset(self, ssh_execute_mock):
@mock.patch.object(BrcdFCZoneClientCLI, 'apply_zone_change')
@mock.patch.object(BrcdFCZoneClientCLI, '_cfg_save')
- def test_delete_zones_activate_false(self, apply_zone_change_mock,
- cfg_save_mock):
- with mock.patch.object(self, '_zone_delete') \
- as zone_delete_mock:
+ def test_delete_zones_activate_false(self, cfg_save_mock,
+ apply_zone_change_mock):
+ with mock.patch.object(self, '_zone_delete') as zone_delete_mock:
self.delete_zones(zone_names_to_delete, False,
active_zoneset_multiple_zones)
- apply_zone_change_mock.assert_called_once()
+ self.assertEqual(1, apply_zone_change_mock.call_count)
zone_delete_mock.assert_called_once_with(zone_names_to_delete)
- cfg_save_mock.assert_called_once()
+ cfg_save_mock.assert_called_once_with()
@patch.object(BrcdFCZoneClientCLI, 'apply_zone_change')
@patch.object(BrcdFCZoneClientCLI, 'activate_zoneset')
- def test_delete_zones_activate_true(self, apply_zone_change_mock,
- activate_zs_mock):
+ def test_delete_zones_activate_true(self, activate_zs_mock,
+ apply_zone_change_mock):
with mock.patch.object(self, '_zone_delete') \
as zone_delete_mock:
self.delete_zones(zone_names_to_delete, True,
active_zoneset_multiple_zones)
- apply_zone_change_mock.assert_called_once()
+ self.assertEqual(1, apply_zone_change_mock.call_count)
zone_delete_mock.assert_called_once_with(zone_names_to_delete)
- activate_zs_mock.assert_called_once()
+ activate_zs_mock.assert_called_once_with(
+ active_zoneset['active_zone_config'])
@patch.object(BrcdFCZoneClientCLI, '_get_switch_info')
def test_get_nameserver_info(self, get_switch_info_mock):
as is_trans_abortable_mock:
is_trans_abortable_mock.return_value = True
self._cfg_trans_abort()
- is_trans_abortable_mock.assert_called_once()
+ is_trans_abortable_mock.assert_called_once_with()
apply_zone_change_mock.assert_called_once_with(cmd_list)
@patch.object(BrcdFCZoneClientCLI, '_run_ssh')