diff options
Diffstat (limited to 'test/test_java_isolation_rootfs.py')
-rw-r--r-- | test/test_java_isolation_rootfs.py | 99 |
1 files changed, 45 insertions, 54 deletions
diff --git a/test/test_java_isolation_rootfs.py b/test/test_java_isolation_rootfs.py index 28668997..66b2a81e 100644 --- a/test/test_java_isolation_rootfs.py +++ b/test/test_java_isolation_rootfs.py @@ -2,74 +2,65 @@ import os import subprocess import pytest -from unit.applications.lang.java import TestApplicationJava +from unit.applications.lang.java import ApplicationJava from unit.option import option +prerequisites = {'modules': {'java': 'all'}, 'privileged_user': True} -class TestJavaIsolationRootfs(TestApplicationJava): - prerequisites = {'modules': {'java': 'all'}} +client = ApplicationJava() - def setup_method(self, is_su): - if not is_su: - pytest.skip('require root') - os.makedirs(f'{option.temp_dir}/jars') - os.makedirs(f'{option.temp_dir}/tmp') - os.chmod(f'{option.temp_dir}/tmp', 0o777) +@pytest.fixture(autouse=True) +def setup_method_fixture(temp_dir): + os.makedirs(f'{temp_dir}/jars') + os.makedirs(f'{temp_dir}/tmp') + os.chmod(f'{temp_dir}/tmp', 0o777) - try: - subprocess.run( - [ - "mount", - "--bind", - f'{option.current_dir}/build', - f'{option.temp_dir}/jars', - ], - stderr=subprocess.STDOUT, - ) - - except KeyboardInterrupt: - raise + try: + subprocess.run( + [ + "mount", + "--bind", + f'{option.current_dir}/build', + f'{temp_dir}/jars', + ], + stderr=subprocess.STDOUT, + ) - except subprocess.CalledProcessError: - pytest.fail("Can't run mount process.") + except KeyboardInterrupt: + raise - def teardown_method(self, is_su): - if not is_su: - return + except subprocess.CalledProcessError: + pytest.fail("Can't run mount process.") - try: - subprocess.run( - ["umount", "--lazy", f"{option.temp_dir}/jars"], - stderr=subprocess.STDOUT, - ) + yield - except KeyboardInterrupt: - raise + try: + subprocess.run( + ["umount", "--lazy", f"{option.temp_dir}/jars"], + stderr=subprocess.STDOUT, + ) - except subprocess.CalledProcessError: - pytest.fail("Can't run umount process.") + except KeyboardInterrupt: + raise - def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir): - if not is_su: - pytest.skip('require root') + except subprocess.CalledProcessError: + pytest.fail("Can't run umount process.") - isolation = { - 'rootfs': temp_dir, - } - self.load('empty_war', isolation=isolation) +def test_java_isolation_rootfs_chroot_war(temp_dir): + client.load('empty_war', isolation={'rootfs': temp_dir}) - assert 'success' in self.conf( - '"/"', - '/config/applications/empty_war/working_directory', - ) + assert 'success' in client.conf( + '"/"', + '/config/applications/empty_war/working_directory', + ) - assert 'success' in self.conf( - '"/jars"', 'applications/empty_war/unit_jars' - ) - assert 'success' in self.conf( - '"/java/empty.war"', 'applications/empty_war/webapp' - ) + assert 'success' in client.conf( + '"/jars"', 'applications/empty_war/unit_jars' + ) + assert 'success' in client.conf( + '"/java/empty.war"', 'applications/empty_war/webapp' + ) - assert self.get()['status'] == 200, 'war' + assert client.get()['status'] == 200, 'war' |