diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c39e69a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +.tox +.testrepository diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..5326db2 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack/charm-hacluster.git diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000..801646b --- /dev/null +++ b/.testr.conf @@ -0,0 +1,8 @@ +[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 ./ ./unit_tests $LISTOPT $IDOPTION + +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/actions/actions.py b/actions/actions.py index 94d8eaf..4d403cd 100755 --- a/actions/actions.py +++ b/actions/actions.py @@ -3,19 +3,20 @@ import sys import os sys.path.append('hooks/') -import subprocess from charmhelpers.core.hookenv import action_fail from utils import ( pause_unit, resume_unit, ) + def pause(args): """Pause the hacluster services. @raises Exception should the service fail to stop. """ pause_unit() + def resume(args): """Resume the hacluster services. @raises Exception should the service fail to start.""" @@ -24,6 +25,7 @@ def resume(args): ACTIONS = {"pause": pause, "resume": resume} + def main(args): action_name = os.path.basename(args[0]) try: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6a3271b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +pbr>=1.8.0,<1.9.0 +PyYAML>=3.1.0 +simplejson>=2.2.0 +netifaces>=0.10.4 +netaddr>=0.7.12,!=0.7.16 +Jinja2>=2.6 # BSD License (3 clause) +six>=1.9.0 +dnspython>=1.12.0 +psutil>=1.1.1,<2.0.0 diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..4faf254 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,9 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +coverage>=3.6 +mock>=1.2 +flake8>=2.2.4,<=2.4.1 +os-testr>=0.4.1 +charm-tools>=2.0.0 +requests==2.6.0 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..c051dba --- /dev/null +++ b/tox.ini @@ -0,0 +1,29 @@ +[tox] +envlist = pep8,py27 +skipsdist = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 +install_command = + pip install --allow-unverified python-apt {opts} {packages} +commands = ostestr {posargs} + +[testenv:py27] +basepython = python2.7 +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt + +[testenv:pep8] +basepython = python2.7 +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} hooks unit_tests tests actions + charm-proof + +[testenv:venv] +commands = {posargs} + +[flake8] +ignore = E402,E226 +exclude = hooks/charmhelpers diff --git a/unit_tests/test_hacluster_hooks.py b/unit_tests/test_hacluster_hooks.py index 4a091e5..3e3f464 100644 --- a/unit_tests/test_hacluster_hooks.py +++ b/unit_tests/test_hacluster_hooks.py @@ -1,8 +1,12 @@ import mock import os +import sys import tempfile import unittest + +mock_apt = mock.MagicMock() +sys.modules['apt_pkg'] = mock_apt import hooks