test_python_isolation.py (1771:94cf6c5fafbd) test_python_isolation.py (1773:6c7e716cdec5)
1
2import pytest
3from unit.applications.lang.python import TestApplicationPython
4from unit.option import option
1
2import pytest
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
5
6
7class TestPythonIsolation(TestApplicationPython):
8 prerequisites = {'modules': {'python': 'any'}, 'features': ['isolation']}
9
10 def test_python_isolation_rootfs(self, is_su, temp_dir):
11 isolation_features = option.available['features']['isolation'].keys()
12

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

55
56 ret = self.getjson(url='/?path=/app/python/ns_inspect')
57
58 assert (
59 ret['body']['FileExists'] == True
60 ), 'application exists in rootfs'
61
62 def test_python_isolation_rootfs_no_language_deps(self, is_su, temp_dir):
8
9
10class TestPythonIsolation(TestApplicationPython):
11 prerequisites = {'modules': {'python': 'any'}, 'features': ['isolation']}
12
13 def test_python_isolation_rootfs(self, is_su, temp_dir):
14 isolation_features = option.available['features']['isolation'].keys()
15

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

58
59 ret = self.getjson(url='/?path=/app/python/ns_inspect')
60
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):
63 isolation_features = option.available['features']['isolation'].keys()
64
65 if not is_su:
66 if not is_su:
66 if not 'unprivileged_userns_clone' in isolation_features:
67 pytest.skip('requires unprivileged userns or root')
67 pytest.skip('requires root')
68
68
69 if 'user' not in isolation_features:
70 pytest.skip('user namespace is not supported')
71
72 if 'mnt' not in isolation_features:
73 pytest.skip('mnt namespace is not supported')
74
75 if 'pid' not in isolation_features:
76 pytest.skip('pid namespace is not supported')
77
78 isolation = {
79 'rootfs': temp_dir,
80 'automount': {'language_deps': False}
81 }
82
69 isolation = {
70 'rootfs': temp_dir,
71 'automount': {'language_deps': False}
72 }
73
83 if not is_su:
84 isolation['namespaces'] = {
85 'mount': True,
86 'credential': True,
87 'pid': True
88 }
89
90 self.load('empty', isolation=isolation)
91
74 self.load('empty', isolation=isolation)
75
76 assert findmnt().find(temp_dir) == -1
92 assert (self.get()['status'] != 200), 'disabled language_deps'
77 assert (self.get()['status'] != 200), 'disabled language_deps'
78 assert findmnt().find(temp_dir) == -1
93
94 isolation['automount']['language_deps'] = True
95
96 self.load('empty', isolation=isolation)
97
79
80 isolation['automount']['language_deps'] = True
81
82 self.load('empty', isolation=isolation)
83
84 assert findmnt().find(temp_dir) == -1
98 assert (self.get()['status'] == 200), 'enabled language_deps'
85 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'