This will need my extra commit to allow empty files to be shipped (sent as RFC).
Also there were a couple of extra long lines. Interdiff:
diff --git a/test/py/ganeti.bdev_unittest.py b/test/py/ganeti.bdev_unittest.py
index 3419182..1245965 100755
--- a/test/py/ganeti.bdev_unittest.py
+++ b/test/py/ganeti.bdev_unittest.py
@@ -350,14 +350,16 @@ class TestRADOSBlockDevice(testutils.GanetiTestCase):
"""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_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_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 = \
@@ -369,7 +371,8 @@ class TestRADOSBlockDevice(testutils.GanetiTestCase):
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.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"
On Tue, Feb 12, 2013 at 1:07 PM, Stratos Psomadakis <[email protected]> wrote:
> 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: Stratos Psomadakis <[email protected]>
> ---
> Sorry for that. :/ It should be fixed now.
>
> Thanks,
> Stratos
>
> Makefile.am | 14 ++++
> test/data/bdev-rbd/json_output_empty.txt | 1 +
> test/data/bdev-rbd/json_output_extra_matches.txt | 1 +
> test/data/bdev-rbd/json_output_no_matches.txt | 1 +
> test/data/bdev-rbd/json_output_ok.txt | 1 +
> test/data/bdev-rbd/output_invalid.txt | 1 +
> .../bdev-rbd/plain_output_new_extra_matches.txt | 5 ++
> test/data/bdev-rbd/plain_output_new_no_matches.txt | 3 +
> test/data/bdev-rbd/plain_output_new_ok.txt | 3 +
> test/data/bdev-rbd/plain_output_old_empty.txt | 1 +
> .../bdev-rbd/plain_output_old_extra_matches.txt | 5 ++
> test/data/bdev-rbd/plain_output_old_no_matches.txt | 3 +
> test/data/bdev-rbd/plain_output_old_ok.txt | 4 +
> test/py/ganeti.bdev_unittest.py | 88
> ++++++++++++++------
> 14 files changed, 104 insertions(+), 27 deletions(-)
> create mode 100644 test/data/bdev-rbd/json_output_empty.txt
> create mode 100644 test/data/bdev-rbd/json_output_extra_matches.txt
> create mode 100644 test/data/bdev-rbd/json_output_no_matches.txt
> create mode 100644 test/data/bdev-rbd/json_output_ok.txt
> create mode 100644 test/data/bdev-rbd/output_invalid.txt
> create mode 100644 test/data/bdev-rbd/plain_output_new_empty.txt
> create mode 100644 test/data/bdev-rbd/plain_output_new_extra_matches.txt
> create mode 100644 test/data/bdev-rbd/plain_output_new_no_matches.txt
> create mode 100644 test/data/bdev-rbd/plain_output_new_ok.txt
> create mode 100644 test/data/bdev-rbd/plain_output_old_empty.txt
> create mode 100644 test/data/bdev-rbd/plain_output_old_extra_matches.txt
> create mode 100644 test/data/bdev-rbd/plain_output_old_no_matches.txt
> create mode 100644 test/data/bdev-rbd/plain_output_old_ok.txt
>
> diff --git a/Makefile.am b/Makefile.am
> index 2b20bf0..f05a58c 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -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,19 @@ 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_empty.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 \
> diff --git a/test/data/bdev-rbd/json_output_empty.txt
> b/test/data/bdev-rbd/json_output_empty.txt
> new file mode 100644
> index 0000000..0967ef4
> --- /dev/null
> +++ b/test/data/bdev-rbd/json_output_empty.txt
> @@ -0,0 +1 @@
> +{}
> diff --git a/test/data/bdev-rbd/json_output_extra_matches.txt
> b/test/data/bdev-rbd/json_output_extra_matches.txt
> new file mode 100644
> index 0000000..321c438
> --- /dev/null
> +++ b/test/data/bdev-rbd/json_output_extra_matches.txt
> @@ -0,0 +1 @@
> +{"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"}}
> diff --git a/test/data/bdev-rbd/json_output_no_matches.txt
> b/test/data/bdev-rbd/json_output_no_matches.txt
> new file mode 100644
> index 0000000..a298788
> --- /dev/null
> +++ b/test/data/bdev-rbd/json_output_no_matches.txt
> @@ -0,0 +1 @@
> +{"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"}}
> diff --git a/test/data/bdev-rbd/json_output_ok.txt
> b/test/data/bdev-rbd/json_output_ok.txt
> new file mode 100644
> index 0000000..0d5173f
> --- /dev/null
> +++ b/test/data/bdev-rbd/json_output_ok.txt
> @@ -0,0 +1 @@
> +{"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"}}
> diff --git a/test/data/bdev-rbd/output_invalid.txt
> b/test/data/bdev-rbd/output_invalid.txt
> new file mode 100644
> index 0000000..27aa7b1
> --- /dev/null
> +++ b/test/data/bdev-rbd/output_invalid.txt
> @@ -0,0 +1 @@
> +invalid rbd output
> diff --git a/test/data/bdev-rbd/plain_output_new_empty.txt
> b/test/data/bdev-rbd/plain_output_new_empty.txt
> new file mode 100644
> index 0000000..e69de29
> diff --git a/test/data/bdev-rbd/plain_output_new_extra_matches.txt
> b/test/data/bdev-rbd/plain_output_new_extra_matches.txt
> new file mode 100644
> index 0000000..f7bc907
> --- /dev/null
> +++ b/test/data/bdev-rbd/plain_output_new_extra_matches.txt
> @@ -0,0 +1,5 @@
> +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
> diff --git a/test/data/bdev-rbd/plain_output_new_no_matches.txt
> b/test/data/bdev-rbd/plain_output_new_no_matches.txt
> new file mode 100644
> index 0000000..bc126b3
> --- /dev/null
> +++ b/test/data/bdev-rbd/plain_output_new_no_matches.txt
> @@ -0,0 +1,3 @@
> +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
> diff --git a/test/data/bdev-rbd/plain_output_new_ok.txt
> b/test/data/bdev-rbd/plain_output_new_ok.txt
> new file mode 100644
> index 0000000..bc25094
> --- /dev/null
> +++ b/test/data/bdev-rbd/plain_output_new_ok.txt
> @@ -0,0 +1,3 @@
> +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
> diff --git a/test/data/bdev-rbd/plain_output_old_empty.txt
> b/test/data/bdev-rbd/plain_output_old_empty.txt
> new file mode 100644
> index 0000000..0bb19ea
> --- /dev/null
> +++ b/test/data/bdev-rbd/plain_output_old_empty.txt
> @@ -0,0 +1 @@
> +id pool image snap device
> diff --git a/test/data/bdev-rbd/plain_output_old_extra_matches.txt
> b/test/data/bdev-rbd/plain_output_old_extra_matches.txt
> new file mode 100644
> index 0000000..52848e4
> --- /dev/null
> +++ b/test/data/bdev-rbd/plain_output_old_extra_matches.txt
> @@ -0,0 +1,5 @@
> +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
> diff --git a/test/data/bdev-rbd/plain_output_old_no_matches.txt
> b/test/data/bdev-rbd/plain_output_old_no_matches.txt
> new file mode 100644
> index 0000000..3632b48
> --- /dev/null
> +++ b/test/data/bdev-rbd/plain_output_old_no_matches.txt
> @@ -0,0 +1,3 @@
> +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
> diff --git a/test/data/bdev-rbd/plain_output_old_ok.txt
> b/test/data/bdev-rbd/plain_output_old_ok.txt
> new file mode 100644
> index 0000000..c2e1e5c
> --- /dev/null
> +++ b/test/data/bdev-rbd/plain_output_old_ok.txt
> @@ -0,0 +1,4 @@
> +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
> diff --git a/test/py/ganeti.bdev_unittest.py b/test/py/ganeti.bdev_unittest.py
> index 4aa3106..3419182 100755
> --- a/test/py/ganeti.bdev_unittest.py
> +++ b/test/py/ganeti.bdev_unittest.py
> @@ -346,35 +346,69 @@ 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")
> + self.plain_output_new_empty = \
> + testutils.ReadTestData("bdev-rbd/plain_output_new_empty.txt")
> + 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):
> --
> 1.7.10.4
>
--
Guido Trotter
Ganeti engineering
Google Germany