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