Replace assertRaisesRegexp with assertRaisesRegex
assertRaisesRegexp is deprecated in python3 https://docs.python.org/3.2/library/unittest.html Co-Authored-By: edan david <edand@mellanox.com> Change-Id: I9446e745239d64ac9adf8fd1a8f95b5befc8cf06
This commit is contained in:
parent
f9979c1228
commit
027642246f
@ -188,14 +188,14 @@ class TestIntrospect(BaseTest):
|
||||
def test_failed_to_get_node(self, client_mock, add_mock, filters_mock):
|
||||
cli = client_mock.return_value
|
||||
cli.node.get.side_effect = exceptions.NotFound()
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Node %s was not found' % self.uuid,
|
||||
introspect.introspect, self.uuid)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Node %s was not found' % self.uuid,
|
||||
introspect.introspect, self.uuid)
|
||||
|
||||
cli.node.get.side_effect = exceptions.BadRequest()
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'%s: Bad Request' % self.uuid,
|
||||
introspect.introspect, self.uuid)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'%s: Bad Request' % self.uuid,
|
||||
introspect.introspect, self.uuid)
|
||||
|
||||
self.assertEqual(0, self.node_info.ports.call_count)
|
||||
self.assertEqual(0, filters_mock.call_count)
|
||||
@ -210,7 +210,7 @@ class TestIntrospect(BaseTest):
|
||||
cli.node.validate.return_value = mock.Mock(power={'result': False,
|
||||
'reason': 'oops'})
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
utils.Error,
|
||||
'Failed validation of power interface',
|
||||
introspect.introspect, self.uuid)
|
||||
@ -227,7 +227,7 @@ class TestIntrospect(BaseTest):
|
||||
cli = client_mock.return_value
|
||||
cli.node.get.return_value = self.node
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
utils.Error, 'Invalid provision state for introspection: "active"',
|
||||
introspect.introspect, self.uuid)
|
||||
|
||||
@ -365,9 +365,9 @@ class TestSetIpmiCredentials(BaseTest):
|
||||
'processing')
|
||||
self._prepare(client_mock)
|
||||
|
||||
self.assertRaisesRegexp(utils.Error, 'disabled',
|
||||
introspect.introspect, self.uuid,
|
||||
new_ipmi_credentials=self.new_creds)
|
||||
self.assertRaisesRegex(utils.Error, 'disabled',
|
||||
introspect.introspect, self.uuid,
|
||||
new_ipmi_credentials=self.new_creds)
|
||||
|
||||
def test_no_username(self, client_mock, add_mock, filters_mock):
|
||||
self._prepare(client_mock)
|
||||
@ -446,8 +446,8 @@ class TestAbort(BaseTest):
|
||||
exc = utils.Error('Not found.', code=404)
|
||||
get_mock.side_effect = exc
|
||||
|
||||
self.assertRaisesRegexp(utils.Error, str(exc),
|
||||
introspect.abort, self.uuid)
|
||||
self.assertRaisesRegex(utils.Error, str(exc),
|
||||
introspect.abort, self.uuid)
|
||||
|
||||
self.assertEqual(0, filters_mock.call_count)
|
||||
self.assertEqual(0, cli.node.set_power_state.call_count)
|
||||
@ -459,8 +459,8 @@ class TestAbort(BaseTest):
|
||||
self.node_info.acquire_lock.return_value = False
|
||||
self.node_info.started_at = time.time()
|
||||
|
||||
self.assertRaisesRegexp(utils.Error, 'Node is locked, please, '
|
||||
'retry later', introspect.abort, self.uuid)
|
||||
self.assertRaisesRegex(utils.Error, 'Node is locked, please, '
|
||||
'retry later', introspect.abort, self.uuid)
|
||||
|
||||
self.assertEqual(0, filters_mock.call_count)
|
||||
self.assertEqual(0, cli.node.set_power_state.call_count)
|
||||
|
@ -33,12 +33,12 @@ class TestWithValidation(test_base.BaseTest):
|
||||
|
||||
def test_required_missing(self):
|
||||
err_re = 'missing required parameter\(s\): x'
|
||||
self.assertRaisesRegexp(ValueError, err_re, self.test.validate, {})
|
||||
self.assertRaisesRegexp(ValueError, err_re, self.test.validate,
|
||||
{'x': None})
|
||||
self.assertRaisesRegexp(ValueError, err_re, self.test.validate,
|
||||
{'y': 1, 'z': 2})
|
||||
self.assertRaisesRegex(ValueError, err_re, self.test.validate, {})
|
||||
self.assertRaisesRegex(ValueError, err_re, self.test.validate,
|
||||
{'x': None})
|
||||
self.assertRaisesRegex(ValueError, err_re, self.test.validate,
|
||||
{'y': 1, 'z': 2})
|
||||
|
||||
def test_unexpected(self):
|
||||
self.assertRaisesRegexp(ValueError, 'unexpected parameter\(s\): foo',
|
||||
self.test.validate, {'foo': 'bar', 'x': 42})
|
||||
self.assertRaisesRegex(ValueError, 'unexpected parameter\(s\): foo',
|
||||
self.test.validate, {'foo': 'bar', 'x': 42})
|
||||
|
@ -144,8 +144,8 @@ class TestFailAction(test_base.BaseTest):
|
||||
self.assertRaises(ValueError, self.act.validate, {})
|
||||
|
||||
def test_apply(self):
|
||||
self.assertRaisesRegexp(utils.Error, 'boom',
|
||||
self.act.apply, None, {'message': 'boom'})
|
||||
self.assertRaisesRegex(utils.Error, 'boom',
|
||||
self.act.apply, None, {'message': 'boom'})
|
||||
|
||||
|
||||
class TestSetAttributeAction(test_base.NodeTest):
|
||||
|
@ -39,9 +39,9 @@ class TestSchedulerHook(test_base.NodeTest):
|
||||
|
||||
def test_no_root_disk(self):
|
||||
del self.inventory['disks']
|
||||
self.assertRaisesRegexp(utils.Error, 'disks key is missing or empty',
|
||||
self.hook.before_update, self.data,
|
||||
self.node_info)
|
||||
self.assertRaisesRegex(utils.Error, 'disks key is missing or empty',
|
||||
self.hook.before_update, self.data,
|
||||
self.node_info)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'patch')
|
||||
def test_ok(self, mock_patch):
|
||||
@ -111,16 +111,16 @@ class TestValidateInterfacesHook(test_base.NodeTest):
|
||||
self.assertRaises(SystemExit, std_plugins.ValidateInterfacesHook)
|
||||
|
||||
def test_no_interfaces(self):
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Hardware inventory is empty or missing',
|
||||
self.hook.before_processing, {})
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Hardware inventory is empty or missing',
|
||||
self.hook.before_processing, {'inventory': {}})
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Hardware inventory is empty or missing',
|
||||
self.hook.before_processing, {})
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Hardware inventory is empty or missing',
|
||||
self.hook.before_processing, {'inventory': {}})
|
||||
del self.inventory['interfaces']
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'interfaces key is missing or empty',
|
||||
self.hook.before_processing, self.data)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'interfaces key is missing or empty',
|
||||
self.hook.before_processing, self.data)
|
||||
|
||||
def test_only_pxe(self):
|
||||
self.hook.before_processing(self.data)
|
||||
@ -139,8 +139,8 @@ class TestValidateInterfacesHook(test_base.NodeTest):
|
||||
|
||||
def test_only_pxe_not_found(self):
|
||||
self.data['boot_interface'] = 'aa:bb:cc:dd:ee:ff'
|
||||
self.assertRaisesRegexp(utils.Error, 'No suitable interfaces',
|
||||
self.hook.before_processing, self.data)
|
||||
self.assertRaisesRegex(utils.Error, 'No suitable interfaces',
|
||||
self.hook.before_processing, self.data)
|
||||
|
||||
def test_only_pxe_no_boot_interface(self):
|
||||
del self.data['boot_interface']
|
||||
@ -179,8 +179,8 @@ class TestValidateInterfacesHook(test_base.NodeTest):
|
||||
# empty
|
||||
{},
|
||||
]
|
||||
self.assertRaisesRegexp(utils.Error, 'No interfaces supplied',
|
||||
self.hook.before_processing, self.data)
|
||||
self.assertRaisesRegex(utils.Error, 'No interfaces supplied',
|
||||
self.hook.before_processing, self.data)
|
||||
|
||||
def test_skipped_interfaces(self):
|
||||
CONF.set_override('add_ports', 'all', 'processing')
|
||||
@ -197,8 +197,8 @@ class TestValidateInterfacesHook(test_base.NodeTest):
|
||||
{'name': 'em4', 'mac_address': 'foobar',
|
||||
'ipv4_address': '2.2.2.2'},
|
||||
]
|
||||
self.assertRaisesRegexp(utils.Error, 'No suitable interfaces found',
|
||||
self.hook.before_processing, self.data)
|
||||
self.assertRaisesRegex(utils.Error, 'No suitable interfaces found',
|
||||
self.hook.before_processing, self.data)
|
||||
|
||||
@mock.patch.object(node_cache.NodeInfo, 'delete_port', autospec=True)
|
||||
def test_keep_all(self, mock_delete_port):
|
||||
@ -252,10 +252,10 @@ class TestRootDiskSelection(test_base.NodeTest):
|
||||
del self.data['inventory']
|
||||
del self.data['root_disk']
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Hardware inventory is empty or missing',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Hardware inventory is empty or missing',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
|
||||
self.assertNotIn('local_gb', self.data)
|
||||
self.assertNotIn('root_disk', self.data)
|
||||
@ -264,10 +264,10 @@ class TestRootDiskSelection(test_base.NodeTest):
|
||||
self.node.properties['root_device'] = {'size': 10}
|
||||
self.inventory['disks'] = []
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'disks key is missing or empty',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'disks key is missing or empty',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
|
||||
def test_one_matches(self):
|
||||
self.node.properties['root_device'] = {'size': 10}
|
||||
@ -289,10 +289,10 @@ class TestRootDiskSelection(test_base.NodeTest):
|
||||
'model': 'Model 42'}
|
||||
del self.data['root_disk']
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'No disks satisfied root device hints',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'No disks satisfied root device hints',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
|
||||
self.assertNotIn('local_gb', self.data)
|
||||
self.assertNotIn('root_disk', self.data)
|
||||
@ -305,10 +305,10 @@ class TestRootDiskSelection(test_base.NodeTest):
|
||||
def test_size_invalid(self):
|
||||
for bad_size in ('foo', None, {}):
|
||||
self.node.properties['root_device'] = {'size': bad_size}
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Invalid root device size hint',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Invalid root device size hint',
|
||||
self.hook.before_update,
|
||||
self.data, self.node_info)
|
||||
|
||||
|
||||
class TestRamdiskError(test_base.InventoryTest):
|
||||
@ -319,6 +319,6 @@ class TestRamdiskError(test_base.InventoryTest):
|
||||
self.data['error'] = self.msg
|
||||
|
||||
def test_no_logs(self):
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
self.msg,
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
self.msg,
|
||||
process.process, self.data)
|
||||
|
@ -100,42 +100,42 @@ class TestProcess(BaseProcessTest):
|
||||
|
||||
def test_not_found_in_cache(self):
|
||||
self.find_mock.side_effect = utils.Error('not found')
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'not found',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'not found',
|
||||
process.process, self.data)
|
||||
self.assertFalse(self.cli.node.get.called)
|
||||
self.assertFalse(self.process_mock.called)
|
||||
|
||||
def test_not_found_in_ironic(self):
|
||||
self.cli.node.get.side_effect = exceptions.NotFound()
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Node %s was not found' % self.uuid,
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Node %s was not found' % self.uuid,
|
||||
process.process, self.data)
|
||||
self.cli.node.get.assert_called_once_with(self.uuid)
|
||||
self.assertFalse(self.process_mock.called)
|
||||
self.node_info.finished.assert_called_once_with(error=mock.ANY)
|
||||
|
||||
def test_already_finished(self):
|
||||
self.node_info.finished_at = time.time()
|
||||
self.assertRaisesRegexp(utils.Error, 'already finished',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error, 'already finished',
|
||||
process.process, self.data)
|
||||
self.assertFalse(self.process_mock.called)
|
||||
self.assertFalse(self.find_mock.return_value.finished.called)
|
||||
|
||||
def test_expected_exception(self):
|
||||
self.process_mock.side_effect = utils.Error('boom')
|
||||
|
||||
self.assertRaisesRegexp(utils.Error, 'boom',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error, 'boom',
|
||||
process.process, self.data)
|
||||
|
||||
self.node_info.finished.assert_called_once_with(error='boom')
|
||||
|
||||
def test_unexpected_exception(self):
|
||||
self.process_mock.side_effect = RuntimeError('boom')
|
||||
|
||||
with self.assertRaisesRegexp(utils.Error,
|
||||
'Unexpected exception') as ctx:
|
||||
with self.assertRaisesRegex(utils.Error,
|
||||
'Unexpected exception') as ctx:
|
||||
process.process(self.data)
|
||||
|
||||
self.assertEqual(500, ctx.exception.http_code)
|
||||
@ -149,8 +149,8 @@ class TestProcess(BaseProcessTest):
|
||||
patcher.start()
|
||||
self.addCleanup(lambda p=patcher: p.stop())
|
||||
|
||||
self.assertRaisesRegexp(utils.Error, 'Unexpected exception',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error, 'Unexpected exception',
|
||||
process.process, self.data)
|
||||
|
||||
self.node_info.finished.assert_called_once_with(
|
||||
error=mock.ANY)
|
||||
@ -167,17 +167,17 @@ class TestProcess(BaseProcessTest):
|
||||
patcher.start()
|
||||
self.addCleanup(lambda p=patcher: p.stop())
|
||||
|
||||
self.assertRaisesRegexp(utils.Error, 'Unexpected exception',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error, 'Unexpected exception',
|
||||
process.process, self.data)
|
||||
|
||||
self.assertFalse(self.node_info.finished.called)
|
||||
|
||||
def test_error_if_node_not_found_hook(self):
|
||||
plugins_base._NOT_FOUND_HOOK_MGR = None
|
||||
self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM')
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Look up error: BOOM',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Look up error: BOOM',
|
||||
process.process, self.data)
|
||||
|
||||
|
||||
@mock.patch.object(example_plugin, 'example_not_found_hook',
|
||||
@ -199,9 +199,9 @@ class TestNodeNotFoundHook(BaseProcessTest):
|
||||
plugins_base._NOT_FOUND_HOOK_MGR = None
|
||||
self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM')
|
||||
hook_mock.return_value = None
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Node not found hook returned nothing',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Node not found hook returned nothing',
|
||||
process.process, self.data)
|
||||
hook_mock.assert_called_once_with(self.data)
|
||||
|
||||
def test_node_not_found_hook_exception(self, hook_mock):
|
||||
@ -209,9 +209,9 @@ class TestNodeNotFoundHook(BaseProcessTest):
|
||||
plugins_base._NOT_FOUND_HOOK_MGR = None
|
||||
self.find_mock.side_effect = utils.NotFoundInCacheError('BOOM')
|
||||
hook_mock.side_effect = Exception('Hook Error')
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Node not found hook failed: Hook Error',
|
||||
process.process, self.data)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Node not found hook failed: Hook Error',
|
||||
process.process, self.data)
|
||||
hook_mock.assert_called_once_with(self.data)
|
||||
|
||||
|
||||
|
@ -55,9 +55,9 @@ class TestCreateRule(BaseTest):
|
||||
|
||||
def test_duplicate_uuid(self):
|
||||
rules.create([], self.actions_json, uuid=self.uuid)
|
||||
self.assertRaisesRegexp(utils.Error, 'already exists',
|
||||
rules.create, [], self.actions_json,
|
||||
uuid=self.uuid)
|
||||
self.assertRaisesRegex(utils.Error, 'already exists',
|
||||
rules.create, [], self.actions_json,
|
||||
uuid=self.uuid)
|
||||
|
||||
def test_with_conditions(self):
|
||||
rule = rules.create(self.conditions_json, self.actions_json)
|
||||
@ -72,62 +72,62 @@ class TestCreateRule(BaseTest):
|
||||
def test_invalid_condition(self):
|
||||
del self.conditions_json[0]['op']
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Validation failed for conditions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Validation failed for conditions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
|
||||
self.conditions_json[0]['op'] = 'foobar'
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Validation failed for conditions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Validation failed for conditions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
|
||||
def test_invalid_condition_field(self):
|
||||
self.conditions_json[0]['field'] = '!*!'
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Unable to parse field JSON path',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Unable to parse field JSON path',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
|
||||
def test_invalid_condition_parameters(self):
|
||||
self.conditions_json[0]['foo'] = 'bar'
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Invalid parameters for operator',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Invalid parameters for operator',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
|
||||
def test_no_actions(self):
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Validation failed for actions',
|
||||
rules.create,
|
||||
self.conditions_json, [])
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Validation failed for actions',
|
||||
rules.create,
|
||||
self.conditions_json, [])
|
||||
|
||||
def test_invalid_action(self):
|
||||
del self.actions_json[0]['action']
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Validation failed for actions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Validation failed for actions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
|
||||
self.actions_json[0]['action'] = 'foobar'
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Validation failed for actions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Validation failed for actions',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
|
||||
def test_invalid_action_parameters(self):
|
||||
self.actions_json[0]['foo'] = 'bar'
|
||||
|
||||
self.assertRaisesRegexp(utils.Error,
|
||||
'Invalid parameters for action',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
self.assertRaisesRegex(utils.Error,
|
||||
'Invalid parameters for action',
|
||||
rules.create,
|
||||
self.conditions_json, self.actions_json)
|
||||
|
||||
|
||||
class TestGetRule(BaseTest):
|
||||
|
Loading…
x
Reference in New Issue
Block a user