Tests: refactored working with processes.
This commit is contained in:
@@ -18,7 +18,7 @@ class TestJavaIsolationRootfs(TestApplicationJava):
|
|||||||
os.chmod(option.temp_dir + '/tmp', 0o777)
|
os.chmod(option.temp_dir + '/tmp', 0o777)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
"mount",
|
"mount",
|
||||||
"--bind",
|
"--bind",
|
||||||
@@ -28,12 +28,10 @@ class TestJavaIsolationRootfs(TestApplicationJava):
|
|||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
pytest.fail('Can\'t run mount process.')
|
pytest.fail('Can\'t run mount process.')
|
||||||
|
|
||||||
def teardown_method(self, is_su):
|
def teardown_method(self, is_su):
|
||||||
@@ -41,18 +39,16 @@ class TestJavaIsolationRootfs(TestApplicationJava):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(
|
subprocess.run(
|
||||||
["umount", "--lazy", option.temp_dir + "/jars"],
|
["umount", "--lazy", option.temp_dir + "/jars"],
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
pytest.fail('Can\'t run mount process.')
|
pytest.fail('Can\'t run umount process.')
|
||||||
|
|
||||||
def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir):
|
def test_java_isolation_rootfs_chroot_war(self, is_su, temp_dir):
|
||||||
if not is_su:
|
if not is_su:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class TestStaticMount(TestApplicationProto):
|
|||||||
Path(temp_dir + '/assets/mount/index.html').write_text('mount')
|
Path(temp_dir + '/assets/mount/index.html').write_text('mount')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
"mount",
|
"mount",
|
||||||
"--bind",
|
"--bind",
|
||||||
@@ -32,35 +32,33 @@ class TestStaticMount(TestApplicationProto):
|
|||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
pytest.fail('Can\'t run mount process.')
|
pytest.fail('Can\'t run mount process.')
|
||||||
|
|
||||||
self._load_conf(
|
self._load_conf(
|
||||||
{
|
{
|
||||||
"listeners": {"*:7080": {"pass": "routes"}},
|
"listeners": {"*:7080": {"pass": "routes"}},
|
||||||
"routes": [{"action": {"share": temp_dir + "/assets/dir$uri"}}],
|
"routes": [
|
||||||
|
{"action": {"share": temp_dir + "/assets/dir$uri"}}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(
|
subprocess.check_output(
|
||||||
["umount", "--lazy", temp_dir + "/assets/dir/mount"],
|
["umount", "--lazy", temp_dir + "/assets/dir/mount"],
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
pytest.fail('Can\'t run umount process.')
|
pytest.fail('Can\'t run umount process.')
|
||||||
|
|
||||||
def test_static_mount(self, temp_dir, skip_alert):
|
def test_static_mount(self, temp_dir, skip_alert):
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class TestTLS(TestApplicationTLS):
|
|||||||
def req(self, name='localhost', subject=None, x509=False):
|
def req(self, name='localhost', subject=None, x509=False):
|
||||||
subj = subject if subject is not None else '/CN=' + name + '/'
|
subj = subject if subject is not None else '/CN=' + name + '/'
|
||||||
|
|
||||||
subprocess.call(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
'openssl',
|
'openssl',
|
||||||
'req',
|
'req',
|
||||||
@@ -87,7 +87,7 @@ basicConstraints = critical,CA:TRUE"""
|
|||||||
f.write('')
|
f.write('')
|
||||||
|
|
||||||
def ca(self, cert='root', out='localhost'):
|
def ca(self, cert='root', out='localhost'):
|
||||||
subprocess.call(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
'openssl',
|
'openssl',
|
||||||
'ca',
|
'ca',
|
||||||
@@ -220,7 +220,7 @@ basicConstraints = critical,CA:TRUE"""
|
|||||||
|
|
||||||
self.openssl_conf()
|
self.openssl_conf()
|
||||||
|
|
||||||
subprocess.call(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
'openssl',
|
'openssl',
|
||||||
'ecparam',
|
'ecparam',
|
||||||
@@ -234,7 +234,7 @@ basicConstraints = critical,CA:TRUE"""
|
|||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
subprocess.call(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
'openssl',
|
'openssl',
|
||||||
'req',
|
'req',
|
||||||
@@ -589,7 +589,7 @@ basicConstraints = critical,CA:TRUE"""
|
|||||||
|
|
||||||
app_id = self.findall(r'(\d+)#\d+ "mirror" application started')[0]
|
app_id = self.findall(r'(\d+)#\d+ "mirror" application started')[0]
|
||||||
|
|
||||||
subprocess.call(['kill', '-9', app_id])
|
subprocess.check_output(['kill', '-9', app_id])
|
||||||
|
|
||||||
skip_alert(r'process .* %s.* exited on signal 9' % app_id)
|
skip_alert(r'process .* %s.* exited on signal 9' % app_id)
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ basicConstraints = critical,CA:TRUE"""
|
|||||||
else '/'
|
else '/'
|
||||||
)
|
)
|
||||||
|
|
||||||
subprocess.call(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
'openssl',
|
'openssl',
|
||||||
'req',
|
'req',
|
||||||
@@ -100,7 +100,7 @@ basicConstraints = critical,CA:TRUE"""
|
|||||||
else '/'
|
else '/'
|
||||||
)
|
)
|
||||||
|
|
||||||
subprocess.call(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
'openssl',
|
'openssl',
|
||||||
'ca',
|
'ca',
|
||||||
|
|||||||
@@ -40,13 +40,12 @@ class TestApplicationGo(TestApplicationProto):
|
|||||||
print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))
|
print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(args, env=env)
|
process = subprocess.run(args, env=env)
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return process
|
return process
|
||||||
|
|||||||
@@ -64,10 +64,17 @@ class TestApplicationJava(TestApplicationProto):
|
|||||||
|
|
||||||
javac = [
|
javac = [
|
||||||
'javac',
|
'javac',
|
||||||
'-target', '8', '-source', '8', '-nowarn',
|
'-target',
|
||||||
'-encoding', 'utf-8',
|
'8',
|
||||||
'-d', classes_path,
|
'-source',
|
||||||
'-classpath', classpath + ':' + ws_jars[0],
|
'8',
|
||||||
|
'-nowarn',
|
||||||
|
'-encoding',
|
||||||
|
'utf-8',
|
||||||
|
'-d',
|
||||||
|
classes_path,
|
||||||
|
'-classpath',
|
||||||
|
classpath + ':' + ws_jars[0],
|
||||||
]
|
]
|
||||||
javac.extend(src)
|
javac.extend(src)
|
||||||
|
|
||||||
@@ -75,13 +82,12 @@ class TestApplicationJava(TestApplicationProto):
|
|||||||
print("\n$ " + " ".join(javac))
|
print("\n$ " + " ".join(javac))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(javac, stderr=subprocess.STDOUT)
|
subprocess.check_output(javac, stderr=subprocess.STDOUT)
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
pytest.fail('Can\'t run javac process.')
|
pytest.fail('Can\'t run javac process.')
|
||||||
|
|
||||||
def load(self, script, **kwargs):
|
def load(self, script, **kwargs):
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class TestApplicationTLS(TestApplicationProto):
|
|||||||
def certificate(self, name='default', load=True):
|
def certificate(self, name='default', load=True):
|
||||||
self.openssl_conf()
|
self.openssl_conf()
|
||||||
|
|
||||||
subprocess.call(
|
subprocess.check_output(
|
||||||
[
|
[
|
||||||
'openssl',
|
'openssl',
|
||||||
'req',
|
'req',
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ def check_go(current_dir, temp_dir, test_dir):
|
|||||||
env['GO111MODULE'] = 'auto'
|
env['GO111MODULE'] = 'auto'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(
|
process = subprocess.run(
|
||||||
[
|
[
|
||||||
'go',
|
'go',
|
||||||
'build',
|
'build',
|
||||||
@@ -20,8 +20,9 @@ def check_go(current_dir, temp_dir, test_dir):
|
|||||||
test_dir + '/go/empty/app.go',
|
test_dir + '/go/empty/app.go',
|
||||||
],
|
],
|
||||||
env=env,
|
env=env,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
process.communicate()
|
|
||||||
|
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
return True
|
return True
|
||||||
@@ -29,5 +30,5 @@ def check_go(current_dir, temp_dir, test_dir):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user