style(armada): converting py2 to py3

- Format code to python 3.5
- using absoulute paths

Change-Id: I7414b5de915429c2c7f85b99f2ab91f395c62121
This commit is contained in:
gardlt 2017-09-18 00:24:10 +00:00
parent d143c6b487
commit cba78d1d03
17 changed files with 107 additions and 110 deletions

View File

@ -10,21 +10,21 @@ RUN apt-get update && \
apt-get upgrade -y && \ apt-get upgrade -y && \
apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
netbase \ netbase \
python-all \ python3-pip && \
python-pip \
python-setuptools && \
apt-get install -y \ apt-get install -y \
build-essential \ build-essential \
curl \ curl \
git \ git \
python-all-dev && \ python3-minimal \
python3-setuptools \
python3-dev && \
useradd -u 1000 -g users -d /armada armada && \ useradd -u 1000 -g users -d /armada armada && \
chown -R armada:users /armada && \ chown -R armada:users /armada && \
\ \
cd /armada && \ cd /armada && \
pip install --upgrade pip && \ pip3 install --upgrade pip && \
pip install -r requirements.txt && \ pip3 install -r requirements.txt && \
pip install . && \ python3 setup.py install && \
\ \
apt-get purge --auto-remove -y \ apt-get purge --auto-remove -y \
build-essential \ build-essential \

View File

@ -12,23 +12,22 @@
# 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 falcon
import os import os
import falcon
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from armada.common import policy
from armada import conf from armada import conf
from armada.api import ArmadaRequest from armada.api import ArmadaRequest
from armada_controller import Apply from armada.api.armada_controller import Apply
from middleware import AuthMiddleware from armada.api.middleware import AuthMiddleware
from middleware import ContextMiddleware from armada.api.middleware import ContextMiddleware
from middleware import LoggingMiddleware from armada.api.middleware import LoggingMiddleware
from tiller_controller import Release from armada.api.tiller_controller import Release
from tiller_controller import Status from armada.api.tiller_controller import Status
from validation_controller import Validate from armada.api.validation_controller import Validate
from armada.common import policy
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
conf.set_app_default_configs() conf.set_app_default_configs()

View File

@ -12,7 +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.
import base_exception as base from armada.exceptions import base_exception as base
class ApiException(base.ArmadaBaseException): class ApiException(base.ArmadaBaseException):

View File

@ -12,7 +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.
import base_exception from armada.exceptions import base_exception
class ArmadaException(base_exception.ArmadaBaseException): class ArmadaException(base_exception.ArmadaBaseException):

View File

@ -12,7 +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.
import base_exception from armada.exceptions import base_exception
class ChartBuilderException(base_exception.ArmadaBaseException): class ChartBuilderException(base_exception.ArmadaBaseException):

View File

@ -12,7 +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.
import base_exception from armada.exceptions import base_exception
class LintException(base_exception.ArmadaBaseException): class LintException(base_exception.ArmadaBaseException):

View File

@ -12,7 +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.
import base_exception from armada.exceptions import base_exception
class SourceException(base_exception.ArmadaBaseException): class SourceException(base_exception.ArmadaBaseException):

View File

@ -12,7 +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.
from base_exception import ArmadaBaseException as ex from armada.exceptions.base_exception import ArmadaBaseException as ex
class TillerException(ex): class TillerException(ex):

View File

