diff --git a/moniker/api/v1/__init__.py b/moniker/api/v1/__init__.py index db64111af..67c0fb972 100644 --- a/moniker/api/v1/__init__.py +++ b/moniker/api/v1/__init__.py @@ -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 diff --git a/moniker/backend/impl_bind9.py b/moniker/backend/impl_bind9.py index 440fc9629..193262157 100644 --- a/moniker/backend/impl_bind9.py +++ b/moniker/backend/impl_bind9.py @@ -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), diff --git a/moniker/backend/impl_dnsmasq.py b/moniker/backend/impl_dnsmasq.py index 2cc212907..3d18990dd 100644 --- a/moniker/backend/impl_dnsmasq.py +++ b/moniker/backend/impl_dnsmasq.py @@ -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') diff --git a/moniker/backend/impl_mysqlbind9.py b/moniker/backend/impl_mysqlbind9.py index e034ff428..a0fbbf4be 100644 --- a/moniker/backend/impl_mysqlbind9.py +++ b/moniker/backend/impl_mysqlbind9.py @@ -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__) diff --git a/moniker/backend/impl_powerdns/__init__.py b/moniker/backend/impl_powerdns/__init__.py index bdb473050..51ce53c1f 100644 --- a/moniker/backend/impl_powerdns/__init__.py +++ b/moniker/backend/impl_powerdns/__init__.py @@ -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) diff --git a/moniker/central/service.py b/moniker/central/service.py index f365fc88b..cb359058f 100644 --- a/moniker/central/service.py +++ b/moniker/central/service.py @@ -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): diff --git a/moniker/manage/base.py b/moniker/manage/base.py index 7f7c136f2..f8565b05d 100644 --- a/moniker/manage/base.py +++ b/moniker/manage/base.py @@ -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) diff --git a/moniker/manage/powerdns.py b/moniker/manage/powerdns.py index 5d133f49a..92a2c6aee 100644 --- a/moniker/manage/powerdns.py +++ b/moniker/manage/powerdns.py @@ -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): diff --git a/moniker/notification_handler/base.py b/moniker/notification_handler/base.py index b2b6b61d7..73bf416b3 100644 --- a/moniker/notification_handler/base.py +++ b/moniker/notification_handler/base.py @@ -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(".") diff --git a/moniker/policy.py b/moniker/policy.py index 8351f6900..fa525452b 100644 --- a/moniker/policy.py +++ b/moniker/policy.py @@ -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: diff --git a/moniker/schema.py b/moniker/schema.py index 54fac392c..abacbb6de 100644 --- a/moniker/schema.py +++ b/moniker/schema.py @@ -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: diff --git a/moniker/storage/impl_sqlalchemy/__init__.py b/moniker/storage/impl_sqlalchemy/__init__.py index 4db8dd49a..405184492 100644 --- a/moniker/storage/impl_sqlalchemy/__init__.py +++ b/moniker/storage/impl_sqlalchemy/__init__.py @@ -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 diff --git a/moniker/storage/impl_sqlalchemy/migrate_repo/utils.py b/moniker/storage/impl_sqlalchemy/migrate_repo/utils.py index 00defdc6c..0b7725749 100644 --- a/moniker/storage/impl_sqlalchemy/migrate_repo/utils.py +++ b/moniker/storage/impl_sqlalchemy/migrate_repo/utils.py @@ -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) diff --git a/moniker/storage/impl_sqlalchemy/migrate_repo/versions/001_add_moniker_schema.py b/moniker/storage/impl_sqlalchemy/migrate_repo/versions/001_add_moniker_schema.py index 013182b2a..4c541571e 100644 --- a/moniker/storage/impl_sqlalchemy/migrate_repo/versions/001_add_moniker_schema.py +++ b/moniker/storage/impl_sqlalchemy/migrate_repo/versions/001_add_moniker_schema.py @@ -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() diff --git a/test-requirements.txt b/test-requirements.txt index bb156a2a6..ade53806d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 diff --git a/tox.ini b/tox.ini index df9ba69a9..16151a685 100644 --- a/tox.ini +++ b/tox.ini @@ -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