Fix flake8 errors

This commit fixes flake8 errors and fixes a minor bug related to
a schema version being v1 rather than v1.0.

OpenStack hacking rules are used to pin down flake8 to sane
standards using [0].

[0] 06e676c461/test-requirements.txt (L5)

Change-Id: Ib236df6f5ec9505c0e635f0faa9877d3397a2e55
This commit is contained in:
Felipe Monteiro 2017-08-14 20:45:43 +01:00
parent e1446bb9e1
commit 6e2238c3d8
22 changed files with 42 additions and 77 deletions

View File

@ -14,6 +14,7 @@
from keystoneauth1.identity import v3 from keystoneauth1.identity import v3
from keystoneauth1 import session from keystoneauth1 import session
from oslo_log import log as logging
from deckhand.conf import config from deckhand.conf import config
from deckhand import errors from deckhand import errors
@ -22,6 +23,7 @@ from barbicanclient import barbican
from barbicanclient import exceptions as barbican_exc from barbicanclient import exceptions as barbican_exc
CONF = config.CONF CONF = config.CONF
LOG = logging.getLogger(__name__)
class BarbicanClientWrapper(object): class BarbicanClientWrapper(object):
@ -41,8 +43,8 @@ class BarbicanClientWrapper(object):
if retry_on_conflict and self._cached_client is not None: if retry_on_conflict and self._cached_client is not None:
return self._cached_client return self._cached_client
# TODO: Deckhand's configuration file needs to be populated with # TODO(fmontei): Deckhand's configuration file needs to be populated
# correct Keysone authentication values as well as the Barbican # with correct Keysone authentication values as well as the Barbican
# endpoint URL automatically. # endpoint URL automatically.
barbican_url = (CONF.barbican.api_endpoint barbican_url = (CONF.barbican.api_endpoint
if CONF.barbican.api_endpoint if CONF.barbican.api_endpoint
@ -53,7 +55,7 @@ class BarbicanClientWrapper(object):
sess = session.Session(auth=auth) sess = session.Session(auth=auth)
try: try:
# TODO: replace with ``barbican_url``. # TODO(fmontei): replace with ``barbican_url``.
cli = barbican.client.Client(endpoint=barbican_url, cli = barbican.client.Client(endpoint=barbican_url,
session=sess) session=sess)
# Cache the client so we don't have to reconstruct and # Cache the client so we don't have to reconstruct and
@ -63,7 +65,7 @@ class BarbicanClientWrapper(object):
except barbican_exc.HTTPAuthError: except barbican_exc.HTTPAuthError:
msg = _("Unable to authenticate Barbican client.") msg = _("Unable to authenticate Barbican client.")
# TODO: Log the error. # TODO(fmontei): Log the error.
raise errors.ApiError(msg) raise errors.ApiError(msg)
return cli return cli
@ -106,9 +108,8 @@ class BarbicanClientWrapper(object):
# client and the next try will start with a fresh one. # client and the next try will start with a fresh one.
if not attempt: if not attempt:
self._invalidate_cached_client() self._invalidate_cached_client()
# TODO: include after implementing oslo.log. LOG.debug("The Barbican client became unauthorized. "
# LOG.debug("The Barbican client became unauthorized. " "Will attempt to reauthorize and try again.")
# "Will attempt to reauthorize and try again.")
else: else:
# This code should be unreachable actually # This code should be unreachable actually
raise raise

View File

@ -37,7 +37,7 @@ def __setup_logging():
logging.register_options(CONF) logging.register_options(CONF)
config.parse_args() config.parse_args()
current_path = os.path.dirname(os.path.realpath(__file__)) current_path = os.path.dirname(os.path.realpath(__file__))
root_path = os.path.abspath(os.path.join(current_path, os.pardir, root_path = os.path.abspath(os.path.join(current_path, os.pardir,
os.pardir)) os.pardir))

View File

@ -26,6 +26,6 @@ class ViewBuilder(object):
_collection_name = None _collection_name = None
def _gen_url(self, revision): def _gen_url(self, revision):
# TODO: Use a config-based url for the base url below. # TODO(fmontei): Use a config-based url for the base url below.
base_url = 'https://deckhand/api/v1.0/%s/%s' base_url = 'https://deckhand/api/v1.0/%s/%s'
return base_url % (self._collection_name, revision.get('id')) return base_url % (self._collection_name, revision.get('id'))

View File

@ -12,14 +12,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import copy
import yaml import yaml
import falcon import falcon
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_log import log as logging from oslo_log import log as logging
from oslo_serialization import jsonutils as json
from deckhand.control import base as api_base from deckhand.control import base as api_base
from deckhand.db.sqlalchemy import api as db_api from deckhand.db.sqlalchemy import api as db_api

View File

@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import falcon import falcon
from oslo_db import exception as db_exc
from deckhand.control import base as api_base from deckhand.control import base as api_base
from deckhand.db.sqlalchemy import api as db_api from deckhand.db.sqlalchemy import api as db_api
@ -25,7 +24,7 @@ class RevisionDocumentsResource(api_base.BaseResource):
def on_get(self, req, resp, revision_id): def on_get(self, req, resp, revision_id):
"""Returns all documents for a `revision_id`. """Returns all documents for a `revision_id`.
Returns a multi-document YAML response containing all the documents Returns a multi-document YAML response containing all the documents
matching the filters specified via query string parameters. Returned matching the filters specified via query string parameters. Returned
documents will be as originally posted with no substitutions or documents will be as originally posted with no substitutions or

View File

@ -25,7 +25,7 @@ class RevisionsResource(api_base.BaseResource):
def on_get(self, req, resp, revision_id=None): def on_get(self, req, resp, revision_id=None):
"""Returns list of existing revisions. """Returns list of existing revisions.
Lists existing revisions and reports basic details including a summary Lists existing revisions and reports basic details including a summary
of validation status for each `deckhand/ValidationPolicy` that is part of validation status for each `deckhand/ValidationPolicy` that is part
of each revision. of each revision.

View File

@ -62,7 +62,7 @@ class ViewBuilder(common.ViewBuilder):
'id': revision.get('id'), 'id': revision.get('id'),
'createdAt': revision.get('created_at'), 'createdAt': revision.get('created_at'),
'url': self._gen_url(revision), 'url': self._gen_url(revision),
# TODO: Not yet implemented. # TODO(fmontei): Not yet implemented.
'validationPolicies': validation_policies, 'validationPolicies': validation_policies,
'status': success_status 'status': success_status
} }

