Fix H201 violations and re-enable gating
H201 got stricter in hacking 0.9, so fix new violations and re-enable gating. Change-Id: Ie79b04bc1ae2d4784318c19661584d02b7bee088 Implements: blueprint reduce-flake8-ignore-rules
This commit is contained in:
parent
a7dd2bb0e4
commit
4876f70b02
@ -153,7 +153,7 @@ def upgrade(migrate_engine):
|
|||||||
for index, table in enumerate(tables):
|
for index, table in enumerate(tables):
|
||||||
try:
|
try:
|
||||||
table.create()
|
table.create()
|
||||||
except:
|
except Exception:
|
||||||
# If an error occurs, drop all tables created so far to return
|
# If an error occurs, drop all tables created so far to return
|
||||||
# to the previously existing state.
|
# to the previously existing state.
|
||||||
meta.drop_all(tables=tables[:index])
|
meta.drop_all(tables=tables[:index])
|
||||||
|
@ -32,6 +32,6 @@ def downgrade(migrate_engine):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
resource.c.id.alter(sqlalchemy.Integer, primary_key=True)
|
resource.c.id.alter(sqlalchemy.Integer, primary_key=True)
|
||||||
except:
|
except Exception:
|
||||||
#XXX: since there is no way to downgrade just passing
|
#XXX: since there is no way to downgrade just passing
|
||||||
pass
|
pass
|
||||||
|
@ -34,7 +34,7 @@ def downgrade(migrate_engine):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
event.c.id.alter(type=sqlalchemy.Integer, primary_key=True)
|
event.c.id.alter(type=sqlalchemy.Integer, primary_key=True)
|
||||||
except:
|
except Exception:
|
||||||
# NOTE(pafuent): since there is no way to downgrade just passing
|
# NOTE(pafuent): since there is no way to downgrade just passing
|
||||||
# The same is did in 018_resource_id_uuid.py
|
# The same is did in 018_resource_id_uuid.py
|
||||||
migrate_util.log.warning(_('If you really want to downgrade to this '
|
migrate_util.log.warning(_('If you really want to downgrade to this '
|
||||||
|
@ -411,7 +411,7 @@ class Resource(object):
|
|||||||
failure = exception.ResourceFailure(ex, self, action)
|
failure = exception.ResourceFailure(ex, self, action)
|
||||||
self.state_set(action, self.FAILED, six.text_type(failure))
|
self.state_set(action, self.FAILED, six.text_type(failure))
|
||||||
raise failure
|
raise failure
|
||||||
except:
|
except: # noqa
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
try:
|
try:
|
||||||
self.state_set(action, self.FAILED,
|
self.state_set(action, self.FAILED,
|
||||||
@ -694,7 +694,7 @@ class Resource(object):
|
|||||||
failure = exception.ResourceFailure(ex, self, self.action)
|
failure = exception.ResourceFailure(ex, self, self.action)
|
||||||
self.state_set(action, self.FAILED, six.text_type(failure))
|
self.state_set(action, self.FAILED, six.text_type(failure))
|
||||||
raise failure
|
raise failure
|
||||||
except:
|
except: # noqa
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
try:
|
try:
|
||||||
self.state_set(action, self.FAILED,
|
self.state_set(action, self.FAILED,
|
||||||
|
@ -185,7 +185,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
|||||||
userdata_parts = None
|
userdata_parts = None
|
||||||
try:
|
try:
|
||||||
userdata_parts = email.message_from_string(userdata)
|
userdata_parts = email.message_from_string(userdata)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if userdata_parts and userdata_parts.is_multipart():
|
if userdata_parts and userdata_parts.is_multipart():
|
||||||
for part in userdata_parts.get_payload():
|
for part in userdata_parts.get_payload():
|
||||||
|
@ -265,7 +265,7 @@ def wrappertask(task):
|
|||||||
except GeneratorExit as ex:
|
except GeneratorExit as ex:
|
||||||
subtask.close()
|
subtask.close()
|
||||||
raise ex
|
raise ex
|
||||||
except:
|
except: # noqa
|
||||||
try:
|
try:
|
||||||
step = subtask.throw(*sys.exc_info())
|
step = subtask.throw(*sys.exc_info())
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
@ -280,7 +280,7 @@ def wrappertask(task):
|
|||||||
except GeneratorExit as ex:
|
except GeneratorExit as ex:
|
||||||
parent.close()
|
parent.close()
|
||||||
raise ex
|
raise ex
|
||||||
except:
|
except: # noqa
|
||||||
subtask = parent.throw(*sys.exc_info())
|
subtask = parent.throw(*sys.exc_info())
|
||||||
else:
|
else:
|
||||||
subtask = next(parent)
|
subtask = next(parent)
|
||||||
@ -340,7 +340,7 @@ class DependencyTaskGroup(object):
|
|||||||
if not self.aggregate_exceptions:
|
if not self.aggregate_exceptions:
|
||||||
raise
|
raise
|
||||||
raised_exceptions.append(e)
|
raised_exceptions.append(e)
|
||||||
except:
|
except: # noqa
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
for r in self._runners.itervalues():
|
for r in self._runners.itervalues():
|
||||||
r.cancel()
|
r.cancel()
|
||||||
@ -466,7 +466,7 @@ class PollingTaskGroup(object):
|
|||||||
yield
|
yield
|
||||||
runners = list(itertools.dropwhile(lambda r: r.step(),
|
runners = list(itertools.dropwhile(lambda r: r.step(),
|
||||||
runners))
|
runners))
|
||||||
except:
|
except: # noqa
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
for r in runners:
|
for r in runners:
|
||||||
r.cancel()
|
r.cancel()
|
||||||
|
@ -131,7 +131,7 @@ class StackLock(object):
|
|||||||
try:
|
try:
|
||||||
self.acquire()
|
self.acquire()
|
||||||
yield
|
yield
|
||||||
except:
|
except: # noqa
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
self.release(stack_id)
|
self.release(stack_id)
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ class StackLock(object):
|
|||||||
try:
|
try:
|
||||||
result = self.try_acquire()
|
result = self.try_acquire()
|
||||||
yield result
|
yield result
|
||||||
except:
|
except: # noqa
|
||||||
if result is None: # Lock was successfully acquired
|
if result is None: # Lock was successfully acquired
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
self.release(stack_id)
|
self.release(stack_id)
|
||||||
|
@ -295,7 +295,7 @@ def stack_context(stack_name, create_res=True):
|
|||||||
create_stack()
|
create_stack()
|
||||||
try:
|
try:
|
||||||
test_fn(test_case, *args, **kwargs)
|
test_fn(test_case, *args, **kwargs)
|
||||||
except:
|
except Exception:
|
||||||
exc_class, exc_val, exc_tb = sys.exc_info()
|
exc_class, exc_val, exc_tb = sys.exc_info()
|
||||||
try:
|
try:
|
||||||
delete_stack()
|
delete_stack()
|
||||||
|
@ -63,7 +63,7 @@ class NovaServerGroupTest(HeatTestCase):
|
|||||||
try:
|
try:
|
||||||
sg = sg_template['resources']['ServerGroup']
|
sg = sg_template['resources']['ServerGroup']
|
||||||
del sg['properties']['name']
|
del sg['properties']['name']
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self._init_template(sg_template)
|
self._init_template(sg_template)
|
||||||
name = 'test'
|
name = 'test'
|
||||||
|
@ -32,6 +32,9 @@ class StackLockTest(HeatTestCase):
|
|||||||
self.stack.action = "CREATE"
|
self.stack.action = "CREATE"
|
||||||
self.engine_id = stack_lock.StackLock.generate_engine_id()
|
self.engine_id = stack_lock.StackLock.generate_engine_id()
|
||||||
|
|
||||||
|
class TestThreadLockException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def test_successful_acquire_new_lock(self):
|
def test_successful_acquire_new_lock(self):
|
||||||
self.m.StubOutWithMock(db_api, "stack_lock_create")
|
self.m.StubOutWithMock(db_api, "stack_lock_create")
|
||||||
db_api.stack_lock_create(
|
db_api.stack_lock_create(
|
||||||
@ -168,11 +171,12 @@ class StackLockTest(HeatTestCase):
|
|||||||
db_api.stack_lock_create = mock.Mock(return_value=None)
|
db_api.stack_lock_create = mock.Mock(return_value=None)
|
||||||
db_api.stack_lock_release = mock.Mock(return_value=None)
|
db_api.stack_lock_release = mock.Mock(return_value=None)
|
||||||
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
|
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
|
||||||
try:
|
|
||||||
|
def check_thread_lock():
|
||||||
with slock.thread_lock(self.stack.id):
|
with slock.thread_lock(self.stack.id):
|
||||||
self.assertEqual(1, db_api.stack_lock_create.call_count)
|
self.assertEqual(1, db_api.stack_lock_create.call_count)
|
||||||
raise Exception
|
raise self.TestThreadLockException
|
||||||
except:
|
self.assertRaises(self.TestThreadLockException, check_thread_lock)
|
||||||
self.assertEqual(1, db_api.stack_lock_release.call_count)
|
self.assertEqual(1, db_api.stack_lock_release.call_count)
|
||||||
|
|
||||||
def test_thread_lock_context_mgr_no_exception(self):
|
def test_thread_lock_context_mgr_no_exception(self):
|
||||||
@ -187,11 +191,12 @@ class StackLockTest(HeatTestCase):
|
|||||||
db_api.stack_lock_create = mock.Mock(return_value=None)
|
db_api.stack_lock_create = mock.Mock(return_value=None)
|
||||||
db_api.stack_lock_release = mock.Mock(return_value=None)
|
db_api.stack_lock_release = mock.Mock(return_value=None)
|
||||||
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
|
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
|
||||||
try:
|
|
||||||
|
def check_thread_lock():
|
||||||
with slock.try_thread_lock(self.stack.id):
|
with slock.try_thread_lock(self.stack.id):
|
||||||
self.assertEqual(1, db_api.stack_lock_create.call_count)
|
self.assertEqual(1, db_api.stack_lock_create.call_count)
|
||||||
raise Exception
|
raise self.TestThreadLockException
|
||||||
except:
|
self.assertRaises(self.TestThreadLockException, check_thread_lock)
|
||||||
self.assertEqual(1, db_api.stack_lock_release.call_count)
|
self.assertEqual(1, db_api.stack_lock_release.call_count)
|
||||||
|
|
||||||
def test_try_thread_lock_context_mgr_no_exception(self):
|
def test_try_thread_lock_context_mgr_no_exception(self):
|
||||||
@ -206,9 +211,10 @@ class StackLockTest(HeatTestCase):
|
|||||||
db_api.stack_lock_create = mock.Mock(return_value=1234)
|
db_api.stack_lock_create = mock.Mock(return_value=1234)
|
||||||
db_api.stack_lock_release = mock.Mock(return_value=None)
|
db_api.stack_lock_release = mock.Mock(return_value=None)
|
||||||
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
|
slock = stack_lock.StackLock(self.context, self.stack, self.engine_id)
|
||||||
try:
|
|
||||||
|
def check_thread_lock():
|
||||||
with slock.try_thread_lock(self.stack.id):
|
with slock.try_thread_lock(self.stack.id):
|
||||||
self.assertEqual(1, db_api.stack_lock_create.call_count)
|
self.assertEqual(1, db_api.stack_lock_create.call_count)
|
||||||
raise Exception
|
raise self.TestThreadLockException
|
||||||
except:
|
self.assertRaises(self.TestThreadLockException, check_thread_lock)
|
||||||
assert not db_api.stack_lock_release.called
|
assert not db_api.stack_lock_release.called
|
||||||
|
3
tox.ini
3
tox.ini
@ -37,11 +37,10 @@ deps = -r{toxinidir}/requirements.txt
|
|||||||
commands = python setup.py build_sphinx
|
commands = python setup.py build_sphinx
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# H201 no 'except:' at least use 'except Exception:'
|
|
||||||
# H302 import only modules.'bla..' does not import a module
|
# H302 import only modules.'bla..' does not import a module
|
||||||
# H404 multi line docstring should start with a summary
|
# H404 multi line docstring should start with a summary
|
||||||
# H803 no full stop at the end of the commit message
|
# H803 no full stop at the end of the commit message
|
||||||
ignore = H201,H302,H404,H803
|
ignore = H302,H404,H803
|
||||||
show-source = true
|
show-source = true
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,*openstack/common*,*lib/python*,*egg,tools,build
|
exclude=.venv,.git,.tox,dist,*openstack/common*,*lib/python*,*egg,tools,build
|
||||||
|
Loading…
Reference in New Issue
Block a user