Adopt hacking 1.1.0

This incorporates flake8 2.6.x and pycodestyle will be used
instead of older pep8.  This ensures future python3 compatibility
and a bit better code styling.

Change-Id: Ia7c7c5a44727f615a151e1e68dd94c7ed42f974f
This commit is contained in:
IWAMOTO Toshihiro 2018-06-20 16:04:28 +09:00
parent d786643214
commit 0f180d8e2e
26 changed files with 39 additions and 21 deletions

View File

@ -25,13 +25,13 @@ extras==1.0.0
fasteners==0.7.0
fixtures==3.0.0
flake8-import-order==0.12
flake8==2.5.5
flake8==2.6.2
future==0.16.0
futurist==1.2.0
gitdb==0.6.4
GitPython==1.0.1
greenlet==0.4.10
hacking==0.12.0
hacking==1.1.0
httplib2==0.9.1
imagesize==0.7.1
iso8601==0.1.11
@ -96,7 +96,7 @@ positional==1.2.1
prettytable==0.7.2
psutil==3.2.2
pycadf==1.1.0
pycodestyle==2.3.1
pycodestyle==2.4.0
pycparser==2.18
pyflakes==0.8.1
Pygments==2.2.0

View File

@ -51,6 +51,7 @@ def get_binary_name():
"""Grab the name of the binary we're running in."""
return os.path.basename(sys.argv[0])[:16].replace(' ', '_')
binary_name = get_binary_name()
# A length of a chain name must be less than or equal to 11 characters.

View File

@ -233,6 +233,7 @@ class CachedResourceConsumerTracker(object):
self._check_expiration()
self._versions.report()
_cached_version_tracker = None

View File

@ -251,6 +251,7 @@ def setup_conf():
conf.register_opts(bind_opts)
return conf
# add a logging setup method here for convenience
setup_logging = config.setup_logging

View File

@ -68,6 +68,7 @@ def is_retriable(e):
# looking savepoints mangled by deadlocks. see bug/1590298 for details.
return _is_nested_instance(e, db_exc.DBError) and '1305' in str(e)
_retry_db_errors = oslo_db_api.wrap_db_retry(
max_retries=MAX_RETRIES,
retry_interval=0.1,

View File

@ -207,6 +207,7 @@ def _validate_name_not_default(data, max_len=db_const.NAME_FIELD_SIZE):
if data.lower() == "default":
raise SecurityGroupDefaultAlreadyExists()
validators.add_validator('name_not_default', _validate_name_not_default)
sg_supported_protocols = ([None] + list(const.IP_PROTOCOL_MAP.keys()))

View File

@ -342,4 +342,5 @@ def subscribe():
resources.SEGMENT,
events.BEFORE_DELETE)
subscribe()

View File

@ -531,4 +531,5 @@ def subscribe():
_delete_port_in_external_dns_service, resources.PORT,
events.BEFORE_DELETE)
subscribe()

View File

@ -31,6 +31,7 @@ class _FeatureFlag(object):
raise RuntimeError(_("A driver can't require a feature and not "
"support it."))
UNSUPPORTED = _FeatureFlag(supports=False, requires=False)
OPTIONAL = _FeatureFlag(supports=True, requires=False)
MANDATORY = _FeatureFlag(supports=True, requires=True)

View File

@ -321,4 +321,5 @@ def subscribe():
resources.NETWORK,
events.PRECOMMIT_DELETE)
subscribe()

View File

@ -40,11 +40,13 @@ def get_tunnel_name_full(cls, network_type, local_ip, remote_ip):
return '%s-%s-%s' % (network_type, source_ip_hash, remote_ip_hash)
ovs_neutron_agent.OVSNeutronAgent.get_tunnel_name = get_tunnel_name_full
def main():
_main()
if __name__ == "__main__":
sys.exit(main())

View File

@ -31,6 +31,7 @@ def print_binary_name():
print(iptables_manager.binary_name)
if __name__ == "__main__":
if 'spawn' in sys.argv:
eventlet.spawn(print_binary_name).wait()

View File

@ -190,7 +190,7 @@ class TestRouterInfo(base.BaseTestCase):
{}, **self.ri_kwargs)
new_mark_ids.pop()
self.assertEqual(new_mark_ids, new_ri.available_mark_ids)
self.assertTrue(ri.available_mark_ids != new_ri.available_mark_ids)
self.assertNotEqual(ri.available_mark_ids, new_ri.available_mark_ids)
def test_process_delete(self):
ri = router_info.RouterInfo(mock.Mock(), _uuid(), {}, **self.ri_kwargs)

View File

@ -362,6 +362,7 @@ def _generate_raw_restore_dump(iptables_args):
'COMMIT\n'
'# Completed by iptables_manager\n' % iptables_args)
MANGLE_DUMP = _generate_mangle_dump(IPTABLES_ARG)
MANGLE_DUMP_V6 = _generate_mangle_dump_v6(IPTABLES_ARG)
RAW_DUMP = _generate_raw_dump(IPTABLES_ARG)

View File

@ -1363,9 +1363,9 @@ class SecurityGroupAgentRpcApiTestCase(base.BaseTestCase):
None, security_groups=[])
self.assertFalse(self.mock_cast.called)
# Note(nati) bn -> binary_name
# id -> device_id
PHYSDEV_MOD = '-m physdev'
PHYSDEV_IS_BRIDGED = '--physdev-is-bridged'

View File

