Do not accept non-by-id path in opencas.conf

Exception: allow passing exported objects paths.

Signed-off-by: Slawomir Jankowski <slawomir.jankowski@intel.com>
This commit is contained in:
Slawomir Jankowski 2020-12-07 16:34:15 +01:00 committed by Robert Baldyga
parent 10e5e017c1
commit 068d90bbea

View File

@ -163,6 +163,7 @@ class casadm:
class cas_config(object): class cas_config(object):
default_location = '/etc/opencas/opencas.conf' default_location = '/etc/opencas/opencas.conf'
_by_id_dir = '/dev/disk/by-id'
class ConflictingConfigException(ValueError): class ConflictingConfigException(ValueError):
pass pass
@ -172,17 +173,16 @@ class cas_config(object):
@staticmethod @staticmethod
def get_by_id_path(path): def get_by_id_path(path):
blocklist = ["lvm", "md-name"] path = os.path.abspath(path)
for id_path in os.listdir('/dev/disk/by-id'): if os.path.exists(path) or cas_config._is_exp_obj_path(path):
if any([id_path.startswith(x) for x in blocklist]): return path
continue else:
raise ValueError(f"Given path {path} isn't correct by-id path.")
full_path = '/dev/disk/by-id/{0}'.format(id_path) @staticmethod
if os.path.realpath(full_path) == os.path.realpath(path): def _is_exp_obj_path(path):
return full_path return re.search(r"cas\d+-\d+", path) is not None
raise ValueError('By-id device link not found for {0}'.format(path))
@staticmethod @staticmethod
def check_block_device(path): def check_block_device(path):