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