@ -439,7 +439,7 @@ class TestThrottler(base.BaseTestCase):
def sleep_mock(amount_to_sleep):
sleep(amount_to_sleep)
self.assertTrue(threshold > amount_to_sleep)
self.assertGreater(threshold, amount_to_sleep)
with mock.patch.object(utils.eventlet, "sleep",
side_effect=sleep_mock):
@ -455,7 +455,7 @@ class TestThrottler(base.BaseTestCase):
throttled_func()
self.assertEqual(3, orig_function.call_count)
self.assertTrue(timestamp < lock_with_timer.timestamp)
self.assertLess(timestamp, lock_with_timer.timestamp)
def test_method_docstring_is_preserved(self):
class Klass(object):

View File

@ -80,6 +80,7 @@ class TestCountableResource(resource.CountableResource):
def default(self):
return self.flag
PROJECT = 'prj_test'
RESOURCE = 'res_test'
ALT_RESOURCE = 'res_test_meh'

View File

@ -14,8 +14,8 @@ import re
from flake8 import engine
from hacking.tests import test_doctest as hacking_doctest
import pep8
import pkg_resources
import pycodestyle
import testscenarios
import testtools
from testtools import content
@ -235,7 +235,7 @@ class HackingTestCase(base.BaseTestCase):
# TODO(amotoki): Migrate existing unit tests above to docstring tests.
# NOTE(amotoki): Is it better to enhance HackingDocTestCase in hacking repo to
# pass filename to pep8.Checker so that we can reuse it in this test.
# pass filename to pycodestyle.Checker so that we can reuse it in this test.
# I am not sure whether unit test class is public.
SELFTEST_REGEX = re.compile(r'\b(Okay|N\d{3})(\((\S+)\))?:\s(.*)')
@ -249,7 +249,7 @@ class HackingDocTestCase(hacking_doctest.HackingTestCase):
scenarios = file_cases
def test_pep8(self):
def test_pycodestyle(self):
# NOTE(jecarey): Add tests marked as off_by_default to enable testing
turn_on = set(['H106'])
@ -258,8 +258,8 @@ class HackingDocTestCase(hacking_doctest.HackingTestCase):
self.options.select = tuple(turn_on)
self.options.ignore = ('N530',)
report = pep8.BaseReport(self.options)
checker = pep8.Checker(filename=self.filename, lines=self.lines,
report = pycodestyle.BaseReport(self.options)
checker = pycodestyle.Checker(filename=self.filename, lines=self.lines,
options=self.options, report=report)
checker.check_all()
self.addDetail('doctest', content.text_content(self.raw))

View File

@ -37,6 +37,7 @@ def nonzero(f):
else:
return f.__nonzero__()
# Useful global dummy variables.
NET_UUID = '3faeebfe-5d37-11e1-a64b-000c29d5f0a7'
LS_ID = 420

View File

@ -2036,7 +2036,7 @@ class TestMl2PortBinding(Ml2PluginV2TestCase,
return_value=[]):
new_context = plugin._bind_port(context)
self.assertEqual(mock_port, new_context.original)
self.assertFalse(new_context == context)
self.assertNotEqual(new_context, context)
class TestMl2PortBindingNoSG(TestMl2PortBinding):
@ -2830,7 +2830,7 @@ class TestML2Segments(Ml2PluginV2TestCase):
# Assert it is not changed
self.assertEqual(seg_id, segment[driver_api.SEGMENTATION_ID])
else:
self.assertTrue(segment[driver_api.SEGMENTATION_ID] > 0)
self.assertGreater(segment[driver_api.SEGMENTATION_ID], 0)
return segment

View File

@ -292,9 +292,9 @@ class TestMeteringPlugin(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
with self.router(tenant_id=self.tenant_id, set_context=True):
with self.metering_label(tenant_id=self.tenant_id,
set_context=True) as label:
l = label['metering_label']
la = label['metering_label']
self.mock_uuid.return_value = second_uuid
with self.metering_label_rule(l['id']):
with self.metering_label_rule(la['id']):
self.mock_add_rule.assert_called_with(self.ctx,
expected_add)
self._delete('metering-label-rules', second_uuid)

View File

@ -943,5 +943,5 @@ class TestQosPlugin(base.BaseQosTestCase):
action_index = mock_manager.mock_calls.index(
get_rule_mock_call)
self.assertTrue(
action_index < mock_manager.mock_calls.index(driver_mock_call))
self.assertLess(
action_index, mock_manager.mock_calls.index(driver_mock_call))

View File

@ -95,6 +95,7 @@ class PlumberTestCase(base.BaseTestCase):
'tap47198374-5c']
self.assertEqual(expected, names)
IP_LINK_OUTPUT = """
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0

View File

@ -308,7 +308,8 @@ class SqlTestCase(BaseSqlTestCase, base.BaseTestCase):
class OpportunisticDBTestMixin(object):
"""Mixin that converts a BaseSqlTestCase to use the OpportunisticSqlFixture.
"""Mixin that converts a BaseSqlTestCase to use the
OpportunisticSqlFixture.
"""
SKIP_ON_UNAVAILABLE_DB = not base.bool_from_env('OS_FAIL_ON_MISSING_DEPS')

View File

@ -1,7 +1,7 @@
# 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!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
hacking>=1.1.0 # Apache-2.0
bandit>=1.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0

View File

@ -162,7 +162,8 @@ commands = sphinx-build -W -b linkcheck doc/source doc/build/linkcheck
# N534 Untranslated exception message
# TODO(amotoki) check the following new rules should be fixed or ignored
# E731 do not assign a lambda expression, use a def
ignore = E125,E126,E128,E731,H404,H405,N530,N534
# W504 line break after binary operator
ignore = E125,E126,E128,E731,H404,H405,N530,N534,W504
# H106: Don't put vim configuration in source files
# H203: Use assertIs(Not)None to check for None
# H204: Use assert(Not)Equal to check for equality