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' 80