@ -18,20 +18,17 @@ import yaml
from oslo_log import log as logging from oslo_log import log as logging
from supermutes.dot import dotify from supermutes.dot import dotify
from chartbuilder import ChartBuilder from armada.handlers.chartbuilder import ChartBuilder
from tiller import Tiller from armada.handlers.tiller import Tiller
from manifest import Manifest from armada.handlers.manifest import Manifest
from armada.exceptions import armada_exceptions
from ..exceptions import armada_exceptions from armada.exceptions import source_exceptions
from ..exceptions import source_exceptions from armada.exceptions import lint_exceptions
from ..exceptions import lint_exceptions from armada.exceptions import tiller_exceptions
from ..exceptions import tiller_exceptions from armada.utils.release import release_prefix
from armada.utils import source
from ..utils.release import release_prefix from armada.utils import lint
from ..utils import source from armada import const
from ..utils import lint
from ..const import KEYWORD_ARMADA, KEYWORD_GROUPS, KEYWORD_CHARTS,\
KEYWORD_PREFIX, STATUS_FAILED
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -105,11 +102,13 @@ class Armada(object):
self.config = self.get_armada_manifest() self.config = self.get_armada_manifest()
# Purge known releases that have failed and are in the current yaml # Purge known releases that have failed and are in the current yaml
prefix = self.config.get(KEYWORD_ARMADA).get(KEYWORD_PREFIX) prefix = self.config.get(const.KEYWORD_ARMADA).get(
failed_releases = self.get_releases_by_status(STATUS_FAILED) const.KEYWORD_PREFIX)
failed_releases = self.get_releases_by_status(const.STATUS_FAILED)
for release in failed_releases: for release in failed_releases:
for group in self.config.get(KEYWORD_ARMADA).get(KEYWORD_GROUPS): for group in self.config.get(const.KEYWORD_ARMADA).get(
for ch in group.get(KEYWORD_CHARTS): const.KEYWORD_GROUPS):
for ch in group.get(const.KEYWORD_CHARTS):
ch_release_name = release_prefix(prefix, ch_release_name = release_prefix(prefix,
ch.get('chart') ch.get('chart')
.get('chart_name')) .get('chart_name'))
@ -123,8 +122,9 @@ class Armada(object):
# We only support a git source type right now, which can also # We only support a git source type right now, which can also
# handle git:// local paths as well # handle git:// local paths as well
repos = {} repos = {}
for group in self.config.get(KEYWORD_ARMADA).get(KEYWORD_GROUPS): for group in self.config.get(const.KEYWORD_ARMADA).get(
for ch in group.get(KEYWORD_CHARTS): const.KEYWORD_GROUPS):
for ch in group.get(const.KEYWORD_CHARTS):
self.tag_cloned_repo(ch, repos) self.tag_cloned_repo(ch, repos)
for dep in ch.get('chart').get('dependencies'): for dep in ch.get('chart').get('dependencies'):
@ -142,11 +142,11 @@ class Armada(object):
tarball_dir = source.get_tarball(location) tarball_dir = source.get_tarball(location)
ch.get('chart')['source_dir'] = (tarball_dir, subpath) ch.get('chart')['source_dir'] = (tarball_dir, subpath)
elif ct_type == 'git': elif ct_type == 'git':
reference = ch.get('chart').get('source').get('reference', reference = ch.get('chart').get('source').get(
'master') 'reference', 'master')
repo_branch = (location, reference) repo_branch = (location, reference)
if repo_branch not in repos.keys(): if repo_branch not in repos:
try: try:
LOG.info('Cloning repo: %s branch: %s', *repo_branch) LOG.info('Cloning repo: %s branch: %s', *repo_branch)
repo_dir = source.git_clone(*repo_branch) repo_dir = source.git_clone(*repo_branch)
@ -181,11 +181,7 @@ class Armada(object):
Syncronize Helm with the Armada Config(s) Syncronize Helm with the Armada Config(s)
''' '''
msg = { msg = {'installed': [], 'upgraded': [], 'diff': []}
'installed': [],
'upgraded': [],
'diff': []
}
# TODO: (gardlt) we need to break up this func into # TODO: (gardlt) we need to break up this func into
# a more cleaner format # a more cleaner format
@ -194,7 +190,8 @@ class Armada(object):
# extract known charts on tiller right now # extract known charts on tiller right now
known_releases = self.tiller.list_charts() known_releases = self.tiller.list_charts()
prefix = self.config.get(KEYWORD_ARMADA).get(KEYWORD_PREFIX) prefix = self.config.get(const.KEYWORD_ARMADA).get(
const.KEYWORD_PREFIX)
if known_releases is None: if known_releases is None:
raise armada_exceptions.KnownReleasesException() raise armada_exceptions.KnownReleasesException()
@ -203,11 +200,11 @@ class Armada(object):
LOG.debug("Release %s, Version %s found on tiller", release[0], LOG.debug("Release %s, Version %s found on tiller", release[0],
release[1]) release[1])
for entry in self.config[KEYWORD_ARMADA][KEYWORD_GROUPS]: for entry in self.config[const.KEYWORD_ARMADA][const.KEYWORD_GROUPS]:
chart_wait = self.wait chart_wait = self.wait
desc = entry.get('description', 'A Chart Group') desc = entry.get('description', 'A Chart Group')
chart_group = entry.get(KEYWORD_CHARTS, []) chart_group = entry.get(const.KEYWORD_CHARTS, [])
test_charts = entry.get('test_charts', False) test_charts = entry.get('test_charts', False)
if entry.get('sequenced', False) or test_charts: if entry.get('sequenced', False) or test_charts:
@ -273,8 +270,8 @@ class Armada(object):
# once we support those # once we support those
upgrade_diff = self.show_diff( upgrade_diff = self.show_diff(
chart, apply_chart, apply_values, chartbuilder.dump(), chart, apply_chart, apply_values,
values, msg) chartbuilder.dump(), values, msg)
if not upgrade_diff: if not upgrade_diff:
LOG.info("There are no updates found in this chart") LOG.info("There are no updates found in this chart")
@ -282,30 +279,31 @@ class Armada(object):
# do actual update # do actual update
LOG.info('wait: %s', chart_wait) LOG.info('wait: %s', chart_wait)
self.tiller.update_release(protoc_chart, self.tiller.update_release(
prefix_chart, protoc_chart,
chart.namespace, prefix_chart,
pre_actions=pre_actions, chart.namespace,
post_actions=post_actions, pre_actions=pre_actions,
dry_run=self.dry_run, post_actions=post_actions,
disable_hooks=chart. dry_run=self.dry_run,
upgrade.no_hooks, disable_hooks=chart.upgrade.no_hooks,
values=yaml.safe_dump(values), values=yaml.safe_dump(values),
wait=chart_wait, wait=chart_wait,
timeout=chart_timeout) timeout=chart_timeout)
msg['upgraded'].append(prefix_chart) msg['upgraded'].append(prefix_chart)
# process install # process install
else: else:
LOG.info("Installing release %s", chart.release) LOG.info("Installing release %s", chart.release)
self.tiller.install_release(protoc_chart, self.tiller.install_release(
prefix_chart, protoc_chart,
chart.namespace, prefix_chart,
dry_run=self.dry_run, chart.namespace,
values=yaml.safe_dump(values), dry_run=self.dry_run,
wait=chart_wait, values=yaml.safe_dump(values),
timeout=chart_timeout) wait=chart_wait,
timeout=chart_timeout)
msg['installed'].append(prefix_chart) msg['installed'].append(prefix_chart)
@ -328,7 +326,8 @@ class Armada(object):
if self.enable_chart_cleanup: if self.enable_chart_cleanup:
self.tiller.chart_cleanup( self.tiller.chart_cleanup(
prefix, self.config[KEYWORD_ARMADA][KEYWORD_GROUPS]) prefix,
self.config[const.KEYWORD_ARMADA][const.KEYWORD_GROUPS])
return msg return msg
@ -337,8 +336,9 @@ class Armada(object):
Operations to run after deployment process has terminated Operations to run after deployment process has terminated
''' '''
# Delete temp dirs used for deployment # Delete temp dirs used for deployment
for group in self.config.get(KEYWORD_ARMADA).get(KEYWORD_GROUPS): for group in self.config.get(const.KEYWORD_ARMADA).get(
for ch in group.get(KEYWORD_CHARTS): const.KEYWORD_GROUPS):
for ch in group.get(const.KEYWORD_CHARTS):
if ch.get('chart').get('source').get('type') == 'git': if ch.get('chart').get('source').get('type') == 'git':
source.source_cleanup(ch.get('chart').get('source_dir')[0]) source.source_cleanup(ch.get('chart').get('source_dir')[0])
@ -351,10 +351,9 @@ class Armada(object):
unified diff output and avoid the use of print unified diff output and avoid the use of print
''' '''
source = str(installed_chart.SerializeToString()).split('\n')
chart_diff = list( chart_diff = list(
difflib.unified_diff( difflib.unified_diff(source, str(target_chart).split('\n')))
installed_chart.SerializeToString().split('\n'),
target_chart.split('\n')))
if len(chart_diff) > 0: if len(chart_diff) > 0:
LOG.info("Chart Unified Diff (%s)", chart.release) LOG.info("Chart Unified Diff (%s)", chart.release)

