Bump hacking

hacking 3.0.x is too old.

Also fix failures detected by the new hacking version.

Change-Id: Ifccbbf2ff7b0824d2079937526d3eee1c536349b
This commit is contained in:
Takashi Kajinami 2024-01-17 01:12:45 +09:00
parent a9ccce8b0c
commit 813f229a08
21 changed files with 50 additions and 58 deletions

View File

@ -50,8 +50,8 @@ done in the OpenStack CI systems.
Heat Specific Commandments
--------------------------
- [Heat301] Use LOG.warning() rather than LOG.warn().
- [Heat302] Python 3: do not use dict.iteritems.
- [Heat303] Python 3: do not use dict.iterkeys.
- [Heat304] Python 3: do not use dict.itervalues.
- [HE301] Use LOG.warning() rather than LOG.warn().
- [HE302] Python 3: do not use dict.iteritems.
- [HE303] Python 3: do not use dict.iterkeys.
- [HE304] Python 3: do not use dict.itervalues.

View File

@ -19,7 +19,7 @@ import sys
def list_types():
return(["text/x-cfninitdata"])
return ["text/x-cfninitdata"]
def handle_part(data, ctype, filename, payload):

View File

@ -277,7 +277,7 @@ class KsClientWrapper(object):
return trust_context
def _get_username(self, username):
if(len(username) > 255):
if len(username) > 255:
LOG.warning("Truncating the username %s to the last 255 "
"characters.", username)
# get the last 255 characters of the username

View File

@ -809,7 +809,7 @@ class Resource(status.ResourceStatus):
if endpoint_exists:
req_extension = cls.required_service_extension
if not req_extension:
return(True, None)
return (True, None)
if isinstance(req_extension, str):
req_extension = re.split(' |,', req_extension)
for ext in req_extension:

View File

@ -545,7 +545,7 @@ class Port(neutron.NeutronResource):
).get_secgroup_uuids(['default'])
if self.REPLACEMENT_POLICY in props:
del(props[self.REPLACEMENT_POLICY])
del props[self.REPLACEMENT_POLICY]
def _store_config_default_properties(self, attrs):
"""A method for storing properties default values.

View File

@ -180,7 +180,7 @@ class SecurityGroup(neutron.NeutronResource):
if 'remote_mode' in rule:
remote_mode = rule.get(self.RULE_REMOTE_MODE)
del(rule[self.RULE_REMOTE_MODE])
del rule[self.RULE_REMOTE_MODE]
if remote_mode == self.RULE_REMOTE_GROUP_ID:
rule[self.RULE_REMOTE_IP_PREFIX] = None

View File

@ -1343,7 +1343,7 @@ class Stack(collections.abc.Mapping):
elif create_if_missing:
kwargs = self.get_kwargs_for_cloning(keep_tags=True)
kwargs['owner_id'] = self.id
del(kwargs['prev_raw_template_id'])
del kwargs['prev_raw_template_id']
prev = type(self)(self.context, self._backup_name(),
copy.deepcopy(self.t),
**kwargs)

View File

@ -26,7 +26,7 @@ Guidelines for writing new hacking checks
- Pick numbers in the range H3xx. Find the current test with
the highest allocated number and then pick the next value.
- Keep the test method code in the source file ordered based
on the Heat3xx value.
on the HE3xx value.
- List the new rule in the top level HACKING.rst file
- Add test cases for each new rule to heat/tests/test_hacking.py
@ -39,31 +39,31 @@ def no_log_warn(logical_line):
https://bugs.launchpad.net/tempest/+bug/1508442
Heat301
HE301
"""
if logical_line.startswith('LOG.warn('):
yield(0, 'Heat301 Use LOG.warning() rather than LOG.warn()')
yield (0, 'HE301 Use LOG.warning() rather than LOG.warn()')
@core.flake8ext
def check_python3_no_iteritems(logical_line):
msg = ("Heat302: Use dict.items() instead of dict.iteritems().")
msg = ("HE302: Use dict.items() instead of dict.iteritems().")
if re.search(r".*\.iteritems\(\)", logical_line):
yield(0, msg)
yield (0, msg)
@core.flake8ext
def check_python3_no_iterkeys(logical_line):
msg = ("Heat303: Use dict.keys() instead of dict.iterkeys().")
msg = ("HE303: Use dict.keys() instead of dict.iterkeys().")
if re.search(r".*\.iterkeys\(\)", logical_line):
yield(0, msg)
yield (0, msg)
@core.flake8ext
def check_python3_no_itervalues(logical_line):
msg = ("Heat304: Use dict.values() instead of dict.itervalues().")
msg = ("HE304: Use dict.values() instead of dict.itervalues().")
if re.search(r".*\.itervalues\(\)", logical_line):
yield(0, msg)
yield (0, msg)

