From 9eada1323e2e269ed4e85c33da68fd32daa43db3 Mon Sep 17 00:00:00 2001 From: Tim Kelsey Date: Wed, 17 Dec 2014 16:26:40 +0000 Subject: [PATCH] Bringing Anchor project setup inline with OpenStack - Adding scaffolding for testing (PEP8 mostly disabled for now) - Adding requirments lists Change-Id: I7b585a1e30c473df089ba508099af159e432cc78 --- .gitignore | 10 +++++++++- .testr.conf | 7 +++++++ README.md | 32 ++++++-------------------------- requirements.txt | 5 +++++ setup.cfg | 29 +++++++++++++++++++++++++++++ setup.py | 43 +++++++++++++++++++------------------------ test-requirements.txt | 9 +++++++++ tests/__init__.py | 15 +++++++++++++++ tests/test_basic.py | 31 +++++++++++++++++++++++++++++++ tox.ini | 35 +++++++++++++++++++++++++++++------ 10 files changed, 159 insertions(+), 57 deletions(-) create mode 100644 .testr.conf create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 test-requirements.txt create mode 100644 tests/__init__.py create mode 100644 tests/test_basic.py diff --git a/.gitignore b/.gitignore index 0f95252..aade865 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ *.pyc temp-*.crt config.cfg -ephemeral_ca.egg-info .venv *.sw[op] certs/*.crt @@ -11,3 +10,12 @@ CA/*.crt dist/* build/* .tox/* +.DS_Store +*.egg +*.egg-info +.testrepository +build/* +cover/* +.cover + + diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000..35d9ba4 --- /dev/null +++ b/.testr.conf @@ -0,0 +1,7 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ + OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ + OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ + ${PYTHON:-python} -m subunit.run discover -t ./ ./tests $LISTOPT $IDOPTION +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/README.md b/README.md index 2e06018..36cebb8 100644 --- a/README.md +++ b/README.md @@ -17,37 +17,17 @@ For virtual environment run: virtualenv .venv . .venv/bin/activate -Currently Anchor requires a modified varient of M2Crypto, which must be -installed manually. Prior to installing M2Crypto, SWIG must be -installed if this is not already present on your system. Test with: - - swig - -If this results with 'command not found' or similar, then install swig -by downloading from http://www.swig.org/download.html or using your -preferred package manager. Download and install the modified M2crypto: - - git clone https://github.com/viraptor/M2Crypto.git - cd M2Crypto - python setup.py build && python setup.py install - cd .. - - Depending on your platform, you may need to add a link between the - location of your openssl libraries and the path used by swig: - (/usr/include) - To install a development version of Anchor, run: - pip install -e '.[develop]' + python setup.py develop + pip install watchdog -To install a production version with some authentication backend, run -(where `auth_xxx` may be `auth_keystone` and/or `auth_ldap`): +Note that watchdog is needed only when running with the --reload option used +later. To install a production version, run: - pip install '.[auth_xxx]' + python setup.py install -The chosen authentication backend is only enabled if it's defined in -the config file. The config file should be copied from `config.py` with -any details updated. +The config file should be copied from `config.py` with any details updated. Anchor requires you to provide a CA signing certificate and private key which is stored in the CA subdirectory by default (as specified in diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9b8e4e7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +cryptography>=0.4 +pecan>=0.8.0 +Paste +netaddr>=0.7.12 + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..fb0eac4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,29 @@ +[metadata] +name = anchor +summary = webservice to auto-sign certificates for short amount of time +description-file = + README.md +author = Hewlett Packard +author-email = openstack-dev@lists.openstack.org +home-page = https://wiki.openstack.org/wiki/Security/Projects/Anchor +classifier = + Environment :: OpenStack + Intended Audience :: Information Technology + Intended Audience :: System Administrators + Intended Audience :: Developers + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Operating System :: MacOS :: MacOS X + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.3 + Topic :: Security + +[files] +packages = + anchor +scripts = + bin/anchor_production + bin/anchor_debug diff --git a/setup.py b/setup.py index bce72d7..70c2b3f 100755 --- a/setup.py +++ b/setup.py @@ -1,27 +1,22 @@ #!/usr/bin/env python +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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 setuptools import setup +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools -setup( - name="anchor", - description="webservice to auto-sign certificates for short amount of time", - version="1.0.0", - packages=['anchor'], - include_package_data=True, - install_requires=[ - 'pecan', - 'paste', - 'setuptools>=1.0', - 'netaddr', - ], - extras_require={ - 'auth_ldap': ['python-ldap'], - 'auth_keystone': ['requests'], - 'develop': ['watchdog'], - 'production': ['uwsgi'], - }, - setup_requires=[ - 'setuptools>=1.0', - ], - zip_safe=False -) +setuptools.setup( + setup_requires=['pbr'], + pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..9bf343a --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,9 @@ +coverage>=3.6 +discover +fixtures>=0.3.14 +hacking>=0.9.2,<0.10 +python-subunit>=0.0.18 +testrepository>=0.0.18 +testscenarios>=0.4 +testtools>=0.9.34 + diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..513f5c3 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# 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. diff --git a/tests/test_basic.py b/tests/test_basic.py new file mode 100644 index 0000000..dfcd870 --- /dev/null +++ b/tests/test_basic.py @@ -0,0 +1,31 @@ +# -*- coding:utf-8 -*- +# +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# +# 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. + +import os + +import unittest + + +class BasicTests(unittest.TestCase): + + def setUp(self): + super(BasicTests, self).setUp() + + def tearDown(self): + pass + + def test_testing(self): + self.assertTrue(True) diff --git a/tox.ini b/tox.ini index 91ccff7..8bf4001 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,34 @@ [tox] -envlist = pep8 +minversion = 1.6 +envlist = py27,py33,pypy,pep8 +skipsdist = True + +[testenv] +usedevelop = True +install_command = pip install -U {opts} {packages} +setenv = + VIRTUAL_ENV={envdir} +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = python setup.py testr --slowest --testr-args='{posargs}' [testenv:pep8] -deps = flake8 -sitepackages = False -commands = flake8 {posargs} +commands = flake8 {posargs} anchor + +[testenv:venv] +commands = {posargs} + +[testenv:cover] +commands = python setup.py testr --coverage --testr-args='{posargs}' [flake8] -max-line-length = 160 -exclude = .git,.tox,.venv +# E123, E125 skipped as they are invalid PEP-8. +# H303 no wild card imports +# F403 unable to detect undefined names +# H104 file contains nothing but comments +# H302 import only modules + +show-source = True +ignore = E123,E125,H303,F403,H104,H302,E501,H301,H305,H405,H404,H306,E226,H904,H307,F401 +builtins = _ +exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build