Relax mount point name checking.
In general, Linux does not care about what a mount point is named as long as it is a vaild directory name (no / or null characters). However, that is too relaxed for swift, which will pass that mount point name around as part of url path construction all over the place. To make sure that the mount point name was sane from that POV, Swift was using isalnum to verify that the mount point name was sane, which is overly restrictive. This patch replaces that test with a test that verifies that the name has no characters that need to be URL encoded. The specific use case this enables is allowing mount points to be named according to the UUID of the filesystem that is being mounted, which will make Swift more robust in the face of device name instability. Change-Id: I4d49b21c1783e97c16d3f394c2171f1f80eea058
This commit is contained in:
parent
711df677cb
commit
956cc0c793
@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import urllib
|
||||
from ConfigParser import ConfigParser, NoSectionError, NoOptionError, \
|
||||
RawConfigParser
|
||||
|
||||
@ -159,7 +160,7 @@ def check_mount(root, drive):
|
||||
:param drive: drive name to be checked
|
||||
:returns: True if it is a valid mounted device, False otherwise
|
||||
"""
|
||||
if not drive.isalnum():
|
||||
if not (urllib.quote_plus(drive) == drive):
|
||||
return False
|
||||
path = os.path.join(root, drive)
|
||||
return os.path.exists(path) and os.path.ismount(path)
|
||||
|
@ -173,6 +173,11 @@ class TestConstraints(unittest.TestCase):
|
||||
self.assertFalse(constraints.check_mount('', ''))
|
||||
constraints.os = MockTrue() # mock os module
|
||||
self.assertTrue(constraints.check_mount('/srv', '1'))
|
||||
self.assertTrue(constraints.check_mount('/srv', 'foo-bar'))
|
||||
self.assertTrue(constraints.check_mount('/srv', '003ed03c-242a-4b2f-bee9-395f801d1699'))
|
||||
self.assertFalse(constraints.check_mount('/srv', 'foo bar'))
|
||||
self.assertFalse(constraints.check_mount('/srv', 'foo/bar'))
|
||||
self.assertFalse(constraints.check_mount('/srv', 'foo?bar'))
|
||||
reload(constraints) # put it back
|
||||
|
||||
def test_check_float(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user