1
1import pytest
2
3from unit.applications.lang.python import TestApplicationPython
4from unit.option import option
5from unit.utils import findmnt
6from unit.utils import waitformount
7from unit.utils import waitforunmount
8
9
10class TestPythonIsolation(TestApplicationPython):

--- 16 unchanged lines hidden (view full) ---

27 pytest.skip('pid namespace is not supported')
28
29 isolation = {'rootfs': temp_dir}
30
31 if not is_su:
32 isolation['namespaces'] = {
33 'mount': True,
34 'credential': True,
35 'pid': True
35 'pid': True,
36 }
37
38 self.load('ns_inspect', isolation=isolation)
39
40 assert (
41 self.getjson(url='/?path=' + temp_dir)['body']['FileExists']
42 == False
43 ), 'temp_dir does not exists in rootfs'
44
45 assert (
46 self.getjson(url='/?path=/proc/self')['body']['FileExists']
47 == True
46 self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True
47 ), 'no /proc/self'
48
49 assert (
50 self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False
51 ), 'no /dev/pts'
52
53 assert (
54 self.getjson(url='/?path=/sys/kernel')['body']['FileExists']

--- 5 unchanged lines hidden (view full) ---

60 assert (
61 ret['body']['FileExists'] == True
62 ), 'application exists in rootfs'
63
64 def test_python_isolation_rootfs_no_language_deps(self, is_su, temp_dir):
65 if not is_su:
66 pytest.skip('requires root')
67
69 isolation = {
70 'rootfs': temp_dir,
71 'automount': {'language_deps': False}
72 }
68 isolation = {'rootfs': temp_dir, 'automount': {'language_deps': False}}
69
70 self.load('empty', isolation=isolation)
71
72 assert findmnt().find(temp_dir) == -1
77 assert (self.get()['status'] != 200), 'disabled language_deps'
73 assert self.get()['status'] != 200, 'disabled language_deps'
74 assert findmnt().find(temp_dir) == -1
75
76 isolation['automount']['language_deps'] = True
77
78 self.load('empty', isolation=isolation)
79
80 assert findmnt().find(temp_dir) == -1
85 assert (self.get()['status'] == 200), 'enabled language_deps'
81 assert self.get()['status'] == 200, 'enabled language_deps'
82 assert waitformount(temp_dir), 'language_deps mount'
83
84 self.conf({"listeners": {}, "applications": {}})
85
86 assert waitforunmount(temp_dir), 'language_deps unmount'
87
88 def test_python_isolation_procfs(self, is_su, temp_dir):
93 isolation_features = option.available['features']['isolation'].keys()
94
89 if not is_su:
90 pytest.skip('requires root')
91
92 isolation = {'rootfs': temp_dir, 'automount': {'procfs': False}}
93
94 self.load('ns_inspect', isolation=isolation)
95
96 assert (
97 self.getjson(url='/?path=/proc/self')['body']['FileExists']
98 == False
99 ), 'no /proc/self'
100
101 isolation['automount']['procfs'] = True
102
103 self.load('ns_inspect', isolation=isolation)
104
105 assert (
106 self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True
107 ), '/proc/self'