diff --git a/.gitignore b/.gitignore index dc42fe296a..0c3eb0c370 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ build .coverage .tox cover +.testrepository +subunit.log AUTHORS ChangeLog *.deb diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000000..081907d599 --- /dev/null +++ b/.testr.conf @@ -0,0 +1,4 @@ +[DEFAULT] +test_command=${PYTHON:-python} -m subunit.run discover -t ./ ./tests $LISTOPT $IDOPTION +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/ceilometer/api/v1/app.py b/ceilometer/api/v1/app.py index cb4db0014f..05bc505e5e 100644 --- a/ceilometer/api/v1/app.py +++ b/ceilometer/api/v1/app.py @@ -29,12 +29,13 @@ from ceilometer import storage storage.register_opts(cfg.CONF) -def make_app(conf, enable_acl=True, attach_storage=True): +def make_app(conf, enable_acl=True, attach_storage=True, + sources_file='sources.json'): app = flask.Flask('ceilometer.api') app.register_blueprint(v1_blueprint.blueprint, url_prefix='/v1') try: - with open("sources.json", "r") as f: + with open(sources_file, "r") as f: sources = jsonutils.load(f) except IOError: sources = {} diff --git a/ceilometer/tests/api.py b/ceilometer/tests/api.py index 0d831c4844..0f667ec6e7 100644 --- a/ceilometer/tests/api.py +++ b/ceilometer/tests/api.py @@ -41,9 +41,13 @@ class TestBase(db_test_base.TestBase): def setUp(self): super(TestBase, self).setUp() cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME) + cfg.CONF.set_override("policy_file", + self.path_get('tests/policy.json')) + sources_file = self.path_get('tests/sources.json') self.app = v1_app.make_app(cfg.CONF, enable_acl=False, - attach_storage=False) + attach_storage=False, + sources_file=sources_file) self.app.register_blueprint(v1_blueprint.blueprint) self.test_app = self.app.test_client() @@ -86,11 +90,7 @@ class FunctionalTest(db_test_base.TestBase): def _make_app(self, enable_acl=False): # Determine where we are so we can set up paths in the config - root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), - '..', - '..', - ) - ) + root_dir = self.path_get() self.config = { diff --git a/ceilometer/tests/base.py b/ceilometer/tests/base.py index befe9b437d..3b15178be8 100644 --- a/ceilometer/tests/base.py +++ b/ceilometer/tests/base.py @@ -42,9 +42,20 @@ class TestCase(testtools.TestCase): # the system. cfg.CONF.set_override( 'pipeline_cfg_file', - '../etc/ceilometer/pipeline.yaml', + self.path_get('etc/ceilometer/pipeline.yaml'), ) + def path_get(self, project_file=None): + root = os.path.abspath(os.path.join(os.path.dirname(__file__), + '..', + '..', + ) + ) + if project_file: + return os.path.join(root, project_file) + else: + return root + def temp_config_file_path(self, name='ceilometer.conf'): return os.path.join(self.tempdir.path, name) diff --git a/nova_tests/.testr.conf b/nova_tests/.testr.conf new file mode 100644 index 0000000000..d328439521 --- /dev/null +++ b/nova_tests/.testr.conf @@ -0,0 +1,4 @@ +[DEFAULT] +test_command=${PYTHON:-python} -m subunit.run discover -t ./nova_tests ./nova_tests $LISTOPT $IDOPTION +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/setup.cfg b/setup.cfg index 6eb458ba1d..603f62d0c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -85,15 +85,6 @@ ceilometer.publisher = meter_publisher = ceilometer.publisher.meter:MeterPublisher meter = ceilometer.publisher.meter:MeterPublisher -[nosetests] -cover-package = ceilometer -cover-html = true -cover-erase = true -cover-inclusive = true -verbosity=2 -detailed-errors=1 -where=tests - [build_sphinx] all_files = 1 build-dir = doc/build diff --git a/tests/api/v2/test_app.py b/tests/api/v2/test_app.py index ede22be933..f98dd6ef01 100644 --- a/tests/api/v2/test_app.py +++ b/tests/api/v2/test_app.py @@ -40,7 +40,7 @@ class TestApp(base.TestCase): group=acl.OPT_GROUP_NAME) cfg.CONF.set_override("auth_version", "v2.0", group=acl.OPT_GROUP_NAME) cfg.CONF.set_override("pipeline_cfg_file", - "../etc/ceilometer/pipeline.yaml") + self.path_get("etc/ceilometer/pipeline.yaml")) api_app = app.setup_app() self.assertEqual(api_app.auth_protocol, 'foottp') @@ -48,7 +48,8 @@ class TestApp(base.TestCase): tmpfile = self.temp_config_file_path() with open(tmpfile, "w") as f: f.write("[DEFAULT]\n") - f.write("pipeline_cfg_file = ../etc/ceilometer/pipeline.yaml\n") + f.write("pipeline_cfg_file = %s\n" % + self.path_get("etc/ceilometer/pipeline.yaml")) f.write("[%s]\n" % acl.OPT_GROUP_NAME) f.write("auth_protocol = barttp\n") f.write("auth_version = v2.0\n") diff --git a/tests/test_bin.py b/tests/test_bin.py index 396b397361..0352a2e7df 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -36,7 +36,7 @@ class BinDbsyncTestCase(base.TestCase): tmp.write("database_connection=log://localhost\n") def test_dbsync_run(self): - subp = subprocess.Popen(["../bin/ceilometer-dbsync", + subp = subprocess.Popen([self.path_get('bin/ceilometer-dbsync'), "--config-file=%s" % self.tempfile]) self.assertEqual(subp.wait(), 0) @@ -45,15 +45,16 @@ class BinSendCounterTestCase(base.TestCase): def setUp(self): super(BinSendCounterTestCase, self).setUp() self.tempfile = self.temp_config_file_path() + pipeline_cfg_file = self.path_get('etc/ceilometer/pipeline.yaml') with open(self.tempfile, 'w') as tmp: tmp.write("[DEFAULT]\n") tmp.write( "rpc_backend=ceilometer.openstack.common.rpc.impl_fake\n") tmp.write( - "pipeline_cfg_file=../etc/ceilometer/pipeline.yaml\n") + "pipeline_cfg_file=%s\n" % pipeline_cfg_file) def test_send_counter_run(self): - subp = subprocess.Popen(["../bin/ceilometer-send-counter", + subp = subprocess.Popen([self.path_get('bin/ceilometer-send-counter'), "--config-file=%s" % self.tempfile, "--counter-resource=someuuid", "--counter-name=mycounter"]) @@ -67,6 +68,8 @@ class BinApiTestCase(base.TestCase): self.api_port = random.randint(10000, 11000) self.http = httplib2.Http() self.tempfile = self.temp_config_file_path() + pipeline_cfg_file = self.path_get('etc/ceilometer/pipeline.yaml') + policy_file = self.path_get('tests/policy.json') with open(self.tempfile, 'w') as tmp: tmp.write("[DEFAULT]\n") tmp.write( @@ -79,8 +82,10 @@ class BinApiTestCase(base.TestCase): tmp.write( "debug=true\n") tmp.write( - "pipeline_cfg_file=../etc/ceilometer/pipeline.yaml\n") - self.subp = subprocess.Popen(["../bin/ceilometer-api", + "pipeline_cfg_file=%s\n" % pipeline_cfg_file) + tmp.write( + "policy_file=%s\n" % policy_file) + self.subp = subprocess.Popen([self.path_get('bin/ceilometer-api'), "--config-file=%s" % self.tempfile]) def tearDown(self): diff --git a/tools/init_testr_if_needed.sh b/tools/init_testr_if_needed.sh new file mode 100755 index 0000000000..9d1e22f996 --- /dev/null +++ b/tools/init_testr_if_needed.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# this is rather stupid script is needed as testr init +# complains if there is already a repo. +if [ -d nova_tests/.testrepository ] +then + exit 0 +fi +testr init -d nova_tests diff --git a/tools/test-requires b/tools/test-requires index 47dfc659d0..4709eb778e 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -1,5 +1,6 @@ -nose +distribute>=0.6.24 coverage +discover mock mox fixtures>=0.3.12 @@ -17,4 +18,6 @@ netifaces sphinx docutils==0.9.1 # for bug 1091333, remove after sphinx >1.1.3 is released. python-spidermonkey +python-subunit +testrepository>=0.0.13 testtools>=0.9.29 diff --git a/tox.ini b/tox.ini index d9556a7039..3c5bf14627 100644 --- a/tox.ini +++ b/tox.ini @@ -5,18 +5,16 @@ envlist = py26,py27,pep8 deps = -r{toxinidir}/tools/test-requires -r{toxinidir}/tools/pip-requires setenv = VIRTUAL_ENV={envdir} - NOSE_WITH_OPENSTACK=1 - NOSE_OPENSTACK_COLOR=1 - NOSE_OPENSTACK_RED=0.05 - NOSE_OPENSTACK_YELLOW=0.025 - NOSE_OPENSTACK_SHOW_ELAPSED=1 + EVENTLET_NO_GREENDNS=yes commands = - nosetests --no-path-adjustment --where=../nova_tests - nosetests --no-path-adjustment {posargs} + python setup.py testr --slowest --testr-args='--concurrency=1 {posargs}' + bash tools/init_testr_if_needed.sh + python setup.py testr --slowest --testr-args='--concurrency=1 --here=nova_tests {posargs}' sitepackages = False [testenv:cover] -commands = nosetests --no-path-adjustment --with-coverage --cover-erase --cover-package=ceilometer --cover-inclusive [] +setenv = VIRTUAL_ENV={envdir} +commands = python setup.py testr --coverage [testenv:pep8] # Install bounded pep8/pyflakes first, then let flake8 install