test_ruby_isolation.py (1490:cecf6b11a1e3) test_ruby_isolation.py (1596:b7e2d4d92624)
1import os
1import os
2import pytest
2import shutil
3import shutil
3import unittest
4
5from unit.applications.lang.ruby import TestApplicationRuby
6from unit.feature.isolation import TestFeatureIsolation
4
5from unit.applications.lang.ruby import TestApplicationRuby
6from unit.feature.isolation import TestFeatureIsolation
7from conftest import option
7
8
9class TestRubyIsolation(TestApplicationRuby):
10 prerequisites = {'modules': {'ruby': 'any'}, 'features': ['isolation']}
11
12 isolation = TestFeatureIsolation()
13
14 @classmethod
8
9
10class TestRubyIsolation(TestApplicationRuby):
11 prerequisites = {'modules': {'ruby': 'any'}, 'features': ['isolation']}
12
13 isolation = TestFeatureIsolation()
14
15 @classmethod
15 def setUpClass(cls, complete_check=True):
16 unit = super().setUpClass(complete_check=False)
16 def setup_class(cls, complete_check=True):
17 unit = super().setup_class(complete_check=False)
17
18
18 TestFeatureIsolation().check(cls.available, unit.testdir)
19 TestFeatureIsolation().check(cls.available, unit.temp_dir)
19
20 return unit if not complete_check else unit.complete()
21
20
21 return unit if not complete_check else unit.complete()
22
22 def test_ruby_isolation_rootfs(self):
23 def test_ruby_isolation_rootfs(self, is_su):
23 isolation_features = self.available['features']['isolation'].keys()
24
25 if 'mnt' not in isolation_features:
24 isolation_features = self.available['features']['isolation'].keys()
25
26 if 'mnt' not in isolation_features:
26 print('requires mnt ns')
27 raise unittest.SkipTest()
27 pytest.skip('requires mnt ns')
28
28
29 if not self.is_su:
29 if not is_su:
30 if 'user' not in isolation_features:
30 if 'user' not in isolation_features:
31 print('requires unprivileged userns or root')
32 raise unittest.SkipTest()
31 pytest.skip('requires unprivileged userns or root')
33
34 if not 'unprivileged_userns_clone' in isolation_features:
32
33 if not 'unprivileged_userns_clone' in isolation_features:
35 print('requires unprivileged userns or root')
36 raise unittest.SkipTest()
34 pytest.skip('requires unprivileged userns or root')
37
35
38 os.mkdir(self.testdir + '/ruby')
36 os.mkdir(self.temp_dir + '/ruby')
39
40 shutil.copytree(
37
38 shutil.copytree(
41 self.current_dir + '/ruby/status_int',
42 self.testdir + '/ruby/status_int',
39 option.test_dir + '/ruby/status_int',
40 self.temp_dir + '/ruby/status_int',
43 )
44 isolation = {
41 )
42 isolation = {
45 'namespaces': {'credential': not self.is_su, 'mount': True},
46 'rootfs': self.testdir,
43 'namespaces': {'credential': not is_su, 'mount': True},
44 'rootfs': self.temp_dir,
47 }
48
49 self.load('status_int', isolation=isolation)
50
45 }
46
47 self.load('status_int', isolation=isolation)
48
51 self.assertIn(
52 'success',
53 self.conf(
54 '"/ruby/status_int/config.ru"',
55 'applications/status_int/script',
56 ),
49 assert 'success' in self.conf(
50 '"/ruby/status_int/config.ru"', 'applications/status_int/script',
57 )
58
51 )
52
59 self.assertIn(
60 'success',
61 self.conf(
62 '"/ruby/status_int"',
63 'applications/status_int/working_directory',
64 ),
53 assert 'success' in self.conf(
54 '"/ruby/status_int"', 'applications/status_int/working_directory',
65 )
66
55 )
56
67 self.assertEqual(self.get()['status'], 200, 'status int')
68
69
70if __name__ == '__main__':
71 TestRubyIsolation.main()
57 assert self.get()['status'] == 200, 'status int'