test_python_isolation.py (1774:8a90da5c0e24) test_python_isolation.py (1848:4bd548074e2c)
1
2import pytest
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,
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 (
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
48 ), 'no /proc/self'
49
50 assert (
51 self.getjson(url='/?path=/dev/pts')['body']['FileExists'] == False
52 ), 'no /dev/pts'
53
54 assert (
55 self.getjson(url='/?path=/sys/kernel')['body']['FileExists']

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

61 assert (
62 ret['body']['FileExists'] == True
63 ), 'application exists in rootfs'
64
65 def test_python_isolation_rootfs_no_language_deps(self, is_su, temp_dir):
66 if not is_su:
67 pytest.skip('requires root')
68
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}}
73
74 self.load('empty', isolation=isolation)
75
76 assert findmnt().find(temp_dir) == -1
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'
78 assert findmnt().find(temp_dir) == -1
79
80 isolation['automount']['language_deps'] = True
81
82 self.load('empty', isolation=isolation)
83
84 assert findmnt().find(temp_dir) == -1
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'
86 assert waitformount(temp_dir), 'language_deps mount'
87
88 self.conf({"listeners": {}, "applications": {}})
89
90 assert waitforunmount(temp_dir), 'language_deps unmount'
91
92 def test_python_isolation_procfs(self, is_su, temp_dir):
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
95 if not is_su:
96 pytest.skip('requires root')
97
98 isolation = {'rootfs': temp_dir, 'automount': {'procfs': False}}
99
100 self.load('ns_inspect', isolation=isolation)
101
102 assert (
103 self.getjson(url='/?path=/proc/self')['body']['FileExists']
104 == False
105 ), 'no /proc/self'
106
107 isolation['automount']['procfs'] = True
108
109 self.load('ns_inspect', isolation=isolation)
110
111 assert (
112 self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True
113 ), '/proc/self'
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'