From: Vratislav Podzimek <vpodzime(a)redhat.com>
Apart from the tests we alway call this code on a particular instance. And
sometimes it's impossible to just tell if a name is valid without looking on
some other properties of the object.
---
blivet/devices/btrfs.py | 3 +--
blivet/devices/device.py | 3 +--
blivet/devices/file.py | 3 +--
blivet/devices/nfs.py | 3 +--
blivet/devices/storage.py | 5 ++---
tests/devices_test/device_names_test.py | 26 ++++++++++++++++++++------
6 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/blivet/devices/btrfs.py b/blivet/devices/btrfs.py
index e2f6ee1..988d830 100644
--- a/blivet/devices/btrfs.py
+++ b/blivet/devices/btrfs.py
@@ -151,8 +151,7 @@ def fstab_spec(self):
spec = super(BTRFSDevice, self).fstab_spec
return spec
- @classmethod
- def is_name_valid(cls, name):
+ def is_name_valid(self, name):
# Override StorageDevice.is_name_valid to allow pretty much anything
return not('\x00' in name)
diff --git a/blivet/devices/device.py b/blivet/devices/device.py
index a111a58..8bc8410 100644
--- a/blivet/devices/device.py
+++ b/blivet/devices/device.py
@@ -301,8 +301,7 @@ def packages(self):
return packages
- @classmethod
- def is_name_valid(cls, name): # pylint: disable=unused-argument
+ def is_name_valid(self, name): # pylint: disable=unused-argument
"""Is the device name valid for the device
type?"""
# By default anything goes
diff --git a/blivet/devices/file.py b/blivet/devices/file.py
index dc53a7a..8bf0e6f 100644
--- a/blivet/devices/file.py
+++ b/blivet/devices/file.py
@@ -128,8 +128,7 @@ def _destroy(self):
log_method_call(self, self.name, status=self.status)
os.unlink(self.path)
- @classmethod
- def is_name_valid(cls, name):
+ def is_name_valid(self, name):
# Override StorageDevice.is_name_valid to allow /
return not('\x00' in name or name == '.' or name ==
'..')
diff --git a/blivet/devices/nfs.py b/blivet/devices/nfs.py
index 3143d7c..f4c96f7 100644
--- a/blivet/devices/nfs.py
+++ b/blivet/devices/nfs.py
@@ -74,7 +74,6 @@ def destroy(self):
def update_size(self):
pass
- @classmethod
- def is_name_valid(cls, name):
+ def is_name_valid(self, name):
# Override StorageDevice.is_name_valid to allow /
return not('\x00' in name or name == '.' or name ==
'..')
diff --git a/blivet/devices/storage.py b/blivet/devices/storage.py
index c91b9d1..7440070 100644
--- a/blivet/devices/storage.py
+++ b/blivet/devices/storage.py
@@ -806,8 +806,7 @@ def populate_ksdata(self, data):
if data.mountpoint.endswith("."):
data.mountpoint += str(self.id)
- @classmethod
- def is_name_valid(cls, name):
+ def is_name_valid(self, name):
# This device corresponds to a file in /dev, so no /'s or nulls,
# and the name cannot be . or ..
@@ -815,7 +814,7 @@ def is_name_valid(cls, name):
# is an imperfect world of joy and sorrow mingled. For cciss, split
# the path into its components and do the real check on each piece
if name.startswith("cciss/"):
- return all(cls.is_name_valid(n) for n in name.split('/'))
+ return all(self.is_name_valid(n) for n in name.split('/'))
badchars = any(c in ('\x00', '/') for c in name)
return not(badchars or name == '.' or name == '..')
diff --git a/tests/devices_test/device_names_test.py
b/tests/devices_test/device_names_test.py
index 2d7ae7f..de255d0 100644
--- a/tests/devices_test/device_names_test.py
+++ b/tests/devices_test/device_names_test.py
@@ -5,6 +5,8 @@
from blivet.devices import LVMVolumeGroupDevice
from blivet.devices import LVMLogicalVolumeDevice
from blivet.devices import StorageDevice
+from blivet.size import Size
+import blivet
class DeviceNameTestCase(unittest.TestCase):
@@ -16,29 +18,41 @@ def test_storage_device(self):
good_names = ['sda1', '1sda', 'good-name',
'cciss/c0d0']
bad_names = ['sda/1', 'sda\x00', '.', '..',
'cciss/..']
+ sd = StorageDevice("tester")
+
for name in good_names:
- self.assertTrue(StorageDevice.is_name_valid(name))
+ self.assertTrue(sd.is_name_valid(name))
for name in bad_names:
- self.assertFalse(StorageDevice.is_name_valid(name))
+ self.assertFalse(sd.is_name_valid(name))
def test_volume_group(self):
good_names = ['vg00', 'group-name', 'groupname-']
bad_names = ['-leading-hyphen', 'Ășnicode', 'sp aces']
+ pv = StorageDevice("pv1",
fmt=blivet.formats.get_format("lvmpv"),
+ size=Size("1 GiB"))
+ vg = LVMVolumeGroupDevice("testvg", parents=[pv])
+
for name in good_names:
- self.assertTrue(LVMVolumeGroupDevice.is_name_valid(name))
+ self.assertTrue(vg.is_name_valid(name))
for name in bad_names:
- self.assertFalse(LVMVolumeGroupDevice.is_name_valid(name))
+ self.assertFalse(vg.is_name_valid(name))
def test_logical_volume(self):
good_names = ['lv00', 'volume-name', 'volumename-']
bad_names = ['-leading-hyphen', 'Ășnicode', 'sp aces',
'snapshot47', 'pvmove0', 'sub_tmetastring']
+ pv = StorageDevice("pv1",
fmt=blivet.formats.get_format("lvmpv"),
+ size=Size("1 GiB"))
+ vg = LVMVolumeGroupDevice("testvg", parents=[pv])
+ lv = LVMLogicalVolumeDevice("testlv", parents=[vg],
+ fmt=blivet.formats.get_format("xfs"))
+
for name in good_names:
- self.assertTrue(LVMLogicalVolumeDevice.is_name_valid(name))
+ self.assertTrue(lv.is_name_valid(name))
for name in bad_names:
- self.assertFalse(LVMLogicalVolumeDevice.is_name_valid(name))
+ self.assertFalse(lv.is_name_valid(name))
--
To view this commit on github, visit
https://github.com/rhinstaller/blivet/commit/b7282125ce85e1f1010b8c339616...