summaryrefslogtreecommitdiffhomepage
path: root/test/test_java_isolation_rootfs.py
blob: bbd2c91507d8b6ab104821d2b3f9cc683b4b167a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import subprocess

import pytest
from unit.applications.lang.java import TestApplicationJava
from unit.option import option

prerequisites = {'modules': {'java': 'all'}, 'privileged_user': True}


class TestJavaIsolationRootfs(TestApplicationJava):
    @pytest.fixture(autouse=True)
    def setup_method_fixture(self, 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'{temp_dir}/jars',
                ],
                stderr=subprocess.STDOUT,
            )

        except KeyboardInterrupt:
            raise

        except subprocess.CalledProcessError:
            pytest.fail("Can't run mount process.")

    def teardown_method(self):
        try:
            subprocess.run(
                ["umount", "--lazy", f"{option.temp_dir}/jars"],
                stderr=subprocess.STDOUT,
            )

        except KeyboardInterrupt:
            raise

        except subprocess.CalledProcessError:
            pytest.fail("Can't run umount process.")

    def test_java_isolation_rootfs_chroot_war(self, temp_dir):
        isolation = {'rootfs': temp_dir}

        self.load('empty_war', isolation=isolation)

        assert 'success' in self.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 self.get()['status'] == 200, 'war'