From: Andrew Schoen Date: Wed, 12 Nov 2014 21:21:27 +0000 (-0600) Subject: Moves all integration tests to an integration folder and provides a new tox env to... X-Git-Tag: 1.1.0~1070^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F357%2Fhead;p=teuthology.git Moves all integration tests to an integration folder and provides a new tox env to run only those tests Signed-off-by: Andrew Schoen --- diff --git a/.coveragerc b/.coveragerc index 9f08918b0..560e80017 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,2 @@ [run] -omit = teuthology/test/* +omit = */test/* diff --git a/pytest.ini b/pytest.ini index 847360a69..b50b1e608 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -norecursedirs = .git build virtualenv teuthology.egg-info .tox +norecursedirs = .git build virtualenv teuthology.egg-info .tox */integration diff --git a/teuthology/orchestra/test/integration/__init__.py b/teuthology/orchestra/test/integration/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/teuthology/orchestra/test/integration/test_integration.py b/teuthology/orchestra/test/integration/test_integration.py new file mode 100644 index 000000000..1fc34966c --- /dev/null +++ b/teuthology/orchestra/test/integration/test_integration.py @@ -0,0 +1,80 @@ +from teuthology.orchestra import monkey +monkey.patch_all() + +from cStringIO import StringIO + +import os +from teuthology.orchestra import connection, remote, run +from teuthology.orchestra.test.util import assert_raises +from teuthology.exceptions import CommandCrashedError, ConnectionLostError + +from pytest import skip + +HOST = None + + +class TestIntegration(): + def setup(self): + try: + host = os.environ['ORCHESTRA_TEST_HOST'] + except KeyError: + skip('To run integration tests, set environment ' + + 'variable ORCHESTRA_TEST_HOST to user@host to use.') + global HOST + HOST = host + + def test_crash(self): + ssh = connection.connect(HOST) + e = assert_raises( + CommandCrashedError, + run.run, + client=ssh, + args=['sh', '-c', 'kill -ABRT $$'], + ) + assert e.command == "sh -c 'kill -ABRT $$'" + assert str(e) == "Command crashed: \"sh -c 'kill -ABRT $$'\"" + + def test_lost(self): + ssh = connection.connect(HOST) + e = assert_raises( + ConnectionLostError, + run.run, + client=ssh, + args=['sh', '-c', 'kill -ABRT $PPID'], + ) + assert e.command == "sh -c 'kill -ABRT $PPID'" + assert str(e) == \ + "SSH connection was lost: \"sh -c 'kill -ABRT $PPID'\"" + + def test_pipe(self): + ssh = connection.connect(HOST) + r = run.run( + client=ssh, + args=['cat'], + stdin=run.PIPE, + stdout=StringIO(), + wait=False, + ) + assert r.stdout.getvalue() == '' + r.stdin.write('foo\n') + r.stdin.write('bar\n') + r.stdin.close() + + r.wait() + got = r.exitstatus + assert got == 0 + assert r.stdout.getvalue() == 'foo\nbar\n' + + def test_and(self): + ssh = connection.connect(HOST) + r = run.run( + client=ssh, + args=['true', run.Raw('&&'), 'echo', 'yup'], + stdout=StringIO(), + ) + assert r.stdout.getvalue() == 'yup\n' + + def test_os(self): + rem = remote.Remote(HOST) + assert rem.os.name + assert rem.os.version diff --git a/teuthology/orchestra/test/test_integration.py b/teuthology/orchestra/test/test_integration.py deleted file mode 100644 index 6d45b28bc..000000000 --- a/teuthology/orchestra/test/test_integration.py +++ /dev/null @@ -1,80 +0,0 @@ -from .. import monkey -monkey.patch_all() - -from cStringIO import StringIO - -import os -from .. import connection, remote, run -from .util import assert_raises -from teuthology.exceptions import CommandCrashedError, ConnectionLostError - -from pytest import skip - -HOST = None - - -class TestIntegration(): - def setup(self): - try: - host = os.environ['ORCHESTRA_TEST_HOST'] - except KeyError: - skip('To run integration tests, set environment ' + - 'variable ORCHESTRA_TEST_HOST to user@host to use.') - global HOST - HOST = host - - def test_crash(self): - ssh = connection.connect(HOST) - e = assert_raises( - CommandCrashedError, - run.run, - client=ssh, - args=['sh', '-c', 'kill -ABRT $$'], - ) - assert e.command == "sh -c 'kill -ABRT $$'" - assert str(e) == "Command crashed: \"sh -c 'kill -ABRT $$'\"" - - def test_lost(self): - ssh = connection.connect(HOST) - e = assert_raises( - ConnectionLostError, - run.run, - client=ssh, - args=['sh', '-c', 'kill -ABRT $PPID'], - ) - assert e.command == "sh -c 'kill -ABRT $PPID'" - assert str(e) == \ - "SSH connection was lost: \"sh -c 'kill -ABRT $PPID'\"" - - def test_pipe(self): - ssh = connection.connect(HOST) - r = run.run( - client=ssh, - args=['cat'], - stdin=run.PIPE, - stdout=StringIO(), - wait=False, - ) - assert r.stdout.getvalue() == '' - r.stdin.write('foo\n') - r.stdin.write('bar\n') - r.stdin.close() - - r.wait() - got = r.exitstatus - assert got == 0 - assert r.stdout.getvalue() == 'foo\nbar\n' - - def test_and(self): - ssh = connection.connect(HOST) - r = run.run( - client=ssh, - args=['true', run.Raw('&&'), 'echo', 'yup'], - stdout=StringIO(), - ) - assert r.stdout.getvalue() == 'yup\n' - - def test_os(self): - rem = remote.Remote(HOST) - assert rem.os.name - assert rem.os.version diff --git a/teuthology/test/integration/__init__.py b/teuthology/test/integration/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/teuthology/test/integration/test_suite.py b/teuthology/test/integration/test_suite.py new file mode 100644 index 000000000..012dbc5f3 --- /dev/null +++ b/teuthology/test/integration/test_suite.py @@ -0,0 +1,86 @@ +import os +import requests +from pytest import raises, skip + +from teuthology.config import config +from teuthology import suite + + +class TestSuiteOnline(object): + def setup(self): + if 'TEST_ONLINE' not in os.environ: + skip("To run these sets, set the environment variable TEST_ONLINE") + + def test_ceph_hash_simple(self): + resp = requests.get( + 'https://api.github.com/repos/ceph/ceph/git/refs/heads/master') + ref_hash = resp.json()['object']['sha'] + assert suite.get_hash('ceph') == ref_hash + + def test_kernel_hash_saya(self): + # We don't currently have these packages. + assert suite.get_hash('kernel', 'master', 'basic', 'saya') is None + + def test_all_master_branches(self): + # Don't attempt to send email + config.results_email = None + job_config = suite.create_initial_config('suite', 'master', + 'master', 'master', 'testing', + 'basic', 'centos', 'plana') + assert ((job_config.branch, job_config.teuthology_branch, + job_config.suite_branch) == ('master', 'master', 'master')) + + def test_config_bogus_kernel_branch(self): + # Don't attempt to send email + config.results_email = None + with raises(suite.ScheduleFailError): + suite.create_initial_config('s', None, 'master', 't', + 'bogus_kernel_branch', 'f', 'd', 'm') + + def test_config_bogus_kernel_flavor(self): + # Don't attempt to send email + config.results_email = None + with raises(suite.ScheduleFailError): + suite.create_initial_config('s', None, 'master', 't', 'k', + 'bogus_kernel_flavor', 'd', 'm') + + def test_config_bogus_ceph_branch(self): + # Don't attempt to send email + config.results_email = None + with raises(suite.ScheduleFailError): + suite.create_initial_config('s', None, 'bogus_ceph_branch', 't', + 'k', 'f', 'd', 'm') + + def test_config_bogus_suite_branch(self): + # Don't attempt to send email + config.results_email = None + with raises(suite.ScheduleFailError): + suite.create_initial_config('s', 'bogus_suite_branch', 'master', + 't', 'k', 'f', 'd', 'm') + + def test_config_bogus_teuthology_branch(self): + # Don't attempt to send email + config.results_email = None + with raises(suite.ScheduleFailError): + suite.create_initial_config('s', None, 'master', + 'bogus_teuth_branch', 'k', 'f', 'd', + 'm') + + def test_config_substitution(self): + # Don't attempt to send email + config.results_email = None + job_config = suite.create_initial_config('MY_SUITE', 'master', + 'master', 'master', 'testing', + 'basic', 'centos', 'plana') + assert job_config['suite'] == 'MY_SUITE' + + def test_config_kernel_section(self): + # Don't attempt to send email + config.results_email = None + job_config = suite.create_initial_config('MY_SUITE', 'master', + 'master', 'master', 'testing', + 'basic', 'centos', 'plana') + assert job_config['kernel']['kdb'] is True + + +# maybe use notario for the above? diff --git a/teuthology/test/test_suite.py b/teuthology/test/test_suite.py index f30f1eea8..f7306d058 100644 --- a/teuthology/test/test_suite.py +++ b/teuthology/test/test_suite.py @@ -1,9 +1,5 @@ -import os -import requests from datetime import datetime -from pytest import raises, skip -from teuthology.config import config from teuthology import suite @@ -56,83 +52,3 @@ class TestSuiteOffline(object): assert isinstance( suite.dict_templ['overrides']['admin_socket']['branch'], suite.Placeholder) - - -class TestSuiteOnline(object): - def setup(self): - if 'TEST_ONLINE' not in os.environ: - skip("To run these sets, set the environment variable TEST_ONLINE") - - def test_ceph_hash_simple(self): - resp = requests.get( - 'https://api.github.com/repos/ceph/ceph/git/refs/heads/master') - ref_hash = resp.json()['object']['sha'] - assert suite.get_hash('ceph') == ref_hash - - def test_kernel_hash_saya(self): - # We don't currently have these packages. - assert suite.get_hash('kernel', 'master', 'basic', 'saya') is None - - def test_all_master_branches(self): - # Don't attempt to send email - config.results_email = None - job_config = suite.create_initial_config('suite', 'master', - 'master', 'master', 'testing', - 'basic', 'centos', 'plana') - assert ((job_config.branch, job_config.teuthology_branch, - job_config.suite_branch) == ('master', 'master', 'master')) - - def test_config_bogus_kernel_branch(self): - # Don't attempt to send email - config.results_email = None - with raises(suite.ScheduleFailError): - suite.create_initial_config('s', None, 'master', 't', - 'bogus_kernel_branch', 'f', 'd', 'm') - - def test_config_bogus_kernel_flavor(self): - # Don't attempt to send email - config.results_email = None - with raises(suite.ScheduleFailError): - suite.create_initial_config('s', None, 'master', 't', 'k', - 'bogus_kernel_flavor', 'd', 'm') - - def test_config_bogus_ceph_branch(self): - # Don't attempt to send email - config.results_email = None - with raises(suite.ScheduleFailError): - suite.create_initial_config('s', None, 'bogus_ceph_branch', 't', - 'k', 'f', 'd', 'm') - - def test_config_bogus_suite_branch(self): - # Don't attempt to send email - config.results_email = None - with raises(suite.ScheduleFailError): - suite.create_initial_config('s', 'bogus_suite_branch', 'master', - 't', 'k', 'f', 'd', 'm') - - def test_config_bogus_teuthology_branch(self): - # Don't attempt to send email - config.results_email = None - with raises(suite.ScheduleFailError): - suite.create_initial_config('s', None, 'master', - 'bogus_teuth_branch', 'k', 'f', 'd', - 'm') - - def test_config_substitution(self): - # Don't attempt to send email - config.results_email = None - job_config = suite.create_initial_config('MY_SUITE', 'master', - 'master', 'master', 'testing', - 'basic', 'centos', 'plana') - assert job_config['suite'] == 'MY_SUITE' - - def test_config_kernel_section(self): - # Don't attempt to send email - config.results_email = None - job_config = suite.create_initial_config('MY_SUITE', 'master', - 'master', 'master', 'testing', - 'basic', 'centos', 'plana') - assert job_config['kernel']['kdb'] is True - - -# maybe use notario for the above? diff --git a/tox.ini b/tox.ini index dbe5b894f..1ce78de42 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, flake8 +envlist = py27, py27-integration, flake8 [testenv:py27] sitepackages=True @@ -14,6 +14,20 @@ deps= commands=py.test --cov=teuthology --cov-report=term -v {posargs:teuthology scripts} +[testenv:py27-integration] +sitepackages=True +deps= + -r{toxinidir}/requirements.txt + pytest + mock + fudge + nose + pytest-cov==1.6 + coverage==3.7.1 + +commands=py.test --cov=teuthology --cov-report=term -v {posargs:teuthology/test/integration teuthology/orchestra/test/integration} +basepython=python2.7 + [testenv:flake8] deps= flake8