View File

@ -15,13 +15,13 @@
import os import os
import yaml import yaml
from hapi.chart.template_pb2 import Template
from hapi.chart.chart_pb2 import Chart from hapi.chart.chart_pb2 import Chart
from hapi.chart.metadata_pb2 import Metadata
from hapi.chart.config_pb2 import Config from hapi.chart.config_pb2 import Config
from hapi.chart.metadata_pb2 import Metadata
from hapi.chart.template_pb2 import Template
from supermutes.dot import dotify from supermutes.dot import dotify
from ..exceptions import chartbuilder_exceptions from armada.exceptions import chartbuilder_exceptions
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -108,10 +108,9 @@ class ChartBuilder(object):
# extract Chart.yaml to construct metadata # extract Chart.yaml to construct metadata
try: try:
chart_yaml = dotify( with open(os.path.join(self.source_directory, 'Chart.yaml')) as f:
yaml.safe_load( chart_yaml = dotify(yaml.safe_load(f.read().encode('utf-8')))
open(os.path.join(self.source_directory, 'Chart.yaml'))
.read()))
except Exception: except Exception:
raise chartbuilder_exceptions.MetadataLoadException() raise chartbuilder_exceptions.MetadataLoadException()
@ -136,8 +135,8 @@ class ChartBuilder(object):
# create config object representing unmarshaled values.yaml # create config object representing unmarshaled values.yaml
if os.path.exists(os.path.join(self.source_directory, 'values.yaml')): if os.path.exists(os.path.join(self.source_directory, 'values.yaml')):
raw_values = open( with open(os.path.join(self.source_directory, 'values.yaml')) as f:
os.path.join(self.source_directory, 'values.yaml')).read() raw_values = f.read()
else: else:
LOG.warn("No values.yaml in %s, using empty values", LOG.warn("No values.yaml in %s, using empty values",
self.source_directory) self.source_directory)
@ -168,10 +167,10 @@ class ChartBuilder(object):
LOG.debug('Ignoring file %s', tname) LOG.debug('Ignoring file %s', tname)
continue continue
templates.append( with open(os.path.join(root, tpl_file)) as f:
Template( templates.append(
name=tname, Template(name=tname, data=f.read().encode()))
data=open(os.path.join(root, tpl_file), 'r').read()))
return templates return templates
def get_helm_chart(self): def get_helm_chart(self):

