xref: /unit/test/test_java_isolation_rootfs.py (revision 2073:bc6ad31ce286)
1import os
2import subprocess
3
4import pytest
5from unit.applications.lang.java import TestApplicationJava
6from unit.option import option
7
8
9class TestJavaIsolationRootfs(TestApplicationJava):
10    prerequisites = {'modules': {'java': 'all'}}
11
12    def setup_method(self, is_su):
13        if not is_su:
14            pytest.skip('require root')
15
16        os.makedirs(option.temp_dir + '/jars')
17        os.makedirs(option.temp_dir + '/tmp')
18        os.chmod(option.temp_dir + '/tmp', 0o777)
19
20        try:
21            subprocess.run(
22                [
23                    "mount",
24                    "--bind",
25                    option.current_dir + "/build",
26                    option.temp_dir + "/jars",
27                ],
28                stderr=subprocess.STDOUT,
29            )
30
31        except KeyboardInterrupt:
32            raise
33
34        except subprocess.CalledProcessError:
35            pytest.fail('Can\'t run mount process.')
36
37    def teardown_method(self, is_su):
38        if not is_su:
39            return
40
41        try:
42            subprocess.run(
43                ["umount", "--lazy", option.temp_dir + "/jars"],
44                stderr=subprocess.STDOUT,
45            )
46
47        except KeyboardInterrupt:
48            raise
49
50        except subprocess.CalledProcessError:
51            pytest.fail('Can\'t run umount process.')
52
53    def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir):
54        if not is_su:
55            pytest.skip('require root')
56
57        isolation = {
58            'rootfs': temp_dir,
59        }
60
61        self.load('empty_war', isolation=isolation)
62
63        assert 'success' in self.conf(
64            '"/"',
65            '/config/applications/empty_war/working_directory',
66        )
67
68        assert 'success' in self.conf(
69            '"/jars"', 'applications/empty_war/unit_jars'
70        )
71        assert 'success' in self.conf(
72            '"/java/empty.war"', 'applications/empty_war/webapp'
73        )
74
75        assert self.get()['status'] == 200, 'war'
76