From 07789a23e9c513dba87b020fae2989a57955e8a6 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Sun, 6 Dec 2020 16:01:59 +0000 Subject: Tests: options moved to the separate class. This change is necessary to separate the logic and prevent possible circular dependency. --- test/test_python_isolation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_python_isolation.py') diff --git a/test/test_python_isolation.py b/test/test_python_isolation.py index 1a157528..66ff2f16 100644 --- a/test/test_python_isolation.py +++ b/test/test_python_isolation.py @@ -2,11 +2,11 @@ import shutil import pytest -from conftest import option from conftest import unit_run from conftest import unit_stop from unit.applications.lang.python import TestApplicationPython from unit.feature.isolation import TestFeatureIsolation +from unit.option import option class TestPythonIsolation(TestApplicationPython): -- cgit From 4c846ae69308983050a55f6467c2d53e78120e0b Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 9 Dec 2020 16:15:50 +0000 Subject: Tests: isolation check moved to the pytest_sessionstart(). This change eliminates the need for some classes to run Unit one more time before running tests. --- test/test_python_isolation.py | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'test/test_python_isolation.py') diff --git a/test/test_python_isolation.py b/test/test_python_isolation.py index 66ff2f16..ad830269 100644 --- a/test/test_python_isolation.py +++ b/test/test_python_isolation.py @@ -2,30 +2,13 @@ import shutil import pytest -from conftest import unit_run -from conftest import unit_stop from unit.applications.lang.python import TestApplicationPython -from unit.feature.isolation import TestFeatureIsolation from unit.option import option class TestPythonIsolation(TestApplicationPython): prerequisites = {'modules': {'python': 'any'}, 'features': ['isolation']} - @classmethod - def setup_class(cls, complete_check=True): - check = super().setup_class(complete_check=False) - - unit = unit_run() - option.temp_dir = unit['temp_dir'] - - TestFeatureIsolation().check(option.available, unit['temp_dir']) - - assert unit_stop() is None - shutil.rmtree(unit['temp_dir']) - - return check if not complete_check else check() - def test_python_isolation_rootfs(self, is_su, temp_dir): isolation_features = option.available['features']['isolation'].keys() -- cgit From 6dc9c47ccd26b23b61b7522803a667c2e515e260 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 13 Jan 2021 06:22:43 +0000 Subject: Tests: style. --- test/test_python_isolation.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/test_python_isolation.py') diff --git a/test/test_python_isolation.py b/test/test_python_isolation.py index ad830269..aa96af51 100644 --- a/test/test_python_isolation.py +++ b/test/test_python_isolation.py @@ -1,7 +1,5 @@ -import shutil import pytest - from unit.applications.lang.python import TestApplicationPython from unit.option import option -- cgit From 22dac5bd62d19c0f8743b63ec8c47b3b071eb000 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 13 Jan 2021 06:24:32 +0000 Subject: Tests: "language_deps" option checked more carefully. --- test/test_python_isolation.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'test/test_python_isolation.py') diff --git a/test/test_python_isolation.py b/test/test_python_isolation.py index aa96af51..e1a42c98 100644 --- a/test/test_python_isolation.py +++ b/test/test_python_isolation.py @@ -2,6 +2,9 @@ import pytest from unit.applications.lang.python import TestApplicationPython from unit.option import option +from unit.utils import findmnt +from unit.utils import waitformount +from unit.utils import waitforunmount class TestPythonIsolation(TestApplicationPython): @@ -60,39 +63,28 @@ class TestPythonIsolation(TestApplicationPython): ), 'application exists in rootfs' def test_python_isolation_rootfs_no_language_deps(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') + pytest.skip('requires root') isolation = { 'rootfs': temp_dir, 'automount': {'language_deps': False} } - if not is_su: - isolation['namespaces'] = { - 'mount': True, - 'credential': True, - 'pid': True - } - self.load('empty', isolation=isolation) + assert findmnt().find(temp_dir) == -1 assert (self.get()['status'] != 200), 'disabled language_deps' + assert findmnt().find(temp_dir) == -1 isolation['automount']['language_deps'] = True self.load('empty', isolation=isolation) + assert findmnt().find(temp_dir) == -1 assert (self.get()['status'] == 200), 'enabled language_deps' + assert waitformount(temp_dir), 'language_deps mount' + + self.conf({"listeners": {}, "applications": {}}) + + assert waitforunmount(temp_dir), 'language_deps unmount' -- cgit From 5d983ea762eba5fe26a07defbc09eeec8ecc5aeb Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 13 Jan 2021 06:24:41 +0000 Subject: Tests: added test for "procfs" option. --- test/test_python_isolation.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/test_python_isolation.py') diff --git a/test/test_python_isolation.py b/test/test_python_isolation.py index e1a42c98..680f2c03 100644 --- a/test/test_python_isolation.py +++ b/test/test_python_isolation.py @@ -88,3 +88,26 @@ class TestPythonIsolation(TestApplicationPython): self.conf({"listeners": {}, "applications": {}}) assert waitforunmount(temp_dir), 'language_deps unmount' + + def test_python_isolation_procfs(self, is_su, temp_dir): + isolation_features = option.available['features']['isolation'].keys() + + if not is_su: + pytest.skip('requires root') + + isolation = {'rootfs': temp_dir, 'automount': {'procfs': False}} + + self.load('ns_inspect', isolation=isolation) + + assert ( + self.getjson(url='/?path=/proc/self')['body']['FileExists'] + == False + ), 'no /proc/self' + + isolation['automount']['procfs'] = True + + self.load('ns_inspect', isolation=isolation) + + assert ( + self.getjson(url='/?path=/proc/self')['body']['FileExists'] == True + ), '/proc/self' -- cgit