Fix test_global_setup unit test
Current code in test_global_setup sets a non valid user_id and leaves it
like that for the rest of the tests, which can lead to error:
ValueError: A string is required in field user_id, not a _SentinelObject
An easy way to reproduce this error is to create a file called fail.txt
with the following content:
cinderlib.tests.unit.test_cinderlib.TestCinderlib.test_global_setup
cinderlib.tests.unit.test_serialization.TestSerialization.test_conn_to_and_from
And then run from the tox virtual environment:
stestr run --serial --load-list=fail.txt
This patch fixes this issue by restoring the values after the test is
run.
Change-Id: I121bc20c1ac4d7c07a1bcd13df19fdb868e65857
This commit is contained in:
@@ -184,40 +184,49 @@ class TestCinderlib(base.BaseTest):
|
||||
cls.global_initialization = False
|
||||
cinder_cfg = {'k': 'v', 'k2': 'v2'}
|
||||
|
||||
cls.global_setup(mock.sentinel.locks_path,
|
||||
mock.sentinel.root_helper,
|
||||
mock.sentinel.ssl_warnings,
|
||||
mock.sentinel.disable_logs,
|
||||
mock.sentinel.non_uuid_ids,
|
||||
mock.sentinel.backend_info,
|
||||
mock.sentinel.project_id,
|
||||
mock.sentinel.user_id,
|
||||
mock.sentinel.pers_cfg,
|
||||
mock.sentinel.fail_missing_backend,
|
||||
mock.sentinel.host,
|
||||
**cinder_cfg)
|
||||
# Save the current class configuration
|
||||
saved_cfg = vars(cls).copy()
|
||||
|
||||
mock_set_config.assert_called_once_with(mock.sentinel.host,
|
||||
mock.sentinel.locks_path,
|
||||
cinder_cfg)
|
||||
try:
|
||||
cls.global_setup(mock.sentinel.locks_path,
|
||||
mock.sentinel.root_helper,
|
||||
mock.sentinel.ssl_warnings,
|
||||
mock.sentinel.disable_logs,
|
||||
mock.sentinel.non_uuid_ids,
|
||||
mock.sentinel.backend_info,
|
||||
mock.sentinel.project_id,
|
||||
mock.sentinel.user_id,
|
||||
mock.sentinel.pers_cfg,
|
||||
mock.sentinel.fail_missing_backend,
|
||||
mock.sentinel.host,
|
||||
**cinder_cfg)
|
||||
|
||||
self.assertEqual(mock.sentinel.fail_missing_backend,
|
||||
cls.fail_on_missing_backend)
|
||||
self.assertEqual(mock.sentinel.project_id, cls.project_id)
|
||||
self.assertEqual(mock.sentinel.user_id, cls.user_id)
|
||||
self.assertEqual(mock.sentinel.non_uuid_ids, cls.non_uuid_ids)
|
||||
mock_set_pers.assert_called_once_with(mock.sentinel.pers_cfg)
|
||||
mock_set_config.assert_called_once_with(mock.sentinel.host,
|
||||
mock.sentinel.locks_path,
|
||||
cinder_cfg)
|
||||
|
||||
mock_serial.setup.assert_called_once_with(cls)
|
||||
mock_log.assert_called_once_with(mock.sentinel.disable_logs)
|
||||
mock_coord.start.assert_called_once_with()
|
||||
self.assertEqual(mock.sentinel.fail_missing_backend,
|
||||
cls.fail_on_missing_backend)
|
||||
self.assertEqual(mock.sentinel.project_id, cls.project_id)
|
||||
self.assertEqual(mock.sentinel.user_id, cls.user_id)
|
||||
self.assertEqual(mock.sentinel.non_uuid_ids, cls.non_uuid_ids)
|
||||
mock_set_pers.assert_called_once_with(mock.sentinel.pers_cfg)
|
||||
|
||||
mock_priv_helper.assert_called_once_with(mock.sentinel.root_helper)
|
||||
mock_serial.setup.assert_called_once_with(cls)
|
||||
mock_log.assert_called_once_with(mock.sentinel.disable_logs)
|
||||
mock_coord.start.assert_called_once_with()
|
||||
|
||||
self.assertEqual(2, mock_disable_warn.call_count)
|
||||
self.assertTrue(cls.global_initialization)
|
||||
self.assertEqual(mock.sentinel.backend_info,
|
||||
cls.output_all_backend_info)
|
||||
mock_priv_helper.assert_called_once_with(mock.sentinel.root_helper)
|
||||
|
||||
self.assertEqual(2, mock_disable_warn.call_count)
|
||||
self.assertTrue(cls.global_initialization)
|
||||
self.assertEqual(mock.sentinel.backend_info,
|
||||
cls.output_all_backend_info)
|
||||
finally:
|
||||
# Restore the class configuration
|
||||
for k, v in saved_cfg.items():
|
||||
if not k.startswith('__'):
|
||||
setattr(cls, k, v)
|
||||
|
||||
@mock.patch('cinderlib.cinderlib.LOG.warning')
|
||||
def test__validate_and_set_options(self, warning_mock):
|
||||
|
||||
Reference in New Issue
Block a user