"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "manila/tests/share/drivers/zfsonlinux/test_driver.py" between
manila-11.0.0.tar.gz and manila-11.0.1.tar.gz

About: OpenStack Manila provides “Shared Filesystems as a service”.
The "Victoria" series (latest release).

test_driver.py  (manila-11.0.0):test_driver.py  (manila-11.0.1)
skipping to change at line 150 skipping to change at line 150
def setUp(self): def setUp(self):
self.mock_object(zfs_driver.CONF, '_check_required_opts') self.mock_object(zfs_driver.CONF, '_check_required_opts')
super(ZFSonLinuxShareDriverTestCase, self).setUp() super(ZFSonLinuxShareDriverTestCase, self).setUp()
self._context = context.get_admin_context() self._context = context.get_admin_context()
self.ssh_executor = self.mock_object(ganesha_utils, 'SSHExecutor') self.ssh_executor = self.mock_object(ganesha_utils, 'SSHExecutor')
self.configuration = FakeConfig() self.configuration = FakeConfig()
self.private_storage = FakeDriverPrivateStorage() self.private_storage = FakeDriverPrivateStorage()
self.driver = zfs_driver.ZFSonLinuxShareDriver( self.driver = zfs_driver.ZFSonLinuxShareDriver(
configuration=self.configuration, configuration=self.configuration,
private_storage=self.private_storage) private_storage=self.private_storage)
self.mock_object(zfs_driver.time, 'sleep')
def test_init(self): def test_init(self):
self.assertTrue(hasattr(self.driver, 'replica_snapshot_prefix')) self.assertTrue(hasattr(self.driver, 'replica_snapshot_prefix'))
self.assertEqual( self.assertEqual(
self.driver.replica_snapshot_prefix, self.driver.replica_snapshot_prefix,
self.configuration.zfs_replica_snapshot_prefix) self.configuration.zfs_replica_snapshot_prefix)
self.assertEqual( self.assertEqual(
self.driver.backend_name, self.driver.backend_name,
self.configuration.share_backend_name) self.configuration.share_backend_name)
self.assertEqual( self.assertEqual(
skipping to change at line 1172 skipping to change at line 1173
"share_id": "fake_share_id", "share_id": "fake_share_id",
"export_locations": [{"path": "1.1.1.1:/%s" % old_dataset_name}], "export_locations": [{"path": "1.1.1.1:/%s" % old_dataset_name}],
"host": "foobackend@foohost#foopool", "host": "foobackend@foohost#foopool",
"share_proto": "NFS", "share_proto": "NFS",
} }
mock_get_extra_specs_from_share = self.mock_object( mock_get_extra_specs_from_share = self.mock_object(
zfs_driver.share_types, zfs_driver.share_types,
'get_extra_specs_from_share', 'get_extra_specs_from_share',
mock.Mock(return_value={})) mock.Mock(return_value={}))
self.mock_object(zfs_driver.time, "sleep")
mock__get_dataset_name = self.mock_object( mock__get_dataset_name = self.mock_object(
self.driver, "_get_dataset_name", self.driver, "_get_dataset_name",
mock.Mock(return_value=new_dataset_name)) mock.Mock(return_value=new_dataset_name))
mock_helper = self.mock_object(self.driver, "_get_share_helper") mock_helper = self.mock_object(self.driver, "_get_share_helper")
mock_zfs = self.mock_object( mock_zfs = self.mock_object(
self.driver, "zfs", self.driver, "zfs",
mock.Mock(return_value=("fake_out", "fake_error"))) mock.Mock(return_value=("fake_out", "fake_error")))
mock_zfs_with_retry = self.mock_object(self.driver, "zfs_with_retry") mock_zfs_with_retry = self.mock_object(self.driver, "zfs_with_retry")
mock_execute_side_effects = [ mock_execute_side_effects = [
skipping to change at line 1316 skipping to change at line 1316
"share_id": "fake_share_id", "share_id": "fake_share_id",
"export_locations": [{"path": "1.1.1.1:/%s" % old_ds_name}], "export_locations": [{"path": "1.1.1.1:/%s" % old_ds_name}],
"host": "foobackend@foohost#foopool", "host": "foobackend@foohost#foopool",
"share_proto": "NFS", "share_proto": "NFS",
} }
mock_get_extra_specs_from_share = self.mock_object( mock_get_extra_specs_from_share = self.mock_object(
zfs_driver.share_types, zfs_driver.share_types,
'get_extra_specs_from_share', 'get_extra_specs_from_share',
mock.Mock(return_value={})) mock.Mock(return_value={}))
self.mock_object(zfs_driver.time, "sleep")
mock__get_dataset_name = self.mock_object( mock__get_dataset_name = self.mock_object(
self.driver, "_get_dataset_name", self.driver, "_get_dataset_name",
mock.Mock(return_value=new_ds_name)) mock.Mock(return_value=new_ds_name))
mock_helper = self.mock_object(self.driver, "_get_share_helper") mock_helper = self.mock_object(self.driver, "_get_share_helper")
mock_zfs = self.mock_object( mock_zfs = self.mock_object(
self.driver, "zfs", self.driver, "zfs",
mock.Mock(return_value=("fake_out", "fake_error"))) mock.Mock(return_value=("fake_out", "fake_error")))
mock_zfs_with_retry = self.mock_object(self.driver, "zfs_with_retry") mock_zfs_with_retry = self.mock_object(self.driver, "zfs_with_retry")
# 10 Retries, would mean 20 calls to check the mount still exists # 10 Retries, would mean 20 calls to check the mount still exists
skipping to change at line 1449 skipping to change at line 1448
"snapshot_id": "fake_snapshot_id", "snapshot_id": "fake_snapshot_id",
} }
self.mock_object(self.driver.private_storage, "delete") self.mock_object(self.driver.private_storage, "delete")
self.driver.unmanage_snapshot(snapshot_instance) self.driver.unmanage_snapshot(snapshot_instance)
self.driver.private_storage.delete.assert_called_once_with( self.driver.private_storage.delete.assert_called_once_with(
snapshot_instance["snapshot_id"]) snapshot_instance["snapshot_id"])
def test__delete_dataset_or_snapshot_with_retry_snapshot(self): def test__delete_dataset_or_snapshot_with_retry_snapshot(self):
self.mock_object(self.driver, 'get_zfs_option') umount_sideeffects = (exception.ProcessExecutionError,
self.mock_object(self.driver, 'zfs') exception.ProcessExecutionError,
exception.ProcessExecutionError)
zfs_destroy_sideeffects = (exception.ProcessExecutionError,
exception.ProcessExecutionError,
None)
self.mock_object(
self.driver, 'get_zfs_option', mock.Mock(return_value='/foo@bar'))
self.mock_object(
self.driver, 'execute', mock.Mock(side_effect=umount_sideeffects))
self.mock_object(
self.driver, 'zfs', mock.Mock(side_effect=zfs_destroy_sideeffects))
self.driver._delete_dataset_or_snapshot_with_retry('foo@bar') self.driver._delete_dataset_or_snapshot_with_retry('foo@bar')
self.driver.get_zfs_option.assert_called_once_with( self.driver.get_zfs_option.assert_called_once_with(
'foo@bar', 'mountpoint') 'foo@bar', 'mountpoint')
self.driver.zfs.assert_called_once_with( self.driver.execute.assert_has_calls(
'destroy', '-f', 'foo@bar') [mock.call('sudo', 'umount', '/foo@bar')] * 3)
self.driver.zfs.assert_has_calls(
def test__delete_dataset_or_snapshot_with_retry_of(self): [mock.call('destroy', '-f', 'foo@bar')] * 3)
self.mock_object(self.driver, 'get_zfs_option') self.assertEqual(3, self.driver.execute.call_count)
self.assertEqual(3, self.driver.zfs.call_count)
def test__delete_dataset_or_snapshot_with_retry_dataset_busy_fail(self):
# simulating local processes that have open files on the mount
lsof_sideeffects = ([('1001, 1002', '0')] * 30)
self.mock_object(self.driver, 'get_zfs_option',
mock.Mock(return_value='/fake/dataset/name'))
self.mock_object( self.mock_object(
self.driver, 'execute', mock.Mock(return_value=('a', 'b'))) self.driver, 'execute', mock.Mock(side_effect=lsof_sideeffects))
self.mock_object(zfs_driver.time, 'sleep')
self.mock_object(zfs_driver.LOG, 'debug') self.mock_object(zfs_driver.LOG, 'debug')
self.mock_object( self.mock_object(
zfs_driver.time, 'time', mock.Mock(side_effect=range(1, 70, 2))) zfs_driver.time, 'time', mock.Mock(side_effect=range(1, 70, 2)))
self.mock_object(self.driver, 'zfs')
dataset_name = 'fake/dataset/name' dataset_name = 'fake/dataset/name'
self.assertRaises( self.assertRaises(
exception.ZFSonLinuxException, exception.ZFSonLinuxException,
self.driver._delete_dataset_or_snapshot_with_retry, self.driver._delete_dataset_or_snapshot_with_retry,
dataset_name, dataset_name,
) )
self.driver.get_zfs_option.assert_called_once_with( self.driver.get_zfs_option.assert_called_once_with(
dataset_name, 'mountpoint') dataset_name, 'mountpoint')
self.assertEqual(29, zfs_driver.LOG.debug.call_count) self.assertEqual(29, zfs_driver.LOG.debug.call_count)
# We should've bailed out before executing "zfs destroy"
self.driver.zfs.assert_not_called()
def test__delete_dataset_or_snapshot_with_retry_temp_of(self): def test__delete_dataset_or_snapshot_with_retry_dataset(self):
self.mock_object(self.driver, 'get_zfs_option') lsof_sideeffects = (('1001', '0'), exception.ProcessExecutionError)
self.mock_object(self.driver, 'zfs') umount_sideeffects = (exception.ProcessExecutionError,
self.mock_object( exception.ProcessExecutionError,
self.driver, 'execute', mock.Mock(side_effect=[ exception.ProcessExecutionError)
('a', 'b'), zfs_destroy_sideeffects = (exception.ProcessExecutionError,
exception.ProcessExecutionError( exception.ProcessExecutionError,
'FAKE lsof returns not found')])) None)
self.mock_object(zfs_driver.time, 'sleep')
self.mock_object(zfs_driver.LOG, 'debug')
self.mock_object(
zfs_driver.time, 'time', mock.Mock(side_effect=range(1, 70, 2)))
dataset_name = 'fake/dataset/name' dataset_name = 'fake/dataset/name'
self.mock_object(self.driver, 'get_zfs_option', mock.Mock(
self.driver._delete_dataset_or_snapshot_with_retry(dataset_name) return_value='/%s' % dataset_name))
self.driver.get_zfs_option.assert_called_once_with(
dataset_name, 'mountpoint')
self.assertEqual(2, self.driver.execute.call_count)
self.assertEqual(1, zfs_driver.LOG.debug.call_count)
zfs_driver.LOG.debug.assert_called_once_with(
mock.ANY, {'name': dataset_name, 'out': 'a'})
zfs_driver.time.sleep.assert_called_once_with(2)
self.driver.zfs.assert_called_once_with('destroy', '-f', dataset_name)
def test__delete_dataset_or_snapshot_with_retry_busy(self):
self.mock_object(self.driver, 'get_zfs_option')
self.mock_object( self.mock_object(
self.driver, 'execute', mock.Mock( self.driver, 'execute', mock.Mock(
side_effect=exception.ProcessExecutionError( side_effect=(lsof_sideeffects + umount_sideeffects)))
'FAKE lsof returns not found')))
self.mock_object( self.mock_object(
self.driver, 'zfs', mock.Mock(side_effect=[ self.driver, 'zfs', mock.Mock(side_effect=zfs_destroy_sideeffects))
exception.ProcessExecutionError(
'cannot destroy FAKE: dataset is busy\n'),
None, None]))
self.mock_object(zfs_driver.time, 'sleep')
self.mock_object(zfs_driver.LOG, 'info') self.mock_object(zfs_driver.LOG, 'info')
dataset_name = 'fake/dataset/name'
self.driver._delete_dataset_or_snapshot_with_retry(dataset_name) self.driver._delete_dataset_or_snapshot_with_retry(dataset_name)
self.driver.get_zfs_option.assert_called_once_with( self.driver.get_zfs_option.assert_called_once_with(
dataset_name, 'mountpoint') dataset_name, 'mountpoint')
self.assertEqual(2, zfs_driver.time.sleep.call_count) self.driver.execute.assert_has_calls(
self.assertEqual(2, self.driver.execute.call_count) [mock.call('lsof', '-w', '/%s' % dataset_name)] * 2 +
self.assertEqual(1, zfs_driver.LOG.info.call_count) [mock.call('sudo', 'umount', '/%s' % dataset_name)] * 3)
self.assertEqual(2, self.driver.zfs.call_count) self.driver.zfs.assert_has_calls(
[mock.call('destroy', '-f', dataset_name)] * 3)
self.assertEqual(6, zfs_driver.time.sleep.call_count)
self.assertEqual(5, self.driver.execute.call_count)
self.assertEqual(3, self.driver.zfs.call_count)
def test_create_replica(self): def test_create_replica(self):
active_replica = { active_replica = {
'id': 'fake_active_replica_id', 'id': 'fake_active_replica_id',
'host': 'hostname1@backend_name1#foo', 'host': 'hostname1@backend_name1#foo',
'size': 5, 'size': 5,
'replica_state': zfs_driver.constants.REPLICA_STATE_ACTIVE, 'replica_state': zfs_driver.constants.REPLICA_STATE_ACTIVE,
} }
replica_list = [active_replica] replica_list = [active_replica]
new_replica = { new_replica = {
skipping to change at line 2522 skipping to change at line 2522
snapshot_tag = 'fake_migration_snapshot_tag' snapshot_tag = 'fake_migration_snapshot_tag'
dst_ssh_cmd = 'fake_dst_ssh_cmd' dst_ssh_cmd = 'fake_dst_ssh_cmd'
self.driver.private_storage.update( self.driver.private_storage.update(
src_share['id'], {'dataset_name': src_dataset_name}) src_share['id'], {'dataset_name': src_dataset_name})
self.driver.private_storage.update( self.driver.private_storage.update(
dst_share['id'], { dst_share['id'], {
'migr_snapshot_tag': snapshot_tag, 'migr_snapshot_tag': snapshot_tag,
'dataset_name': dst_dataset_name, 'dataset_name': dst_dataset_name,
'ssh_cmd': dst_ssh_cmd, 'ssh_cmd': dst_ssh_cmd,
}) })
self.mock_object(zfs_driver.time, 'sleep')
mock_delete_dataset = self.mock_object( mock_delete_dataset = self.mock_object(
self.driver, '_delete_dataset_or_snapshot_with_retry') self.driver, '_delete_dataset_or_snapshot_with_retry')
ps_output = ( ps_output = (
"fake_line1\nfoo_user 12345 foo_dataset_name@%s\n" "fake_line1\nfoo_user 12345 foo_dataset_name@%s\n"
"fake_line2") % snapshot_tag "fake_line2") % snapshot_tag
self.mock_object( self.mock_object(
self.driver, 'execute', self.driver, 'execute',
mock.Mock(return_value=(ps_output, 'fake_err')) mock.Mock(return_value=(ps_output, 'fake_err'))
) )
skipping to change at line 2568 skipping to change at line 2567
snapshot_tag = 'fake_migration_snapshot_tag' snapshot_tag = 'fake_migration_snapshot_tag'
dst_ssh_cmd = 'fake_dst_ssh_cmd' dst_ssh_cmd = 'fake_dst_ssh_cmd'
self.driver.private_storage.update( self.driver.private_storage.update(
src_share['id'], {'dataset_name': src_dataset_name}) src_share['id'], {'dataset_name': src_dataset_name})
self.driver.private_storage.update( self.driver.private_storage.update(
dst_share['id'], { dst_share['id'], {
'migr_snapshot_tag': snapshot_tag, 'migr_snapshot_tag': snapshot_tag,
'dataset_name': dst_dataset_name, 'dataset_name': dst_dataset_name,
'ssh_cmd': dst_ssh_cmd, 'ssh_cmd': dst_ssh_cmd,
}) })
self.mock_object(zfs_driver.time, 'sleep')
mock_delete_dataset = self.mock_object( mock_delete_dataset = self.mock_object(
self.driver, '_delete_dataset_or_snapshot_with_retry') self.driver, '_delete_dataset_or_snapshot_with_retry')
self.mock_object( self.mock_object(
self.driver, 'execute', self.driver, 'execute',
mock.Mock(side_effect=exception.ProcessExecutionError), mock.Mock(side_effect=exception.ProcessExecutionError),
) )
self.driver.migration_cancel( self.driver.migration_cancel(
self._context, src_share, dst_share, [], {}) self._context, src_share, dst_share, [], {})
 End of changes. 16 change blocks. 
51 lines changed or deleted 49 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)