Merge "Skip osd-devices not absolute paths"

This commit is contained in:
Jenkins 2017-05-21 21:07:59 +00:00 committed by Gerrit Code Review
commit 290a32832e
3 changed files with 36 additions and 8 deletions

View File

@ -59,9 +59,13 @@ def add_device(request, device_path, bucket=None):
def get_devices():
return [
os.path.realpath(path)
for path in action_get('osd-devices').split(' ')]
devices = []
for path in action_get('osd-devices').split(' '):
path = path.strip()
if os.path.isabs(path):
devices.append(path)
return devices
if __name__ == "__main__":

View File

@ -365,12 +365,17 @@ def reformat_osd():
def get_devices():
devices = []
if config('osd-devices'):
devices = [
os.path.realpath(path)
for path in config('osd-devices').split(' ')]
else:
devices = []
for path in config('osd-devices').split(' '):
path = path.strip()
# Make sure its a device which is specified using an
# absolute path so that the current working directory
# or any relative path under this directory is not used
if os.path.isabs(path):
devices.append(os.path.realpath(path))
# List storage instances for the 'osd-devices'
# store declared for this charm too, and add
# their block device paths to the list.

View File

@ -72,6 +72,25 @@ class GetDevicesTestCase(test_utils.CharmTestCase):
self.test_config.set("osd-devices", "{} {}".format(device1, device2))
self.assertEqual([device1, device2], hooks.get_devices())
def test_get_devices_extra_spaces(self):
"""
Multiple spaces do not result in additional devices.
"""
device1 = os.path.join(self.tmp_dir, "device1")
device2 = os.path.join(self.tmp_dir, "device2")
self.test_config.set("osd-devices", "{} {}".format(device1, device2))
self.assertEqual([device1, device2], hooks.get_devices())
def test_get_devices_non_absolute_path(self):
"""
Charm does not allow relative paths as this may result in a path
on the root device/within the charm directory.
"""
device1 = os.path.join(self.tmp_dir, "device1")
device2 = "foo"
self.test_config.set("osd-devices", "{} {}".format(device1, device2))
self.assertEqual([device1], hooks.get_devices())
def test_get_devices_symlink(self):
"""
If a symlink is specified in osd-devices, get_devices() resolves