Fix(linting): Make Armada pep8 compliant

This patch set makes Armada pep8 compliant. Note the hapi/** is
autogenerated and therefore should be excluded from linting.

Change-Id: I123eefb543f9bd9cf0bc6bd98ed95646d8d72cc3
This commit is contained in:
Pete Birley 2017-09-28 16:42:28 -05:00
parent 6ca2875c81
commit 746cbd0bd8
25 changed files with 70 additions and 12 deletions

View File

@ -12,10 +12,10 @@
# 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.
__all__ = ['__version__']
import pbr.version import pbr.version
__all__ = ['__version__']
version_info = pbr.version.VersionInfo('armada') version_info = pbr.version.VersionInfo('armada')
try: try:
__version__ = version_info.version_string() __version__ = version_info.version_string()

View File

@ -22,6 +22,7 @@ from armada.handlers.armada import Armada
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class Apply(api.BaseResource): class Apply(api.BaseResource):
''' '''
apply armada endpoint service apply armada endpoint service

View File

@ -16,6 +16,7 @@ from cliff import command as cmd
from armada.handlers.armada import Armada from armada.handlers.armada import Armada
def applyCharts(args): def applyCharts(args):
armada = Armada(open(args.file).read(), armada = Armada(open(args.file).read(),
@ -30,6 +31,7 @@ def applyCharts(args):
args.debug_logging) args.debug_logging)
armada.sync() armada.sync()
class ApplyChartsCommand(cmd.Command): class ApplyChartsCommand(cmd.Command):
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(ApplyChartsCommand, self).get_parser(prog_name) parser = super(ApplyChartsCommand, self).get_parser(prog_name)

View File

@ -23,6 +23,7 @@ LOG = logging.getLogger(__name__)
CONF = cfg.CONF CONF = cfg.CONF
def tillerServer(args): def tillerServer(args):
tiller = Tiller() tiller = Tiller()
@ -37,6 +38,7 @@ def tillerServer(args):
LOG.info("Release: %s ( namespace= %s )", release.name, LOG.info("Release: %s ( namespace= %s )", release.name,
release.namespace) release.namespace)
class TillerServerCommand(cmd.Command): class TillerServerCommand(cmd.Command):
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(TillerServerCommand, self).get_parser(prog_name) parser = super(TillerServerCommand, self).get_parser(prog_name)

View File

@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__)
CONF = cfg.CONF CONF = cfg.CONF
def validateYaml(args): def validateYaml(args):
documents = yaml.safe_load_all(open(args.file).read()) documents = yaml.safe_load_all(open(args.file).read())
manifest_obj = Manifest(documents).get_manifest() manifest_obj = Manifest(documents).get_manifest()
@ -37,6 +38,7 @@ def validateYaml(args):
except Exception: except Exception:
raise Exception('Failed to validate: %s', args.file) raise Exception('Failed to validate: %s', args.file)
class ValidateYamlCommand(cmd.Command): class ValidateYamlCommand(cmd.Command):
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(ValidateYamlCommand, self).get_parser(prog_name) parser = super(ValidateYamlCommand, self).get_parser(prog_name)

View File

@ -24,5 +24,6 @@ CONF = cfg.CONF
if (os.path.exists('etc/armada/armada.conf')): if (os.path.exists('etc/armada/armada.conf')):
CONF(['--config-file', 'etc/armada/armada.conf']) CONF(['--config-file', 'etc/armada/armada.conf'])
def set_app_default_configs(): def set_app_default_configs():
default.register_opts(CONF) default.register_opts(CONF)

View File

@ -68,8 +68,10 @@ The Keystone project domain name used for authentication.
help=utils.fmt('IDs of approved API access roles.')) help=utils.fmt('IDs of approved API access roles.'))
] ]
def register_opts(conf): def register_opts(conf):
conf.register_opts(default_options) conf.register_opts(default_options)
def list_opts(): def list_opts():
return {'DEFAULT': default_options} return {'DEFAULT': default_options}

View File

@ -14,6 +14,7 @@
import base_exception as base import base_exception as base
class ApiException(base.ArmadaBaseException): class ApiException(base.ArmadaBaseException):
'''Base class for API exceptions and error handling.''' '''Base class for API exceptions and error handling.'''

View File

@ -14,11 +14,13 @@
import base_exception import base_exception
class ArmadaException(base_exception.ArmadaBaseException): class ArmadaException(base_exception.ArmadaBaseException):
'''Base class for Armada handler exception and error handling.''' '''Base class for Armada handler exception and error handling.'''
message = 'An unknown Armada handler error occured.' message = 'An unknown Armada handler error occured.'
class KnownReleasesException(ArmadaException): class KnownReleasesException(ArmadaException):
'''Exception that occurs when no known releases are found''' '''Exception that occurs when no known releases are found'''

View File

@ -14,11 +14,13 @@
import base_exception import base_exception
class ChartBuilderException(base_exception.ArmadaBaseException): class ChartBuilderException(base_exception.ArmadaBaseException):
'''Base class for the Chartbuilder handler exception and error handling.''' '''Base class for the Chartbuilder handler exception and error handling.'''
message = 'An unknown Armada handler error occured.' message = 'An unknown Armada handler error occured.'
class DependencyException(ChartBuilderException): class DependencyException(ChartBuilderException):
'''Exception that occurs when dependencies cannot be resolved.''' '''Exception that occurs when dependencies cannot be resolved.'''
@ -29,6 +31,7 @@ class DependencyException(ChartBuilderException):
super(DependencyException, self).__init__(self._message) super(DependencyException, self).__init__(self._message)
class HelmChartBuildException(ChartBuilderException): class HelmChartBuildException(ChartBuilderException):
'''Exception that occurs when Helm Chart fails to build.''' '''Exception that occurs when Helm Chart fails to build.'''
@ -39,17 +42,20 @@ class HelmChartBuildException(ChartBuilderException):
super(HelmChartBuildException, self).__init__(self._message) super(HelmChartBuildException, self).__init__(self._message)
class IgnoredFilesLoadException(ChartBuilderException): class IgnoredFilesLoadException(ChartBuilderException):
'''Exception that occurs when there is an error loading ignored files.''' '''Exception that occurs when there is an error loading ignored files.'''
message = 'An error occured while loading the ignored files in \ message = 'An error occured while loading the ignored files in \
.helmignore' .helmignore'
class MetadataLoadException(ChartBuilderException): class MetadataLoadException(ChartBuilderException):
''' Exception that occurs when metadata loading fails.''' ''' Exception that occurs when metadata loading fails.'''
message = 'Failed to load metadata from chart yaml file' message = 'Failed to load metadata from chart yaml file'
class UnknownChartSourceException(ChartBuilderException): class UnknownChartSourceException(ChartBuilderException):
'''Exception for unknown chart source type.''' '''Exception for unknown chart source type.'''

View File

@ -14,31 +14,37 @@
import base_exception import base_exception
class LintException(base_exception.ArmadaBaseException): class LintException(base_exception.ArmadaBaseException):
'''Base class for linting exceptions and errors.''' '''Base class for linting exceptions and errors.'''
message = 'An unknown linting error occured.' message = 'An unknown linting error occured.'
class InvalidManifestException(LintException): class InvalidManifestException(LintException):
'''Exception for invalid manifests.''' '''Exception for invalid manifests.'''
message = 'Armada manifest invalid.' message = 'Armada manifest invalid.'
class InvalidChartNameException(LintException): class InvalidChartNameException(LintException):
'''Exception that occurs when an invalid filename is encountered.''' '''Exception that occurs when an invalid filename is encountered.'''
message = 'Chart name must be a string,' message = 'Chart name must be a string,'
class InvalidChartDefinitionException(LintException): class InvalidChartDefinitionException(LintException):
'''Exception when invalid chart definition is encountered.''' '''Exception when invalid chart definition is encountered.'''
message = 'Invalid chart definition.Chart definition must be array.' message = 'Invalid chart definition.Chart definition must be array.'
class InvalidReleaseException(LintException): class InvalidReleaseException(LintException):
'''Exception that occurs when a release is invalid.''' '''Exception that occurs when a release is invalid.'''
message = 'Release needs to be a string.' message = 'Release needs to be a string.'
class InvalidArmadaObjectException(LintException): class InvalidArmadaObjectException(LintException):
'''Exception that occurs when an Armada object is not declared.''' '''Exception that occurs when an Armada object is not declared.'''

View File

@ -14,11 +14,13 @@
import base_exception import base_exception
class SourceException(base_exception.ArmadaBaseException): class SourceException(base_exception.ArmadaBaseException):
'''Base class for Git exceptions and error handling.''' '''Base class for Git exceptions and error handling.'''
message = 'An unknown error occured while accessing a chart source' message = 'An unknown error occured while accessing a chart source'
class GitLocationException(SourceException): class GitLocationException(SourceException):
'''Exception that occurs when an error occurs cloning a Git repository.''' '''Exception that occurs when an error occurs cloning a Git repository.'''
@ -28,6 +30,7 @@ class GitLocationException(SourceException):
super(GitLocationException, self).__init__(self._message) super(GitLocationException, self).__init__(self._message)
class SourceCleanupException(SourceException): class SourceCleanupException(SourceException):
'''Exception that occurs for an invalid dir.''' '''Exception that occurs for an invalid dir.'''
@ -37,6 +40,7 @@ class SourceCleanupException(SourceException):
super(SourceCleanupException, self).__init__(self._message) super(SourceCleanupException, self).__init__(self._message)
class TarballDownloadException(SourceException): class TarballDownloadException(SourceException):
'''Exception that occurs when the tarball cannot be downloaded '''Exception that occurs when the tarball cannot be downloaded
from the provided URL from the provided URL
@ -48,6 +52,7 @@ class TarballDownloadException(SourceException):
super(TarballDownloadException, self).__init__(self._message) super(TarballDownloadException, self).__init__(self._message)
class TarballExtractException(SourceException): class TarballExtractException(SourceException):
'''Exception that occurs when extracting the tarball fails''' '''Exception that occurs when extracting the tarball fails'''
@ -57,6 +62,7 @@ class TarballExtractException(SourceException):
super(TarballExtractException, self).__init__(self._message) super(TarballExtractException, self).__init__(self._message)
class InvalidPathException(SourceException): class InvalidPathException(SourceException):
'''Exception that occurs when a nonexistant path is accessed''' '''Exception that occurs when a nonexistant path is accessed'''

View File

@ -14,16 +14,19 @@
from base_exception import ArmadaBaseException as ex from base_exception import ArmadaBaseException as ex
class TillerException(ex): class TillerException(ex):
'''Base class for Tiller exceptions and error handling.''' '''Base class for Tiller exceptions and error handling.'''
message = 'An unknown Tiller error occured.' message = 'An unknown Tiller error occured.'
class TillerServicesUnavailableException(TillerException): class TillerServicesUnavailableException(TillerException):
'''Exception for tiller services unavailable.''' '''Exception for tiller services unavailable.'''
message = 'Tiller services unavailable.' message = 'Tiller services unavailable.'
class ChartCleanupException(TillerException): class ChartCleanupException(TillerException):
'''Exception that occures during chart cleanup.''' '''Exception that occures during chart cleanup.'''
@ -32,11 +35,13 @@ class ChartCleanupException(TillerException):
chart_name) chart_name)
super(ChartCleanupException, self).__init__(message) super(ChartCleanupException, self).__init__(message)
class ListChartsException(TillerException): class ListChartsException(TillerException):
'''Exception that occurs when listing charts''' '''Exception that occurs when listing charts'''
message = 'There was an error listing the helm chart releases.' message = 'There was an error listing the helm chart releases.'
class PostUpdateJobDeleteException(TillerException): class PostUpdateJobDeleteException(TillerException):
'''Exception that occurs when a job deletion''' '''Exception that occurs when a job deletion'''
@ -47,6 +52,7 @@ class PostUpdateJobDeleteException(TillerException):
super(PostUpdateJobDeleteException, self).__init__(message) super(PostUpdateJobDeleteException, self).__init__(message)
class PostUpdateJobCreateException(TillerException): class PostUpdateJobCreateException(TillerException):
'''Exception that occurs when a job creation fails.''' '''Exception that occurs when a job creation fails.'''
@ -57,6 +63,7 @@ class PostUpdateJobCreateException(TillerException):
super(PostUpdateJobCreateException, self).__init__(message) super(PostUpdateJobCreateException, self).__init__(message)
class PreUpdateJobDeleteException(TillerException): class PreUpdateJobDeleteException(TillerException):
'''Exception that occurs when a job deletion''' '''Exception that occurs when a job deletion'''
@ -67,6 +74,7 @@ class PreUpdateJobDeleteException(TillerException):
super(PreUpdateJobDeleteException, self).__init__(message) super(PreUpdateJobDeleteException, self).__init__(message)
class PreUpdateJobCreateException(TillerException): class PreUpdateJobCreateException(TillerException):
'''Exception that occurs when a job creation fails.''' '''Exception that occurs when a job creation fails.'''
@ -77,6 +85,7 @@ class PreUpdateJobCreateException(TillerException):
super(PreUpdateJobCreateException, self).__init__(message) super(PreUpdateJobCreateException, self).__init__(message)
class ReleaseException(TillerException): class ReleaseException(TillerException):
'''Exception that occurs when a release fails to install.''' '''Exception that occurs when a release fails to install.'''
@ -87,11 +96,13 @@ class ReleaseException(TillerException):
super(ReleaseException, self).__init__(message) super(ReleaseException, self).__init__(message)
class ChannelException(TillerException): class ChannelException(TillerException):
'''Exception that occurs during a failed GRPC channel creation''' '''Exception that occurs during a failed GRPC channel creation'''
message = 'Failed to create GRPC channel.' message = 'Failed to create GRPC channel.'
class GetReleaseStatusException(TillerException): class GetReleaseStatusException(TillerException):
'''Exception that occurs during a failed Release Testing''' '''Exception that occurs during a failed Release Testing'''
@ -101,6 +112,7 @@ class GetReleaseStatusException(TillerException):
super(GetReleaseStatusException, self).__init__(message) super(GetReleaseStatusException, self).__init__(message)
class GetReleaseContentException(TillerException): class GetReleaseContentException(TillerException):
'''Exception that occurs during a failed Release Testing''' '''Exception that occurs during a failed Release Testing'''
@ -110,6 +122,7 @@ class GetReleaseContentException(TillerException):
super(GetReleaseContentException, self).__init__(message) super(GetReleaseContentException, self).__init__(message)
class TillerVersionException(TillerException): class TillerVersionException(TillerException):
'''Exception that occurs during a failed Release Testing''' '''Exception that occurs during a failed Release Testing'''

View File

@ -80,7 +80,7 @@ class ChartBuilder(object):
if os.path.exists(os.path.join(self.source_directory, if os.path.exists(os.path.join(self.source_directory,
'.helmignore')): '.helmignore')):
with open(os.path.join(self.source_directory, with open(os.path.join(self.source_directory,
'.helmignore')) as f: '.helmignore')) as f:
ignored_files = f.readlines() ignored_files = f.readlines()
return [filename.strip() for filename in ignored_files] return [filename.strip() for filename in ignored_files]
except Exception: except Exception:
@ -94,8 +94,8 @@ class ChartBuilder(object):
false otherwise false otherwise
''' '''
for ignored_file in self.ignored_files: for ignored_file in self.ignored_files:
if (ignored_file.startswith('*') if (ignored_file.startswith('*') and
and filename.endswith(ignored_file.strip('*'))): filename.endswith(ignored_file.strip('*'))):
return True return True
elif ignored_file == filename: elif ignored_file == filename:
return True return True

View File

@ -168,8 +168,8 @@ class K8s(object):
new_pod_name = event_name new_pod_name = event_name
elif new_pod_name: elif new_pod_name:
for condition in pod_conditions: for condition in pod_conditions:
if (condition.type == 'Ready' if (condition.type == 'Ready' and
and condition.status == 'True'): condition.status == 'True'):
LOG.info('New pod %s deployed', new_pod_name) LOG.info('New pod %s deployed', new_pod_name)
w.stop() w.stop()

View File

@ -14,6 +14,7 @@
from ..const import DOCUMENT_CHART, DOCUMENT_GROUP, DOCUMENT_MANIFEST from ..const import DOCUMENT_CHART, DOCUMENT_GROUP, DOCUMENT_MANIFEST
class Manifest(object): class Manifest(object):
def __init__(self, documents): def __init__(self, documents):
self.config = None self.config = None

View File

@ -23,6 +23,7 @@ import armada
CONF = cfg.CONF CONF = cfg.CONF
class ArmadaApp(app.App): class ArmadaApp(app.App):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(ArmadaApp, self).__init__( super(ArmadaApp, self).__init__(
@ -42,6 +43,7 @@ class ArmadaApp(app.App):
log.set_defaults(default_log_levels=CONF.default_log_levels) log.set_defaults(default_log_levels=CONF.default_log_levels)
log.setup(CONF, 'armada') log.setup(CONF, 'armada')
def main(argv=None): def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv[1:] argv = sys.argv[1:]

View File

@ -64,7 +64,8 @@ class TestAPI(APITestCase):
# Mock tiller status value # Mock tiller status value
mock_tiller.tiller_status.return_value = 'Active' mock_tiller.tiller_status.return_value = 'Active'
doc = {u'message': u'Tiller Server is Active'} # FIXME(lamt) This variable is unused. Uncomment when it is.
# doc = {u'message': u'Tiller Server is Active'}
result = self.simulate_get('/v1.0/status') result = self.simulate_get('/v1.0/status')
@ -85,7 +86,8 @@ class TestAPI(APITestCase):
# Mock tiller status value # Mock tiller status value
mock_tiller.list_releases.return_value = None mock_tiller.list_releases.return_value = None
doc = {u'releases': {}} # FIXME(lamt) This variable is unused. Uncomment when it is.
# doc = {u'releases': {}}
result = self.simulate_get('/v1.0/releases') result = self.simulate_get('/v1.0/releases')

View File

@ -18,6 +18,7 @@ import os
from armada.utils import lint from armada.utils import lint
class LintTestCase(unittest.TestCase): class LintTestCase(unittest.TestCase):
def setUp(self): def setUp(self):

View File

@ -16,6 +16,7 @@ import unittest
from armada.utils import release as rel from armada.utils import release as rel
class ReleaseTestCase(unittest.TestCase): class ReleaseTestCase(unittest.TestCase):
def test_release_prefix_pass(self): def test_release_prefix_pass(self):

View File

@ -19,6 +19,7 @@ from armada.exceptions import source_exceptions
from armada.utils import source from armada.utils import source
class GitTestCase(unittest.TestCase): class GitTestCase(unittest.TestCase):
SOURCE_UTILS_LOCATION = 'armada.utils.source' SOURCE_UTILS_LOCATION = 'armada.utils.source'

View File

@ -12,6 +12,7 @@
# 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.
def release_prefix(prefix, chart): def release_prefix(prefix, chart):
''' '''
how to attach prefix to chart how to attach prefix to chart

View File

@ -24,6 +24,7 @@ from git import Git
from ..exceptions import source_exceptions from ..exceptions import source_exceptions
def git_clone(repo_url, branch='master'): def git_clone(repo_url, branch='master'):
''' '''
:params repo_url - URL of git repo to clone :params repo_url - URL of git repo to clone
@ -47,10 +48,12 @@ def git_clone(repo_url, branch='master'):
return _tmp_dir return _tmp_dir
def get_tarball(tarball_url): def get_tarball(tarball_url):
tarball_path = download_tarball(tarball_url) tarball_path = download_tarball(tarball_url)
return extract_tarball(tarball_path) return extract_tarball(tarball_path)
def download_tarball(tarball_url): def download_tarball(tarball_url):
''' '''
Downloads a tarball to /tmp and returns the path Downloads a tarball to /tmp and returns the path
@ -64,6 +67,7 @@ def download_tarball(tarball_url):
raise source_exceptions.TarballDownloadException(tarball_url) raise source_exceptions.TarballDownloadException(tarball_url)
return tarball_filename return tarball_filename
def extract_tarball(tarball_path): def extract_tarball(tarball_path):
''' '''
Extracts a tarball to /tmp and returns the path Extracts a tarball to /tmp and returns the path
@ -80,6 +84,7 @@ def extract_tarball(tarball_path):
raise source_exceptions.TarballExtractException(tarball_path) raise source_exceptions.TarballExtractException(tarball_path)
return _tmp_dir return _tmp_dir
def source_cleanup(target_dir): def source_cleanup(target_dir):
''' '''
Clean up source Clean up source

View File

@ -12,10 +12,10 @@
# 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.
__all__ = ['__version__']
import pbr.version import pbr.version
__all__ = ['__version__']
version_info = pbr.version.VersionInfo('armada') version_info = pbr.version.VersionInfo('armada')
try: try:
__version__ = version_info.version_string() __version__ = version_info.version_string()

View File

@ -42,5 +42,5 @@ commands =
[flake8] [flake8]
filename= *.py filename= *.py
ignore = W503,E302 ignore =
exclude= .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi exclude= .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi