Skip osd-devices not absolute paths
This change skips over any devices which does not start with a leading folder separator ('/'). Allowing such entries causes an OSD to be created out of the charm directory. This can be caused by something as innocuous as 2 spaces between devices. The result is that the root device is also running an OSD, which is undesirable. Change-Id: I0b5530dc4ec4306a9efedb090e583fb4e2089749 Closes-Bug: 1652175
This commit is contained in:
parent
bdf5b370f9
commit
665ea2b6fc
@ -59,9 +59,13 @@ def add_device(request, device_path, bucket=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_devices():
|
def get_devices():
|
||||||
return [
|
devices = []
|
||||||
os.path.realpath(path)
|
for path in action_get('osd-devices').split(' '):
|
||||||
for path in action_get('osd-devices').split(' ')]
|
path = path.strip()
|
||||||
|
if os.path.isabs(path):
|
||||||
|
devices.append(path)
|
||||||
|
|
||||||
|
return devices
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -213,7 +213,7 @@ def use_short_objects():
|
|||||||
if config('osd-format') in ('ext4'):
|
if config('osd-format') in ('ext4'):
|
||||||
return True
|
return True
|
||||||
for device in config('osd-devices'):
|
for device in config('osd-devices'):
|
||||||
if not device.startswith('/dev'):
|
if device and not device.startswith('/dev'):
|
||||||
# TODO: determine format of directory based
|
# TODO: determine format of directory based
|
||||||
# OSD location
|
# OSD location
|
||||||
return True
|
return True
|
||||||
@ -412,12 +412,15 @@ def reformat_osd():
|
|||||||
|
|
||||||
|
|
||||||
def get_devices():
|
def get_devices():
|
||||||
if config('osd-devices'):
|
|
||||||
devices = [
|
|
||||||
os.path.realpath(path)
|
|
||||||
for path in config('osd-devices').split(' ')]
|
|
||||||
else:
|
|
||||||
devices = []
|
devices = []
|
||||||
|
if config('osd-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'
|
# List storage instances for the 'osd-devices'
|
||||||
# store declared for this charm too, and add
|
# store declared for this charm too, and add
|
||||||
|
@ -72,6 +72,25 @@ class GetDevicesTestCase(test_utils.CharmTestCase):
|
|||||||
self.test_config.set("osd-devices", "{} {}".format(device1, device2))
|
self.test_config.set("osd-devices", "{} {}".format(device1, device2))
|
||||||
self.assertEqual([device1, device2], hooks.get_devices())
|
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):
|
def test_get_devices_symlink(self):
|
||||||
"""
|
"""
|
||||||
If a symlink is specified in osd-devices, get_devices() resolves
|
If a symlink is specified in osd-devices, get_devices() resolves
|
||||||
|
Loading…
Reference in New Issue
Block a user