View File

@ -12,7 +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.
from ..const import DOCUMENT_CHART, DOCUMENT_GROUP, DOCUMENT_MANIFEST from armada.const import DOCUMENT_CHART, DOCUMENT_GROUP, DOCUMENT_MANIFEST
class Manifest(object): class Manifest(object):

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.
import yaml
import grpc import grpc
import yaml
from hapi.chart.config_pb2 import Config from hapi.chart.config_pb2 import Config
from hapi.services.tiller_pb2 import GetReleaseContentRequest from hapi.services.tiller_pb2 import GetReleaseContentRequest
@ -28,10 +28,10 @@ from hapi.services.tiller_pb2 import UpdateReleaseRequest
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from ..const import STATUS_DEPLOYED, STATUS_FAILED from armada.const import STATUS_DEPLOYED, STATUS_FAILED
from ..exceptions import tiller_exceptions as ex from armada.exceptions import tiller_exceptions as ex
from ..utils.release import release_prefix from armada.handlers.k8s import K8s
from k8s import K8s from armada.utils.release import release_prefix
TILLER_PORT = 44134 TILLER_PORT = 44134
@ -238,8 +238,8 @@ class Tiller(object):
label_selector = 'release_name={}'.format(release_name) label_selector = 'release_name={}'.format(release_name)
for label in resource_labels: for label in resource_labels:
label_selector += ', {}={}'.format(label.keys()[0], label_selector += ', {}={}'.format(list(label.keys())[0],
label.values()[0]) list(label.values())[0])
if 'job' in resource_type: if 'job' in resource_type:
LOG.info("Deleting %s in namespace: %s", resource_name, namespace) LOG.info("Deleting %s in namespace: %s", resource_name, namespace)

View File

@ -18,11 +18,13 @@ import unittest
import falcon import falcon
from falcon import testing from falcon import testing
from oslo_config import cfg
from armada import conf as cfg from armada import conf
from armada.api import server from armada.api import server
CONF = cfg.CONF CONF = cfg.CONF
conf.set_app_default_configs()
class APITestCase(testing.TestCase): class APITestCase(testing.TestCase):

View File

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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 unittest import unittest
import mock import mock
@ -83,4 +84,4 @@ class ChartBuilderTestCase(unittest.TestCase):
resp = chartbuilder.get_metadata() resp = chartbuilder.get_metadata()
self.assertIsNotNone(resp) self.assertIsNotNone(resp)
self.assertIsInstance(resp, basestring) self.assertIsInstance(resp, str)

View File

@ -7,16 +7,14 @@ kubernetes>=1.0.0
protobuf==3.2.0 protobuf==3.2.0
PyYAML==3.12 PyYAML==3.12
requests==2.17.3 requests==2.17.3
sphinx_rtd_theme
supermutes==0.2.5 supermutes==0.2.5
urllib3==1.21.1 urllib3==1.21.1
uwsgi>=2.0.15
Paste>=2.0.3 Paste>=2.0.3
PasteDeploy>=1.5.2 PasteDeploy>=1.5.2
# API # API
falcon==1.1.0 falcon==1.1.0
gunicorn==19.7.1 uwsgi>=2.0.15
# CLI # CLI
cliff==2.7.0 cliff==2.7.0

View File

@ -3,10 +3,10 @@ tox
# Docs # Docs
sphinx>=1.6.2 sphinx>=1.6.2
sphinx_rtd_theme==0.2.4 sphinx_rtd_theme>=0.2.4
# Testing # Testing
flake8==3.3.0 flake8>=3.3.0
nose==1.3.7 nose==1.3.7
testtools==2.3.0 testtools==2.3.0
codecov codecov

View File

@ -1,9 +1,8 @@
[tox] [tox]
skipsdist = True skipsdist = True
envlist = py27, pep8, coverage, bandit envlist = py35, pep8, coverage, bandit
[testenv] [testenv]
basepython=python2.7
deps= deps=
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt