Commit 2e076ede authored by Stratos Psomadakis's avatar Stratos Psomadakis Committed by Guido Trotter

Add unit tests for RADOSBLockDevice

Add unit tests for the RADOSBlockDevice JSON output parsing function,
and modify the unit tests for the plain output parsing function to
work with the new code.
Signed-off-by: default avatarStratos Psomadakis <psomas@grnet.gr>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent bdecfea2
......@@ -106,6 +106,7 @@ DIRS = \
qa \
test \
test/data \
test/data/bdev-rbd \
test/data/ovfdata \
test/data/ovfdata/other \
test/py \
......@@ -986,6 +987,18 @@ TEST_FILES = \
test/data/bdev-drbd-disk.txt \
test/data/bdev-drbd-net-ip4.txt \
test/data/bdev-drbd-net-ip6.txt \
test/data/bdev-rbd/json_output_empty.txt \
test/data/bdev-rbd/json_output_extra_matches.txt \
test/data/bdev-rbd/json_output_no_matches.txt \
test/data/bdev-rbd/json_output_ok.txt \
test/data/bdev-rbd/plain_output_new_extra_matches.txt \
test/data/bdev-rbd/plain_output_new_no_matches.txt \
test/data/bdev-rbd/plain_output_new_ok.txt \
test/data/bdev-rbd/plain_output_old_empty.txt \
test/data/bdev-rbd/plain_output_old_extra_matches.txt \
test/data/bdev-rbd/plain_output_old_no_matches.txt \
test/data/bdev-rbd/plain_output_old_ok.txt \
test/data/bdev-rbd/output_invalid.txt \
test/data/cert1.pem \
test/data/cert2.pem \
test/data/instance-minor-pairing.txt \
......
{"4":{"pool":"rbd","name":"d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0","snap":"-","device":"\/dev\/rbd4"},"1":{"pool":"rbd","name":"b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0","snap":"-","device":"\/dev\/rbd1"},"2":{"pool":"rbd","name":"abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0","snap":"-","device":"\/dev\/rbd2"},"3":{"pool":"rbd","name":"d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0","snap":"-","device":"\/dev\/rbd3"}}
{"1":{"pool":"rbd","name":"b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0","snap":"-","device":"\/dev\/rbd1"},"2":{"pool":"rbd","name":"abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0","snap":"-","device":"\/dev\/rbd2"}}
{"1":{"pool":"rbd","name":"b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0","snap":"-","device":"\/dev\/rbd1"},"2":{"pool":"rbd","name":"abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0","snap":"-","device":"\/dev\/rbd2"},"3":{"pool":"rbd","name":"d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0","snap":"-","device":"\/dev\/rbd3"}}
id pool image snap device
4 rbd d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0 - /dev/rbd4
1 rbd b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0 - /dev/rbd1
2 rbd abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0 - /dev/rbd2
3 rbd d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0 - /dev/rbd3
id pool image snap device
1 rbd b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0 - /dev/rbd1
2 rbd abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0 - /dev/rbd2
1 rbd b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0 - /dev/rbd1
2 rbd abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0 - /dev/rbd2
3 rbd d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0 - /dev/rbd3
id pool image snap device
4 rbd d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0 - /dev/rbd4
1 rbd b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0 - /dev/rbd1
2 rbd abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0 - /dev/rbd2
3 rbd d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0 - /dev/rbd3
id pool image snap device
1 rbd b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0 - /dev/rbd1
2 rbd abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0 - /dev/rbd2
id pool image snap device
1 rbd b9e31bb3-4d4f-4a2c-bc63-207a0bc4b287.rbd.disk0 - /dev/rbd1
2 rbd abe7957a-ec96-490f-9c08-53b1c51cecf0.rbd.disk0 - /dev/rbd2
3 rbd d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0 - /dev/rbd3
......@@ -346,35 +346,72 @@ class TestDRBD8Status(testutils.GanetiTestCase):
class TestRADOSBlockDevice(testutils.GanetiTestCase):
def test_ParseRbdShowmappedOutput(self):
volume_name = "abc9778-8e8ace5b.rbd.disk0"
output_ok = \
("0\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
"1\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd16\n"
"line\twith\tfewer\tfields\n"
"")
output_empty = ""
output_no_matches = \
("0\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
"1\trbd\tabcdef01-9817.rbd.disk0\t-\t/dev/rbd10\n"
"2\trbd\tcdef0123-9817.rbd.disk0\t-\t/dev/rbd12\n"
"something\twith\tfewer\tfields"
"")
output_extra_matches = \
("0\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd11\n"
"1\trbd\te69f28e5-9817.rbd.disk0\t-\t/dev/rbd0\n"
"2\t/dev/rbd0\tabc9778-8e8ace5b.rbd.disk0\t-\t/dev/rbd16\n"
"something\twith\tfewer\tfields"
"")
parse_function = bdev.RADOSBlockDevice._ParseRbdShowmappedOutput
self.assertEqual(parse_function(output_ok, volume_name), "/dev/rbd16")
def setUp(self):
"""Set up input data"""
testutils.GanetiTestCase.setUp(self)
self.plain_output_old_ok = \
testutils.ReadTestData("bdev-rbd/plain_output_old_ok.txt")
self.plain_output_old_no_matches = \
testutils.ReadTestData("bdev-rbd/plain_output_old_no_matches.txt")
self.plain_output_old_extra_matches = \
testutils.ReadTestData("bdev-rbd/plain_output_old_extra_matches.txt")
self.plain_output_old_empty = \
testutils.ReadTestData("bdev-rbd/plain_output_old_empty.txt")
self.plain_output_new_ok = \
testutils.ReadTestData("bdev-rbd/plain_output_new_ok.txt")
self.plain_output_new_no_matches = \
testutils.ReadTestData("bdev-rbd/plain_output_new_no_matches.txt")
self.plain_output_new_extra_matches = \
testutils.ReadTestData("bdev-rbd/plain_output_new_extra_matches.txt")
# This file is completely empty, and as such it's not shipped.
self.plain_output_new_empty = ""
self.json_output_ok = testutils.ReadTestData("bdev-rbd/json_output_ok.txt")
self.json_output_no_matches = \
testutils.ReadTestData("bdev-rbd/json_output_no_matches.txt")
self.json_output_extra_matches = \
testutils.ReadTestData("bdev-rbd/json_output_extra_matches.txt")
self.json_output_empty = \
testutils.ReadTestData("bdev-rbd/json_output_empty.txt")
self.output_invalid = testutils.ReadTestData("bdev-rbd/output_invalid.txt")
self.volume_name = "d7ab910a-4933-4ffe-88d0-faf2ce31390a.rbd.disk0"
def test_ParseRbdShowmappedJson(self):
parse_function = bdev.RADOSBlockDevice._ParseRbdShowmappedJson
self.assertEqual(parse_function(self.json_output_ok, self.volume_name),
"/dev/rbd3")
self.assertEqual(parse_function(self.json_output_empty, self.volume_name),
None)
self.assertEqual(parse_function(self.json_output_no_matches,
self.volume_name), None)
self.assertRaises(errors.BlockDeviceError, parse_function,
output_empty, volume_name)
self.assertEqual(parse_function(output_no_matches, volume_name), None)
self.json_output_extra_matches, self.volume_name)
self.assertRaises(errors.BlockDeviceError, parse_function,
output_extra_matches, volume_name)
self.output_invalid, self.volume_name)
def test_ParseRbdShowmappedPlain(self):
parse_function = bdev.RADOSBlockDevice._ParseRbdShowmappedPlain
self.assertEqual(parse_function(self.plain_output_new_ok,
self.volume_name), "/dev/rbd3")
self.assertEqual(parse_function(self.plain_output_old_ok,
self.volume_name), "/dev/rbd3")
self.assertEqual(parse_function(self.plain_output_new_empty,
self.volume_name), None)
self.assertEqual(parse_function(self.plain_output_old_empty,
self.volume_name), None)
self.assertEqual(parse_function(self.plain_output_new_no_matches,
self.volume_name), None)
self.assertEqual(parse_function(self.plain_output_old_no_matches,
self.volume_name), None)
self.assertRaises(errors.BlockDeviceError, parse_function,
self.plain_output_new_extra_matches, self.volume_name)
self.assertRaises(errors.BlockDeviceError, parse_function,
self.plain_output_old_extra_matches, self.volume_name)
self.assertRaises(errors.BlockDeviceError, parse_function,
self.output_invalid, self.volume_name)
class TestComputeWrongFileStoragePathsInternal(unittest.TestCase):
def testPaths(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment