Commit 6cf5c4d9 authored by Thomas Gambier's avatar Thomas Gambier

manager: fix links handling in devperm

Fixup of 89863d6c

For links like this:

$ ls -l /dev/disk/by-path/pci-0000:42:00.0-nvme-1
lrwxrwxrwx 1 root root 13 Oct 25 15:19 /dev/disk/by-path/pci-0000:42:00.0-nvme-1 -> ../../nvme7n1

os.readlink() returns "../../nvme7n1" while we want "/dev/nvme7n1".
parent 17f4ffcd
...@@ -122,8 +122,7 @@ class Manager(object): ...@@ -122,8 +122,7 @@ class Manager(object):
disk = str(disk) disk = str(disk)
original = disk original = disk
try: try:
while os.path.islink(disk): disk = os.path.realpath(disk)
disk = os.readlink(disk)
except OSError: except OSError:
logger.warning("Problem resolving link: %s " % original, exc_info=True) logger.warning("Problem resolving link: %s " % original, exc_info=True)
continue continue
......
...@@ -3351,8 +3351,6 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase): ...@@ -3351,8 +3351,6 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase):
patch.object(os.path, 'exists', new=self.os_path_exists), patch.object(os.path, 'exists', new=self.os_path_exists),
patch.object(os, 'stat', new=self.os_stat), patch.object(os, 'stat', new=self.os_stat),
patch.object(os, 'chown', new=self.os_chown), patch.object(os, 'chown', new=self.os_chown),
patch.object(os, 'readlink', new=self.os_readlink),
patch.object(os.path, 'islink', new=self.os_path_islink),
patch.object(slapmanager.devperm.Manager, '_getLsblkJsonDict', new=self._getLsblkJsonDict) patch.object(slapmanager.devperm.Manager, '_getLsblkJsonDict', new=self._getLsblkJsonDict)
] ]
[q.start() for q in self.patcher_list] [q.start() for q in self.patcher_list]
...@@ -3388,20 +3386,6 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase): ...@@ -3388,20 +3386,6 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase):
else: else:
original(path, uid, gid) original(path, uid, gid)
def os_readlink(self, path, original=os.readlink):
if path == 'some_link':
return '/dev/tst'
elif path == 'bad_link':
return '/dev/non'
else:
return original(path)
def os_path_islink(self, path, original=os.path.islink):
if path in ['some_link', 'bad_link']:
return True
else:
return original(path)
def test(self): def test(self):
with self._mock_requests(): with self._mock_requests():
with open(self.disk_device_filename, 'w+') as f: with open(self.disk_device_filename, 'w+') as f:
...@@ -3418,9 +3402,12 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase): ...@@ -3418,9 +3402,12 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase):
) )
def test_link(self): def test_link(self):
temp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, temp_dir)
os.symlink('/dev/tst', os.path.join(temp_dir, 'some_link'))
with self._mock_requests(): with self._mock_requests():
with open(self.disk_device_filename, 'w+') as f: with open(self.disk_device_filename, 'w+') as f:
json.dump([{'disk': 'some_link'}], f) json.dump([{'disk': os.path.join(temp_dir, 'some_link')}], f)
self.partition.requested_state = 'started' self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT) self.partition.software.setBuildout(WRAPPER_CONTENT)
...@@ -3433,9 +3420,12 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase): ...@@ -3433,9 +3420,12 @@ class TestSlapgridWithDevPermLsblk(MasterMixin, unittest.TestCase):
) )
def test_bad_link(self): def test_bad_link(self):
temp_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, temp_dir)
os.symlink('/dev/non', os.path.join(temp_dir, 'bad_link'))
with self._mock_requests(): with self._mock_requests():
with open(self.disk_device_filename, 'w+') as f: with open(self.disk_device_filename, 'w+') as f:
json.dump([{'disk': 'bad_link'}], f) json.dump([{'disk': os.path.join(temp_dir, 'bad_link')}], f)
self.partition.requested_state = 'started' self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT) self.partition.software.setBuildout(WRAPPER_CONTENT)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment