diff --git a/armada/handlers/chartbuilder.py b/armada/handlers/chartbuilder.py index 22bbec2e..c21670aa 100644 --- a/armada/handlers/chartbuilder.py +++ b/armada/handlers/chartbuilder.py @@ -109,7 +109,7 @@ class ChartBuilder(object): try: chart_yaml = dotify( - yaml.load( + yaml.safe_load( open(os.path.join(self.source_directory, 'Chart.yaml')) .read())) except Exception: diff --git a/armada/utils/source.py b/armada/utils/source.py index a8015ddf..099f6443 100644 --- a/armada/utils/source.py +++ b/armada/utils/source.py @@ -1,10 +1,25 @@ +# Copyright 2017 The Armada Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from os import path import os import requests +import shutil import tarfile import tempfile -import shutil + from git import Repo -from os import path from ..exceptions import source_exceptions @@ -20,7 +35,7 @@ def git_clone(repo_url, branch='master'): raise source_exceptions.GitLocationException(repo_url) os.environ['GIT_TERMINAL_PROMPT'] = '0' - _tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp') + _tmp_dir = tempfile.mkdtemp(prefix='armada') try: Repo.clone_from(repo_url, _tmp_dir, **{'branch': branch}) @@ -38,7 +53,7 @@ def download_tarball(tarball_url): Downloads a tarball to /tmp and returns the path ''' try: - tarball_filename = tempfile.mkstemp(prefix='armada', dir='/tmp')[1] + tarball_filename = tempfile.mkstemp(prefix='armada')[1] response = requests.get(tarball_url) with open(tarball_filename, 'wb') as f: f.write(response.content) @@ -53,7 +68,7 @@ def extract_tarball(tarball_path): if not path.exists(tarball_path): raise source_exceptions.InvalidPathException(tarball_path) - _tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp') + _tmp_dir = tempfile.mkdtemp(prefix='armada') try: file = tarfile.open(tarball_path) diff --git a/docs/source/development/getting-started.rst b/docs/source/development/getting-started.rst index a4c40902..250a66cd 100644 --- a/docs/source/development/getting-started.rst +++ b/docs/source/development/getting-started.rst @@ -36,7 +36,17 @@ From the directory of the forked repository: pip install -r requirements.txt pip install -r test-requirements.txt - pip install -e . + + pip install . + + # Testing your armada code + # The tox command will execute lint, bandit, cover + tox + + # For targeted test + tox -e pep8 + tox -e bandit + tox -e cover .. note:: diff --git a/setup.py b/setup.py index b9d5367a..c53ce4f7 100755 --- a/setup.py +++ b/setup.py @@ -1,22 +1,5 @@ -from setuptools.command.test import test as TestCommand -import sys import setuptools -class Tox(TestCommand): - """Runs Tox comands""" - def finalize_options(self): - """preps test suite""" - TestCommand.finalize_options(self) - self.test_args = [] - self.test_suite = True - - def run_tests(self): - """runs test suite""" - import tox - errcode = tox.cmdline(self.test_args) - sys.exit(errcode) - - try: import multiprocessing # noqa except ImportError: diff --git a/test-requirements.txt b/test-requirements.txt index 5066d592..358d094b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -10,3 +10,5 @@ nose==1.3.7 testtools==2.3.0 codecov mock +bandit +pytest==3.2.1 diff --git a/tox.ini b/tox.ini index 52e16561..bc19b7c1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,26 +1,47 @@ [tox] -envlist = py27 +skipsdist = True +envlist = py27, pep8, coverage, bandit [testenv] deps= -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt setenv= - PYTHONWARNINGS=all + VIRTUAL_ENV={envdir} +usedevelop = True +commands = + find . -type f -name "*.pyc" -delete + python -V + py.test -vvv -s --ignore=hapi [testenv:docs] -commands = python setup.py build_sphinx +commands = + python setup.py build_sphinx [testenv:genconfig] -commands = oslo-config-generator --config-file=etc/armada/config-generator.conf +commands = + oslo-config-generator --config-file=etc/armada/config-generator.conf -[testenv:lint] -commands = flake8 . +[testenv:pep8] +deps= + {[testenv]deps} +commands = + flake8 {posargs} -[testenv:testing] -commands = nosetest -w armada +[testenv:bandit] +deps = .[bandit] +commands = + bandit -r armada -x armada/tests -n 5 -[flake8] #TODO: Remove E402 -ignore=E302,H306,E402,W503 +[testenv:coverage] +deps= + {[testenv]deps} + +commands = + nosetests -w armada/tests/unit --cover-package=armada --with-coverage --cover-tests --exclude=.tox + +[flake8] +filename= *.py +ignore = W503,E302 exclude= .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi