Merge "Add hacking check for line continuation backslash"
This commit is contained in:
commit
a95d0920c3
|
@ -46,11 +46,12 @@ def random_blacklist(name='testblacklist'):
|
||||||
|
|
||||||
|
|
||||||
def random_zone_file(name='testzoneimport'):
|
def random_zone_file(name='testzoneimport'):
|
||||||
return "$ORIGIN {0}{1}.com.\n" \
|
return ("$ORIGIN {0}{1}.com.\n"
|
||||||
"$TTL 300\n" \
|
"$TTL 300\n"
|
||||||
"{0}{1}.com. 300 IN SOA ns.{0}{1}.com. " \
|
"{0}{1}.com. 300 IN SOA ns.{0}{1}.com. "
|
||||||
"nsadmin.{0}{1}.com. 42 42 42 42 42\n" \
|
"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 NS ns.{0}{1}.com.\n"
|
||||||
"{0}{1}.com. 300 IN MX 10 mail.{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" \
|
"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())
|
"mail.{0}{1}.com. 300 IN A 10.0.0.2\n".format(name,
|
||||||
|
random_digits()))
|
||||||
|
|
|
@ -101,9 +101,9 @@ class TestRecordset(BaseDesignateTest):
|
||||||
class TestRecordsetNegative(BaseDesignateTest):
|
class TestRecordsetNegative(BaseDesignateTest):
|
||||||
|
|
||||||
def test_invalid_option_on_recordset_create(self):
|
def test_invalid_option_on_recordset_create(self):
|
||||||
cmd = 'recordset create de47d30b-41c5-4e38-b2c5-e0b908e19ec7 ' \
|
cmd = ('recordset create de47d30b-41c5-4e38-b2c5-e0b908e19ec7 '
|
||||||
'aaa.desig.com. --type A --records 1.2.3.4 ' \
|
'aaa.desig.com. --type A --records 1.2.3.4 '
|
||||||
'--invalid "not valid"'
|
'--invalid "not valid"')
|
||||||
self.assertRaises(CommandFailed, self.clients.openstack, cmd)
|
self.assertRaises(CommandFailed, self.clients.openstack, cmd)
|
||||||
|
|
||||||
def test_invalid_recordset_command(self):
|
def test_invalid_recordset_command(self):
|
||||||
|
|
|
@ -27,6 +27,7 @@ import pycodestyle
|
||||||
# D708: Do not use xrange. Use range for large loops.
|
# D708: Do not use xrange. Use range for large loops.
|
||||||
# D709: LOG.audit is deprecated, please use LOG.info!
|
# D709: LOG.audit is deprecated, please use LOG.info!
|
||||||
# D710: LOG.warn() is not allowed. Use LOG.warning()
|
# D710: LOG.warn() is not allowed. Use LOG.warning()
|
||||||
|
# D711: Don't use backslashes for line continuation.
|
||||||
|
|
||||||
UNDERSCORE_IMPORT_FILES = []
|
UNDERSCORE_IMPORT_FILES = []
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ graduated_oslo_libraries_import_re = re.compile(
|
||||||
r"^\s*(?:import|from) designate\.openstack\.common\.?.*?"
|
r"^\s*(?:import|from) designate\.openstack\.common\.?.*?"
|
||||||
r"(gettextutils|rpc)"
|
r"(gettextutils|rpc)"
|
||||||
r".*?")
|
r".*?")
|
||||||
|
no_line_continuation_backslash_re = re.compile(r'.*(\\)\n')
|
||||||
|
|
||||||
|
|
||||||
@core.flake8ext
|
@core.flake8ext
|
||||||
|
@ -161,3 +163,25 @@ def check_no_log_warn(logical_line):
|
||||||
"""
|
"""
|
||||||
if logical_line.startswith('LOG.warn('):
|
if logical_line.startswith('LOG.warn('):
|
||||||
yield(0, "D710:Use LOG.warning() rather than 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
|
||||||
|
|
|
@ -42,8 +42,8 @@ def get_item_properties(item, fields, mixed_case_fields=(), formatters=None):
|
||||||
field_name = field.replace(' ', '_')
|
field_name = field.replace(' ', '_')
|
||||||
else:
|
else:
|
||||||
field_name = field.lower().replace(' ', '_')
|
field_name = field.lower().replace(' ', '_')
|
||||||
if not hasattr(item, field_name) and \
|
if (not hasattr(item, field_name) and
|
||||||
(isinstance(item, dict) and field_name in item):
|
(isinstance(item, dict) and field_name in item)):
|
||||||
data = item[field_name]
|
data = item[field_name]
|
||||||
else:
|
else:
|
||||||
data = getattr(item, field_name, '')
|
data = getattr(item, field_name, '')
|
||||||
|
|
|
@ -74,20 +74,20 @@ def set_hard_delete(client, value):
|
||||||
|
|
||||||
def set_all_common_headers(client, parsed_args):
|
def set_all_common_headers(client, parsed_args):
|
||||||
|
|
||||||
if parsed_args.all_projects is not None and \
|
if (parsed_args.all_projects is not None and
|
||||||
isinstance(parsed_args.all_projects, bool):
|
isinstance(parsed_args.all_projects, bool)):
|
||||||
set_all_projects(client, parsed_args.all_projects)
|
set_all_projects(client, parsed_args.all_projects)
|
||||||
|
|
||||||
if hasattr(parsed_args, 'edit_managed') and \
|
if (hasattr(parsed_args, 'edit_managed') and
|
||||||
parsed_args.edit_managed is not None and \
|
parsed_args.edit_managed is not None and
|
||||||
isinstance(parsed_args.edit_managed, bool):
|
isinstance(parsed_args.edit_managed, bool)):
|
||||||
set_edit_managed(client, parsed_args.edit_managed)
|
set_edit_managed(client, parsed_args.edit_managed)
|
||||||
|
|
||||||
if parsed_args.sudo_project_id is not None and \
|
if (parsed_args.sudo_project_id is not None and
|
||||||
isinstance(parsed_args.sudo_project_id, str):
|
isinstance(parsed_args.sudo_project_id, str)):
|
||||||
set_sudo_project_id(client, parsed_args.sudo_project_id)
|
set_sudo_project_id(client, parsed_args.sudo_project_id)
|
||||||
|
|
||||||
if hasattr(parsed_args, 'hard_delete') and \
|
if (hasattr(parsed_args, 'hard_delete') and
|
||||||
parsed_args.hard_delete is not None and \
|
parsed_args.hard_delete is not None and
|
||||||
isinstance(parsed_args.hard_delete, bool):
|
isinstance(parsed_args.hard_delete, bool)):
|
||||||
set_hard_delete(client, parsed_args.hard_delete)
|
set_hard_delete(client, parsed_args.hard_delete)
|
||||||
|
|
|
@ -159,8 +159,8 @@ class CreateZoneCommand(command.ShowOne):
|
||||||
k, v = attr.split(':')
|
k, v = attr.split(':')
|
||||||
payload["attributes"][k] = v
|
payload["attributes"][k] = v
|
||||||
except ValueError:
|
except ValueError:
|
||||||
msg = "Attribute '%s' is in an incorrect format. "\
|
msg = ("Attribute '%s' is in an incorrect format. "
|
||||||
"Attributes are <key>:<value> formated"
|
"Attributes are <key>:<value> formated")
|
||||||
raise osc_exc.CommandError(msg % attr)
|
raise osc_exc.CommandError(msg % attr)
|
||||||
|
|
||||||
if parsed_args.type == 'PRIMARY':
|
if parsed_args.type == 'PRIMARY':
|
||||||
|
@ -177,8 +177,8 @@ class CreateZoneCommand(command.ShowOne):
|
||||||
elif parsed_args.type == 'SECONDARY':
|
elif parsed_args.type == 'SECONDARY':
|
||||||
payload["masters"] = parsed_args.masters
|
payload["masters"] = parsed_args.masters
|
||||||
else:
|
else:
|
||||||
msg = "Type %s is not supported. Please choose between " \
|
msg = ("Type %s is not supported. Please choose between "
|
||||||
"PRIMARY or SECONDARY"
|
"PRIMARY or SECONDARY")
|
||||||
raise osc_exc.CommandError(msg % parsed_args.type)
|
raise osc_exc.CommandError(msg % parsed_args.type)
|
||||||
|
|
||||||
data = client.zones.create(
|
data = client.zones.create(
|
||||||
|
|
|
@ -24,8 +24,8 @@ class RecordSetController(V2Controller):
|
||||||
zone_info = None
|
zone_info = None
|
||||||
|
|
||||||
# If we get a zone name we'll need to get the ID of it before POST.
|
# If we get a zone name we'll need to get the ID of it before POST.
|
||||||
if isinstance(zone, str) and not \
|
if (isinstance(zone, str) and not
|
||||||
uuidutils.is_uuid_like(zone):
|
uuidutils.is_uuid_like(zone)):
|
||||||
zone_info = self.client.zones.get(zone)
|
zone_info = self.client.zones.get(zone)
|
||||||
elif isinstance(zone, dict):
|
elif isinstance(zone, dict):
|
||||||
zone_info = zone
|
zone_info = zone
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -112,4 +112,5 @@ extension =
|
||||||
D708 = checks:check_python3_xrange
|
D708 = checks:check_python3_xrange
|
||||||
D709 = checks:check_no_log_audit
|
D709 = checks:check_no_log_audit
|
||||||
D710 = checks:check_no_log_warn
|
D710 = checks:check_no_log_warn
|
||||||
|
D711 = checks:check_line_continuation_no_backslash
|
||||||
paths = ./designateclient/hacking
|
paths = ./designateclient/hacking
|
||||||
|
|
Loading…
Reference in New Issue