1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

python: Unit test ws fixes

pep8 corrections for:
    - mixed leading ws (tabs & spaces)
    - spacing around arithmetic operators

Signed-off-by: Tony Asleson <tasleson@redhat.com>
This commit is contained in:
Tony Asleson 2015-04-07 15:36:11 -05:00
parent 2b557b595a
commit f29df9acfe

View File

@ -44,8 +44,8 @@ def rs(rand_len=10):
""" """
Generate a random string Generate a random string
""" """
return ''.join(random.choice(string.ascii_uppercase) return ''.join(
for x in range(rand_len)) random.choice(string.ascii_uppercase)for x in range(rand_len))
def _get_allowed_devices(): def _get_allowed_devices():
@ -131,15 +131,15 @@ class TestLvm(unittest.TestCase):
for d in device_list: for d in device_list:
vg.extend(d) vg.extend(d)
vg.createLvThinpool(pool_name, vg.getSize()/2, 0, 0, vg.createLvThinpool(
lvm.THIN_DISCARDS_PASSDOWN, 1) pool_name, vg.getSize() / 2, 0, 0, lvm.THIN_DISCARDS_PASSDOWN, 1)
return vg return vg
@staticmethod @staticmethod
def _create_thin_lv(pv_devices, name): def _create_thin_lv(pv_devices, name):
thin_pool_name = 'thin_vg_pool_' + rs(4) thin_pool_name = 'thin_vg_pool_' + rs(4)
vg = TestLvm._create_thin_pool(pv_devices, thin_pool_name) vg = TestLvm._create_thin_pool(pv_devices, thin_pool_name)
vg.createLvThin(thin_pool_name, name, vg.getSize()/8) vg.createLvThin(thin_pool_name, name, vg.getSize() / 8)
vg.close() vg.close()
vg = None vg = None
@ -239,7 +239,7 @@ class TestLvm(unittest.TestCase):
curr_size = pv.getSize() curr_size = pv.getSize()
dev_size = pv.getDevSize() dev_size = pv.getDevSize()
self.assertTrue(curr_size == dev_size) self.assertTrue(curr_size == dev_size)
pv.resize(curr_size/2) pv.resize(curr_size / 2)
with AllowedPVS() as pvs: with AllowedPVS() as pvs:
pv = pvs[0] pv = pvs[0]
resized_size = pv.getSize() resized_size = pv.getSize()
@ -298,17 +298,21 @@ class TestLvm(unittest.TestCase):
self.assertEqual(type(pv.getUuid()), str) self.assertEqual(type(pv.getUuid()), str)
self.assertTrue(len(pv.getUuid()) > 0) self.assertTrue(len(pv.getUuid()) > 0)
self.assertTrue(type(pv.getMdaCount()) == int or self.assertTrue(
type(pv.getMdaCount()) == long) type(pv.getMdaCount()) == int or
type(pv.getMdaCount()) == long)
self.assertTrue(type(pv.getSize()) == int or self.assertTrue(
type(pv.getSize()) == long) type(pv.getSize()) == int or
type(pv.getSize()) == long)
self.assertTrue(type(pv.getDevSize()) == int or self.assertTrue(
type(pv.getSize()) == long) type(pv.getDevSize()) == int or
type(pv.getSize()) == long)
self.assertTrue(type(pv.getFree()) == int or self.assertTrue(
type(pv.getFree()) == long) type(pv.getFree()) == int or
type(pv.getFree()) == long)
def _test_prop(self, prop_obj, prop, var_type, settable): def _test_prop(self, prop_obj, prop, var_type, settable):
result = prop_obj.getProperty(prop) result = prop_obj.getProperty(prop)
@ -516,7 +520,7 @@ class TestLvm(unittest.TestCase):
lv, vg = TestLvm._get_lv(None, lv_name) lv, vg = TestLvm._get_lv(None, lv_name)
curr_size = lv.getSize() curr_size = lv.getSize()
lv.resize(curr_size+(1024*1024)) lv.resize(curr_size + (1024 * 1024))
latest = lv.getSize() latest = lv.getSize()
self.assertTrue(curr_size != latest) self.assertTrue(curr_size != latest)
@ -542,8 +546,9 @@ class TestLvm(unittest.TestCase):
new_extent = 1024 * 1024 * 4 new_extent = 1024 * 1024 * 4
self.assertFalse(vg.getExtentSize() != new_extent, self.assertFalse(
"Cannot determine if it works if they are the same") vg.getExtentSize() != new_extent,
"Cannot determine if it works if they are the same")
vg.setExtentSize(new_extent) vg.setExtentSize(new_extent)
self.assertEqual(vg.getExtentSize(), new_extent) self.assertEqual(vg.getExtentSize(), new_extent)
@ -602,8 +607,8 @@ class TestLvm(unittest.TestCase):
if len(lvs): if len(lvs):
lv = lvs[0] lv = lvs[0]
lv_name = lv.getName() lv_name = lv.getName()
self.assertRaises(lvm.LibLVMError, vg.createLvLinear, lv_name, self.assertRaises(
lv.getSize()) lvm.LibLVMError, vg.createLvLinear, lv_name, lv.getSize())
vg.close() vg.close()
def test_vg_uuids(self): def test_vg_uuids(self):
@ -653,10 +658,10 @@ class TestLvm(unittest.TestCase):
pv_name_lookup = vg.pvFromName(name) pv_name_lookup = vg.pvFromName(name)
pv_uuid_lookup = vg.pvFromUuid(uuid) pv_uuid_lookup = vg.pvFromUuid(uuid)
self.assertTrue(pv_name_lookup.getName() == self.assertTrue(
pv_uuid_lookup.getName()) pv_name_lookup.getName() == pv_uuid_lookup.getName())
self.assertTrue(pv_name_lookup.getUuid() == self.assertTrue(
pv_uuid_lookup.getUuid()) pv_name_lookup.getUuid() == pv_uuid_lookup.getUuid())
self.assertTrue(name == pv_name_lookup.getName()) self.assertTrue(name == pv_name_lookup.getName())
self.assertTrue(uuid == pv_uuid_lookup.getUuid()) self.assertTrue(uuid == pv_uuid_lookup.getUuid())
@ -738,9 +743,10 @@ class TestLvm(unittest.TestCase):
self.assertTrue(len(uuid) > 0) self.assertTrue(len(uuid) > 0)
vg.close() vg.close()
RETURN_NUMERIC = ["getSeqno", "getSize", "getFreeSize", "getFreeSize", RETURN_NUMERIC = [
"getExtentSize", "getExtentCount", "getFreeExtentCount", "getSeqno", "getSize", "getFreeSize", "getFreeSize",
"getPvCount", "getMaxPv", "getMaxLv"] "getExtentSize", "getExtentCount", "getFreeExtentCount",
"getPvCount", "getMaxPv", "getMaxLv"]
def test_vg_getters(self): def test_vg_getters(self):
device_names = TestLvm._get_pv_device_names() device_names = TestLvm._get_pv_device_names()
@ -804,7 +810,7 @@ class TestLvm(unittest.TestCase):
i = 0 i = 0
for d in device_names: for d in device_names:
if i % 2 == 0: if i % 2 == 0:
TestLvm._create_thin_lv([d], "thin_lv%d" % i) TestLvm._create_thin_lv([d], "thin_lv%d" % i)
else: else:
TestLvm._create_thick_lv([d], "thick_lv%d" % i) TestLvm._create_thick_lv([d], "thick_lv%d" % i)
i += 1 i += 1
@ -854,7 +860,7 @@ class TestLvm(unittest.TestCase):
lvm.pvCreate(d) lvm.pvCreate(d)
def test_pv_create(self): def test_pv_create(self):
size = [0, 1024*1024*4] size = [0, 1024 * 1024 * 4]
pvmeta_copies = [0, 1, 2] pvmeta_copies = [0, 1, 2]
pvmeta_size = [0, 255, 512, 1024] pvmeta_size = [0, 255, 512, 1024]
data_alignment = [0, 2048, 4096] data_alignment = [0, 2048, 4096]
@ -873,9 +879,9 @@ class TestLvm(unittest.TestCase):
self.assertRaises(lvm.LibLVMError, lvm.pvCreate, '') self.assertRaises(lvm.LibLVMError, lvm.pvCreate, '')
self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 4) self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 4)
self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 4) self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 4)
self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 0, 0, 2**34) self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 0, 0, 2 ** 34)
self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 0, 0, 4096, self.assertRaises(
2**34) lvm.LibLVMError, lvm.pvCreate, d, 0, 0, 0, 4096, 2 ** 34)
#Try a number of combinations and permutations #Try a number of combinations and permutations
for s in size: for s in size:
@ -891,12 +897,14 @@ class TestLvm(unittest.TestCase):
lvm.pvCreate(d, s, copies, pv_size, align) lvm.pvCreate(d, s, copies, pv_size, align)
lvm.pvRemove(d) lvm.pvRemove(d)
for align_offset in data_alignment_offset: for align_offset in data_alignment_offset:
lvm.pvCreate(d, s, copies, pv_size, align, lvm.pvCreate(
align * align_offset) d, s, copies, pv_size, align,
align * align_offset)
lvm.pvRemove(d) lvm.pvRemove(d)
for z in zero: for z in zero:
lvm.pvCreate(d, s, copies, pv_size, align, lvm.pvCreate(
align * align_offset, z) d, s, copies, pv_size, align,
align * align_offset, z)
lvm.pvRemove(d) lvm.pvRemove(d)
#Restore #Restore
@ -960,7 +968,7 @@ class TestLvm(unittest.TestCase):
method(t) method(t)
def _test_bad_names(self, method, dupe_name): def _test_bad_names(self, method, dupe_name):
# Test for duplicate name # Test for duplicate name
self.assertRaises(lvm.LibLVMError, method, dupe_name) self.assertRaises(lvm.LibLVMError, method, dupe_name)
# Test for too long a name # Test for too long a name
@ -983,8 +991,9 @@ class TestLvm(unittest.TestCase):
def _lv_reserved_names(self, method): def _lv_reserved_names(self, method):
prefixes = ['snapshot', 'pvmove'] prefixes = ['snapshot', 'pvmove']
reserved = ['_mlog', '_mimage', '_pmspare', '_rimage', '_rmeta', reserved = [
'_vorigin', '_tdata', '_tmeta'] '_mlog', '_mimage', '_pmspare', '_rimage', '_rmeta',
'_vorigin', '_tdata', '_tmeta']
for p in prefixes: for p in prefixes:
self.assertRaises(lvm.LibLVMError, method, p + rs(3)) self.assertRaises(lvm.LibLVMError, method, p + rs(3))