diff --git a/deckhand/barbican/client_wrapper.py b/deckhand/barbican/client_wrapper.py index c4594e5f..5f418829 100644 --- a/deckhand/barbican/client_wrapper.py +++ b/deckhand/barbican/client_wrapper.py @@ -14,6 +14,7 @@ from keystoneauth1.identity import v3 from keystoneauth1 import session +from oslo_log import log as logging from deckhand.conf import config from deckhand import errors @@ -22,6 +23,7 @@ from barbicanclient import barbican from barbicanclient import exceptions as barbican_exc CONF = config.CONF +LOG = logging.getLogger(__name__) class BarbicanClientWrapper(object): @@ -41,8 +43,8 @@ class BarbicanClientWrapper(object): if retry_on_conflict and self._cached_client is not None: return self._cached_client - # TODO: Deckhand's configuration file needs to be populated with - # correct Keysone authentication values as well as the Barbican + # TODO(fmontei): Deckhand's configuration file needs to be populated + # with correct Keysone authentication values as well as the Barbican # endpoint URL automatically. barbican_url = (CONF.barbican.api_endpoint if CONF.barbican.api_endpoint @@ -53,7 +55,7 @@ class BarbicanClientWrapper(object): sess = session.Session(auth=auth) try: - # TODO: replace with ``barbican_url``. + # TODO(fmontei): replace with ``barbican_url``. cli = barbican.client.Client(endpoint=barbican_url, session=sess) # Cache the client so we don't have to reconstruct and @@ -63,7 +65,7 @@ class BarbicanClientWrapper(object): except barbican_exc.HTTPAuthError: msg = _("Unable to authenticate Barbican client.") - # TODO: Log the error. + # TODO(fmontei): Log the error. raise errors.ApiError(msg) return cli @@ -106,9 +108,8 @@ class BarbicanClientWrapper(object): # client and the next try will start with a fresh one. if not attempt: self._invalidate_cached_client() - # TODO: include after implementing oslo.log. - # LOG.debug("The Barbican client became unauthorized. " - # "Will attempt to reauthorize and try again.") + LOG.debug("The Barbican client became unauthorized. " + "Will attempt to reauthorize and try again.") else: # This code should be unreachable actually raise diff --git a/deckhand/control/api.py b/deckhand/control/api.py index e36815ec..b6807097 100644 --- a/deckhand/control/api.py +++ b/deckhand/control/api.py @@ -37,7 +37,7 @@ def __setup_logging(): logging.register_options(CONF) config.parse_args() - + current_path = os.path.dirname(os.path.realpath(__file__)) root_path = os.path.abspath(os.path.join(current_path, os.pardir, os.pardir)) diff --git a/deckhand/control/common.py b/deckhand/control/common.py index 67c214b7..738b1e5a 100644 --- a/deckhand/control/common.py +++ b/deckhand/control/common.py @@ -26,6 +26,6 @@ class ViewBuilder(object): _collection_name = None 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' return base_url % (self._collection_name, revision.get('id')) diff --git a/deckhand/control/documents.py b/deckhand/control/documents.py index b9ed2223..1549d4a6 100644 --- a/deckhand/control/documents.py +++ b/deckhand/control/documents.py @@ -12,14 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy import yaml import falcon from oslo_db import exception as db_exc from oslo_log import log as logging -from oslo_serialization import jsonutils as json from deckhand.control import base as api_base from deckhand.db.sqlalchemy import api as db_api diff --git a/deckhand/control/revision_documents.py b/deckhand/control/revision_documents.py index d4394869..0e84d0e3 100644 --- a/deckhand/control/revision_documents.py +++ b/deckhand/control/revision_documents.py @@ -13,7 +13,6 @@ # limitations under the License. import falcon -from oslo_db import exception as db_exc from deckhand.control import base as api_base 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): """Returns all documents for a `revision_id`. - + Returns a multi-document YAML response containing all the documents matching the filters specified via query string parameters. Returned documents will be as originally posted with no substitutions or diff --git a/deckhand/control/revisions.py b/deckhand/control/revisions.py index e69031d2..6db1a3ed 100644 --- a/deckhand/control/revisions.py +++ b/deckhand/control/revisions.py @@ -25,7 +25,7 @@ class RevisionsResource(api_base.BaseResource): def on_get(self, req, resp, revision_id=None): """Returns list of existing revisions. - + Lists existing revisions and reports basic details including a summary of validation status for each `deckhand/ValidationPolicy` that is part of each revision. diff --git a/deckhand/control/views/revision.py b/deckhand/control/views/revision.py index e0052552..b957d605 100644 --- a/deckhand/control/views/revision.py +++ b/deckhand/control/views/revision.py @@ -62,7 +62,7 @@ class ViewBuilder(common.ViewBuilder): 'id': revision.get('id'), 'createdAt': revision.get('created_at'), 'url': self._gen_url(revision), - # TODO: Not yet implemented. + # TODO(fmontei): Not yet implemented. 'validationPolicies': validation_policies, 'status': success_status } diff --git a/deckhand/db/sqlalchemy/api.py b/deckhand/db/sqlalchemy/api.py index 355fae7d..3609cf16 100644 --- a/deckhand/db/sqlalchemy/api.py +++ b/deckhand/db/sqlalchemy/api.py @@ -17,7 +17,6 @@ import ast import copy -import datetime import threading 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.sqlalchemy import session from oslo_log import log as logging -from oslo_utils import excutils 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 -from sqlalchemy import sql -import sqlalchemy.sql as sa_sql from deckhand.db.sqlalchemy import models from deckhand import errors @@ -82,22 +73,6 @@ def get_session(autocommit=True, expire_on_commit=False): 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(): """Unset global configuration variables for database.""" global _FACADE @@ -255,7 +230,7 @@ def _filter_revision_documents(documents, **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 = [] for document in documents: diff --git a/deckhand/db/sqlalchemy/models.py b/deckhand/db/sqlalchemy/models.py index 7bcac00c..523f8a1b 100644 --- a/deckhand/db/sqlalchemy/models.py +++ b/deckhand/db/sqlalchemy/models.py @@ -23,12 +23,9 @@ from sqlalchemy import DateTime from sqlalchemy.ext import declarative from sqlalchemy import ForeignKey from sqlalchemy import Integer -from sqlalchemy import orm -from sqlalchemy.orm import backref, relationship +from sqlalchemy.orm import relationship from sqlalchemy import schema from sqlalchemy import String -from sqlalchemy import Text -from sqlalchemy.types import TypeDecorator # Declarative base class which maintains a catalog of classes and tables @@ -121,7 +118,8 @@ class Revision(BASE, DeckhandBase): class DocumentMixin(object): """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) schema = Column(String(64), nullable=False) diff --git a/deckhand/engine/document_validation.py b/deckhand/engine/document_validation.py index 9acf665d..b5f42518 100644 --- a/deckhand/engine/document_validation.py +++ b/deckhand/engine/document_validation.py @@ -120,7 +120,7 @@ class DocumentValidation(object): validation_policy_factory = factories.ValidationPolicyFactory() for document in self.documents: - document_validations = self._validate_one(document) + self._validate_one(document) deckhand_schema_validation = validation_policy_factory.gen( types.DECKHAND_SCHEMA_VALIDATION, status='success') @@ -156,12 +156,12 @@ class DocumentValidation(object): document_type=document['schema']) else: LOG.info('Skipping schema validation for abstract ' - 'document: %s.' % document) + 'document: %s.', document) def _is_abstract(self, document): try: is_abstract = document['metadata']['layeringDefinition'][ - 'abstract'] == True + 'abstract'] is True return is_abstract # NOTE(fmontei): If the document is of ``document_schema`` type and # no "layeringDefinition" or "abstract" property is found, then treat diff --git a/deckhand/factories.py b/deckhand/factories.py index 2322e721..29e03ddb 100644 --- a/deckhand/factories.py +++ b/deckhand/factories.py @@ -14,6 +14,7 @@ import abc import copy +import six from oslo_log import log as logging @@ -23,8 +24,8 @@ from deckhand import types LOG = logging.getLogger(__name__) +@six.add_metaclass(abc.ABCMeta) class DeckhandFactory(object): - __metaclass__ = abc.ABCMeta @abc.abstractmethod def gen(self, *args): diff --git a/deckhand/tests/functional/base.py b/deckhand/tests/functional/base.py index 4ff9c45b..1ecd1f43 100644 --- a/deckhand/tests/functional/base.py +++ b/deckhand/tests/functional/base.py @@ -14,7 +14,6 @@ import mock -import falcon from falcon import testing as falcon_testing from deckhand.control import api diff --git a/deckhand/tests/functional/test_documents.py b/deckhand/tests/functional/test_documents.py index ed9cbf0b..301d1fa2 100644 --- a/deckhand/tests/functional/test_documents.py +++ b/deckhand/tests/functional/test_documents.py @@ -17,9 +17,7 @@ import yaml import falcon -from deckhand.control import api from deckhand.tests.functional import base as test_base -from deckhand import types 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) 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 # document corresponding to ``yaml_data``. resp_documents = [d for d in yaml.safe_load_all(result.text)] diff --git a/deckhand/tests/unit/base.py b/deckhand/tests/unit/base.py index ad69e0a6..22a7571e 100644 --- a/deckhand/tests/unit/base.py +++ b/deckhand/tests/unit/base.py @@ -17,9 +17,7 @@ from oslo_config import cfg from oslo_log import log as logging import testtools -from deckhand.conf import config from deckhand.db.sqlalchemy import api as db_api -from deckhand.db.sqlalchemy import models as db_models CONF = cfg.CONF logging.register_options(CONF) diff --git a/deckhand/tests/unit/db/base.py b/deckhand/tests/unit/db/base.py index 8749c938..32b2cffd 100644 --- a/deckhand/tests/unit/db/base.py +++ b/deckhand/tests/unit/db/base.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import testtools from testtools import matchers from deckhand.db.sqlalchemy import api as db_api diff --git a/deckhand/tests/unit/db/test_revisions.py b/deckhand/tests/unit/db/test_revisions.py index b153e011..1afd4dd0 100644 --- a/deckhand/tests/unit/db/test_revisions.py +++ b/deckhand/tests/unit/db/test_revisions.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from deckhand.tests.unit.db import base from deckhand import factories +from deckhand.tests.unit.db import base from deckhand import types diff --git a/deckhand/tests/unit/engine/base.py b/deckhand/tests/unit/engine/base.py index b4922fa3..71e2a9fd 100644 --- a/deckhand/tests/unit/engine/base.py +++ b/deckhand/tests/unit/engine/base.py @@ -16,11 +16,6 @@ import copy import os 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 diff --git a/deckhand/tests/unit/resources/sample_layering_policy.yaml b/deckhand/tests/unit/resources/sample_layering_policy.yaml index de0a7a98..5a1391bc 100644 --- a/deckhand/tests/unit/resources/sample_layering_policy.yaml +++ b/deckhand/tests/unit/resources/sample_layering_policy.yaml @@ -2,7 +2,7 @@ --- schema: deckhand/LayeringPolicy/v1.0 metadata: - schema: metadata/Control/v1 + schema: metadata/Control/v1.0 name: a-unique-config-name-12345 data: layerOrder: diff --git a/deckhand/tests/unit/views/test_views.py b/deckhand/tests/unit/views/test_views.py index f6b73d96..4441bb26 100644 --- a/deckhand/tests/unit/views/test_views.py +++ b/deckhand/tests/unit/views/test_views.py @@ -14,8 +14,8 @@ from deckhand.control.views import revision from deckhand import factories -from deckhand.tests.unit.db import base from deckhand.tests import test_utils +from deckhand.tests.unit.db import base from deckhand import types @@ -103,9 +103,6 @@ class TestRevisionViews(base.TestDbBase): expected_attrs = ('id', 'url', 'createdAt', 'validationPolicies', 'status') - expected_validation_policies = [ - {'name': 'deckhand-schema-validation'}, 'status' - ] for attr in expected_attrs: self.assertIn(attr, revision_view) @@ -118,7 +115,6 @@ class TestRevisionViews(base.TestDbBase): self.assertEqual(revision_view['validationPolicies'][0]['status'], 'success') - def test_show_revision_failed_validation_policy(self): # Simulate 4 document payload with an internally generated validation # policy which executes 'deckhand-schema-validation'. @@ -134,9 +130,6 @@ class TestRevisionViews(base.TestDbBase): expected_attrs = ('id', 'url', 'createdAt', 'validationPolicies', 'status') - expected_validation_policies = [ - {'name': 'deckhand-schema-validation'}, 'status' - ] for attr in expected_attrs: self.assertIn(attr, revision_view) diff --git a/requirements.txt b/requirements.txt index 9f2c0bab..76e705ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT diff --git a/test-requirements.txt b/test-requirements.txt index da76afd5..5e85168c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 mock>=2.0 diff --git a/tox.ini b/tox.ini index 4c0840c6..462fc91f 100644 --- a/tox.ini +++ b/tox.ini @@ -47,5 +47,6 @@ commands = flake8 {posargs} [flake8] # D100-104 deal with docstrings in public functions # 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 -exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools/xenserver*,releasenotes +enable-extensions = H106,H203,H904 +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