Switch to Flake8 and add Hacking checks

Change-Id: I44a235e22677031262025152b869ea7d82ee266a
This commit is contained in:
Kiall Mac Innes 2013-06-09 14:30:05 +01:00
parent 8c4124098a
commit ea765d52ef
16 changed files with 63 additions and 38 deletions

View File

@ -18,7 +18,8 @@ import webob.dec
from stevedore import extension
from stevedore import named
from werkzeug import exceptions as wexceptions
from werkzeug.routing import BaseConverter, ValidationError
from werkzeug.routing import BaseConverter
from werkzeug.routing import ValidationError
from moniker.openstack.common import cfg
from moniker.openstack.common import jsonutils as json
from moniker.openstack.common import log as logging

View File

@ -40,7 +40,7 @@ class Bind9Backend(base.Backend):
def start(self):
super(Bind9Backend, self).start()
# TODO: This is a hack to ensure the data dir is 100% up to date
# TODO(kiall): This is a hack to ensure the data dir is 100% up to date
domains = self.central_service.get_domains(self.admin_context)
for domain in domains:
@ -74,7 +74,7 @@ class Bind9Backend(base.Backend):
def _sync_domains(self):
""" Sync the list of domains this server handles """
# TODO: Rewrite this entire thing ASAP
# TODO(kiall): Rewrite this entire thing ASAP
LOG.debug('Synchronising domains')
domains = self.central_service.get_domains(self.admin_context)
@ -112,7 +112,7 @@ class Bind9Backend(base.Backend):
def _sync_delete_domain(self, domain, new_domain_flag=False):
""" Remove domain zone files and reload bind config """
# TODO: Rewrite this entire thing ASAP
# TODO(kiall): Rewrite this entire thing ASAP
LOG.debug('Delete Domain: %s' % domain['id'])
output_folder = os.path.join(os.path.abspath(cfg.CONF.state_path),

View File

@ -37,11 +37,12 @@ class DnsmasqBackend(base.Backend):
if not os.path.exists(self.output_folder):
os.makedirs(self.output_folder)
# TODO: Remove this..
# TODO(Andrey): Remove this..
self._sync_domains_hack()
def _sync_domains_hack(self):
# TODO: This is a hack to ensure the data dir is 100% up to date
# TODO(Andrey): This is a hack to ensure the data dir is 100% up to
# date
domains = self.central_service.get_domains(self.admin_context)
for domain in domains:
@ -118,6 +119,7 @@ class DnsmasqBackend(base.Backend):
shutil.copyfileobj(in_fh, out_fh)
def _reload_dnsmasq(self):
# Send HUP to dnsmasq
# TODO: Lets be a little more targetted that every dnsmasq instance
""" Send HUP to dnsmasq """
# TODO(Andrey): Lets be a little more targetted that every dnsmasq
# instance
utils.execute('killall', '-HUP', 'dnsmasq')

View File

@ -22,7 +22,8 @@ from moniker import utils
from moniker.backend import base
from sqlalchemy.ext.sqlsoup import SqlSoup
from sqlalchemy.engine.url import _parse_rfc1738_args
from moniker.sqlalchemy.session import get_engine, SQLOPTS
from moniker.sqlalchemy.session import get_engine
from moniker.sqlalchemy.session import SQLOPTS
LOG = logging.getLogger(__name__)

View File

@ -24,7 +24,8 @@ from moniker.openstack.common import log as logging
from moniker import exceptions
from moniker.backend import base
from moniker.backend.impl_powerdns import models
from moniker.sqlalchemy.session import get_session, SQLOPTS
from moniker.sqlalchemy.session import get_session
from moniker.sqlalchemy.session import SQLOPTS
from moniker.sqlalchemy.expressions import InsertFromSelect
LOG = logging.getLogger(__name__)
@ -163,7 +164,7 @@ class PowerDNSBackend(base.Backend):
record_m.save(self.session)
def update_domain(self, context, domain):
# TODO: Sync Server List
# TODO(kiall): Sync Server List
self._update_soa(domain)

View File

@ -459,8 +459,8 @@ class Service(rpc_service.Service):
if criterion is None:
criterion = {}
# TODO: Once we allow domains to be allocated on 1 of N server
# pools, return the filtered list here.
# TODO(kiall): Once we allow domains to be allocated on 1 of N server
# pools, return the filtered list here.
return self.storage.get_servers(context, criterion)
def find_domains(self, context, criterion):

View File

@ -47,6 +47,6 @@ class Command(CliffCommand):
return data
def take_action(self, parsed_args):
# TODO: Common Exception Handling Here
# TODO(kiall): Common Exception Handling Here
results = self.execute(parsed_args)
return self.post_execute(results)

View File

@ -49,7 +49,7 @@ class DatabaseSyncCommand(base.Command):
""" Sync PowerDNS database """
def execute(self, parsed_args):
# TODO: Support specifying version
# TODO(kiall): Support specifying version
url = cfg.CONF['backend:powerdns'].database_connection
if not os.path.exists(REPOSITORY):

View File

@ -34,7 +34,7 @@ def get_ip_data(addr_dict):
'ip_version': version
}
# TODO: Add v6 support
# TODO(endre): Add v6 support
if version == 4:
data['ip_address'] = ip.replace('.', '-')
ip_data = ip.split(".")

View File

@ -51,7 +51,7 @@ def check(rule, ctxt, target={}, exc=exceptions.Forbidden):
try:
result = policy.check(rule, target, creds, exc)
except:
except Exception:
result = False
raise
else:

View File

@ -64,7 +64,8 @@ class StaticResolver(object):
return document
# TODO: We shouldn't hard code this list.. Or define it half way down the page
# TODO(kiall): We shouldn't hard code this list.. Or define it half way down
# the page.
resolver = StaticResolver(store={
'/schemas/domain': utils.load_schema('v1', 'domain'),
'/schemas/domains': utils.load_schema('v1', 'domains'),
@ -96,13 +97,14 @@ class SchemaValidator(jsonschema.Draft3Validator):
if self.is_type(instance, "string"):
try:
iso8601.parse_date(instance)
except:
except Exception:
msg = "%s is not an ISO 8601 date" % (instance)
yield jsonschema.ValidationError(msg)
elif format == "date":
# YYYY-MM-DD
if self.is_type(instance, "string"):
# TODO: I'm sure there is a more accurate regex than this..
# TODO(kiall): I'm sure there is a more accurate regex than
# this..
pattern = ('^[0-9]{4}-(((0[13578]|(10|12))-'
'(0[1-9]|[1-2][0-9]|3[0-1]))|'
'(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-'
@ -114,7 +116,8 @@ class SchemaValidator(jsonschema.Draft3Validator):
elif format == "time":
# hh:mm:ss
if self.is_type(instance, "string"):
# TODO: I'm sure there is a more accurate regex than this..
# TODO(kiall): I'm sure there is a more accurate regex than
# this..
pattern = "^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$"
if not re.match(pattern, instance):
msg = "%s is not a time" % (instance)
@ -258,7 +261,7 @@ class Schema(object):
def _filter_array(self, instance, schema):
if 'items' in schema and isinstance(schema['items'], list):
# TODO: We currently don't make use of this..
# NOTE(kiall): We currently don't make use of this..
raise NotImplementedError()
elif 'items' in schema:

View File

@ -21,7 +21,9 @@ from moniker.openstack.common import log as logging
from moniker import exceptions
from moniker.storage import base
from moniker.storage.impl_sqlalchemy import models
from moniker.sqlalchemy.session import get_session, get_engine, SQLOPTS
from moniker.sqlalchemy.session import get_session
from moniker.sqlalchemy.session import get_engine
from moniker.sqlalchemy.session import SQLOPTS
LOG = logging.getLogger(__name__)
@ -438,7 +440,7 @@ class SQLAlchemyStorage(base.Storage):
try:
result = self.engine.execute('SELECT 1').first()
except:
except Exception:
status = False
else:
status = True if result[0] == 1 else False

View File

@ -39,7 +39,7 @@ def drop_tables(tables):
def Table(*args, **kwargs):
if not 'mysql_engine' in kwargs:
if 'mysql_engine' not in kwargs:
kwargs['mysql_engine'] = 'INNODB'
return SqlaTable(*args, **kwargs)

View File

@ -20,9 +20,11 @@ from sqlalchemy import ForeignKey, Enum, Integer, String, DateTime, Text
from sqlalchemy.schema import Column, MetaData
from moniker.openstack.common import timeutils
from moniker.openstack.common.uuidutils import generate_uuid
from moniker.storage.impl_sqlalchemy.migrate_repo.utils import (
Table, create_tables, drop_tables)
from moniker.sqlalchemy.types import Inet, UUID
from moniker.storage.impl_sqlalchemy.migrate_repo.utils import Table
from moniker.storage.impl_sqlalchemy.migrate_repo.utils import create_tables
from moniker.storage.impl_sqlalchemy.migrate_repo.utils import drop_tables
from moniker.sqlalchemy.types import Inet
from moniker.sqlalchemy.types import UUID
meta = MetaData()

View File

@ -1,3 +1,15 @@
# Packages needed for dev testing
distribute>=0.6.24
# Install bounded pep8/pyflakes first, then let flake8 install
pep8==1.4.5
pyflakes==0.7.2
flake8==2.0
hacking>=0.5.3,<0.6
coverage>=3.6
nosexcover
nose
openstack.nose_plugin>=0.7
nosehtmloutput>=0.0.3

21
tox.ini
View File

@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,pep8,pyflakes
envlist = py26,py27,flake8
minversion = 1.4.0
[tox:jenkins]
@ -18,21 +18,22 @@ setenv = VIRTUAL_ENV={envdir}
commands = nosetests {posargs}
[testenv:cover]
deps = {[testenv]deps}
coverage
nosexcover
setenv = {[testenv]setenv}
NOSE_WITH_COVERAGE=1
[testenv:flake8]
commands = flake8
[testenv:pep8]
deps = {[testenv]deps}
pep8==1.4.5
commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack moniker setup.py bin/moniker-api bin/moniker-central bin/moniker-agent bin/moniker-sink bin/moniker-manage
commands = flake8
[testenv:pyflakes]
deps = {[testenv]deps}
pyflakes==0.7.2
commands = pyflakes moniker bin setup.py
commands = flake8
[testenv:venv]
commands = {posargs}
[flake8]
ignore = H302,H306,H401,H402,H404
builtins = _
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools