From e7f734a082e4b9891bcced27522439562cabe392 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Tue, 29 Nov 2016 10:05:16 -0500 Subject: [PATCH 1/3] tests: create tests for collocated journals Signed-off-by: Alfredo Deza Resolves: colocated#tests --- tests/functional/tests/osd/__init__.py | 0 tests/functional/tests/osd/test_collocated.py | 90 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 tests/functional/tests/osd/__init__.py create mode 100644 tests/functional/tests/osd/test_collocated.py diff --git a/tests/functional/tests/osd/__init__.py b/tests/functional/tests/osd/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/functional/tests/osd/test_collocated.py b/tests/functional/tests/osd/test_collocated.py new file mode 100644 index 000000000..bf64be156 --- /dev/null +++ b/tests/functional/tests/osd/test_collocated.py @@ -0,0 +1,90 @@ +import os +import pytest +import subprocess + + +uses_collocated_journals = pytest.mark.skipif( + 'collocated_journals' not in pytest.config.slaveinput['node_config']['components'], + reason="only run in osds with collocated journals" +) + +# XXX These could/should probably move to fixtures + + +def which(executable): + locations = ( + '/usr/local/bin', + '/bin', + '/usr/bin', + '/usr/local/sbin', + '/usr/sbin', + '/sbin', + ) + + for location in locations: + executable_path = os.path.join(location, executable) + if os.path.exists(executable_path): + return executable_path + + +def get_system_devices(): + """ + uses ceph-disk to get a list of devices of a system, and formats the output nicely + so that tests can consume it to make assertions: + + From: + + /dev/sda : + /dev/sda2 other, 0x5 + /dev/sda5 other, LVM2_member + /dev/sda1 other, ext2, mounted on /boot + /dev/sdb : + /dev/sdb1 ceph data, active, cluster ceph, osd.0, journal /dev/sdc1 + /dev/sdc : + /dev/sdc1 ceph journal, for /dev/sdb1 + /dev/sr0 other, unknown + + To: + + {"/dev/sda2": "other, 0x5", + "/dev/sda5": "other, LVM2_member", + "/dev/sda1": "other, ext2, mounted on /boot", + "/dev/sdb1": "ceph data, active, cluster ceph, osd.0, journal /dev/sdc1", + "/dev/sdc1": "ceph journal, for /dev/sdb1", + "/dev/sr0": "other, unknown"} + """ + cmd = ['sudo', which('ceph-disk'), 'list'] + process = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True + ) + stdout = process.stdout.read().splitlines() + stderr = process.stderr.read().splitlines() + returncode = process.wait() + if not stdout: + raise RuntimeError("'ceph-disk list' failed with: %s" % ' '.join(stderr)) + + device_map = {} + + for line in stdout: + dev, comment = line.strip().split(' ', 1) + if line.endswith(':'): + continue + device_map[dev] = comment + + return device_map + + +# XXX This test needs to be revisited. The loops obfuscate the values. They +# could very well be parametrized +class TestOSD(object): + + @uses_collocated_journals + def test_osds_are_all_collocated(self, node_config): + system_devices = get_system_devices() + devices = node_config.get('devices', []) + for device in devices: + osd_devices = dict((d, comment) for d, comment in system_devices.items() if d.startswith(device)) + journal = dict((d, comment) for d, comment in osd_devices.items() if 'ceph journal' in comment) + osd = dict((d, comment) for d, comment in osd_devices.items() if 'ceph data' in comment) + assert journal != {}, 'no journal found for device: %s' % device + assert osd != {}, 'no osd found for device: %s' % device From d0b2b13f4f2acfecd9187880daf3f4eed961d4fb Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Tue, 29 Nov 2016 10:05:49 -0500 Subject: [PATCH 2/3] tests: specify the devices for OSDs in the scenario for collocation Signed-off-by: Alfredo Deza Resolves: colocated#tests --- tests/functional/centos/7/journal-collocation/scenario.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/centos/7/journal-collocation/scenario.py b/tests/functional/centos/7/journal-collocation/scenario.py index 44d530091..e51221591 100644 --- a/tests/functional/centos/7/journal-collocation/scenario.py +++ b/tests/functional/centos/7/journal-collocation/scenario.py @@ -14,6 +14,7 @@ nodes = { }, 'osd0': { 'username': 'vagrant', - 'components': [], + 'components': ['collocated_journals'], + 'devices': ['/dev/sda', '/dev/sdb'], }, } From 10df63dcf92d18357639213d8705b2428ca1ca02 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Tue, 29 Nov 2016 15:01:31 -0500 Subject: [PATCH 3/3] tests: use underscores to prevent tox combinatorial issues Signed-off-by: Alfredo Deza Resolves: colocated#tests --- tox.ini | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tox.ini b/tox.ini index ae59c364e..b163734c8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {ansible2.2}-{xenial-conf-tests,xenial-mon-osd,xenial-cluster,journal-collocation,centos7-cluster,dmcrypt-journal,dmcrypt-journal-collocation} +envlist = {ansible2.2}-{xenial_conf_tests,xenial_mon_osd,xenial_cluster,journal_collocation,centos7_cluster,dmcrypt_journal,dmcrypt_journal_collocation} skipsdist = True [testenv] @@ -17,19 +17,19 @@ deps= -r{toxinidir}/tests/requirements.txt changedir= # test a 3 mon cluster and ensures ceph.conf is rendered correctly - xenial-conf-tests: {toxinidir}/tests/functional/ubuntu/16.04/mon + xenial_conf_tests: {toxinidir}/tests/functional/ubuntu/16.04/mon # tests a 1 mon 1 osd xenial cluster using raw_multi_journal OSD scenario - xenial-mon-osd: {toxinidir}/tests/functional/ubuntu/16.04/mon-osd + xenial_mon_osd: {toxinidir}/tests/functional/ubuntu/16.04/mon-osd # tests a 1 mon, 1 osd, 1 mds and 1 rgw xenial cluster using raw_multi_journal OSD scenario - xenial-cluster: {toxinidir}/tests/functional/ubuntu/16.04/mon-osd-mds-rgw + xenial_cluster: {toxinidir}/tests/functional/ubuntu/16.04/mon-osd-mds-rgw # tests a 1 mon 1 osd centos7 cluster using journal_collocation OSD scenario - journal-collocation: {toxinidir}/tests/functional/centos/7/journal-collocation + journal_collocation: {toxinidir}/tests/functional/centos/7/journal-collocation # tests a 1 mon 1 osd centos7 cluster using dmcrypt_dedicated_journal OSD scenario - dmcrypt-journal: {toxinidir}/tests/functional/centos/7/dmcrypt-dedicated-journal + dmcrypt_journal: {toxinidir}/tests/functional/centos/7/dmcrypt-dedicated-journal # tests a 1 mon 1 osd centos7 cluster using dmcrypt_journal_collocation OSD scenario - dmcrypt-journal-collocation: {toxinidir}/tests/functional/centos/7/dmcrypt-journal-collocation + dmcrypt_journal_collocation: {toxinidir}/tests/functional/centos/7/dmcrypt-journal-collocation # tests a 1 mon, 1 osd, 1 mds and 1 rgw centos7 cluster using raw_multi_journal OSD scenario - centos7-cluster: {toxinidir}/tests/functional/centos/7/mon-osd-mds-rgw + centos7_cluster: {toxinidir}/tests/functional/centos/7/mon-osd-mds-rgw commands= vagrant up --no-provision {posargs:--provider=virtualbox} bash {toxinidir}/tests/scripts/generate_ssh_config.sh {changedir}