test_python_isolation_chroot.py (1490:cecf6b11a1e3) test_python_isolation_chroot.py (1596:b7e2d4d92624)
1import unittest
1import pytest
2
3from unit.applications.lang.python import TestApplicationPython
4from unit.feature.isolation import TestFeatureIsolation
5
6
7class TestPythonIsolation(TestApplicationPython):
8 prerequisites = {'modules': {'python': 'any'}}
9
2
3from unit.applications.lang.python import TestApplicationPython
4from unit.feature.isolation import TestFeatureIsolation
5
6
7class TestPythonIsolation(TestApplicationPython):
8 prerequisites = {'modules': {'python': 'any'}}
9
10 def test_python_isolation_chroot(self):
11 if not self.is_su:
12 print('requires root')
13 raise unittest.SkipTest()
10 def test_python_isolation_chroot(self, is_su):
11 if not is_su:
12 pytest.skip('requires root')
14
15 isolation = {
13
14 isolation = {
16 'rootfs': self.testdir,
15 'rootfs': self.temp_dir,
17 }
18
19 self.load('empty', isolation=isolation)
20
16 }
17
18 self.load('empty', isolation=isolation)
19
21 self.assertEqual(self.get()['status'], 200, 'python chroot')
20 assert self.get()['status'] == 200, 'python chroot'
22
23 self.load('ns_inspect', isolation=isolation)
24
21
22 self.load('ns_inspect', isolation=isolation)
23
25 self.assertEqual(
26 self.getjson(url='/?path=' + self.testdir)['body']['FileExists'],
27 False,
28 'testdir does not exists in rootfs',
29 )
24 assert (
25 self.getjson(url='/?path=' + self.temp_dir)['body']['FileExists']
26 == False
27 ), 'temp_dir does not exists in rootfs'
30
28
31 self.assertEqual(
32 self.getjson(url='/?path=/proc/self')['body']['FileExists'],
33 False,
34 'no /proc/self',
35 )
29 assert (
30 self.getjson(url='/?path=/proc/self')['body']['FileExists']
31 == False
32 ), 'no /proc/self'
36
33
37 self.assertEqual(
38 self.getjson(url='/?path=/dev/pts')['body']['FileExists'],
39 False,
40 'no /dev/pts',
41 )
34 assert (
35 self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False
36 ), 'no /dev/pts'
42
37
43 self.assertEqual(
44 self.getjson(url='/?path=/sys/kernel')['body']['FileExists'],
45 False,
46 'no /sys/kernel',
47 )
38 assert (
39 self.getjson(url='/?path=/sys/kernel')['body']['FileExists']
40 == False
41 ), 'no /sys/kernel'
48
49 ret = self.getjson(url='/?path=/app/python/ns_inspect')
50
42
43 ret = self.getjson(url='/?path=/app/python/ns_inspect')
44
51 self.assertEqual(
52 ret['body']['FileExists'], True, 'application exists in rootfs',
53 )
54
55
56if __name__ == '__main__':
57 TestPythonIsolation.main()
45 assert (
46 ret['body']['FileExists'] == True
47 ), 'application exists in rootfs'