On 06/04/2014 12:05 PM, David Shea wrote:
In addition to FileDevice and its subclasses, allow / in name for
NFSDevice, BTRFSSubVolumeDevice, and any StorageDevice trying to create
a name starting with 'cciss/'.
---
blivet/devices.py | 16 ++++++++++++++++
tests/devices_test.py | 4 ++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/blivet/devices.py b/blivet/devices.py
index cdd0642..fbfa095 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -1120,6 +1120,13 @@ class StorageDevice(Device):
def isNameValid(cls, name):
# This device corresponds to a file in /dev, so no /'s or nulls,
# and the name cannot be . or ..
+
+ # ...except some names *do* contain directory components, for this
+ # 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.isNameValid(n) for n in name.split('/'))
+
badchars = any(c in ('\x00', '/') for c in name)
return not(badchars or name == '.' or name == '..')
@@ -4609,6 +4616,10 @@ class NFSDevice(StorageDevice, NetworkStorageDevice):
""" Destroy the device. """
log_method_call(self, self.name, status=self.status)
+ @classmethod
+ def isNameValid(cls, name):
+ # Override StorageDevice.isNameValid to allow /
+ return not('\x00' in name or name == '.' or name ==
'..')
class BTRFSDevice(StorageDevice):
""" Base class for BTRFS volume and sub-volume devices.
"""
@@ -4965,3 +4976,8 @@ class BTRFSSubVolumeDevice(BTRFSDevice):
data.subvol = True
data.name = self.name
data.preexist = self.exists
+
+ @classmethod
+ def isNameValid(cls, name):
+ # Override StorageDevice.isNameValid to allow /
+ return not('\x00' in name or name == '.' or name ==
'..')
diff --git a/tests/devices_test.py b/tests/devices_test.py
index 6598eba..faefde0 100644
--- a/tests/devices_test.py
+++ b/tests/devices_test.py
@@ -508,8 +508,8 @@ class DeviceNameTestCase(unittest.TestCase):
def testStorageDefvice(self):
s/Defvice/Device/ above
# Check that / and NUL are rejected along with . and ..
- good_names = ['sda1', '1sda', 'good-name']
- bad_names = ['sda/1', 'sda\x00', '.', '..']
+ good_names = ['sda1', '1sda', 'good-name',
'cciss/c0d0']
+ bad_names = ['sda/1', 'sda\x00', '.', '..',
'cciss/..']
for name in good_names:
self.assertTrue(StorageDevice.isNameValid(name))
Looks good other than the inconsequential typo pointed out above.
David