summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTin Lam <tin@irrational.io>2018-11-26 02:24:09 -0600
committerTin Lam <tin@irrational.io>2019-01-01 00:18:03 -0600
commit1a325a400b32a1bc990544ad688a177c2540e9ae (patch)
treec4a88d160588ff3e3c65d0a5c7f1f4e29a5e0a25
parent213ca596e3b21f81af96587e9f13ded1f3abccaf (diff)
Add hacking extension
This patch set adds hacking rule to pegleg and fixes outstanding non- docstring related violations. Change-Id: I5bb5e78c211f24cf95669124bfcf9603bea8bf15 Signed-off-by: Tin Lam <tin@irrational.io>
Notes
Notes (review): Code-Review+1: Chris Wedgwood <cw@f00f.org> Code-Review+2: Felipe Monteiro <felipe.monteiro@att.com> Workflow+1: Felipe Monteiro <felipe.monteiro@att.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 01 Jan 2019 18:13:07 +0000 Reviewed-on: https://review.openstack.org/619981 Project: openstack/airship-pegleg Branch: refs/heads/master
-rw-r--r--pegleg/engine/lint.py2
-rw-r--r--pegleg/engine/repository.py2
-rw-r--r--pegleg/engine/secrets.py4
-rw-r--r--pegleg/engine/site.py2
-rw-r--r--pegleg/engine/util/deckhand.py6
-rw-r--r--pegleg/engine/util/encryption.py5
-rw-r--r--pegleg/engine/util/files.py9
-rw-r--r--pegleg/engine/util/pegleg_managed_document.py4
-rw-r--r--pegleg/engine/util/pegleg_secret_management.py11
-rw-r--r--pegleg/engine/util/shipyard_helper.py14
-rw-r--r--test-requirements.txt2
-rw-r--r--tests/unit/engine/test_site_repository.py3
-rw-r--r--tox.ini10
13 files changed, 43 insertions, 31 deletions
diff --git a/pegleg/engine/lint.py b/pegleg/engine/lint.py
index c0706ce..7b2f725 100644
--- a/pegleg/engine/lint.py
+++ b/pegleg/engine/lint.py
@@ -216,7 +216,7 @@ def _verify_file_contents(*, sitename=None):
216 216
217def _verify_single_file(filename, schemas): 217def _verify_single_file(filename, schemas):
218 errors = [] 218 errors = []
219 LOG.debug("Validating file %s." % filename) 219 LOG.debug("Validating file %s.", filename)
220 with open(filename) as f: 220 with open(filename) as f:
221 if not f.read(4) == '---\n': 221 if not f.read(4) == '---\n':
222 errors.append((FILE_MISSING_YAML_DOCUMENT_HEADER, 222 errors.append((FILE_MISSING_YAML_DOCUMENT_HEADER,
diff --git a/pegleg/engine/repository.py b/pegleg/engine/repository.py
index 52d7285..7c8bdfd 100644
--- a/pegleg/engine/repository.py
+++ b/pegleg/engine/repository.py
@@ -196,7 +196,7 @@ def _get_and_validate_site_repositories(site_name, site_data):
196 LOG.info("The repository for site_name: %s does not contain a " 196 LOG.info("The repository for site_name: %s does not contain a "
197 "site-definition.yaml with a 'repositories' key. Ensure " 197 "site-definition.yaml with a 'repositories' key. Ensure "
198 "your repository is self-contained and doesn't require " 198 "your repository is self-contained and doesn't require "
199 "extra repositories for correct rendering." % site_name) 199 "extra repositories for correct rendering.", site_name)
200 return site_data.get('repositories', {}) 200 return site_data.get('repositories', {})
201 201
202 202
diff --git a/pegleg/engine/secrets.py b/pegleg/engine/secrets.py
index 08688bc..19afb59 100644
--- a/pegleg/engine/secrets.py
+++ b/pegleg/engine/secrets.py
@@ -15,9 +15,9 @@
15import logging 15import logging
16import os 16import os
17 17
18from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
19from pegleg.engine.util import files
20from pegleg.engine.util import definition 18from pegleg.engine.util import definition
19from pegleg.engine.util import files
20from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
21 21
22__all__ = ('encrypt', 'decrypt') 22__all__ = ('encrypt', 'decrypt')
23 23
diff --git a/pegleg/engine/site.py b/pegleg/engine/site.py
index 2a03074..390ea50 100644
--- a/pegleg/engine/site.py
+++ b/pegleg/engine/site.py
@@ -67,7 +67,7 @@ def _collect_to_file(site_name, save_location):
67 save_file = os.path.join(save_location, repo_name + '.yaml') 67 save_file = os.path.join(save_location, repo_name + '.yaml')
68 if repo_name not in save_files: 68 if repo_name not in save_files:
69 save_files[repo_name] = open(save_file, "w") 69 save_files[repo_name] = open(save_file, "w")
70 LOG.debug("Collecting file %s to file %s" % (filename, save_file)) 70 LOG.debug("Collecting file %s to file %s", filename, save_file)
71 save_files[repo_name].writelines(_read_and_format_yaml(filename)) 71 save_files[repo_name].writelines(_read_and_format_yaml(filename))
72 except Exception as ex: 72 except Exception as ex:
73 raise click.ClickException("Error saving output: %s" % str(ex)) 73 raise click.ClickException("Error saving output: %s" % str(ex))
diff --git a/pegleg/engine/util/deckhand.py b/pegleg/engine/util/deckhand.py
index afb3e57..c1d42fd 100644
--- a/pegleg/engine/util/deckhand.py
+++ b/pegleg/engine/util/deckhand.py
@@ -12,11 +12,13 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA 15
16from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
17from deckhand.engine import layering 16from deckhand.engine import layering
18from deckhand import errors as dh_errors 17from deckhand import errors as dh_errors
19 18
19from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA
20from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
21
20 22
21def load_schemas_from_docs(documents): 23def load_schemas_from_docs(documents):
22 ''' 24 '''
diff --git a/pegleg/engine/util/encryption.py b/pegleg/engine/util/encryption.py
index c84f61d..626a151 100644
--- a/pegleg/engine/util/encryption.py
+++ b/pegleg/engine/util/encryption.py
@@ -12,13 +12,14 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15import logging
16import base64 15import base64
16import logging
17
18from cryptography.exceptions import InvalidSignature
17from cryptography.fernet import Fernet 19from cryptography.fernet import Fernet
18from cryptography.hazmat.backends import default_backend 20from cryptography.hazmat.backends import default_backend
19from cryptography.hazmat.primitives import hashes 21from cryptography.hazmat.primitives import hashes
20from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC 22from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
21from cryptography.exceptions import InvalidSignature
22 23
23KEY_LENGTH = 32 24KEY_LENGTH = 32
24ITERATIONS = 10000 25ITERATIONS = 10000
diff --git a/pegleg/engine/util/files.py b/pegleg/engine/util/files.py
index 7a18285..02cb33e 100644
--- a/pegleg/engine/util/files.py
+++ b/pegleg/engine/util/files.py
@@ -12,11 +12,12 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15import click
16import collections 15import collections
16import logging
17import os 17import os
18
19import click
18import yaml 20import yaml
19import logging
20 21
21from pegleg import config 22from pegleg import config
22from pegleg.engine import util 23from pegleg.engine import util
@@ -330,7 +331,7 @@ def search(search_paths):
330 search_paths = [search_paths] 331 search_paths = [search_paths]
331 332
332 for search_path in search_paths: 333 for search_path in search_paths:
333 LOG.debug("Recursively collecting YAMLs from %s" % search_path) 334 LOG.debug("Recursively collecting YAMLs from %s", search_path)
334 for root, _, filenames in os.walk(search_path): 335 for root, _, filenames in os.walk(search_path):
335 336
336 # Ignore hidden folders like .tox or .git for faster processing. 337 # Ignore hidden folders like .tox or .git for faster processing.
@@ -372,7 +373,7 @@ def check_file_save_location(save_location):
372 373
373 374
374def collect_files_by_repo(site_name): 375def collect_files_by_repo(site_name):
375 """ Collects file by repo name in memory.""" 376 """Collects file by repo name in memory."""
376 377
377 collected_files_by_repo = collections.defaultdict(list) 378 collected_files_by_repo = collections.defaultdict(list)
378 for repo_base, filename in util.definition.site_files_by_repo( 379 for repo_base, filename in util.definition.site_files_by_repo(
diff --git a/pegleg/engine/util/pegleg_managed_document.py b/pegleg/engine/util/pegleg_managed_document.py
index 94527be..1cfd504 100644
--- a/pegleg/engine/util/pegleg_managed_document.py
+++ b/pegleg/engine/util/pegleg_managed_document.py
@@ -12,8 +12,8 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15import logging
16from datetime import datetime 15from datetime import datetime
16import logging
17 17
18PEGLEG_MANAGED_SCHEMA = 'pegleg/PeglegManagedDocument/v1' 18PEGLEG_MANAGED_SCHEMA = 'pegleg/PeglegManagedDocument/v1'
19ENCRYPTED = 'encrypted' 19ENCRYPTED = 'encrypted'
@@ -22,7 +22,7 @@ METADATA = 'metadata'
22LOG = logging.getLogger(__name__) 22LOG = logging.getLogger(__name__)
23 23
24 24
25class PeglegManagedSecretsDocument(): 25class PeglegManagedSecretsDocument(object):
26 """Object representing one Pegleg managed secret document.""" 26 """Object representing one Pegleg managed secret document."""
27 27
28 def __init__(self, secrets_document): 28 def __init__(self, secrets_document):
diff --git a/pegleg/engine/util/pegleg_secret_management.py b/pegleg/engine/util/pegleg_secret_management.py
index a939f2d..364fab4 100644
--- a/pegleg/engine/util/pegleg_secret_management.py
+++ b/pegleg/engine/util/pegleg_secret_management.py
@@ -14,16 +14,17 @@
14 14
15import logging 15import logging
16import os 16import os
17import yaml
18import sys
19import re 17import re
18import sys
19
20import click 20import click
21import yaml
21 22
22from pegleg.engine.util.encryption import encrypt
23from pegleg.engine.util.encryption import decrypt 23from pegleg.engine.util.encryption import decrypt
24from pegleg.engine.util.encryption import encrypt
25from pegleg.engine.util import files
24from pegleg.engine.util.pegleg_managed_document import \ 26from pegleg.engine.util.pegleg_managed_document import \
25 PeglegManagedSecretsDocument as PeglegManagedSecret 27 PeglegManagedSecretsDocument as PeglegManagedSecret
26from pegleg.engine.util import files
27 28
28LOG = logging.getLogger(__name__) 29LOG = logging.getLogger(__name__)
29PASSPHRASE_PATTERN = '^.{24,}$' 30PASSPHRASE_PATTERN = '^.{24,}$'
@@ -31,7 +32,7 @@ ENV_PASSPHRASE = 'PEGLEG_PASSPHRASE'
31ENV_SALT = 'PEGLEG_SALT' 32ENV_SALT = 'PEGLEG_SALT'
32 33
33 34
34class PeglegSecretManagement(): 35class PeglegSecretManagement(object):
35 """An object to handle operations on of a pegleg managed file.""" 36 """An object to handle operations on of a pegleg managed file."""
36 37
37 def __init__(self, file_path=None, docs=None): 38 def __init__(self, file_path=None, docs=None):
diff --git a/pegleg/engine/util/shipyard_helper.py b/pegleg/engine/util/shipyard_helper.py
index 4c58580..07de7ea 100644
--- a/pegleg/engine/util/shipyard_helper.py
+++ b/pegleg/engine/util/shipyard_helper.py
@@ -18,8 +18,8 @@ import uuid
18 18
19import yaml 19import yaml
20 20
21from pegleg.engine.util import files
22from pegleg.engine.exceptions import PeglegBaseException 21from pegleg.engine.exceptions import PeglegBaseException
22from pegleg.engine.util import files
23 23
24from shipyard_client.api_client.shipyard_api_client import ShipyardClient 24from shipyard_client.api_client.shipyard_api_client import ShipyardClient
25from shipyard_client.api_client.shipyardclient_context import \ 25from shipyard_client.api_client.shipyardclient_context import \
@@ -36,7 +36,7 @@ class AuthValuesError(PeglegBaseException):
36 36
37 37
38class DocumentUploadError(PeglegBaseException): 38class DocumentUploadError(PeglegBaseException):
39 """ Exception occurs while uploading documents""" 39 """Exception occurs while uploading documents"""
40 40
41 def __init__(self, message): 41 def __init__(self, message):
42 self.message = message 42 self.message = message
@@ -65,18 +65,18 @@ class ShipyardHelper(object):
65 self.context_marker = self.ctx.obj['context_marker'] 65 self.context_marker = self.ctx.obj['context_marker']
66 if self.context_marker is None: 66 if self.context_marker is None:
67 self.context_marker = str(uuid.uuid4()) 67 self.context_marker = str(uuid.uuid4())
68 LOG.debug("context_marker is %s" % self.context_marker) 68 LOG.debug("context_marker is %s", self.context_marker)
69 self.site_name = self.ctx.obj['site_name'] 69 self.site_name = self.ctx.obj['site_name']
70 self.client_context = ShipyardClientContext( 70 self.client_context = ShipyardClientContext(
71 self.auth_vars, self.context_marker) 71 self.auth_vars, self.context_marker)
72 self.api_client = ShipyardClient(self.client_context) 72 self.api_client = ShipyardClient(self.client_context)
73 73
74 def upload_documents(self): 74 def upload_documents(self):
75 """ Uploads documents to Shipyard """ 75 """Uploads documents to Shipyard """
76 76
77 collected_documents = files.collect_files_by_repo(self.site_name) 77 collected_documents = files.collect_files_by_repo(self.site_name)
78 78
79 LOG.info("Uploading %s collection(s) " % len(collected_documents)) 79 LOG.info("Uploading %d collection(s) ", len(collected_documents))
80 for idx, document in enumerate(collected_documents): 80 for idx, document in enumerate(collected_documents):
81 # Append flag is not required for the first 81 # Append flag is not required for the first
82 # collection being uploaded to Shipyard. It 82 # collection being uploaded to Shipyard. It
@@ -129,7 +129,7 @@ class ShipyardHelper(object):
129 raise DocumentUploadError(resp_text) 129 raise DocumentUploadError(resp_text)
130 else: 130 else:
131 output = self.formatted_response_handler(resp_text) 131 output = self.formatted_response_handler(resp_text)
132 LOG.info("Uploaded document in buffer %s " % output) 132 LOG.info("Uploaded document in buffer %s ", output)
133 133
134 # Commit in the last iteration of the loop when all the documents 134 # Commit in the last iteration of the loop when all the documents
135 # have been pushed to Shipyard buffer. 135 # have been pushed to Shipyard buffer.
@@ -137,7 +137,7 @@ class ShipyardHelper(object):
137 return self.commit_documents() 137 return self.commit_documents()
138 138
139 def commit_documents(self): 139 def commit_documents(self):
140 """ Commit Shipyard buffer documents """ 140 """Commit Shipyard buffer documents """
141 141
142 LOG.info("Commiting Shipyard buffer documents") 142 LOG.info("Commiting Shipyard buffer documents")
143 143
diff --git a/test-requirements.txt b/test-requirements.txt
index 010aa6d..1f28230 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -7,7 +7,7 @@ mock==2.0.0
7yapf==0.20.0 7yapf==0.20.0
8 8
9# Linting 9# Linting
10flake8==3.3.0 10hacking>=1.1.0,<1.2.0 # Apache-2.0
11 11
12# Security 12# Security
13bandit>=1.5.0 13bandit>=1.5.0
diff --git a/tests/unit/engine/test_site_repository.py b/tests/unit/engine/test_site_repository.py
index 27df345..2dd8bdc 100644
--- a/tests/unit/engine/test_site_repository.py
+++ b/tests/unit/engine/test_site_repository.py
@@ -455,8 +455,7 @@ def test_process_repositories_without_repositories_key_in_site_definition(
455 _test_process_repositories_inner( 455 _test_process_repositories_inner(
456 site_name=mock.sentinel.site, expected_extra_repos={}) 456 site_name=mock.sentinel.site, expected_extra_repos={})
457 msg = ("The repository for site_name: %s does not contain a " 457 msg = ("The repository for site_name: %s does not contain a "
458 "site-definition.yaml with a 'repositories' key" % str( 458 "site-definition.yaml with a 'repositories' key")
459 mock.sentinel.site))
460 assert any(msg in x[1][0] for x in m_log.info.mock_calls) 459 assert any(msg in x[1][0] for x in m_log.info.mock_calls)
461 460
462 461
diff --git a/tox.ini b/tox.ini
index 53f825b..75efc85 100644
--- a/tox.ini
+++ b/tox.ini
@@ -74,6 +74,14 @@ commands = {posargs}
74[flake8] 74[flake8]
75filename = *.py 75filename = *.py
76show-source = true 76show-source = true
77ignore = 77# [H106] Don't put vim configuration in source files.
78# [H210] Require 'autospec', 'spec', or 'spec_set' in mock.patch/mock.patch.object calls
79# [H904] Delay string interpolations at logging calls.
80enable-extensions = H106,H201,H904
81# TODO(lamt) Clean up these docstring violations if possible
82# [H403] multi line docstrings should end on a new line
83# [H404] multi line docstring should start without a leading new line
84# [H405] multi line docstring summary not separated with an empty line
85ignore = H403,H404,H405
78exclude=.venv,.git,.tox,build,dist,*lib/python*,*egg,tools,*.ini,*.po,*.pot 86exclude=.venv,.git,.tox,build,dist,*lib/python*,*egg,tools,*.ini,*.po,*.pot
79max-complexity = 24 87max-complexity = 24