From 7f4a6211bfd3ba68410b7911271155258ee71297 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 6 Jul 2018 13:58:21 +0100 Subject: [PATCH] Mark raw strings as such This is raising warnings now and will be an error in future versions of Python 3. Change-Id: I8827cb36ef2ef85e8f245a2a181fb23ee75bfd16 --- tempest/api/compute/keypairs/test_keypairs_negative.py | 2 +- tempest/api/compute/servers/test_list_server_filters.py | 2 +- tempest/api/network/admin/test_negative_quotas.py | 2 +- tempest/cmd/account_generator.py | 1 + tempest/cmd/init.py | 2 +- tempest/cmd/subunit_describe_calls.py | 2 +- tempest/cmd/verify_tempest_config.py | 1 + tempest/common/credentials_factory.py | 1 + tempest/common/custom_matchers.py | 4 ++-- tempest/common/utils/__init__.py | 1 + tempest/hacking/checks.py | 4 ++-- .../api_schema/response/compute/v2_1/flavors_extra_specs.py | 4 ++-- tempest/lib/api_schema/response/compute/v2_47/servers.py | 2 +- tempest/lib/cli/output_parser.py | 2 +- tempest/lib/cmd/check_uuid.py | 1 + tempest/tests/common/utils/linux/test_remote_client.py | 2 +- tempest/tests/fake_config.py | 1 + tempest/tests/lib/common/utils/test_data_utils.py | 2 +- tempest/tests/test_list_tests.py | 2 +- tools/check_logs.py | 3 ++- tools/generate-tempest-plugins-list.py | 3 ++- 21 files changed, 26 insertions(+), 18 deletions(-) diff --git a/tempest/api/compute/keypairs/test_keypairs_negative.py b/tempest/api/compute/keypairs/test_keypairs_negative.py index f9050a87ea..81635caafb 100644 --- a/tempest/api/compute/keypairs/test_keypairs_negative.py +++ b/tempest/api/compute/keypairs/test_keypairs_negative.py @@ -84,6 +84,6 @@ class KeyPairsNegativeTestJSON(base.BaseKeypairTest): @decorators.idempotent_id('45fbe5e0-acb5-49aa-837a-ff8d0719db91') def test_create_keypair_invalid_name(self): # Keypairs with name being an invalid name should not be created - k_name = 'key_/.\@:' + k_name = r'key_/.\@:' self.assertRaises(lib_exc.BadRequest, self.create_keypair, k_name) diff --git a/tempest/api/compute/servers/test_list_server_filters.py b/tempest/api/compute/servers/test_list_server_filters.py index 14aecfda5a..3dffd01e4c 100644 --- a/tempest/api/compute/servers/test_list_server_filters.py +++ b/tempest/api/compute/servers/test_list_server_filters.py @@ -227,7 +227,7 @@ class ListServerFiltersTestJSON(base.BaseV2ComputeTest): @decorators.idempotent_id('24a89b0c-0d55-4a28-847f-45075f19b27b') def test_list_servers_filtered_by_name_regex(self): # list of regex that should match s1, s2 and s3 - regexes = ['^.*\-instance\-[0-9]+$', '^.*\-instance\-.*$'] + regexes = [r'^.*\-instance\-[0-9]+$', r'^.*\-instance\-.*$'] for regex in regexes: params = {'name': regex} body = self.client.list_servers(**params) diff --git a/tempest/api/network/admin/test_negative_quotas.py b/tempest/api/network/admin/test_negative_quotas.py index 6849653be9..e79f8c3d6b 100644 --- a/tempest/api/network/admin/test_negative_quotas.py +++ b/tempest/api/network/admin/test_negative_quotas.py @@ -59,7 +59,7 @@ class QuotasNegativeTest(base.BaseAdminNetworkTest): # Try to create a third network while the quota is two with self.assertRaisesRegex( lib_exc.Conflict, - "Quota exceeded for resources: \['network'\].*"): + r"Quota exceeded for resources: \['network'\].*"): n3 = self.networks_client.create_network() self.addCleanup(self.networks_client.delete_network, n3['network']['id']) diff --git a/tempest/cmd/account_generator.py b/tempest/cmd/account_generator.py index 1c671eceb8..9be8ee260f 100755 --- a/tempest/cmd/account_generator.py +++ b/tempest/cmd/account_generator.py @@ -311,5 +311,6 @@ def main(opts=None): resources.extend(generate_resources(cred_provider, opts.admin)) dump_accounts(resources, opts.identity_version, opts.accounts) + if __name__ == "__main__": main() diff --git a/tempest/cmd/init.py b/tempest/cmd/init.py index 84c8631404..d84f3a3345 100644 --- a/tempest/cmd/init.py +++ b/tempest/cmd/init.py @@ -26,7 +26,7 @@ from tempest.cmd import workspace LOG = logging.getLogger(__name__) -STESTR_CONF = """[DEFAULT] +STESTR_CONF = r"""[DEFAULT] test_path=%s top_dir=%s group_regex=([^\.]*\.)* diff --git a/tempest/cmd/subunit_describe_calls.py b/tempest/cmd/subunit_describe_calls.py index a4402feea8..8dcf575ae6 100644 --- a/tempest/cmd/subunit_describe_calls.py +++ b/tempest/cmd/subunit_describe_calls.py @@ -95,7 +95,7 @@ class UrlParser(testtools.TestResult): ip_re = re.compile(r'(^|[^0-9])[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]' '{1,3}([^0-9]|$)') url_re = re.compile(r'.*INFO.*Request \((?P.*)\): (?P[\d]{3}) ' - '(?P\w*) (?P.*) .*') + r'(?P\w*) (?P.*) .*') port_re = re.compile(r'.*:(?P\d+).*') path_re = re.compile(r'http[s]?://[^/]*/(?P.*)') request_re = re.compile(r'.* Request - Headers: (?P.*)') diff --git a/tempest/cmd/verify_tempest_config.py b/tempest/cmd/verify_tempest_config.py index 15af27123d..aa333b3022 100644 --- a/tempest/cmd/verify_tempest_config.py +++ b/tempest/cmd/verify_tempest_config.py @@ -488,5 +488,6 @@ class TempestVerifyConfig(command.Command): traceback.print_exc() raise + if __name__ == "__main__": main() diff --git a/tempest/common/credentials_factory.py b/tempest/common/credentials_factory.py index 75db155693..c6e5dcb85e 100644 --- a/tempest/common/credentials_factory.py +++ b/tempest/common/credentials_factory.py @@ -210,6 +210,7 @@ def is_alt_available(identity_version): except exceptions.InvalidConfiguration: return False + # === Credentials # Type of credentials available from configuration diff --git a/tempest/common/custom_matchers.py b/tempest/common/custom_matchers.py index ed11b21ef5..c702d88963 100644 --- a/tempest/common/custom_matchers.py +++ b/tempest/common/custom_matchers.py @@ -225,9 +225,9 @@ class AreAllWellFormatted(object): elif key in ('content-type', 'date', 'last-modified', 'x-copied-from-last-modified') and not value: return InvalidFormat(key, value) - elif key == 'x-timestamp' and not re.match("^\d+\.?\d*\Z", value): + elif key == 'x-timestamp' and not re.match(r"^\d+\.?\d*\Z", value): return InvalidFormat(key, value) - elif key == 'x-copied-from' and not re.match("\S+/\S+", value): + elif key == 'x-copied-from' and not re.match(r"\S+/\S+", value): return InvalidFormat(key, value) elif key == 'x-trans-id' and \ not re.match("^tx[0-9a-f]{21}-[0-9a-f]{10}.*", value): diff --git a/tempest/common/utils/__init__.py b/tempest/common/utils/__init__.py index 225a713ee2..167bf5b5a8 100644 --- a/tempest/common/utils/__init__.py +++ b/tempest/common/utils/__init__.py @@ -40,6 +40,7 @@ class DataUtils(object): self.__dict__[attr] = attr_obj return attr_obj + data_utils = DataUtils() diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py index b6e7f8c245..a57a360880 100644 --- a/tempest/hacking/checks.py +++ b/tempest/hacking/checks.py @@ -287,10 +287,10 @@ def dont_put_admin_tests_on_nonadmin_path(logical_line, physical_line, if pep8.noqa(physical_line): return - if not re.match('class .*Test.*\(.*Admin.*\):', logical_line): + if not re.match(r'class .*Test.*\(.*Admin.*\):', logical_line): return - if not re.match('.\/tempest\/api\/.*\/admin\/.*', filename): + if not re.match(r'.\/tempest\/api\/.*\/admin\/.*', filename): msg = 'T115: All admin tests should exist under admin path.' yield(0, msg) diff --git a/tempest/lib/api_schema/response/compute/v2_1/flavors_extra_specs.py b/tempest/lib/api_schema/response/compute/v2_1/flavors_extra_specs.py index a438d48694..483fd68450 100644 --- a/tempest/lib/api_schema/response/compute/v2_1/flavors_extra_specs.py +++ b/tempest/lib/api_schema/response/compute/v2_1/flavors_extra_specs.py @@ -20,7 +20,7 @@ set_get_flavor_extra_specs = { 'extra_specs': { 'type': 'object', 'patternProperties': { - '^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'} + r'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'} } } }, @@ -34,7 +34,7 @@ set_get_flavor_extra_specs_key = { 'response_body': { 'type': 'object', 'patternProperties': { - '^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'} + r'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'} } } } diff --git a/tempest/lib/api_schema/response/compute/v2_47/servers.py b/tempest/lib/api_schema/response/compute/v2_47/servers.py index 935be7050f..5d6d4c3602 100644 --- a/tempest/lib/api_schema/response/compute/v2_47/servers.py +++ b/tempest/lib/api_schema/response/compute/v2_47/servers.py @@ -26,7 +26,7 @@ flavor = { 'extra_specs': { 'type': 'object', 'patternProperties': { - '^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'} + r'^[a-zA-Z0-9_\-\. :]+$': {'type': 'string'} } } }, diff --git a/tempest/lib/cli/output_parser.py b/tempest/lib/cli/output_parser.py index a7d5e495c3..45d41c7231 100644 --- a/tempest/lib/cli/output_parser.py +++ b/tempest/lib/cli/output_parser.py @@ -25,7 +25,7 @@ from tempest.lib import exceptions LOG = logging.getLogger(__name__) -delimiter_line = re.compile('^\+\-[\+\-]+\-\+$') +delimiter_line = re.compile(r'^\+\-[\+\-]+\-\+$') def details_multiple(output_lines, with_label=False): diff --git a/tempest/lib/cmd/check_uuid.py b/tempest/lib/cmd/check_uuid.py index d1f0888853..82fcd0b86a 100755 --- a/tempest/lib/cmd/check_uuid.py +++ b/tempest/lib/cmd/check_uuid.py @@ -358,5 +358,6 @@ def run(): "Run 'tox -v -e uuidgen' to automatically fix tests with\n" "missing @decorators.idempotent_id decorators.") + if __name__ == '__main__': run() diff --git a/tempest/tests/common/utils/linux/test_remote_client.py b/tempest/tests/common/utils/linux/test_remote_client.py index 739357babc..1f0080fa86 100644 --- a/tempest/tests/common/utils/linux/test_remote_client.py +++ b/tempest/tests/common/utils/linux/test_remote_client.py @@ -77,7 +77,7 @@ class TestRemoteClient(base.TestCase): def test_write_to_console_special_chars(self): self._test_write_to_console_helper( - '\`', + r'\`', 'sudo sh -c "echo \\"\\\\\\`\\" >/dev/console"') self.conn.write_to_console('$') self._assert_exec_called_with( diff --git a/tempest/tests/fake_config.py b/tempest/tests/fake_config.py index 4a2fff42d3..be54130818 100644 --- a/tempest/tests/fake_config.py +++ b/tempest/tests/fake_config.py @@ -59,6 +59,7 @@ class FakePrivate(config.TempestConfigPrivate): self._set_attrs() self.lock_path = cfg.CONF.oslo_concurrency.lock_path + fake_service1_group = cfg.OptGroup(name='fake-service1', title='Fake service1') FakeService1Group = [ diff --git a/tempest/tests/lib/common/utils/test_data_utils.py b/tempest/tests/lib/common/utils/test_data_utils.py index b8385b2a86..a0267d0c78 100644 --- a/tempest/tests/lib/common/utils/test_data_utils.py +++ b/tempest/tests/lib/common/utils/test_data_utils.py @@ -88,7 +88,7 @@ class TestDataUtils(base.TestCase): def test_rand_url(self): actual = data_utils.rand_url() self.assertIsInstance(actual, str) - self.assertRegex(actual, "^https://url-[0-9]*\.com$") + self.assertRegex(actual, r"^https://url-[0-9]*\.com$") actual2 = data_utils.rand_url() self.assertNotEqual(actual, actual2) diff --git a/tempest/tests/test_list_tests.py b/tempest/tests/test_list_tests.py index 4af74630d5..1cc9c9a417 100644 --- a/tempest/tests/test_list_tests.py +++ b/tempest/tests/test_list_tests.py @@ -34,7 +34,7 @@ class TestTestList(base.TestCase): "error on import %s" % ids) ids = six.text_type(ids).split('\n') for test_id in ids: - if re.match('(\w+\.){3}\w+', test_id): + if re.match(r'(\w+\.){3}\w+', test_id): if not test_id.startswith('tempest.'): parts = test_id.partition('tempest') fail_id = parts[1] + parts[2] diff --git a/tools/check_logs.py b/tools/check_logs.py index b80ccc010f..de7e41d958 100755 --- a/tools/check_logs.py +++ b/tools/check_logs.py @@ -96,7 +96,7 @@ def scan_content(content, regexp, whitelist): def collect_url_logs(url): page = urlreq.urlopen(url) content = page.read() - logs = re.findall('(screen-[\w-]+\.txt\.gz)', content) + logs = re.findall(r'(screen-[\w-]+\.txt\.gz)', content) return logs @@ -162,6 +162,7 @@ def main(opts): print("ok") return 0 + usage = """ Find non-white-listed log errors in log files from a devstack-gate run. Log files will be searched for ERROR or CRITICAL messages. If any diff --git a/tools/generate-tempest-plugins-list.py b/tools/generate-tempest-plugins-list.py index bbb9019442..4eb78fb05e 100644 --- a/tools/generate-tempest-plugins-list.py +++ b/tools/generate-tempest-plugins-list.py @@ -63,12 +63,13 @@ def has_tempest_plugin(proj): except HTTPError as err: if err.code == 404: return False - p = re.compile('^tempest\.test_plugins', re.M) + p = re.compile(r'^tempest\.test_plugins', re.M) if p.findall(r.read().decode('utf-8')): return True else: False + r = urllib.urlopen(url) # Gerrit prepends 4 garbage octets to the JSON, in order to counter # cross-site scripting attacks. Therefore we must discard it so the