View File

@ -17,7 +17,6 @@
import ast import ast
import copy import copy
import datetime
import threading import threading
from oslo_config import cfg from oslo_config import cfg
@ -25,16 +24,8 @@ from oslo_db import exception as db_exception
from oslo_db import options from oslo_db import options
from oslo_db.sqlalchemy import session from oslo_db.sqlalchemy import session
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils
import six import six
from six.moves import range
import sqlalchemy
from sqlalchemy.ext.compiler import compiles
from sqlalchemy import desc
from sqlalchemy import MetaData, Table
import sqlalchemy.orm as sa_orm import sqlalchemy.orm as sa_orm
from sqlalchemy import sql
import sqlalchemy.sql as sa_sql
from deckhand.db.sqlalchemy import models from deckhand.db.sqlalchemy import models
from deckhand import errors from deckhand import errors
@ -82,22 +73,6 @@ def get_session(autocommit=True, expire_on_commit=False):
expire_on_commit=expire_on_commit) expire_on_commit=expire_on_commit)
def _validate_db_int(**kwargs):
"""Make sure that all arguments are less than or equal to 2 ** 31 - 1.
This limitation is introduced because databases stores INT in 4 bytes.
If the validation fails for some argument, exception. Invalid is raised
with appropriate information.
"""
max_int = (2 ** 31) - 1
for param_key, param_value in kwargs.items():
if param_value and param_value > max_int:
msg = _("'%(param)s' value out of range, "
"must not exceed %(max)d.") % {"param": param_key,
"max": max_int}
raise exception.Invalid(msg)
def clear_db_env(): def clear_db_env():
"""Unset global configuration variables for database.""" """Unset global configuration variables for database."""
global _FACADE global _FACADE
@ -255,7 +230,7 @@ def _filter_revision_documents(documents, **filters):
:returns: list of documents that match specified filters. :returns: list of documents that match specified filters.
""" """
# TODO: Implement this as an sqlalchemy query. # TODO(fmontei): Implement this as an sqlalchemy query.
filtered_documents = [] filtered_documents = []
for document in documents: for document in documents:

