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