xref: /unit/test/test_java_isolation_rootfs.py (revision 1971:3410f9d2a662)
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            return
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            process = subprocess.Popen(
22                [
23                    "mount",
24                    "--bind",
25                    option.current_dir + "/build",
26                    option.temp_dir + "/jars",
27                ],
28                stderr=subprocess.STDOUT,
29            )
30
31            process.communicate()
32
33        except KeyboardInterrupt:
34            raise
35
36        except:
37            pytest.fail('Can\'t run mount process.')
38
39    def teardown_method(self, is_su):
40        if not is_su:
41            return
42
43        try:
44            process = subprocess.Popen(
45                ["umount", "--lazy", option.temp_dir + "/jars"],
46                stderr=subprocess.STDOUT,
47            )
48
49            process.communicate()
50
51        except KeyboardInterrupt:
52            raise
53
54        except:
55            pytest.fail('Can\'t run mount process.')
56
57    def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir):
58        if not is_su:
59            pytest.skip('require root')
60
61        isolation = {
62            'rootfs': temp_dir,
63        }
64
65        self.load('empty_war', isolation=isolation)
66
67        assert 'success' in self.conf(
68            '"/"', '/config/applications/empty_war/working_directory',
69        )
70
71        assert 'success' in self.conf(
72            '"/jars"', 'applications/empty_war/unit_jars'
73        )
74        assert 'success' in self.conf(
75            '"/java/empty.war"', 'applications/empty_war/webapp'
76        )
77
78        assert self.get()['status'] == 200, 'war'
79