diff --git a/nova/api/ec2/ec2utils.py b/nova/api/ec2/ec2utils.py index 3134e309e51f..9fb1582dba4f 100644 --- a/nova/api/ec2/ec2utils.py +++ b/nova/api/ec2/ec2utils.py @@ -232,7 +232,7 @@ def ec2_vol_id_to_uuid(ec2_id): return get_volume_uuid_from_int_id(ctxt, int_id) -_ms_time_regex = re.compile('^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3,6}Z$') +_ms_time_regex = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3,6}Z$') def status_to_ec2_attach_status(volume): @@ -462,4 +462,4 @@ def regex_from_ec2_regex(ec2_re): py_re += '\\\\' + next_char else: py_re += re.escape(char) - return '\A%s\Z(?s)' % py_re + return r'(?s)\A%s\Z' % py_re diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 087c447b2116..d6429cc416a3 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -166,7 +166,7 @@ class ProjectMapper(APIMapper): # NOTE(sdague): project_id parameter is only valid if its hex # or hex + dashes (note, integers are a subset of this). This # is required to hand our overlaping routes issues. - project_id_regex = '[0-9a-f\-]+' + project_id_regex = '[0-9a-f-]+' if CONF.osapi_v21.project_id_regex: project_id_regex = CONF.osapi_v21.project_id_regex diff --git a/nova/api/openstack/compute/schemas/flavor_manage.py b/nova/api/openstack/compute/schemas/flavor_manage.py index 08899a21eee1..ad3ebe57a7a2 100644 --- a/nova/api/openstack/compute/schemas/flavor_manage.py +++ b/nova/api/openstack/compute/schemas/flavor_manage.py @@ -39,7 +39,7 @@ create = { # positive ( > 0) float 'rxtx_factor': { 'type': ['number', 'string'], - 'pattern': '^[0-9]+(\.[0-9]+)?$', + 'pattern': r'^[0-9]+(\.[0-9]+)?$', 'minimum': 0, 'exclusiveMinimum': True, # maximum's value is limited to db constant's # SQL_SP_FLOAT_MAX (in nova/db/constants.py) diff --git a/nova/api/openstack/compute/schemas/servers.py b/nova/api/openstack/compute/schemas/servers.py index 1c71cf688957..1b048e170423 100644 --- a/nova/api/openstack/compute/schemas/servers.py +++ b/nova/api/openstack/compute/schemas/servers.py @@ -136,7 +136,7 @@ _hints = { 'build_near_host_ip': parameter_types.ip_address, 'cidr': { 'type': 'string', - 'pattern': '^\/[0-9a-f.:]+$' + 'pattern': '^/[0-9a-f.:]+$' }, }, # NOTE: As this Mail: diff --git a/nova/api/validation/validators.py b/nova/api/validation/validators.py index f36393463c18..eef05c72827e 100644 --- a/nova/api/validation/validators.py +++ b/nova/api/validation/validators.py @@ -75,7 +75,7 @@ def _validate_cidr_format(cidr): return False if '/' not in cidr: return False - if re.search('\s', cidr): + if re.search(r'\s', cidr): return False return True diff --git a/nova/block_device.py b/nova/block_device.py index 89c203b1d774..2f1afb07332a 100644 --- a/nova/block_device.py +++ b/nova/block_device.py @@ -419,7 +419,7 @@ def validate_and_default_volume_size(bdm): details=_("Invalid volume_size.")) -_ephemeral = re.compile('^ephemeral(\d|[1-9]\d+)$') +_ephemeral = re.compile(r'^ephemeral(\d|[1-9]\d+)$') def is_ephemeral(device_name): @@ -499,7 +499,7 @@ def strip_prefix(device_name): return _pref.sub('', device_name) if device_name else device_name -_nums = re.compile('\d+') +_nums = re.compile(r'\d+') def get_device_letter(device_name): diff --git a/nova/conf/hyperv.py b/nova/conf/hyperv.py index d9ba3c5b1223..caa7a8702b8d 100644 --- a/nova/conf/hyperv.py +++ b/nova/conf/hyperv.py @@ -149,7 +149,7 @@ Possible values: """), cfg.StrOpt('qemu_img_cmd', default="qemu-img.exe", - help=""" + help=r""" qemu-img command qemu-img is required for some of the image related operations diff --git a/nova/conf/serial_console.py b/nova/conf/serial_console.py index 233aa70faedf..2781a2765b58 100644 --- a/nova/conf/serial_console.py +++ b/nova/conf/serial_console.py @@ -36,7 +36,7 @@ This service is typically executed on the controller node. cfg.StrOpt('port_range', default=DEFAULT_PORT_RANGE, regex=r'^\d+:\d+$', - help=""" + help=r""" A range of TCP ports a guest can use for its backend. Each instance which gets created will use one port out of this range. If the @@ -45,9 +45,9 @@ instance won't get launched. Possible values: -* Each string which passes the regex ``^\d+:\d+$`` For example ``10000:20000``. - Be sure that the first port number is lower than the second port number - and that both are in range from 0 to 65535. +* Each string which passes the regex ``^\d+:\d+$`` For example + ``10000:20000``. Be sure that the first port number is lower than the second + port number and that both are in range from 0 to 65535. """), # TODO(macsz) check if WS protocol is still being used cfg.URIOpt('base_url', diff --git a/nova/hacking/checks.py b/nova/hacking/checks.py index 5ac954fa54eb..09a689dc5aa2 100644 --- a/nova/hacking/checks.py +++ b/nova/hacking/checks.py @@ -48,10 +48,10 @@ virt_config_re = re.compile( r"CONF\.import_opt\('.*?', 'nova\.virt\.(\w+)('|.)") asse_trueinst_re = re.compile( r"(.)*assertTrue\(isinstance\((\w|\.|\'|\"|\[|\])+, " - "(\w|\.|\'|\"|\[|\])+\)\)") + r"(\w|\.|\'|\"|\[|\])+\)\)") asse_equal_type_re = re.compile( r"(.)*assertEqual\(type\((\w|\.|\'|\"|\[|\])+\), " - "(\w|\.|\'|\"|\[|\])+\)") + r"(\w|\.|\'|\"|\[|\])+\)") asse_equal_in_end_with_true_or_false_re = re.compile(r"assertEqual\(" r"(\w|[][.'\"])+ in (\w|[][.'\", ])+, (True|False)\)") asse_equal_in_start_with_true_or_false_re = re.compile(r"assertEqual\(" @@ -76,7 +76,7 @@ asse_raises_regexp = re.compile(r"assertRaisesRegexp\(") conf_attribute_set_re = re.compile(r"CONF\.[a-z0-9_.]+\s*=\s*\w") translated_log = re.compile( r"(.)*LOG\.(audit|error|info|critical|exception)" - "\(\s*_\(\s*('|\")") + r"\(\s*_\(\s*('|\")") mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])") string_translation = re.compile(r"[^_]*_\(\s*('|\")") underscore_import_check = re.compile(r"(.)*import _(.)*") diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 7a2d22fd11a1..a57f2a4503d6 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -690,7 +690,7 @@ def ensure_vpn_forward(public_ip, port, private_ip): def ensure_floating_forward(floating_ip, fixed_ip, device, network): """Ensure floating IP forwarding rule.""" # NOTE(vish): Make sure we never have duplicate rules for the same ip - regex = '.*\s+%s(/32|\s+|$)' % floating_ip + regex = r'.*\s+%s(/32|\s+|$)' % floating_ip num_rules = iptables_manager.ipv4['nat'].remove_rules_regex(regex) if num_rules: LOG.warning('Removed %(num)d duplicate rules for floating IP ' diff --git a/nova/network/manager.py b/nova/network/manager.py index c3c1b3ac8f27..fa509dc6f71e 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -70,7 +70,7 @@ def get_my_linklocal(interface): try: if_str = processutils.execute( 'ip', '-f', 'inet6', '-o', 'addr', 'show', interface) - condition = '\s+inet6\s+([0-9a-f:]+)/\d+\s+scope\s+link' + condition = r'\s+inet6\s+([0-9a-f:]+)/\d+\s+scope\s+link' links = [re.search(condition, x) for x in if_str[0].split('\n')] address = [w.group(1) for w in links if w is not None] if address[0] is not None: diff --git a/nova/pci/utils.py b/nova/pci/utils.py index 221508574aa3..5b0a0821f944 100644 --- a/nova/pci/utils.py +++ b/nova/pci/utils.py @@ -26,9 +26,9 @@ from nova import exception LOG = logging.getLogger(__name__) -PCI_VENDOR_PATTERN = "^(hex{4})$".replace("hex", "[\da-fA-F]") +PCI_VENDOR_PATTERN = "^(hex{4})$".replace("hex", r"[\da-fA-F]") _PCI_ADDRESS_PATTERN = ("^(hex{4}):(hex{2}):(hex{2}).(oct{1})$". - replace("hex", "[\da-fA-F]"). + replace("hex", r"[\da-fA-F]"). replace("oct", "[0-7]")) _PCI_ADDRESS_REGEX = re.compile(_PCI_ADDRESS_PATTERN) @@ -186,7 +186,7 @@ def get_vf_num_by_pci_address(pci_addr): A VF is associated with an VF number, which ip link command uses to configure it. This number can be obtained from the PCI device filesystem. """ - VIRTFN_RE = re.compile("virtfn(\d+)") + VIRTFN_RE = re.compile(r"virtfn(\d+)") virtfns_path = "/sys/bus/pci/devices/%s/physfn/virtfn*" % (pci_addr) vf_num = None try: diff --git a/nova/tests/fixtures.py b/nova/tests/fixtures.py index 9689fc582977..4009fdd90a76 100644 --- a/nova/tests/fixtures.py +++ b/nova/tests/fixtures.py @@ -870,7 +870,7 @@ class WarningsFixture(fixtures.Fixture): # TODO(mriedem): Change (or remove) this DeprecationWarning once # https://bugs.launchpad.net/sqlalchemy-migrate/+bug/1814288 is fixed. warnings.filterwarnings( - 'ignore', message='inspect\.getargspec\(\) is deprecated', + 'ignore', message='inspect.getargspec() is deprecated', category=DeprecationWarning, module='migrate.versioning.script.py') diff --git a/nova/tests/functional/api_sample_tests/test_aggregates.py b/nova/tests/functional/api_sample_tests/test_aggregates.py index 99d1d629ab88..d5bb13abed93 100644 --- a/nova/tests/functional/api_sample_tests/test_aggregates.py +++ b/nova/tests/functional/api_sample_tests/test_aggregates.py @@ -28,7 +28,7 @@ class AggregatesSampleJsonTest(api_sample_base.ApiSampleTestBaseV21): def _test_aggregate_create(self): subs = { - "aggregate_id": '(?P\d+)' + "aggregate_id": r'(?P\d+)' } response = self._do_post('os-aggregates', 'aggregate-post-req', subs) return self._verify_response('aggregate-post-resp', @@ -102,7 +102,7 @@ class AggregatesV2_41_SampleJsonTest(AggregatesSampleJsonTest): def _test_aggregate_create(self): subs = { - "aggregate_id": '(?P\d+)', + "aggregate_id": r'(?P\d+)', } response = self._do_post('os-aggregates', 'aggregate-post-req', subs) # This feels like cheating since we're getting the uuid from the diff --git a/nova/tests/functional/api_sample_tests/test_remote_consoles.py b/nova/tests/functional/api_sample_tests/test_remote_consoles.py index 65ae3f1f5d1d..09229265b0d3 100644 --- a/nova/tests/functional/api_sample_tests/test_remote_consoles.py +++ b/nova/tests/functional/api_sample_tests/test_remote_consoles.py @@ -34,7 +34,7 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase): 'get-vnc-console-post-req', {'action': 'os-getVNCConsole'}) subs = {"url": - "((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)"} + "((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"} self._verify_response('get-vnc-console-post-resp', subs, response, 200) def test_get_spice_console(self): @@ -43,7 +43,7 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase): 'get-spice-console-post-req', {'action': 'os-getSPICEConsole'}) subs = {"url": - "((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)"} + "((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"} self._verify_response('get-spice-console-post-resp', subs, response, 200) @@ -53,7 +53,7 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase): 'get-rdp-console-post-req', {'action': 'os-getRDPConsole'}) subs = {"url": - "((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)"} + "((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"} self._verify_response('get-rdp-console-post-resp', subs, response, 200) @@ -63,7 +63,7 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase): 'get-serial-console-post-req', {'action': 'os-getSerialConsole'}) subs = {"url": - "((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)"} + "((https?):((//)|(\\\\))+([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*)"} self._verify_response('get-serial-console-post-resp', subs, response, 200) @@ -78,7 +78,7 @@ class ConsolesV26SampleJsonTests(test_servers.ServersSampleBase): def setUp(self): super(ConsolesV26SampleJsonTests, self).setUp() - self.http_regex = "(https?://)([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*" + self.http_regex = '(https?://)([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*' def test_create_console(self): uuid = self._post_server() @@ -97,7 +97,7 @@ class ConsolesV28SampleJsonTests(test_servers.ServersSampleBase): def setUp(self): super(ConsolesV28SampleJsonTests, self).setUp() - self.http_regex = "(https?://)([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*" + self.http_regex = '(https?://)([\\w\\d:#@%/;$()~_?\\+-=\\\\.&](#!)?)*' self.flags(enabled=True, group='mks') def test_create_mks_console(self): diff --git a/nova/tests/functional/api_sample_tests/test_rescue.py b/nova/tests/functional/api_sample_tests/test_rescue.py index f5b21e9e7790..3c5545c297ff 100644 --- a/nova/tests/functional/api_sample_tests/test_rescue.py +++ b/nova/tests/functional/api_sample_tests/test_rescue.py @@ -45,7 +45,7 @@ class RescueJsonTest(test_servers.ServersSampleBase): subs['status'] = 'RESCUE' subs['access_ip_v4'] = '1.2.3.4' subs['access_ip_v6'] = '80fe::' - subs['instance_name'] = 'instance-\d{8}' + subs['instance_name'] = r'instance-\d{8}' subs['hypervisor_hostname'] = r'[\w\.\-]+' subs['cdrive'] = '.*' self._verify_response('server-get-resp-rescue', subs, response, 200) @@ -69,7 +69,7 @@ class RescueJsonTest(test_servers.ServersSampleBase): subs['status'] = 'RESCUE' subs['access_ip_v4'] = '1.2.3.4' subs['access_ip_v6'] = '80fe::' - subs['instance_name'] = 'instance-\d{8}' + subs['instance_name'] = r'instance-\d{8}' subs['hypervisor_hostname'] = r'[\w\.\-]+' subs['cdrive'] = '.*' self._verify_response('server-get-resp-rescue', subs, response, 200) @@ -88,7 +88,7 @@ class RescueJsonTest(test_servers.ServersSampleBase): subs['status'] = 'ACTIVE' subs['access_ip_v4'] = '1.2.3.4' subs['access_ip_v6'] = '80fe::' - subs['instance_name'] = 'instance-\d{8}' + subs['instance_name'] = r'instance-\d{8}' subs['hypervisor_hostname'] = r'[\w\.\-]+' subs['cdrive'] = '.*' self._verify_response('server-get-resp-unrescue', subs, response, 200) diff --git a/nova/tests/functional/api_sample_tests/test_server_tags.py b/nova/tests/functional/api_sample_tests/test_server_tags.py index a82f1e44f4be..14917661ece3 100644 --- a/nova/tests/functional/api_sample_tests/test_server_tags.py +++ b/nova/tests/functional/api_sample_tests/test_server_tags.py @@ -36,7 +36,7 @@ class ServerTagsJsonTest(test_servers.ServersSampleBase): subs['access_ip_v4'] = '1.2.3.4' subs['access_ip_v6'] = '80fe::' subs['hostname'] = r'[\w\.\-]+' - subs['instance_name'] = 'instance-\d{8}' + subs['instance_name'] = r'instance-\d{8}' subs['hypervisor_hostname'] = r'[\w\.\-]+' subs['cdrive'] = '.*' subs['user_data'] = (self.user_data if six.PY2 diff --git a/nova/tests/functional/api_sample_tests/test_servers.py b/nova/tests/functional/api_sample_tests/test_servers.py index dbfe96d1b36d..2467300b92c2 100644 --- a/nova/tests/functional/api_sample_tests/test_servers.py +++ b/nova/tests/functional/api_sample_tests/test_servers.py @@ -118,7 +118,7 @@ class ServersSampleJsonTest(ServersSampleBase): subs = {} subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid - subs['instance_name'] = 'instance-\d{8}' + subs['instance_name'] = r'instance-\d{8}' subs['hypervisor_hostname'] = r'[\w\.\-]+' subs['hostname'] = r'[\w\.\-]+' subs['mac_addr'] = '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}' @@ -145,7 +145,7 @@ class ServersSampleJsonTest(ServersSampleBase): subs = {} subs['hostid'] = '[a-f0-9]+' subs['id'] = uuid - subs['instance_name'] = 'instance-\d{8}' + subs['instance_name'] = r'instance-\d{8}' subs['hypervisor_hostname'] = r'[\w\.\-]+' subs['hostname'] = r'[\w\.\-]+' subs['mac_addr'] = '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}' @@ -261,7 +261,7 @@ class ServersSampleJson263Test(ServersSampleBase): super(ServersSampleJson263Test, self).setUp() self.common_subs = { 'hostid': '[a-f0-9]+', - 'instance_name': 'instance-\d{8}', + 'instance_name': r'instance-\d{8}', 'hypervisor_hostname': r'[\w\.\-]+', 'hostname': r'[\w\.\-]+', 'access_ip_v4': '1.2.3.4', @@ -330,7 +330,7 @@ class ServersSampleJson266Test(ServersSampleBase): super(ServersSampleJson266Test, self).setUp() self.common_subs = { 'hostid': '[a-f0-9]+', - 'instance_name': 'instance-\d{8}', + 'instance_name': r'instance-\d{8}', 'hypervisor_hostname': r'[\w\.\-]+', 'hostname': r'[\w\.\-]+', 'access_ip_v4': '1.2.3.4', @@ -430,7 +430,7 @@ class ServersSampleJson271Test(ServersSampleBase): super(ServersSampleJson271Test, self).setUp() self.common_subs = { 'hostid': '[a-f0-9]+', - 'instance_name': 'instance-\d{8}', + 'instance_name': r'instance-\d{8}', 'hypervisor_hostname': r'[\w\.\-]+', 'hostname': r'[\w\.\-]+', 'access_ip_v4': '1.2.3.4', diff --git a/nova/tests/functional/api_samples_test_base.py b/nova/tests/functional/api_samples_test_base.py index 581c7327ebfe..d9bd8a215ceb 100644 --- a/nova/tests/functional/api_samples_test_base.py +++ b/nova/tests/functional/api_samples_test_base.py @@ -337,7 +337,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): project_id_exp = '(%s|%s)' % (PROJECT_ID, self.project_id) - url_re = self._get_host() + "/v(2|2\.1)/" + project_id_exp + url_re = self._get_host() + r"/v(2|2\.1)/" + project_id_exp new_url = self._get_host() + "/" + self.api_major_version if self._use_project_id: new_url += "/" + self.project_id @@ -431,13 +431,13 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): def _get_regexes(self): text = r'(\\"|[^"])*' - isotime_re = '\d{4}-[0,1]\d-[0-3]\dT\d{2}:\d{2}:\d{2}Z' - strtime_re = '\d{4}-[0,1]\d-[0-3]\dT\d{2}:\d{2}:\d{2}\.\d{6}' - strtime_url_re = ('\d{4}-[0,1]\d-[0-3]\d' - '\+\d{2}\%3A\d{2}\%3A\d{2}\.\d{6}') - xmltime_re = ('\d{4}-[0,1]\d-[0-3]\d ' - '\d{2}:\d{2}:\d{2}' - '(\.\d{6})?(\+00:00)?') + isotime_re = r'\d{4}-[0,1]\d-[0-3]\dT\d{2}:\d{2}:\d{2}Z' + strtime_re = r'\d{4}-[0,1]\d-[0-3]\dT\d{2}:\d{2}:\d{2}\.\d{6}' + strtime_url_re = (r'\d{4}-[0,1]\d-[0-3]\d' + r'\+\d{2}\%3A\d{2}\%3A\d{2}\.\d{6}') + xmltime_re = (r'\d{4}-[0,1]\d-[0-3]\d ' + r'\d{2}:\d{2}:\d{2}' + r'(\.\d{6})?(\+00:00)?') # NOTE(claudiub): the x509 keypairs are different from the # ssh keypairs. For example, the x509 fingerprint has 40 bytes. diff --git a/nova/tests/functional/test_nova_manage.py b/nova/tests/functional/test_nova_manage.py index 28fa78baab21..0fa541b51499 100644 --- a/nova/tests/functional/test_nova_manage.py +++ b/nova/tests/functional/test_nova_manage.py @@ -869,7 +869,7 @@ class TestDBArchiveDeletedRows(integrated_helpers._IntegratedTestBase): self.cli.archive_deleted_rows(verbose=True) # Assert only one instance_group_member record was deleted. self.assertRegex(self.output.getvalue(), - ".*instance_group_member.*\| 1.*") + r".*instance_group_member.*\| 1.*") # And that we still have one remaining group member. self.assertEqual( 1, len(self.api.get_server_group(group['id'])['members'])) diff --git a/nova/tests/functional/test_report_client.py b/nova/tests/functional/test_report_client.py index 03467242a828..58ddad6a30bb 100644 --- a/nova/tests/functional/test_report_client.py +++ b/nova/tests/functional/test_report_client.py @@ -325,7 +325,7 @@ class SchedulerReportClientTests(SchedulerReportClientTestBase): global_request_id=global_request_id) def test_get_provider_tree_with_nested_and_aggregates(self): - """A more in-depth test of get_provider_tree_and_ensure_root with + r"""A more in-depth test of get_provider_tree_and_ensure_root with nested and sharing resource providers. ss1(DISK) ss2(DISK) ss3(DISK) @@ -1013,7 +1013,7 @@ class SchedulerReportClientTests(SchedulerReportClientTestBase): self.context, utils.ResourceRequest()) def _set_up_provider_tree(self): - """Create two compute nodes in placement ("this" one, and another one) + r"""Create two compute nodes in placement ("this" one, and another one) and a storage provider sharing with both. +-----------------------+ +------------------------+ diff --git a/nova/tests/functional/test_servers_provider_tree.py b/nova/tests/functional/test_servers_provider_tree.py index 217e456297ef..e499b5d65408 100644 --- a/nova/tests/functional/test_servers_provider_tree.py +++ b/nova/tests/functional/test_servers_provider_tree.py @@ -156,7 +156,7 @@ class ProviderTreeTests(integrated_helpers.ProviderUsageBaseTestCase): def _update_provider_tree_multiple_providers(self, startup=False, do_reshape=False): - """Make update_provider_tree create multiple providers, including an + r"""Make update_provider_tree create multiple providers, including an additional root as a sharing provider; and some descendants in the compute node's tree. diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index 07140d382b82..62e22ffd5584 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -1509,13 +1509,13 @@ class ServersControllerTest(ControllerTest): cell_down_support=False, all_tenants=False): self.assertIsNotNone(search_opts) self.assertIn('ip', search_opts) - self.assertEqual(search_opts['ip'], '10\..*') + self.assertEqual(search_opts['ip'], r'10\..*') return objects.InstanceList( objects=[fakes.stub_instance_obj(100, uuid=uuids.fake)]) self.mock_get_all.side_effect = fake_get_all - req = self.req('/fake/servers?ip=10\..*') + req = self.req(r'/fake/servers?ip=10\..*') servers = self.controller.index(req)['servers'] self.assertEqual(1, len(servers)) diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index bee2eda5b67a..cd3fa88a762c 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -9472,7 +9472,7 @@ class ComputeAPITestCase(BaseTestCase): # ip ends up matching 2nd octet here.. so all 3 match ip # but 'name' only matches one instances = self.compute_api.get_all(c, - search_opts={'ip': '.*\.1', 'name': 'not.*'}) + search_opts={'ip': r'.*\.1', 'name': 'not.*'}) self.assertEqual(len(instances), 1) self.assertEqual(instances[0]['uuid'], instance3['uuid']) @@ -9480,19 +9480,19 @@ class ComputeAPITestCase(BaseTestCase): # so instance 1 and 3.. but name should only match #1 # but 'name' only matches one instances = self.compute_api.get_all(c, - search_opts={'ip': '.*\.1$', 'name': '^woo.*'}) + search_opts={'ip': r'.*\.1$', 'name': '^woo.*'}) self.assertEqual(len(instances), 1) self.assertEqual(instances[0]['uuid'], instance1['uuid']) # same as above but no match on name (name matches instance1 # but the ip query doesn't instances = self.compute_api.get_all(c, - search_opts={'ip': '.*\.2$', 'name': '^woot.*'}) + search_opts={'ip': r'.*\.2$', 'name': '^woot.*'}) self.assertEqual(len(instances), 0) # ip matches all 3... ipv6 matches #2+#3...name matches #3 instances = self.compute_api.get_all(c, - search_opts={'ip': '.*\.1', + search_opts={'ip': r'.*\.1', 'name': 'not.*', 'ip6': '^.*12.*34.*'}) self.assertEqual(len(instances), 1) diff --git a/nova/tests/unit/conf_fixture.py b/nova/tests/unit/conf_fixture.py index 6e4f5a8ee2fa..3a6c6b3b6613 100644 --- a/nova/tests/unit/conf_fixture.py +++ b/nova/tests/unit/conf_fixture.py @@ -46,7 +46,7 @@ class ConfFixture(config_fixture.Config): # We should fix the tests to use real # UUIDs then drop this work around. self.conf.set_default('project_id_regex', - '[0-9a-fk\-]+', 'osapi_v21') + '[0-9a-fk-]+', 'osapi_v21') self.conf.set_default('use_ipv6', True) self.conf.set_default('vlan_interface', 'eth0') diff --git a/nova/tests/unit/objects/test_numa.py b/nova/tests/unit/objects/test_numa.py index db49106b3688..5db03a87d73e 100644 --- a/nova/tests/unit/objects/test_numa.py +++ b/nova/tests/unit/objects/test_numa.py @@ -60,9 +60,8 @@ class _TestNUMA(object): numacell.pin_cpus(set([2, 3])) self.assertEqual(set([4]), numacell.free_cpus) - expect_msg = ( - exception.CPUPinningUnknown.msg_fmt % {'requested': "\[1, 55\]", - 'cpuset': "\[1, 2, 3, 4\]"}) + expect_msg = exception.CPUPinningUnknown.msg_fmt % { + 'requested': r'\[1, 55\]', 'cpuset': r'\[1, 2, 3, 4\]'} with testtools.ExpectedException(exception.CPUPinningUnknown, expect_msg): numacell.pin_cpus(set([1, 55])) @@ -70,8 +69,8 @@ class _TestNUMA(object): self.assertRaises(exception.CPUPinningInvalid, numacell.pin_cpus, set([1, 4])) - expect_msg = (exception.CPUUnpinningUnknown.msg_fmt % - {'requested': "\[1, 55\]", 'cpuset': "\[1, 2, 3, 4\]"}) + expect_msg = exception.CPUUnpinningUnknown.msg_fmt % { + 'requested': r'\[1, 55\]', 'cpuset': r'\[1, 2, 3, 4\]'} with testtools.ExpectedException(exception.CPUUnpinningUnknown, expect_msg): numacell.unpin_cpus(set([1, 55])) diff --git a/nova/tests/unit/test_iptables_network.py b/nova/tests/unit/test_iptables_network.py index f8f1144b8c4a..45b0052a5923 100644 --- a/nova/tests/unit/test_iptables_network.py +++ b/nova/tests/unit/test_iptables_network.py @@ -143,7 +143,7 @@ class IptablesManagerTestCase(test.NoDBTestCase): table.add_rule('OUTPUT', '-d 10.10.10.11 -j DNAT --to 10.0.0.10') new_lines = self.manager._modify_rules(current_lines, table, 'nat') self.assertEqual(len(new_lines) - len(current_lines), 8) - regex = '.*\s+%s(/32|\s+|$)' + regex = r'.*\s+%s(/32|\s+|$)' num_removed = table.remove_rules_regex(regex % '10.10.10.10') self.assertEqual(num_removed, 4) new_lines = self.manager._modify_rules(current_lines, table, 'nat') diff --git a/nova/tests/unit/virt/libvirt/storage/test_rbd.py b/nova/tests/unit/virt/libvirt/storage/test_rbd.py index f6629b79f183..5464f1ba7b2c 100644 --- a/nova/tests/unit/virt/libvirt/storage/test_rbd.py +++ b/nova/tests/unit/virt/libvirt/storage/test_rbd.py @@ -23,7 +23,7 @@ from nova.virt.libvirt.storage import rbd_utils from nova.virt.libvirt import utils as libvirt_utils -CEPH_MON_DUMP = """dumped monmap epoch 1 +CEPH_MON_DUMP = r"""dumped monmap epoch 1 { "epoch": 1, "fsid": "33630410-6d93-4d66-8e42-3b953cf194aa", "modified": "2013-05-22 17:44:56.343618", diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 146d9194cffe..794a8a9c4f77 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -13171,8 +13171,8 @@ class LibvirtConnTestCase(test.NoDBTestCase, return None def fake_node_device_lookup_by_name(address): - pattern = ("pci_%(hex)s{4}_%(hex)s{2}_%(hex)s{2}_%(oct)s{1}" - % dict(hex='[\da-f]', oct='[0-8]')) + pattern = "pci_%(hex)s{4}_%(hex)s{2}_%(hex)s{2}_%(oct)s{1}" % { + 'hex': r'[\da-f]', 'oct': '[0-8]'} pattern = re.compile(pattern) if pattern.match(address) is None: raise fakelibvirt.libvirtError() @@ -15801,8 +15801,8 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.assertRaisesRegex( exception.InvalidNetworkNUMAAffinity, "Invalid NUMA network affinity configured: the physnet 'bar' " - "was listed in '\[neutron\] physnets' but no corresponding " - "'\[neutron_physnet_bar\] numa_nodes' option was defined.", + "was listed in '\\[neutron\\] physnets' but no corresponding " + "'\\[neutron_physnet_bar\\] numa_nodes' option was defined.", drvr._get_host_numa_topology) @mock.patch.object(host.Host, 'has_min_version', return_value=True) diff --git a/nova/tests/unit/virt/libvirt/test_firewall.py b/nova/tests/unit/virt/libvirt/test_firewall.py index 317e3695f1d1..07f458302c76 100644 --- a/nova/tests/unit/virt/libvirt/test_firewall.py +++ b/nova/tests/unit/virt/libvirt/test_firewall.py @@ -280,13 +280,13 @@ class IptablesFirewallTestCase(test.NoDBTestCase): self.assertTrue(security_group_chain, "The security group chain wasn't added") - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p icmp ' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p icmp ' '-s 192.168.11.0/24') match_rules = [rule for rule in self.out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, "ICMP acceptance rule wasn't added") - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p icmp -m icmp ' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p icmp -m icmp ' '--icmp-type 8 -s 192.168.11.0/24') match_rules = [rule for rule in self.out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, @@ -295,13 +295,13 @@ class IptablesFirewallTestCase(test.NoDBTestCase): for ip in network_model.fixed_ips(): if ip['version'] != 4: continue - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p tcp -m multiport ' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p tcp -m multiport ' '--dports 80:81 -s %s' % ip['address']) match_rules = [rule for rule in self.out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, "TCP port 80/81 acceptance rule wasn't added") - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -s ' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -s ' '%s' % ip['address']) match_rules = [rule for rule in self.out_rules if regex.match(rule)] @@ -309,7 +309,7 @@ class IptablesFirewallTestCase(test.NoDBTestCase): "Protocol/port-less acceptance rule" " wasn't added") - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p tcp ' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p tcp ' '-m multiport --dports 80:81 -s 192.168.10.0/24') match_rules = [rule for rule in self.out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, diff --git a/nova/tests/unit/virt/libvirt/volume/test_vzstorage.py b/nova/tests/unit/virt/libvirt/volume/test_vzstorage.py index 822ba08d6bd6..883cebb55a14 100644 --- a/nova/tests/unit/virt/libvirt/volume/test_vzstorage.py +++ b/nova/tests/unit/virt/libvirt/volume/test_vzstorage.py @@ -58,8 +58,9 @@ class LibvirtVZStorageTestCase(test_volume.LibvirtVolumeBaseTestCase): connection_info = {'data': {'export': wrong_export_string, 'name': self.name}} - err_pattern = ("^Valid share format is " - "\[mds\[,mds1\[\.\.\.\]\]:/\]clustername\[:password\]$") + err_pattern = ( + "^Valid share format is " + r"\[mds\[,mds1\[\.\.\.\]\]:/\]clustername\[:password\]$") self.assertRaisesRegex(exception.InvalidVolume, err_pattern, drv.connect_volume, diff --git a/nova/tests/unit/virt/test_hardware.py b/nova/tests/unit/virt/test_hardware.py index d5f11b5153aa..38ee3fb10350 100644 --- a/nova/tests/unit/virt/test_hardware.py +++ b/nova/tests/unit/virt/test_hardware.py @@ -1734,9 +1734,9 @@ class NUMATopologyTest(test.NoDBTestCase): self.assertEqual(hostusage.cells[1].memory_usage, 128) def test_topo_usage_with_network_metadata(self): - """Validate behavior with network_metadata. + r"""Validate behavior with network_metadata. - Ensure we handle ``NUMACell``\s that have ``network_metadata`` set + Ensure we handle ``NUMACell``\ s that have ``network_metadata`` set along with those where this is unset. """ diff --git a/nova/tests/unit/virt/vmwareapi/test_ds_util.py b/nova/tests/unit/virt/vmwareapi/test_ds_util.py index 1d502e64d551..ce10dc430fbf 100644 --- a/nova/tests/unit/virt/vmwareapi/test_ds_util.py +++ b/nova/tests/unit/virt/vmwareapi/test_ds_util.py @@ -311,7 +311,7 @@ class DsUtilTestCase(test.NoDBTestCase): def test_get_datastore_with_regex(self): # Test with a regex that matches with a datastore - datastore_valid_regex = re.compile("^openstack.*\d$") + datastore_valid_regex = re.compile(r"^openstack.*\d$") fake_objects = fake.FakeRetrieveResult() fake_objects.add_object(fake.Datastore("openstack-ds0")) fake_objects.add_object(fake.Datastore("fake-ds0")) @@ -323,7 +323,7 @@ class DsUtilTestCase(test.NoDBTestCase): self.assertEqual("openstack-ds0", result.name) def test_get_datastore_with_token(self): - regex = re.compile("^ds.*\d$") + regex = re.compile(r"^ds.*\d$") fake0 = fake.FakeRetrieveResult() fake0.add_object(fake.Datastore("ds0", 10 * units.Gi, 5 * units.Gi)) fake0.add_object(fake.Datastore("foo", 10 * units.Gi, 9 * units.Gi)) diff --git a/nova/tests/unit/virt/xenapi/test_xenapi.py b/nova/tests/unit/virt/xenapi/test_xenapi.py index 4c4db2ebe341..f699dddcf0fd 100644 --- a/nova/tests/unit/virt/xenapi/test_xenapi.py +++ b/nova/tests/unit/virt/xenapi/test_xenapi.py @@ -2935,19 +2935,19 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase): self.assertTrue(security_group_chain, "The security group chain wasn't added") - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p icmp' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p icmp' ' -s 192.168.11.0/24') match_rules = [rule for rule in self._out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, "ICMP acceptance rule wasn't added") - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p icmp -m icmp' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p icmp -m icmp' ' --icmp-type 8 -s 192.168.11.0/24') match_rules = [rule for rule in self._out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, "ICMP Echo Request acceptance rule wasn't added") - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p tcp --dport 80:81' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p tcp --dport 80:81' ' -s 192.168.10.0/24') match_rules = [rule for rule in self._out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, @@ -2991,7 +2991,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase): for ip in network_model.fixed_ips(): if ip['version'] != 4: continue - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p tcp' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p tcp' ' --dport 80:81 -s %s' % ip['address']) match_rules = [rule for rule in self._out_rules if regex.match(rule)] @@ -3063,7 +3063,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase): 'cidr': '192.168.99.0/24'}) # validate the extra rule self.fw.refresh_security_group_rules(secgroup) - regex = re.compile('\[0\:0\] -A .* -j ACCEPT -p udp --dport 200:299' + regex = re.compile(r'\[0\:0\] -A .* -j ACCEPT -p udp --dport 200:299' ' -s 192.168.99.0/24') match_rules = [rule for rule in self._out_rules if regex.match(rule)] self.assertGreater(len(match_rules), 0, diff --git a/nova/utils.py b/nova/utils.py index 7f453cfca837..71d50f2d4b9c 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -515,7 +515,7 @@ def sanitize_hostname(hostname, default_name=None): hostname = truncate_hostname(hostname) hostname = re.sub('[ _]', '-', hostname) - hostname = re.sub('[^\w.-]+', '', hostname) + hostname = re.sub(r'[^\w.-]+', '', hostname) hostname = hostname.lower() hostname = hostname.strip('.-') # NOTE(eliqiao): set hostname to default_display_name to avoid diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py index 2720e832bcee..77c8f07df1c5 100644 --- a/nova/virt/vmwareapi/driver.py +++ b/nova/virt/vmwareapi/driver.py @@ -88,7 +88,7 @@ class VMwareVCDriver(driver.ComputeDriver): # We assume consists of alphanumeric, _ and -. # We assume cluster name is everything between the first ( and the last ). # We pull out for re-use. - LEGACY_NODENAME = re.compile('([\w-]+)\(.+\)') + LEGACY_NODENAME = re.compile(r'([\w-]+)\(.+\)') # The vCenter driver includes API that acts on ESX hosts or groups # of ESX hosts in clusters or non-cluster logical-groupings. diff --git a/nova/virt/vmwareapi/network_util.py b/nova/virt/vmwareapi/network_util.py index c3169a8b5e47..f62ecd405f81 100644 --- a/nova/virt/vmwareapi/network_util.py +++ b/nova/virt/vmwareapi/network_util.py @@ -35,7 +35,7 @@ LOG = logging.getLogger(__name__) # Examples: # - vxw-dvs-22-virtualwire-89-sid-5008-NAME # - vxw-dvs-22-virtualwire-89-sid-5008-UUID -VWIRE_REGEX = re.compile('vxw-dvs-(\d+)-virtualwire-(\d+)-sid-(\d+)-(.*)') +VWIRE_REGEX = re.compile(r'vxw-dvs-(\d+)-virtualwire-(\d+)-sid-(\d+)-(.*)') def _get_name_from_dvs_name(dvs_name): diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index a191e2f95b7b..cf140a5fe6dd 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -161,7 +161,7 @@ class HostState(object): :returns: a list of pci devices on the node """ def _compile_hex(pattern): - """Return a compiled regular expression pattern into which we have + r"""Return a compiled regular expression pattern into which we have replaced occurrences of hex by [\da-fA-F]. """ return re.compile(pattern.replace("hex", r"[\da-fA-F]")) diff --git a/tox.ini b/tox.ini index 22aa1760531c..657eaf0dde36 100644 --- a/tox.ini +++ b/tox.ini @@ -237,10 +237,10 @@ commands = bandit -r nova -x tests -n 5 -ll # # W504 skipped since you must choose either W503 or W504 (they conflict) # -# W605 and E731 temporarily skipped because of the number of +# E731 temporarily skipped because of the number of # these that have to be fixed enable-extensions = H106,H203,H904 -ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405,W504,W605,E731 +ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405,W504,E731 exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,tools/xenserver*,releasenotes # To get a list of functions that are more complex than 25, set max-complexity # to 25 and run 'tox -epep8'.