View File

@ -23,12 +23,9 @@ from sqlalchemy import DateTime
from sqlalchemy.ext import declarative from sqlalchemy.ext import declarative
from sqlalchemy import ForeignKey from sqlalchemy import ForeignKey
from sqlalchemy import Integer from sqlalchemy import Integer
from sqlalchemy import orm from sqlalchemy.orm import relationship
from sqlalchemy.orm import backref, relationship
from sqlalchemy import schema from sqlalchemy import schema
from sqlalchemy import String from sqlalchemy import String
from sqlalchemy import Text
from sqlalchemy.types import TypeDecorator
# Declarative base class which maintains a catalog of classes and tables # Declarative base class which maintains a catalog of classes and tables
@ -121,7 +118,8 @@ class Revision(BASE, DeckhandBase):
class DocumentMixin(object): class DocumentMixin(object):
"""Mixin class for sharing common columns across all document resources """Mixin class for sharing common columns across all document resources
such as documents themselves, layering policies and validation policies.""" such as documents themselves, layering policies and validation policies.
"""
name = Column(String(64), nullable=False) name = Column(String(64), nullable=False)
schema = Column(String(64), nullable=False) schema = Column(String(64), nullable=False)

View File

@ -120,7 +120,7 @@ class DocumentValidation(object):
validation_policy_factory = factories.ValidationPolicyFactory() validation_policy_factory = factories.ValidationPolicyFactory()
for document in self.documents: for document in self.documents:
document_validations = self._validate_one(document) self._validate_one(document)
deckhand_schema_validation = validation_policy_factory.gen( deckhand_schema_validation = validation_policy_factory.gen(
types.DECKHAND_SCHEMA_VALIDATION, status='success') types.DECKHAND_SCHEMA_VALIDATION, status='success')
@ -156,12 +156,12 @@ class DocumentValidation(object):
document_type=document['schema']) document_type=document['schema'])
else: else:
LOG.info('Skipping schema validation for abstract ' LOG.info('Skipping schema validation for abstract '
'document: %s.' % document) 'document: %s.', document)
def _is_abstract(self, document): def _is_abstract(self, document):
try: try:
is_abstract = document['metadata']['layeringDefinition'][ is_abstract = document['metadata']['layeringDefinition'][
'abstract'] == True 'abstract'] is True
return is_abstract return is_abstract
# NOTE(fmontei): If the document is of ``document_schema`` type and # NOTE(fmontei): If the document is of ``document_schema`` type and
# no "layeringDefinition" or "abstract" property is found, then treat # no "layeringDefinition" or "abstract" property is found, then treat

View File

