Merge "Add hacking check for line continuation backslash"

This commit is contained in:
Zuul 2023-02-21 05:29:36 +00:00 committed by Gerrit Code Review
commit a95d0920c3
8 changed files with 55 additions and 29 deletions

View File

@ -46,11 +46,12 @@ def random_blacklist(name='testblacklist'):
def random_zone_file(name='testzoneimport'):
return "$ORIGIN {0}{1}.com.\n" \
"$TTL 300\n" \
"{0}{1}.com. 300 IN SOA ns.{0}{1}.com. " \
"nsadmin.{0}{1}.com. 42 42 42 42 42\n" \
"{0}{1}.com. 300 IN NS ns.{0}{1}.com.\n" \
"{0}{1}.com. 300 IN MX 10 mail.{0}{1}.com.\n" \
"ns.{0}{1}.com. 300 IN A 10.0.0.1\n" \
"mail.{0}{1}.com. 300 IN A 10.0.0.2\n".format(name, random_digits())
return ("$ORIGIN {0}{1}.com.\n"
"$TTL 300\n"
"{0}{1}.com. 300 IN SOA ns.{0}{1}.com. "
"nsadmin.{0}{1}.com. 42 42 42 42 42\n"
"{0}{1}.com. 300 IN NS ns.{0}{1}.com.\n"
"{0}{1}.com. 300 IN MX 10 mail.{0}{1}.com.\n"
"ns.{0}{1}.com. 300 IN A 10.0.0.1\n"
"mail.{0}{1}.com. 300 IN A 10.0.0.2\n".format(name,
random_digits()))

View File

@ -101,9 +101,9 @@ class TestRecordset(BaseDesignateTest):
class TestRecordsetNegative(BaseDesignateTest):
def test_invalid_option_on_recordset_create(self):
cmd = 'recordset create de47d30b-41c5-4e38-b2c5-e0b908e19ec7 ' \
'aaa.desig.com. --type A --records 1.2.3.4 ' \
'--invalid "not valid"'
cmd = ('recordset create de47d30b-41c5-4e38-b2c5-e0b908e19ec7 '
'aaa.desig.com. --type A --records 1.2.3.4 '
'--invalid "not valid"')
self.assertRaises(CommandFailed, self.clients.openstack, cmd)
def test_invalid_recordset_command(self):

View File

@ -27,6 +27,7 @@ import pycodestyle
# D708: Do not use xrange. Use range for large loops.
# D709: LOG.audit is deprecated, please use LOG.info!
# D710: LOG.warn() is not allowed. Use LOG.warning()
# D711: Don't use backslashes for line continuation.
UNDERSCORE_IMPORT_FILES = []
@ -44,6 +45,7 @@ graduated_oslo_libraries_import_re = re.compile(
r"^\s*(?:import|from) designate\.openstack\.common\.?.*?"
r"(gettextutils|rpc)"
r".*?")
no_line_continuation_backslash_re = re.compile(r'.*(\\)\n')
@core.flake8ext
@ -161,3 +163,25 @@ def check_no_log_warn(logical_line):
"""
if logical_line.startswith('LOG.warn('):
yield(0, "D710:Use LOG.warning() rather than LOG.warn()")
@core.flake8ext
def check_line_continuation_no_backslash(logical_line, tokens):
"""D711 - Don't use backslashes for line continuation.
:param logical_line: The logical line to check. Not actually used.
:param tokens: List of tokens to check.
:returns: None if the tokens don't contain any issues, otherwise a tuple
is yielded that contains the offending index in the logical
line and a message describe the check validation failure.
"""
backslash = None
for token_type, text, start, end, orig_line in tokens:
m = no_line_continuation_backslash_re.match(orig_line)
if m:
backslash = (start[0], m.start(1))
break
if backslash is not None:
msg = 'D711 Backslash line continuations not allowed'
yield backslash, msg

View File

@ -42,8 +42,8 @@ def get_item_properties(item, fields, mixed_case_fields=(), formatters=None):
field_name = field.replace(' ', '_')
else:
field_name = field.lower().replace(' ', '_')
if not hasattr(item, field_name) and \
(isinstance(item, dict) and field_name in item):
if (not hasattr(item, field_name) and
(isinstance(item, dict) and field_name in item)):
data = item[field_name]
else:
data = getattr(item, field_name, '')

View File

@ -74,20 +74,20 @@ def set_hard_delete(client, value):
def set_all_common_headers(client, parsed_args):
if parsed_args.all_projects is not None and \
isinstance(parsed_args.all_projects, bool):
if (parsed_args.all_projects is not None and
isinstance(parsed_args.all_projects, bool)):
set_all_projects(client, parsed_args.all_projects)
if hasattr(parsed_args, 'edit_managed') and \
parsed_args.edit_managed is not None and \
isinstance(parsed_args.edit_managed, bool):
if (hasattr(parsed_args, 'edit_managed') and
parsed_args.edit_managed is not None and
isinstance(parsed_args.edit_managed, bool)):
set_edit_managed(client, parsed_args.edit_managed)
if parsed_args.sudo_project_id is not None and \
isinstance(parsed_args.sudo_project_id, str):
if (parsed_args.sudo_project_id is not None and
isinstance(parsed_args.sudo_project_id, str)):
set_sudo_project_id(client, parsed_args.sudo_project_id)
if hasattr(parsed_args, 'hard_delete') and \
parsed_args.hard_delete is not None and \
isinstance(parsed_args.hard_delete, bool):
if (hasattr(parsed_args, 'hard_delete') and
parsed_args.hard_delete is not None and
isinstance(parsed_args.hard_delete, bool)):
set_hard_delete(client, parsed_args.hard_delete)

View File

@ -159,8 +159,8 @@ class CreateZoneCommand(command.ShowOne):
k, v = attr.split(':')
payload["attributes"][k] = v
except ValueError:
msg = "Attribute '%s' is in an incorrect format. "\
"Attributes are <key>:<value> formated"
msg = ("Attribute '%s' is in an incorrect format. "
"Attributes are <key>:<value> formated")
raise osc_exc.CommandError(msg % attr)
if parsed_args.type == 'PRIMARY':
@ -177,8 +177,8 @@ class CreateZoneCommand(command.ShowOne):
elif parsed_args.type == 'SECONDARY':
payload["masters"] = parsed_args.masters
else:
msg = "Type %s is not supported. Please choose between " \
"PRIMARY or SECONDARY"
msg = ("Type %s is not supported. Please choose between "
"PRIMARY or SECONDARY")
raise osc_exc.CommandError(msg % parsed_args.type)
data = client.zones.create(

View File

@ -24,8 +24,8 @@ class RecordSetController(V2Controller):
zone_info = None
# If we get a zone name we'll need to get the ID of it before POST.
if isinstance(zone, str) and not \
uuidutils.is_uuid_like(zone):
if (isinstance(zone, str) and not
uuidutils.is_uuid_like(zone)):
zone_info = self.client.zones.get(zone)
elif isinstance(zone, dict):
zone_info = zone

View File

@ -112,4 +112,5 @@ extension =
D708 = checks:check_python3_xrange
D709 = checks:check_no_log_audit
D710 = checks:check_no_log_warn
D711 = checks:check_line_continuation_no_backslash
paths = ./designateclient/hacking