]> sourceware.org Git - lvm2.git/commitdiff
python_lvm_unit.py: Add test for new name validate methods
authorTony Asleson <tasleson@redhat.com>
Mon, 18 Nov 2013 21:09:09 +0000 (15:09 -0600)
committerTony Asleson <tasleson@redhat.com>
Tue, 19 Nov 2013 20:40:47 +0000 (14:40 -0600)
Test naming validate names for VG and LV names.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
test/api/python_lvm_unit.py

index fc8c198ff0fae17047bbf80db5ed0b641b8c1149..8208d91ffff7857b33eddcfbf1c9ddee0f6fa96e 100755 (executable)
@@ -17,6 +17,7 @@ import random
 import string
 import lvm
 import os
+import itertools
 
 # Set of basic unit tests for the python bindings.
 #
@@ -808,5 +809,110 @@ class TestLvm(unittest.TestCase):
                for d in device_names:
                        lvm.pvCreate(d)
 
+       def test_vg_reduce(self):
+               # Test the case where we try to reduce a vg where the last PV has
+               # no metadata copies.  In this case the reduce should fail.
+               vg_name = TestLvm.VG_P + 'reduce_test'
+
+               device_names = TestLvm._get_pv_device_names()
+
+               for d in device_names:
+                       lvm.pvRemove(d)
+
+               lvm.pvCreate(device_names[0], 0, 0)  # Size all, pvmetadatacopies 0
+               lvm.pvCreate(device_names[1])
+               lvm.pvCreate(device_names[2])
+               lvm.pvCreate(device_names[3])
+
+               vg = lvm.vgCreate(vg_name)
+
+               vg.extend(device_names[3])
+               vg.extend(device_names[2])
+               vg.extend(device_names[1])
+               vg.extend(device_names[0])
+               vg.close()
+
+               vg = None
+
+               vg = lvm.vgOpen(vg_name, 'w')
+
+               vg.reduce(device_names[3])
+               vg.reduce(device_names[2])
+
+               self.assertRaises(lvm.LibLVMError, vg.reduce, device_names[1])
+
+               vg.close()
+               vg = None
+
+               vg = lvm.vgOpen(vg_name, 'w')
+               vg.remove()
+               vg.close()
+
+       @staticmethod
+       def _test_valid_names(method):
+               sample = 'azAZ09._-+'
+
+               method('x' * 127)
+               method('.X')
+               method('..X')
+
+               for i in range(1, 7):
+                       tests = (''.join(i) for i in itertools.product(sample, repeat=i))
+                       for t in tests:
+                               if t == '.' or t == '..':
+                                       t += 'X'
+                               elif t.startswith('-'):
+                                       t = 'H' + t
+                               method(t)
+
+       def _test_bad_names(self, method, dupe_name):
+                # Test for duplicate name
+               self.assertRaises(lvm.LibLVMError, method, dupe_name)
+
+               # Test for too long a name
+               self.assertRaises(lvm.LibLVMError, method, ('x' * 128))
+
+               # Test empty
+               self.assertRaises(lvm.LibLVMError, method, '')
+
+               # Invalid characters
+               self.assertRaises(lvm.LibLVMError, method, '&invalid^char')
+
+               # Cannot start with .. and no following characters
+               self.assertRaises(lvm.LibLVMError, method, '..')
+
+               # Cannot start with . and no following characters
+               self.assertRaises(lvm.LibLVMError, method, '.')
+
+               # Cannot start with a hyphen
+               self.assertRaises(lvm.LibLVMError, method, '-not_good')
+
+       def _lv_reserved_names(self, method):
+               prefixes = ['snapshot', 'pvmove']
+               reserved = ['_mlog', '_mimage', '_pmspare', '_rimage', '_rmeta',
+                                       '_vorigin', '_tdata', '_tmeta']
+
+               for p in prefixes:
+                       self.assertRaises(lvm.LibLVMError, method, p + rs(3))
+
+               for r in reserved:
+                       self.assertRaises(lvm.LibLVMError, method, rs(3) + r + rs(1))
+                       self.assertRaises(lvm.LibLVMError, method, r + rs(1))
+
+       def test_vg_lv_name_validate(self):
+               lv_name = 'vg_lv_name_validate'
+               TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+               lv, vg = TestLvm._get_lv(None, lv_name)
+
+               self._test_bad_names(lvm.vgNameValidate, vg.getName())
+               self._test_bad_names(vg.lvNameValidate, lv.getName())
+
+               # Test good values
+               TestLvm._test_valid_names(lvm.vgNameValidate)
+               TestLvm._test_valid_names(vg.lvNameValidate)
+               self._lv_reserved_names(vg.lvNameValidate)
+
+               vg.close()
+
 if __name__ == "__main__":
        unittest.main()
This page took 0.047849 seconds and 5 git commands to generate.