@ -14,6 +14,7 @@
import abc import abc
import copy import copy
import six
from oslo_log import log as logging from oslo_log import log as logging
@ -23,8 +24,8 @@ from deckhand import types
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class DeckhandFactory(object): class DeckhandFactory(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod @abc.abstractmethod
def gen(self, *args): def gen(self, *args):

View File

@ -14,7 +14,6 @@
import mock import mock
import falcon
from falcon import testing as falcon_testing from falcon import testing as falcon_testing
from deckhand.control import api from deckhand.control import api

View File

@ -17,9 +17,7 @@ import yaml
import falcon import falcon
from deckhand.control import api
from deckhand.tests.functional import base as test_base from deckhand.tests.functional import base as test_base
from deckhand import types
class TestDocumentsApi(test_base.TestFunctionalBase): class TestDocumentsApi(test_base.TestFunctionalBase):
@ -38,10 +36,6 @@ class TestDocumentsApi(test_base.TestFunctionalBase):
result = self.app.simulate_post('/api/v1.0/documents', body=yaml_data) result = self.app.simulate_post('/api/v1.0/documents', body=yaml_data)
self.assertEqual(falcon.HTTP_201, result.status) self.assertEqual(falcon.HTTP_201, result.status)
expected_documents = [yaml.safe_load(yaml_data)]
expected_validation_policy = self.validation_policy_factory.gen(
types.DECKHAND_SCHEMA_VALIDATION, status='success')
# Validate that the correct number of documents were created: one # Validate that the correct number of documents were created: one
# document corresponding to ``yaml_data``. # document corresponding to ``yaml_data``.
resp_documents = [d for d in yaml.safe_load_all(result.text)] resp_documents = [d for d in yaml.safe_load_all(result.text)]

View File

@ -17,9 +17,7 @@ from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import testtools import testtools
from deckhand.conf import config
from deckhand.db.sqlalchemy import api as db_api from deckhand.db.sqlalchemy import api as db_api
from deckhand.db.sqlalchemy import models as db_models
CONF = cfg.CONF CONF = cfg.CONF
logging.register_options(CONF) logging.register_options(CONF)

View File

@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import testtools
from testtools import matchers from testtools import matchers
from deckhand.db.sqlalchemy import api as db_api from deckhand.db.sqlalchemy import api as db_api

View File

@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from deckhand.tests.unit.db import base
from deckhand import factories from deckhand import factories
from deckhand.tests.unit.db import base
from deckhand import types from deckhand import types

View File

@ -16,11 +16,6 @@ import copy
import os import os
import yaml import yaml
import mock
import six
from deckhand.engine import document_validation
from deckhand import errors
from deckhand.tests.unit import base as test_base from deckhand.tests.unit import base as test_base

View File

@ -2,7 +2,7 @@
--- ---
schema: deckhand/LayeringPolicy/v1.0 schema: deckhand/LayeringPolicy/v1.0
metadata: metadata:
schema: metadata/Control/v1 schema: metadata/Control/v1.0
name: a-unique-config-name-12345 name: a-unique-config-name-12345
data: data:
layerOrder: layerOrder:

View File

@ -14,8 +14,8 @@
from deckhand.control.views import revision from deckhand.control.views import revision
from deckhand import factories from deckhand import factories
from deckhand.tests.unit.db import base
from deckhand.tests import test_utils from deckhand.tests import test_utils
from deckhand.tests.unit.db import base
from deckhand import types from deckhand import types
@ -103,9 +103,6 @@ class TestRevisionViews(base.TestDbBase):
expected_attrs = ('id', 'url', 'createdAt', 'validationPolicies', expected_attrs = ('id', 'url', 'createdAt', 'validationPolicies',
'status') 'status')
expected_validation_policies = [
{'name': 'deckhand-schema-validation'}, 'status'
]
for attr in expected_attrs: for attr in expected_attrs:
self.assertIn(attr, revision_view) self.assertIn(attr, revision_view)
@ -118,7 +115,6 @@ class TestRevisionViews(base.TestDbBase):
self.assertEqual(revision_view['validationPolicies'][0]['status'], self.assertEqual(revision_view['validationPolicies'][0]['status'],
'success') 'success')
def test_show_revision_failed_validation_policy(self): def test_show_revision_failed_validation_policy(self):
# Simulate 4 document payload with an internally generated validation # Simulate 4 document payload with an internally generated validation
# policy which executes 'deckhand-schema-validation'. # policy which executes 'deckhand-schema-validation'.
@ -134,9 +130,6 @@ class TestRevisionViews(base.TestDbBase):
expected_attrs = ('id', 'url', 'createdAt', 'validationPolicies', expected_attrs = ('id', 'url', 'createdAt', 'validationPolicies',
'status') 'status')
expected_validation_policies = [
{'name': 'deckhand-schema-validation'}, 'status'
]
for attr in expected_attrs: for attr in expected_attrs:
self.assertIn(attr, revision_view) self.assertIn(attr, revision_view)

View File

@ -1,3 +1,10 @@
# 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!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
falcon==1.1.0 falcon==1.1.0
jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT

View File

@ -1,3 +1,10 @@
# 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!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
falcon==1.1.0 falcon==1.1.0
mock>=2.0 mock>=2.0

View File

@ -47,5 +47,6 @@ commands = flake8 {posargs}
[flake8] [flake8]
# D100-104 deal with docstrings in public functions # D100-104 deal with docstrings in public functions
# D205, D400, D401 deal with docstring formatting # D205, D400, D401 deal with docstring formatting
ignore=E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405,D100,D101,D102,D103,D104,D205,D400,D401,H101,I100 enable-extensions = H106,H203,H904
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools/xenserver*,releasenotes ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E251,H405
exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,tools/xenserver*,releasenotes