Replace assertRaisesRegexp with assertRaisesRegex
assertRaisesRegexp is deprecated in python3 https://docs.python.org/3.2/library/unittest.html Change-Id: I91c84cb8a49dc6ce7a522e4c2114507ce4b81925
This commit is contained in:
parent
b83040bd30
commit
5a5e5772ad
@ -2518,59 +2518,59 @@ class TestPut(test_api_base.BaseApiTest):
|
||||
class TestCheckCleanSteps(base.TestCase):
|
||||
def test__check_clean_steps_not_list(self):
|
||||
clean_steps = {"step": "upgrade_firmware", "interface": "deploy"}
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
"not of type 'array'",
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
"not of type 'array'",
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_not_dict(self):
|
||||
clean_steps = ['clean step']
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
"not of type 'object'",
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
"not of type 'object'",
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_key_invalid(self):
|
||||
clean_steps = [{"step": "upgrade_firmware", "interface": "deploy",
|
||||
"unknown": "upgrade_firmware"}]
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'unexpected',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'unexpected',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_missing_interface(self):
|
||||
clean_steps = [{"step": "upgrade_firmware"}]
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'interface',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'interface',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_missing_step_key(self):
|
||||
clean_steps = [{"interface": "deploy"}]
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'step',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'step',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_missing_step_value(self):
|
||||
clean_steps = [{"step": None, "interface": "deploy"}]
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
"not of type 'string'",
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
"not of type 'string'",
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_min_length_step_value(self):
|
||||
clean_steps = [{"step": "", "interface": "deploy"}]
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'is too short',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'is too short',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_interface_value_invalid(self):
|
||||
clean_steps = [{"step": "upgrade_firmware", "interface": "not"}]
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'is not one of',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'is not one of',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_step_args_value_invalid(self):
|
||||
clean_steps = [{"step": "upgrade_firmware", "interface": "deploy",
|
||||
"args": "invalid args"}]
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'args',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'args',
|
||||
api_node._check_clean_steps, clean_steps)
|
||||
|
||||
def test__check_clean_steps_valid(self):
|
||||
clean_steps = [{"step": "upgrade_firmware", "interface": "deploy"}]
|
||||
|
@ -51,12 +51,12 @@ class FSMTest(base.TestCase):
|
||||
self.fsm._validate_target_state('working')
|
||||
|
||||
# target doesn't exist
|
||||
self.assertRaisesRegexp(excp.InvalidState, "does not exist",
|
||||
self.fsm._validate_target_state, 'new state')
|
||||
self.assertRaisesRegex(excp.InvalidState, "does not exist",
|
||||
self.fsm._validate_target_state, 'new state')
|
||||
|
||||
# target isn't a stable state
|
||||
self.assertRaisesRegexp(excp.InvalidState, "stable",
|
||||
self.fsm._validate_target_state, 'daydream')
|
||||
self.assertRaisesRegex(excp.InvalidState, "stable",
|
||||
self.fsm._validate_target_state, 'daydream')
|
||||
|
||||
def test_initialize(self):
|
||||
# no start state
|
||||
|
@ -718,16 +718,16 @@ class GetUpdatedCapabilitiesTestCase(base.TestCase):
|
||||
self.assertEqual(65535, port)
|
||||
|
||||
def test_validate_network_port_fail(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'Port "65536" is out of range.',
|
||||
utils.validate_network_port,
|
||||
'65536')
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'fake_port "-1" is out of range.',
|
||||
utils.validate_network_port,
|
||||
'-1',
|
||||
'fake_port')
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'Port "invalid" is not a valid integer.',
|
||||
utils.validate_network_port,
|
||||
'invalid')
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'Port "65536" is out of range.',
|
||||
utils.validate_network_port,
|
||||
'65536')
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'fake_port "-1" is out of range.',
|
||||
utils.validate_network_port,
|
||||
'-1',
|
||||
'fake_port')
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'Port "invalid" is not a valid integer.',
|
||||
utils.validate_network_port,
|
||||
'invalid')
|
||||
|
@ -155,8 +155,8 @@ class StartStopTestCase(mgr_utils.ServiceSetUpMixin, tests_db_base.DbTestCase):
|
||||
|
||||
def test_prevent_double_start(self):
|
||||
self._start_service()
|
||||
self.assertRaisesRegexp(RuntimeError, 'already running',
|
||||
self.service.init_host)
|
||||
self.assertRaisesRegex(RuntimeError, 'already running',
|
||||
self.service.init_host)
|
||||
|
||||
@mock.patch.object(base_manager, 'LOG')
|
||||
def test_warning_on_low_workers_pool(self, log_mock):
|
||||
|
@ -526,10 +526,10 @@ class NodeCleaningStepsTestCase(base.DbTestCase):
|
||||
{'step': 'bad_step', 'interface': 'deploy'}]
|
||||
|
||||
with task_manager.acquire(self.context, node.uuid) as task:
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
"does not support.*bad_step",
|
||||
conductor_utils._validate_user_clean_steps,
|
||||
task, user_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
"does not support.*bad_step",
|
||||
conductor_utils._validate_user_clean_steps,
|
||||
task, user_steps)
|
||||
mock_steps.assert_called_once_with(task, enabled=False, sort=False)
|
||||
|
||||
@mock.patch.object(conductor_utils, '_get_cleaning_steps')
|
||||
@ -541,10 +541,10 @@ class NodeCleaningStepsTestCase(base.DbTestCase):
|
||||
{'step': 'erase_disks', 'interface': 'deploy'}]
|
||||
|
||||
with task_manager.acquire(self.context, node.uuid) as task:
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
"update_firmware.*invalid.*arg1",
|
||||
conductor_utils._validate_user_clean_steps,
|
||||
task, user_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
"update_firmware.*invalid.*arg1",
|
||||
conductor_utils._validate_user_clean_steps,
|
||||
task, user_steps)
|
||||
mock_steps.assert_called_once_with(task, enabled=False, sort=False)
|
||||
|
||||
@mock.patch.object(conductor_utils, '_get_cleaning_steps')
|
||||
@ -555,10 +555,10 @@ class NodeCleaningStepsTestCase(base.DbTestCase):
|
||||
{'step': 'build_raid', 'interface': 'deploy'}]
|
||||
|
||||
with task_manager.acquire(self.context, node.uuid) as task:
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
"build_raid.*missing.*arg1",
|
||||
conductor_utils._validate_user_clean_steps,
|
||||
task, user_steps)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
"build_raid.*missing.*arg1",
|
||||
conductor_utils._validate_user_clean_steps,
|
||||
task, user_steps)
|
||||
mock_steps.assert_called_once_with(task, enabled=False, sort=False)
|
||||
|
||||
|
||||
|
@ -99,7 +99,7 @@ class FirmwareProcessorTestCase(base.TestCase):
|
||||
'component': 'bios'
|
||||
}
|
||||
# | WHEN | & | THEN |
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
exception.MissingParameterValue, 'checksum',
|
||||
ilo_fw_processor.get_and_validate_firmware_image_info,
|
||||
invalid_firmware_image_info)
|
||||
@ -113,7 +113,7 @@ class FirmwareProcessorTestCase(base.TestCase):
|
||||
'component': ''
|
||||
}
|
||||
# | WHEN | & | THEN |
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
exception.MissingParameterValue, 'component',
|
||||
ilo_fw_processor.get_and_validate_firmware_image_info,
|
||||
invalid_firmware_image_info)
|
||||
|
@ -56,15 +56,15 @@ class OneViewCommonTestCase(db_base.DbTestCase):
|
||||
"capabilities": ("enclosure_group_uri:fake_eg_uri,"
|
||||
"server_profile_template_uri:fake_spt_uri")
|
||||
}
|
||||
with self.assertRaisesRegexp(exception.MissingParameterValue,
|
||||
"server_hardware_type_uri"):
|
||||
with self.assertRaisesRegex(exception.MissingParameterValue,
|
||||
"server_hardware_type_uri"):
|
||||
common.verify_node_info(self.node)
|
||||
|
||||
def test_verify_node_info_missing_node_driver_info(self):
|
||||
self.node.driver_info = {}
|
||||
|
||||
with self.assertRaisesRegexp(exception.MissingParameterValue,
|
||||
"server_hardware_uri"):
|
||||
with self.assertRaisesRegex(exception.MissingParameterValue,
|
||||
"server_hardware_uri"):
|
||||
common.verify_node_info(self.node)
|
||||
|
||||
def test_verify_node_info_missing_spt(self):
|
||||
@ -73,8 +73,8 @@ class OneViewCommonTestCase(db_base.DbTestCase):
|
||||
"enclosure_group_uri:fake_eg_uri")
|
||||
|
||||
self.node.properties = properties
|
||||
with self.assertRaisesRegexp(exception.MissingParameterValue,
|
||||
"server_profile_template_uri"):
|
||||
with self.assertRaisesRegex(exception.MissingParameterValue,
|
||||
"server_profile_template_uri"):
|
||||
common.verify_node_info(self.node)
|
||||
|
||||
def test_verify_node_info_missing_sh(self):
|
||||
@ -90,8 +90,8 @@ class OneViewCommonTestCase(db_base.DbTestCase):
|
||||
|
||||
self.node.properties = properties
|
||||
self.node.driver_info = driver_info
|
||||
with self.assertRaisesRegexp(exception.MissingParameterValue,
|
||||
"server_hardware_uri"):
|
||||
with self.assertRaisesRegex(exception.MissingParameterValue,
|
||||
"server_hardware_uri"):
|
||||
common.verify_node_info(self.node)
|
||||
|
||||
def test_verify_node_info_missing_sht(self):
|
||||
@ -104,8 +104,8 @@ class OneViewCommonTestCase(db_base.DbTestCase):
|
||||
|
||||
self.node.properties = properties
|
||||
self.node.driver_info = driver_info
|
||||
with self.assertRaisesRegexp(exception.MissingParameterValue,
|
||||
"server_hardware_type_uri"):
|
||||
with self.assertRaisesRegex(exception.MissingParameterValue,
|
||||
"server_hardware_type_uri"):
|
||||
common.verify_node_info(self.node)
|
||||
|
||||
def test_get_oneview_info(self):
|
||||
@ -255,8 +255,8 @@ class OneViewCommonTestCase(db_base.DbTestCase):
|
||||
)
|
||||
|
||||
def test__verify_node_info_missing_values_empty_string(self):
|
||||
with self.assertRaisesRegexp(exception.MissingParameterValue,
|
||||
"'properties:a', 'properties:b'"):
|
||||
with self.assertRaisesRegex(exception.MissingParameterValue,
|
||||
"'properties:a', 'properties:b'"):
|
||||
common._verify_node_info("properties",
|
||||
{"a": '', "b": None, "c": "something"},
|
||||
["a", "b", "c"])
|
||||
|
@ -120,7 +120,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
|
||||
'A Server Profile is not associated with node %s.'
|
||||
% self.node.uuid
|
||||
)
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
exception.OperationNotPermitted,
|
||||
expected_msg,
|
||||
self.driver.management.set_boot_device,
|
||||
|
@ -425,9 +425,9 @@ class TestAgentDeploy(db_base.DbTestCase):
|
||||
'image_https_proxy': 'git://spam.ni',
|
||||
'image_http_proxy': 'http://spam.ni',
|
||||
'image_no_proxy': '1' * 500})
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'image_https_proxy.*image_no_proxy',
|
||||
task.driver.deploy.validate, task)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'image_https_proxy.*image_no_proxy',
|
||||
task.driver.deploy.validate, task)
|
||||
pxe_boot_validate_mock.assert_called_once_with(
|
||||
task.driver.boot, task)
|
||||
show_mock.assert_called_once_with(self.context, 'fake-image')
|
||||
|
@ -125,47 +125,47 @@ class CleanStepDecoratorTestCase(base.TestCase):
|
||||
'arg2': {'description': 'desc2'}})
|
||||
|
||||
def test__validate_argsinfo_not_dict(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'argsinfo.+dictionary',
|
||||
driver_base._validate_argsinfo, 'not-a-dict')
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'argsinfo.+dictionary',
|
||||
driver_base._validate_argsinfo, 'not-a-dict')
|
||||
|
||||
def test__validate_argsinfo_arg_not_dict(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'Argument.+dictionary',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': 'not-a-dict'})
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'Argument.+dictionary',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': 'not-a-dict'})
|
||||
|
||||
def test__validate_argsinfo_arg_empty_dict(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'description',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {}})
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'description',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {}})
|
||||
|
||||
def test__validate_argsinfo_arg_missing_description(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'description',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'required': True}})
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'description',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'required': True}})
|
||||
|
||||
def test__validate_argsinfo_arg_description_invalid(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'string',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'description': True}})
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'string',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'description': True}})
|
||||
|
||||
def test__validate_argsinfo_arg_required_invalid(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'Boolean',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'description': 'desc1',
|
||||
'required': 'maybe'}})
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'Boolean',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'description': 'desc1',
|
||||
'required': 'maybe'}})
|
||||
|
||||
def test__validate_argsinfo_arg_unknown_key(self):
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
'invalid',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'description': 'desc1',
|
||||
'unknown': 'bad'}})
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
'invalid',
|
||||
driver_base._validate_argsinfo,
|
||||
{'arg1': {'description': 'desc1',
|
||||
'unknown': 'bad'}})
|
||||
|
||||
def test_clean_step_priority_only(self):
|
||||
d = driver_base.clean_step(priority=10)
|
||||
@ -188,8 +188,8 @@ class CleanStepDecoratorTestCase(base.TestCase):
|
||||
|
||||
def test_clean_step_bad_priority(self):
|
||||
d = driver_base.clean_step(priority='hi')
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue, 'priority',
|
||||
d, self.method)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue, 'priority',
|
||||
d, self.method)
|
||||
self.assertTrue(self.method._is_clean_step)
|
||||
self.assertFalse(hasattr(self.method, '_clean_step_priority'))
|
||||
self.assertFalse(hasattr(self.method, '_clean_step_abortable'))
|
||||
@ -197,8 +197,8 @@ class CleanStepDecoratorTestCase(base.TestCase):
|
||||
|
||||
def test_clean_step_bad_abortable(self):
|
||||
d = driver_base.clean_step(priority=0, abortable='blue')
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue, 'abortable',
|
||||
d, self.method)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue, 'abortable',
|
||||
d, self.method)
|
||||
self.assertTrue(self.method._is_clean_step)
|
||||
self.assertEqual(0, self.method._clean_step_priority)
|
||||
self.assertFalse(hasattr(self.method, '_clean_step_abortable'))
|
||||
|
@ -163,8 +163,8 @@ class TestNodeObject(base.DbTestCase):
|
||||
node = objects.Node.get(self.context, uuid)
|
||||
node.properties = {"local_gb": "5G", "memory_mb": "5",
|
||||
'cpus': '-1', 'cpu_arch': 'x86_64'}
|
||||
self.assertRaisesRegexp(exception.InvalidParameterValue,
|
||||
".*local_gb=5G, cpus=-1$", node.save)
|
||||
self.assertRaisesRegex(exception.InvalidParameterValue,
|
||||
".*local_gb=5G, cpus=-1$", node.save)
|
||||
mock_get_node.assert_called_once_with(uuid)
|
||||
|
||||
def test__validate_property_values_success(self):
|
||||
|
@ -176,7 +176,7 @@ class _TestObject(object):
|
||||
fields = {'foobar': fields.IntegerField()}
|
||||
obj = Foo(self.context)
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
NotImplementedError, "Cannot load 'foobar' in the base class",
|
||||
getattr, obj, 'foobar')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user