diff --git a/.bzrignore b/.bzrignore index a2c7a09..9ad1b67 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,2 +1,5 @@ bin .coverage +.testrepository +.tox +tags 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/requirements.txt b/requirements.txt new file mode 100644 index 0000000..426002d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +# 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. +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..3af44d7 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,8 @@ +# 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 diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py index f08ca66..6672f06 100644 --- a/tests/basic_deployment.py +++ b/tests/basic_deployment.py @@ -14,7 +14,6 @@ from charmhelpers.contrib.openstack.amulet.deployment import ( from charmhelpers.contrib.openstack.amulet.utils import ( OpenStackAmuletUtils, DEBUG, - #ERROR ) # Use DEBUG to turn on debug logging @@ -306,12 +305,15 @@ class CinderCephBasicDeployment(OpenStackAmuletDeployment): def get_broker_response(self): broker_request = self.get_broker_request() response_key = "broker-rsp-cinder-ceph-0" - ceph_sentrys = [self.ceph0_sentry, self.ceph1_sentry, self.ceph2_sentry] + ceph_sentrys = [self.ceph0_sentry, + self.ceph1_sentry, + self.ceph2_sentry] for sentry in ceph_sentrys: relation_data = sentry.relation('client', 'cinder-ceph:ceph') if relation_data.get(response_key): broker_response = json.loads(relation_data[response_key]) - if broker_request['request-id'] == broker_response['request-id']: + if (broker_request['request-id'] == + broker_response['request-id']): return broker_response def test_200_cinderceph_ceph_ceph_relation(self): @@ -321,8 +323,10 @@ class CinderCephBasicDeployment(OpenStackAmuletDeployment): relation = ['ceph', 'ceph:client'] req = { - "api-version": 1, - "ops": [{"replicas": 3, "name": "cinder-ceph", "op": "create-pool"}] + "api-version": 1, + "ops": [{"replicas": 3, + "name": "cinder-ceph", + "op": "create-pool"}] } expected = { 'private-address': u.valid_ip, @@ -340,7 +344,6 @@ class CinderCephBasicDeployment(OpenStackAmuletDeployment): def test_201_ceph_cinderceph_ceph_relation(self): u.log.debug('Checking ceph:client to cinder-ceph:ceph ' 'relation data...') - response_key = "broker-rsp-cinder-ceph-0" ceph_unit = self.ceph0_sentry relation = ['client', 'cinder-ceph:ceph'] expected = { @@ -355,7 +358,8 @@ class CinderCephBasicDeployment(OpenStackAmuletDeployment): amulet.raise_status(amulet.FAIL, msg=msg) broker_response = self.get_broker_response() if not broker_response or broker_response['exit-code'] != 0: - msg='Broker request invalid or failed: {}'.format(broker_response) + msg = ('Broker request invalid' + ' or failed: {}'.format(broker_response)) amulet.raise_status(amulet.FAIL, msg=msg) def test_202_cinderceph_cinder_backend_relation(self): diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..4e328e4 --- /dev/null +++ b/tox.ini @@ -0,0 +1,29 @@ +[tox] +envlist = lint,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:lint] +basepython = python2.7 +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} hooks unit_tests tests + charm proof + +[testenv:venv] +commands = {posargs} + +[flake8] +ignore = E402,E226 +exclude = hooks/charmhelpers diff --git a/unit_tests/test_cinder_hooks.py b/unit_tests/test_cinder_hooks.py index 9832450..c623796 100644 --- a/unit_tests/test_cinder_hooks.py +++ b/unit_tests/test_cinder_hooks.py @@ -155,4 +155,4 @@ class TestCinderHooks(CharmTestCase): backend_name='test', subordinate_configuration=json.dumps({'test': 1}), stateless=True, - ) + )