xref: /unit/test/test_java_isolation_rootfs.py (revision 2073:bc6ad31ce286)
11490St.nateldemoura@f5.comimport os
21490St.nateldemoura@f5.comimport subprocess
31635Szelenkov@nginx.com
41596Szelenkov@nginx.comimport pytest
51490St.nateldemoura@f5.comfrom unit.applications.lang.java import TestApplicationJava
61730Szelenkov@nginx.comfrom unit.option import option
71490St.nateldemoura@f5.com
81490St.nateldemoura@f5.com
91490St.nateldemoura@f5.comclass TestJavaIsolationRootfs(TestApplicationJava):
101490St.nateldemoura@f5.com    prerequisites = {'modules': {'java': 'all'}}
111490St.nateldemoura@f5.com
121596Szelenkov@nginx.com    def setup_method(self, is_su):
131596Szelenkov@nginx.com        if not is_su:
14*2073Szelenkov@nginx.com            pytest.skip('require root')
151490St.nateldemoura@f5.com
161654Szelenkov@nginx.com        os.makedirs(option.temp_dir + '/jars')
171654Szelenkov@nginx.com        os.makedirs(option.temp_dir + '/tmp')
181654Szelenkov@nginx.com        os.chmod(option.temp_dir + '/tmp', 0o777)
191490St.nateldemoura@f5.com
201490St.nateldemoura@f5.com        try:
212004Szelenkov@nginx.com            subprocess.run(
221490St.nateldemoura@f5.com                [
231490St.nateldemoura@f5.com                    "mount",
241490St.nateldemoura@f5.com                    "--bind",
251621Szelenkov@nginx.com                    option.current_dir + "/build",
261654Szelenkov@nginx.com                    option.temp_dir + "/jars",
271490St.nateldemoura@f5.com                ],
281490St.nateldemoura@f5.com                stderr=subprocess.STDOUT,
291490St.nateldemoura@f5.com            )
301490St.nateldemoura@f5.com
311706Smax.romanov@nginx.com        except KeyboardInterrupt:
321706Smax.romanov@nginx.com            raise
331706Smax.romanov@nginx.com
342004Szelenkov@nginx.com        except subprocess.CalledProcessError:
351706Smax.romanov@nginx.com            pytest.fail('Can\'t run mount process.')
361490St.nateldemoura@f5.com
371596Szelenkov@nginx.com    def teardown_method(self, is_su):
381596Szelenkov@nginx.com        if not is_su:
391490St.nateldemoura@f5.com            return
401490St.nateldemoura@f5.com
411490St.nateldemoura@f5.com        try:
422004Szelenkov@nginx.com            subprocess.run(
431654Szelenkov@nginx.com                ["umount", "--lazy", option.temp_dir + "/jars"],
441490St.nateldemoura@f5.com                stderr=subprocess.STDOUT,
451490St.nateldemoura@f5.com            )
461490St.nateldemoura@f5.com
471706Smax.romanov@nginx.com        except KeyboardInterrupt:
481706Smax.romanov@nginx.com            raise
491706Smax.romanov@nginx.com
502004Szelenkov@nginx.com        except subprocess.CalledProcessError:
512004Szelenkov@nginx.com            pytest.fail('Can\'t run umount process.')
521490St.nateldemoura@f5.com
531654Szelenkov@nginx.com    def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir):
541596Szelenkov@nginx.com        if not is_su:
551596Szelenkov@nginx.com            pytest.skip('require root')
561490St.nateldemoura@f5.com
571490St.nateldemoura@f5.com        isolation = {
581654Szelenkov@nginx.com            'rootfs': temp_dir,
591490St.nateldemoura@f5.com        }
601490St.nateldemoura@f5.com
611490St.nateldemoura@f5.com        self.load('empty_war', isolation=isolation)
621490St.nateldemoura@f5.com
631596Szelenkov@nginx.com        assert 'success' in self.conf(
64*2073Szelenkov@nginx.com            '"/"',
65*2073Szelenkov@nginx.com            '/config/applications/empty_war/working_directory',
661490St.nateldemoura@f5.com        )
671490St.nateldemoura@f5.com
681596Szelenkov@nginx.com        assert 'success' in self.conf(
691596Szelenkov@nginx.com            '"/jars"', 'applications/empty_war/unit_jars'
701490St.nateldemoura@f5.com        )
711596Szelenkov@nginx.com        assert 'success' in self.conf(
721596Szelenkov@nginx.com            '"/java/empty.war"', 'applications/empty_war/webapp'
731490St.nateldemoura@f5.com        )
741490St.nateldemoura@f5.com
751596Szelenkov@nginx.com        assert self.get()['status'] == 200, 'war'
76