Commit 89863d6c authored by Łukasz Nowak's avatar Łukasz Nowak

manager: Follow links in devperm

parent 74d4b39e
...@@ -73,6 +73,14 @@ class Manager(object): ...@@ -73,6 +73,14 @@ class Manager(object):
logger.warning("Disk is None: %s " % disk_list, exc_info=True) logger.warning("Disk is None: %s " % disk_list, exc_info=True)
continue continue
original = disk
try:
while os.path.islink(disk):
disk = os.readlink(disk)
except OSError:
logger.warning("Problem resolving link: %s " % original, exc_info=True)
continue
if not str(disk).startswith("/dev/"): if not str(disk).startswith("/dev/"):
logger.warning("Bad disk definition: %s " % disk_list, exc_info=True) logger.warning("Bad disk definition: %s " % disk_list, exc_info=True)
continue continue
......
...@@ -3110,6 +3110,20 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase): ...@@ -3110,6 +3110,20 @@ class TestSlapgridWithDevPerm(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:
...@@ -3134,6 +3148,55 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase): ...@@ -3134,6 +3148,55 @@ class TestSlapgridWithDevPerm(MasterMixin, unittest.TestCase):
] ]
) )
def test_link(self):
with self._mock_requests():
with open(self.disk_device_filename, 'w+') as f:
json.dump([{'disk': 'some_link'}], f)
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
with \
patch.object(os.path, 'exists', new=self.os_path_exists), \
patch.object(os, 'stat', new=self.os_stat), \
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):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
gid = grp.getgrnam("disk").gr_gid
uid = os.stat(os.environ['HOME']).st_uid
self.assertEqual(
self.os_chown_call_list,
[
['/dev/tst', uid, gid],
['/dev/tst', uid, gid],
]
)
def test_bad_link(self):
with self._mock_requests():
with open(self.disk_device_filename, 'w+') as f:
json.dump([{'disk': 'bad_link'}], f)
self.partition.requested_state = 'started'
self.partition.software.setBuildout(WRAPPER_CONTENT)
with \
patch.object(os.path, 'exists', new=self.os_path_exists), \
patch.object(os, 'stat', new=self.os_stat), \
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):
self.assertEqual(self.grid.processComputerPartitionList(), slapgrid.SLAPGRID_SUCCESS)
gid = grp.getgrnam("disk").gr_gid
uid = os.stat(os.environ['HOME']).st_uid
self.assertEqual(
self.os_chown_call_list,
[]
)
def test_long(self): def test_long(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:
......
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