View File

@ -266,8 +266,8 @@ class CfnStackControllerTest(common.HeatTestCase):
u'stack_status': u'COMPLETE',
u'description': u'blah',
u'disable_rollback': 'true',
u'timeout_mins':60,
u'capabilities':[]}]
u'timeout_mins': 60,
u'capabilities': []}]
self.m_call.side_effect = [identity, engine_resp]
@ -358,8 +358,8 @@ class CfnStackControllerTest(common.HeatTestCase):
u'stack_status': u'COMPLETE',
u'description': u'blah',
u'disable_rollback': 'true',
u'timeout_mins':60,
u'capabilities':[]}]
u'timeout_mins': 60,
u'capabilities': []}]
self.m_call.return_value = engine_resp

View File

@ -28,8 +28,8 @@ class RoutesTest(common.HeatTestCase):
class_name = reflection.get_class_name(route['controller'].controller,
fully_qualified=False)
self.assertEqual(controller, class_name)
del(route['action'])
del(route['controller'])
del route['action']
del route['controller']
self.assertEqual(params, route)
def setUp(self):

View File

@ -1608,7 +1608,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
u'stack_status': u'COMPLETE',
u'description': u'blah',
u'disable_rollback': True,
u'timeout_mins':60,
u'timeout_mins': 60,
u'capabilities': [],
}
]
@ -1674,7 +1674,7 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
u'stack_status': u'COMPLETE',
u'description': u'blah',
u'disable_rollback': True,
u'timeout_mins':60,
u'timeout_mins': 60,
u'capabilities': [],
}
]

View File

@ -54,13 +54,13 @@ class Engine(message_processor.MessageProcessor):
if props:
props_def = {}
for prop_name, prop_value in props.items():
if type(prop_value) == scenario_template.GetRes:
prop_res = getattr(prop_value, "target_name")
prop_value = {'get_resource': prop_res}
elif type(prop_value) == scenario_template.GetAtt:
if isinstance(prop_value, scenario_template.GetAtt):
prop_res = getattr(prop_value, "target_name")
prop_attr = getattr(prop_value, "attr")
prop_value = {'get_attr': [prop_res, prop_attr]}
elif isinstance(prop_value, scenario_template.GetRes):
prop_res = getattr(prop_value, "target_name")
prop_value = {'get_resource': prop_res}
props_def[prop_name] = prop_value
res_defn["properties"] = props_def
if depends:

View File

@ -76,7 +76,7 @@ outputs:
before_refid = self.rsrc.FnGetRefId()
self.assertIsNotNone(before_refid)
new_t = self.t.copy()
del(new_t['resources']['none']['properties']['ignored'])
del new_t['resources']['none']['properties']['ignored']
utils.update_stack(self.stack, new_t)
self.assertEqual((self.stack.UPDATE, self.stack.COMPLETE),
self.stack.state)

View File

@ -368,7 +368,7 @@ class RemoteStackTest(tests_common.HeatTestCase):
ca_cert=ca_cert)
self.assertEqual(ca_cert, rsrc._cacert)
self.assertEqual(ca_cert, rsrc.cacert)
self.assertTrue('/tmp/' in rsrc._ssl_verify)
self.assertIn('/tmp/', rsrc._ssl_verify)
def test_create_with_insecure(self):
rsrc = self._create_with_remote_credential(insecure=True)

View File

@ -1318,7 +1318,7 @@ class SoftwareDeploymentTest(common.HeatTestCase):
mock.call('swift_signal_url')],
self.deployment.data_delete.mock_calls)
del(dep_data['swift_signal_object_name'])
del dep_data['swift_signal_object_name']
self.deployment.physical_resource_name = mock.Mock()
self.deployment._delete_swift_signal_url()
self.assertFalse(self.deployment.physical_resource_name.called)

View File

@ -156,10 +156,10 @@ class NeutronFloatingIPTest(common.HeatTestCase):
raise ex
def find_network_port(self, value):
return('9c1eb3fe-7bba-479d-bd43-fdb0bc7cd151')
return '9c1eb3fe-7bba-479d-bd43-fdb0bc7cd151'
def find_network_ip(self, value):
return('477e8273-60a7-4c41-b683-1d497e53c384')
return '477e8273-60a7-4c41-b683-1d497e53c384'
self.ctx = utils.dummy_context()
tpl = template_format.parse(neutron_floating_template)
@ -694,7 +694,7 @@ class NeutronFloatingIPTest(common.HeatTestCase):
# test update FloatingIp with None port_id
props = copy.deepcopy(fip.properties.data)
del(props['port_id'])
del props['port_id']
update_snippet = rsrc_defn.ResourceDefinition(fip.name, fip.type(),
stack.t.parse(stack.defn,
props))

View File

@ -125,7 +125,7 @@ class TestRequestContext(common.HeatTestCase):
user_domain_id=ctx_origin.get('user_domain_id'),
project_domain_id=ctx_origin.get('project_domain_id'))
ctx_dict = ctx.to_dict()
del(ctx_dict['request_id'])
del ctx_dict['request_id']
self.assertEqual(ctx_origin, ctx_dict)
def test_request_context_from_dict(self):

View File

@ -47,7 +47,7 @@ class EnvironmentTest(common.HeatTestCase):
u'resource_registry': {u'resources': {}}}
env = environment.Environment(old)
self.assertEqual(expected, env.env_as_dict())
del(expected['encrypted_param_names'])
del expected['encrypted_param_names']
self.assertEqual(expected, env.user_env_as_dict())
def test_load_new_env(self):
@ -59,7 +59,7 @@ class EnvironmentTest(common.HeatTestCase):
u'resources': {}}}
env = environment.Environment(new_env)
self.assertEqual(new_env, env.env_as_dict())
del(new_env['encrypted_param_names'])
del new_env['encrypted_param_names']
self.assertEqual(new_env, env.user_env_as_dict())
def test_global_registry(self):

View File

@ -56,12 +56,12 @@ class JsonToYamlTest(common.HeatTestCase):
self.assertEqual(u'2012-12-12', yml[u'HeatTemplateFormatVersion'])
self.assertNotIn(u'AWSTemplateFormatVersion', yml)
del(yml[u'HeatTemplateFormatVersion'])
del yml[u'HeatTemplateFormatVersion']
jsn = template_format.parse(json_str)
if u'AWSTemplateFormatVersion' in jsn:
del(jsn[u'AWSTemplateFormatVersion'])
del jsn[u'AWSTemplateFormatVersion']
self.assertEqual(yml, jsn)
@ -189,7 +189,7 @@ class JsonYamlResolvedCompareTest(common.HeatTestCase):
def compare_stacks(self, json_file, yaml_file, parameters):
t1 = self.load_template(json_file)
t2 = self.load_template(yaml_file)
del(t1[u'AWSTemplateFormatVersion'])
del t1[u'AWSTemplateFormatVersion']
t1[u'HeatTemplateFormatVersion'] = t2[u'HeatTemplateFormatVersion']
stack1 = utils.parse_stack(t1, parameters)
stack2 = utils.parse_stack(t2, parameters)
@ -197,10 +197,10 @@ class JsonYamlResolvedCompareTest(common.HeatTestCase):
# compare resources separately so that resolved static data
# is compared
t1nr = dict(stack1.t.t)
del(t1nr['Resources'])
del t1nr['Resources']
t2nr = dict(stack2.t.t)
del(t2nr['Resources'])
del t2nr['Resources']
self.assertEqual(t1nr, t2nr)
self.assertEqual(set(stack1), set(stack2))

View File

@ -1,13 +1,5 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
# Hacking already pins down pep8, pyflakes and flake8
hacking>=3.0.1,<3.1.0 # Apache-2.0
# remove this pyflakes from here once you bump the
# hacking to 3.2.0 or above. hacking 3.2.0 takes
# care of pyflakes version compatibilty.
pyflakes>=2.1.1
hacking>=6.1.0,<6.2.0 # Apache-2.0
bandit!=1.6.0,>=1.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0

View File

@ -132,10 +132,10 @@ import_exceptions = heat.common.i18n
[flake8:local-plugins]
extension =
Heat301 = checks:no_log_warn
Heat302 = checks:check_python3_no_iteritems
Heat303 = checks:check_python3_no_iterkeys
Heat304 = checks:check_python3_no_itervalues
HE301 = checks:no_log_warn
HE302 = checks:check_python3_no_iteritems
HE303 = checks:check_python3_no_iterkeys
HE304 = checks:check_python3_no_itervalues
paths = ./heat/hacking
[testenv:debug]