Tests: prerequisites checking reworked.
Prerequisites check moved to the module level to simplify class structure. Discovery and prerequisites checks functions moved to the separate files. Introduced "require" fixture to provide per-test requirements check.
This commit is contained in:
@@ -10,10 +10,10 @@ from unit.utils import findmnt
|
||||
from unit.utils import waitformount
|
||||
from unit.utils import waitforunmount
|
||||
|
||||
prerequisites = {'modules': {'python': 'any'}, 'features': {'isolation': True}}
|
||||
|
||||
|
||||
class TestPythonIsolation(TestApplicationPython):
|
||||
prerequisites = {'modules': {'python': 'any'}, 'features': ['isolation']}
|
||||
|
||||
def get_cgroup(self, app_name):
|
||||
output = subprocess.check_output(
|
||||
['ps', 'ax', '-o', 'pid', '-o', 'cmd']
|
||||
@@ -31,25 +31,23 @@ class TestPythonIsolation(TestApplicationPython):
|
||||
with open(cgroup, 'r') as f:
|
||||
return f.read().rstrip()
|
||||
|
||||
def test_python_isolation_rootfs(self, is_su, temp_dir):
|
||||
isolation_features = option.available['features']['isolation'].keys()
|
||||
|
||||
if not is_su:
|
||||
if not 'unprivileged_userns_clone' in isolation_features:
|
||||
pytest.skip('requires unprivileged userns or root')
|
||||
|
||||
if 'user' not in isolation_features:
|
||||
pytest.skip('user namespace is not supported')
|
||||
|
||||
if 'mnt' not in isolation_features:
|
||||
pytest.skip('mnt namespace is not supported')
|
||||
|
||||
if 'pid' not in isolation_features:
|
||||
pytest.skip('pid namespace is not supported')
|
||||
|
||||
def test_python_isolation_rootfs(self, is_su, require, temp_dir):
|
||||
isolation = {'rootfs': temp_dir}
|
||||
|
||||
if not is_su:
|
||||
require(
|
||||
{
|
||||
'features': {
|
||||
'isolation': [
|
||||
'unprivileged_userns_clone',
|
||||
'user',
|
||||
'mnt',
|
||||
'pid',
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
isolation['namespaces'] = {
|
||||
'mount': True,
|
||||
'credential': True,
|
||||
@@ -78,9 +76,8 @@ class TestPythonIsolation(TestApplicationPython):
|
||||
|
||||
assert ret['body']['FileExists'], 'application exists in rootfs'
|
||||
|
||||
def test_python_isolation_rootfs_no_language_deps(self, is_su, temp_dir):
|
||||
if not is_su:
|
||||
pytest.skip('requires root')
|
||||
def test_python_isolation_rootfs_no_language_deps(self, require, temp_dir):
|
||||
require({'privileged_user': True})
|
||||
|
||||
isolation = {'rootfs': temp_dir, 'automount': {'language_deps': False}}
|
||||
self.load('empty', isolation=isolation)
|
||||
@@ -103,9 +100,8 @@ class TestPythonIsolation(TestApplicationPython):
|
||||
|
||||
assert waitforunmount(python_path), 'language_deps unmount'
|
||||
|
||||
def test_python_isolation_procfs(self, is_su, temp_dir):
|
||||
if not is_su:
|
||||
pytest.skip('requires root')
|
||||
def test_python_isolation_procfs(self, require, temp_dir):
|
||||
require({'privileged_user': True})
|
||||
|
||||
isolation = {'rootfs': temp_dir, 'automount': {'procfs': False}}
|
||||
|
||||
@@ -123,12 +119,10 @@ class TestPythonIsolation(TestApplicationPython):
|
||||
'FileExists'
|
||||
], '/proc/self'
|
||||
|
||||
def test_python_isolation_cgroup(self, is_su):
|
||||
if not is_su:
|
||||
pytest.skip('requires root')
|
||||
|
||||
if not 'cgroup' in option.available['features']['isolation']:
|
||||
pytest.skip('cgroup is not supported')
|
||||
def test_python_isolation_cgroup(self, require):
|
||||
require(
|
||||
{'privileged_user': True, 'features': {'isolation': ['cgroup']}}
|
||||
)
|
||||
|
||||
def set_cgroup_path(path):
|
||||
isolation = {'cgroup': {'path': path}}
|
||||
@@ -146,12 +140,10 @@ class TestPythonIsolation(TestApplicationPython):
|
||||
|
||||
assert len(cgroup_rel.parts) >= len(cgroup_abs.parts)
|
||||
|
||||
def test_python_isolation_cgroup_two(self, is_su):
|
||||
if not is_su:
|
||||
pytest.skip('requires root')
|
||||
|
||||
if not 'cgroup' in option.available['features']['isolation']:
|
||||
pytest.skip('cgroup is not supported')
|
||||
def test_python_isolation_cgroup_two(self, require):
|
||||
require(
|
||||
{'privileged_user': True, 'features': {'isolation': ['cgroup']}}
|
||||
)
|
||||
|
||||
def set_two_cgroup_path(path, path2):
|
||||
script_path = f'{option.test_dir}/python/empty'
|
||||
@@ -193,12 +185,10 @@ class TestPythonIsolation(TestApplicationPython):
|
||||
set_two_cgroup_path('/scope/python', '/scope2/python')
|
||||
assert self.get_cgroup('one') != self.get_cgroup('two')
|
||||
|
||||
def test_python_isolation_cgroup_invalid(self, is_su):
|
||||
if not is_su:
|
||||
pytest.skip('requires root')
|
||||
|
||||
if not 'cgroup' in option.available['features']['isolation']:
|
||||
pytest.skip('cgroup is not supported')
|
||||
def test_python_isolation_cgroup_invalid(self, require):
|
||||
require(
|
||||
{'privileged_user': True, 'features': {'isolation': ['cgroup']}}
|
||||
)
|
||||
|
||||
def check_invalid(path):
|
||||
script_path = f'{option.test_dir}/python/empty'
|
||||
|
||||
Reference in New Issue
Block a user