cf-charmers team mailing list archive
-
cf-charmers team
-
Mailing list archive
-
Message #00071
[Merge] lp:~lomov-as/charms/trusty/cf-cloud-controller/tests into lp:~cf-charmers/charms/trusty/cf-cloud-controller/trunk
Alex Lomov has proposed merging lp:~lomov-as/charms/trusty/cf-cloud-controller/tests into lp:~cf-charmers/charms/trusty/cf-cloud-controller/trunk.
Requested reviews:
Cloud Foundry Charmers (cf-charmers)
For more details, see:
https://code.launchpad.net/~lomov-as/charms/trusty/cf-cloud-controller/tests/+merge/215906
Add tests to cf-cloud-controller
This is my first time using lbox.
https://codereview.appspot.com/88100045/
--
https://code.launchpad.net/~lomov-as/charms/trusty/cf-cloud-controller/tests/+merge/215906
Your team Cloud Foundry Charmers is requested to review the proposed merge of lp:~lomov-as/charms/trusty/cf-cloud-controller/tests into lp:~cf-charmers/charms/trusty/cf-cloud-controller/trunk.
=== modified file '.bzrignore'
--- .bzrignore 2014-04-13 18:03:48 +0000
+++ .bzrignore 2014-04-15 15:41:08 +0000
@@ -6,4 +6,5 @@
.coverage
.noseids
.git
+installc
=== modified file 'Makefile'
--- Makefile 2014-03-28 23:47:20 +0000
+++ Makefile 2014-04-15 15:41:08 +0000
@@ -1,13 +1,56 @@
-test: lint
- charm proof
-
-lint:
- @flake8 --exclude=hooks/charmhelpers hooks tests
+PROJECT=cf-cloud-controller
+PYTHON := /usr/bin/env python
+SUITE=unstable
+TESTS=tests/
+
+all:
+ @echo "make source - Create source package"
+ @echo "make sdeb - Create debian source package"
+ @echo "make deb - Create debian package"
+ @echo "make clean"
+ @echo "make userinstall - Install locally"
+ @echo "make test - Run unit tests"
+
+sdeb: source
+ scripts/build source
+
+deb: source
+ scripts/build
+
+source: setup.py
+ scripts/update-revno
+ python setup.py sdist
clean:
+ # python setup.py clean
+ rm -rf build/ MANIFEST
find . -name '*.pyc' -delete
- find . -name '*.bak' -delete
- @rm -rf .venv
-
-sync:
- charm-helpers-sync -c charm-helpers.yaml
+ rm -rf dist/*
+ rm -rf .venv
+ # dh_clean
+
+userinstall:
+ scripts/update-revno
+ python setup.py install --user
+
+test: .venv
+ @echo Starting tests...
+ @./bin/nosetests --nologcapture
+
+coverage: .venv
+ @echo Starting tests...
+ @./bin/nosetests --nologcapture --with-coverage
+
+
+ftest:
+ @echo Starting fast tests...
+ @./bin/nosetests --attr '!slow' --nologcapture
+
+lint:
+ @echo Checking for Python syntax...
+ @flake8 --ignore=E123,E501 $(PROJECT) $(TESTS) && echo OK
+
+.venv:
+ ./bin/test_setup
+
+build: test lint
=== added directory 'bin'
=== added file 'bin/README'
--- bin/README 1970-01-01 00:00:00 +0000
+++ bin/README 2014-04-15 15:41:08 +0000
@@ -0,0 +1,1 @@
+This directory contains executables for accessing cf-cloud-controller juju charm functionality
=== added file 'bin/nosetests'
--- bin/nosetests 1970-01-01 00:00:00 +0000
+++ bin/nosetests 2014-04-15 15:41:08 +0000
@@ -0,0 +1,3 @@
+#!/bin/bash
+. .venv/bin/activate
+nosetests $@
=== added file 'bin/test_setup'
--- bin/test_setup 1970-01-01 00:00:00 +0000
+++ bin/test_setup 2014-04-15 15:41:08 +0000
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+if [ ! -d .venv ] ; then
+ virtualenv --system-site-packages .venv
+ . .venv/bin/activate
+ pip install --upgrade pip
+ pip install wheel
+ pip install --use-wheel -f deps -r test_requirements.txt
+ # python setup.py develop
+fi
+
=== added directory 'deps'
=== added file 'deps/Jinja2-2.7.2-py2-none-any.whl'
Binary files deps/Jinja2-2.7.2-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/Jinja2-2.7.2-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/Tempita-0.5.2-py2-none-any.whl'
Binary files deps/Tempita-0.5.2-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/Tempita-0.5.2-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/extras-0.0.3-py2-none-any.whl'
Binary files deps/extras-0.0.3-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/extras-0.0.3-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/httplib2-0.8-py2-none-any.whl'
Binary files deps/httplib2-0.8-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/httplib2-0.8-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/keyring-3.7-py2-none-any.whl'
Binary files deps/keyring-3.7-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/keyring-3.7-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/launchpadlib-1.10.2-py2-none-any.whl'
Binary files deps/launchpadlib-1.10.2-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/launchpadlib-1.10.2-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/lazr.authentication-0.1.2-py2-none-any.whl'
Binary files deps/lazr.authentication-0.1.2-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/lazr.authentication-0.1.2-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/lazr.restfulclient-0.13.3-py2-none-any.whl'
Binary files deps/lazr.restfulclient-0.13.3-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/lazr.restfulclient-0.13.3-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/lazr.uri-1.0.3-py2-none-any.whl'
Binary files deps/lazr.uri-1.0.3-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/lazr.uri-1.0.3-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/mock-1.0.1-py2-none-any.whl'
Binary files deps/mock-1.0.1-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/mock-1.0.1-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/netaddr-0.7.11-py2-none-any.whl'
Binary files deps/netaddr-0.7.11-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/netaddr-0.7.11-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/nose-1.3.1-py2-none-any.whl'
Binary files deps/nose-1.3.1-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/nose-1.3.1-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/oauth-1.0.1-py2-none-any.whl'
Binary files deps/oauth-1.0.1-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/oauth-1.0.1-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/python_mimeparse-0.1.4-py2-none-any.whl'
Binary files deps/python_mimeparse-0.1.4-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/python_mimeparse-0.1.4-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/setuptools-3.4.1-py2.py3-none-any.whl'
Binary files deps/setuptools-3.4.1-py2.py3-none-any.whl 1970-01-01 00:00:00 +0000 and deps/setuptools-3.4.1-py2.py3-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/shelltoolbox-0.2.1-py2-none-any.whl'
Binary files deps/shelltoolbox-0.2.1-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/shelltoolbox-0.2.1-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/shelltoolbox-0.2.1-py2.7.egg'
Binary files deps/shelltoolbox-0.2.1-py2.7.egg 1970-01-01 00:00:00 +0000 and deps/shelltoolbox-0.2.1-py2.7.egg 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/testresources-0.2.7-py2-none-any.whl'
Binary files deps/testresources-0.2.7-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/testresources-0.2.7-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/testtools-0.9.35-py2-none-any.whl'
Binary files deps/testtools-0.9.35-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/testtools-0.9.35-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/wadllib-1.3.2-py2-none-any.whl'
Binary files deps/wadllib-1.3.2-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/wadllib-1.3.2-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/wsgi_intercept-0.6.1-py2-none-any.whl'
Binary files deps/wsgi_intercept-0.6.1-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/wsgi_intercept-0.6.1-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== added file 'deps/wsgiref-0.1.2-py2-none-any.whl'
Binary files deps/wsgiref-0.1.2-py2-none-any.whl 1970-01-01 00:00:00 +0000 and deps/wsgiref-0.1.2-py2-none-any.whl 2014-04-15 15:41:08 +0000 differ
=== modified file 'hooks/install'
--- hooks/install 2014-04-13 18:03:48 +0000
+++ hooks/install 2014-04-15 15:41:08 +0000
@@ -3,11 +3,8 @@
import os
from charmhelpers.core import hookenv, host
-from charmhelpers.core.hookenv import log, DEBUG
-from charmhelpers.contrib.cloudfoundry.install import install as helper_install
-from charmhelpers.contrib.cloudfoundry.common import (
- chownr, run, prepare_cloudfoundry_environment, chdir
-)
+from charmhelpers.contrib.cloudfoundry import install
+from charmhelpers.contrib.cloudfoundry import common
from charmhelpers.contrib.cloudfoundry.upstart_helper import (
install_upstart_scripts
)
@@ -16,17 +13,18 @@
def cc_db_migrate():
- helper_install(os.path.join(hookenv.charm_dir(), 'files',
- 'config',
- 'cloud_controller.yml'),
- CC_CONFIG_FILE, fileprops={'mode': '664', 'owner': 'vcap'})
- log("Starting db:migrate...", DEBUG)
- with chdir(CC_DIR) as dir:
+ install.install(
+ os.path.join(hookenv.charm_dir(), 'files',
+ 'config',
+ 'cloud_controller.yml'),
+ CC_CONFIG_FILE, fileprops={'mode': '664', 'owner': 'vcap'})
+ hookenv.log("Starting db:migrate...")
+ with common.chdir(CC_DIR) as dir:
#TODO: make it idempotent by deleting existing db if exists
- run(['sudo', '-u', 'vcap', '-g', 'vcap',
- 'CLOUD_CONTROLLER_NG_CONFIG={}'.format(CC_CONFIG_FILE),
- 'bundle', 'exec', 'rake', 'db:migrate'])
- log("Finished db:migrate in %s." % (dir))
+ common.run(['sudo', '-u', 'vcap', '-g', 'vcap',
+ 'CLOUD_CONTROLLER_NG_CONFIG={}'.format(CC_CONFIG_FILE),
+ 'bundle', 'exec', 'rake', 'db:migrate'])
+ hookenv.log("Finished db:migrate in %s." % (dir))
def disable_nginx_service():
@@ -40,9 +38,9 @@
run(['update-rc.d', '-f', 'nginx', 'remove'])
-def install():
+def install_charm():
# TODO build of directory service
- prepare_cloudfoundry_environment(hookenv.config(), CC_PACKAGES)
+ common.prepare_cloudfoundry_environment(hookenv.config(), CC_PACKAGES)
if not os.path.isfile(CC_DB_FILE):
# TODO check permission of database file
host.write_file(CC_DB_FILE, '', owner='vcap', group='vcap', perms=0664)
@@ -53,12 +51,12 @@
'/var/vcap/data/cloud_controller_ng/tmp/staged_droplet_uploads']
for item in dirs:
host.mkdir(item, owner='vcap', group='vcap', perms=0775)
- chownr('/var/vcap', owner='vcap', group='vcap')
- chownr(CF_DIR, owner='vcap', group='vcap')
+ common.chownr('/var/vcap', owner='vcap', group='vcap')
+ common.chownr(CF_DIR, owner='vcap', group='vcap')
disable_nginx_service()
install_upstart_scripts()
cc_db_migrate()
if __name__ == '__main__':
- install()
+ install_charm()
=== added file 'test_requirements.txt'
--- test_requirements.txt 1970-01-01 00:00:00 +0000
+++ test_requirements.txt 2014-04-15 15:41:08 +0000
@@ -0,0 +1,16 @@
+shelltoolbox==0.2.1
+coverage==3.7.1
+Jinja2==2.7.2
+MarkupSafe==0.19
+mock==1.0.1
+netaddr==0.7.11
+netifaces==0.8
+nose==1.3.1
+python-apt
+python-mimeparse==0.1.4
+PyYAML==3.11
+Tempita==0.5.2
+testtools==0.9.35
+wsgiref==0.1.2
+launchpadlib==1.10.2
+
=== added file 'tests/test_install.py'
--- tests/test_install.py 1970-01-01 00:00:00 +0000
+++ tests/test_install.py 2014-04-15 15:41:08 +0000
@@ -0,0 +1,36 @@
+import os
+import sys
+import mock
+import unittest
+import imp
+import tempfile
+
+sys.path.append('hooks')
+
+import config
+from charmhelpers.contrib.cloudfoundry import install
+from charmhelpers.contrib.cloudfoundry import common
+import charmhelpers.core.hookenv
+
+temp_charm_dir = tempfile.mkdtemp()
+# this is needed to import instal module
+charmhelpers.core.hookenv.charm_dir = mock.Mock(return_value=temp_charm_dir)
+
+module_file = open('./hooks/install', 'r')
+install_module = imp.load_source('install', 'install', module_file)
+
+
+class TestInstall(unittest.TestCase):
+
+ @mock.patch('charmhelpers.contrib.cloudfoundry.install.install')
+ @mock.patch('charmhelpers.contrib.cloudfoundry.common.run')
+ @mock.patch('charmhelpers.contrib.cloudfoundry.common.chdir')
+ @mock.patch('charmhelpers.core.hookenv.log')
+ def test_cc_db_migrate(self, minstall, mrun, mchdir, mlog):
+ install_module.cc_db_migrate()
+ self.assertTrue(minstall.called)
+ self.assertTrue(mrun.called)
+
+
+if __name__ == '__main__':
+ unittest.main()
References