1import pytest 2from unit.applications.lang.python import TestApplicationPython 3 4 5class TestPythonIsolation(TestApplicationPython): 6 prerequisites = {'modules': {'python': 'any'}} 7 8 def test_python_isolation_chroot(self, is_su, temp_dir): 9 if not is_su: 10 pytest.skip('requires root') 11 12 isolation = { 13 'rootfs': temp_dir, 14 } 15 16 self.load('ns_inspect', isolation=isolation) 17 18 assert ( 19 self.getjson(url=f'/?path={temp_dir}')['body']['FileExists'] 20 == False 21 ), 'temp_dir does not exists in rootfs' 22 23 assert ( 24 self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True 25 ), 'no /proc/self' 26 27 assert ( 28 self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False 29 ), 'no /dev/pts' 30 31 assert ( 32 self.getjson(url='/?path=/sys/kernel')['body']['FileExists'] 33 == False 34 ), 'no /sys/kernel' 35 36 ret = self.getjson(url='/?path=/app/python/ns_inspect') 37 38 assert ret['body']['FileExists'] == True, 'application exists in rootfs' 39