Tests: fixed isolation detection.
This commit is contained in:
@@ -9,7 +9,7 @@ from unit.applications.proto import TestApplicationProto
|
|||||||
|
|
||||||
|
|
||||||
class TestApplicationJava(TestApplicationProto):
|
class TestApplicationJava(TestApplicationProto):
|
||||||
def load(self, script, name='app', **kwargs):
|
def prepare_env(self, script):
|
||||||
app_path = option.temp_dir + '/java'
|
app_path = option.temp_dir + '/java'
|
||||||
web_inf_path = app_path + '/WEB-INF/'
|
web_inf_path = app_path + '/WEB-INF/'
|
||||||
classes_path = web_inf_path + 'classes/'
|
classes_path = web_inf_path + 'classes/'
|
||||||
@@ -75,6 +75,9 @@ class TestApplicationJava(TestApplicationProto):
|
|||||||
except:
|
except:
|
||||||
pytest.fail('Cann\'t run javac process.')
|
pytest.fail('Cann\'t run javac process.')
|
||||||
|
|
||||||
|
def load(self, script, **kwargs):
|
||||||
|
self.prepare_env(script)
|
||||||
|
|
||||||
self._load_conf(
|
self._load_conf(
|
||||||
{
|
{
|
||||||
"listeners": {"*:7080": {"pass": "applications/" + script}},
|
"listeners": {"*:7080": {"pass": "applications/" + script}},
|
||||||
@@ -83,8 +86,11 @@ class TestApplicationJava(TestApplicationProto):
|
|||||||
"unit_jars": option.current_dir + '/build',
|
"unit_jars": option.current_dir + '/build',
|
||||||
"type": 'java',
|
"type": 'java',
|
||||||
"processes": {"spare": 0},
|
"processes": {"spare": 0},
|
||||||
"working_directory": script_path,
|
"working_directory": option.test_dir
|
||||||
"webapp": app_path,
|
+ '/java/'
|
||||||
|
+ script
|
||||||
|
+ '/',
|
||||||
|
"webapp": option.temp_dir + '/java',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from unit.applications.proto import TestApplicationProto
|
|||||||
|
|
||||||
|
|
||||||
class TestApplicationNode(TestApplicationProto):
|
class TestApplicationNode(TestApplicationProto):
|
||||||
def load(self, script, name='app.js', **kwargs):
|
def prepare_env(self, script):
|
||||||
# copy application
|
# copy application
|
||||||
|
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
@@ -23,6 +23,9 @@ class TestApplicationNode(TestApplicationProto):
|
|||||||
|
|
||||||
public_dir(option.temp_dir + '/node')
|
public_dir(option.temp_dir + '/node')
|
||||||
|
|
||||||
|
def load(self, script, name='app.js', **kwargs):
|
||||||
|
self.prepare_env(script)
|
||||||
|
|
||||||
self._load_conf(
|
self._load_conf(
|
||||||
{
|
{
|
||||||
"listeners": {
|
"listeners": {
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ import os
|
|||||||
from unit.applications.lang.go import TestApplicationGo
|
from unit.applications.lang.go import TestApplicationGo
|
||||||
from unit.applications.lang.java import TestApplicationJava
|
from unit.applications.lang.java import TestApplicationJava
|
||||||
from unit.applications.lang.node import TestApplicationNode
|
from unit.applications.lang.node import TestApplicationNode
|
||||||
from unit.applications.lang.perl import TestApplicationPerl
|
|
||||||
from unit.applications.lang.php import TestApplicationPHP
|
|
||||||
from unit.applications.lang.python import TestApplicationPython
|
|
||||||
from unit.applications.lang.ruby import TestApplicationRuby
|
|
||||||
from unit.applications.proto import TestApplicationProto
|
from unit.applications.proto import TestApplicationProto
|
||||||
|
from conftest import option
|
||||||
|
|
||||||
|
|
||||||
class TestFeatureIsolation(TestApplicationProto):
|
class TestFeatureIsolation(TestApplicationProto):
|
||||||
@@ -16,40 +13,119 @@ class TestFeatureIsolation(TestApplicationProto):
|
|||||||
def check(self, available, temp_dir):
|
def check(self, available, temp_dir):
|
||||||
test_conf = {"namespaces": {"credential": True}}
|
test_conf = {"namespaces": {"credential": True}}
|
||||||
|
|
||||||
module = ''
|
conf = ''
|
||||||
app = 'empty'
|
|
||||||
if 'go' in available['modules']:
|
if 'go' in available['modules']:
|
||||||
module = TestApplicationGo()
|
TestApplicationGo().prepare_env('empty', 'app')
|
||||||
|
|
||||||
|
conf = {
|
||||||
|
"listeners": {"*:7080": {"pass": "applications/empty"}},
|
||||||
|
"applications": {
|
||||||
|
"empty": {
|
||||||
|
"type": "external",
|
||||||
|
"processes": {"spare": 0},
|
||||||
|
"working_directory": option.test_dir + "/go/empty",
|
||||||
|
"executable": option.temp_dir + "/go/app",
|
||||||
|
"isolation": {"namespaces": {"credential": True}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
elif 'python' in available['modules']:
|
elif 'python' in available['modules']:
|
||||||
module = TestApplicationPython()
|
conf = {
|
||||||
|
"listeners": {"*:7080": {"pass": "applications/empty"}},
|
||||||
|
"applications": {
|
||||||
|
"empty": {
|
||||||
|
"type": "python",
|
||||||
|
"processes": {"spare": 0},
|
||||||
|
"path": option.test_dir + "/python/empty",
|
||||||
|
"working_directory": option.test_dir + "/python/empty",
|
||||||
|
"module": "wsgi",
|
||||||
|
"isolation": {"namespaces": {"credential": True}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
elif 'php' in available['modules']:
|
elif 'php' in available['modules']:
|
||||||
module = TestApplicationPHP()
|
conf = {
|
||||||
app = 'phpinfo'
|
"listeners": {"*:7080": {"pass": "applications/phpinfo"}},
|
||||||
|
"applications": {
|
||||||
|
"phpinfo": {
|
||||||
|
"type": "php",
|
||||||
|
"processes": {"spare": 0},
|
||||||
|
"root": option.test_dir + "/php/phpinfo",
|
||||||
|
"working_directory": option.test_dir + "/php/phpinfo",
|
||||||
|
"index": "index.php",
|
||||||
|
"isolation": {"namespaces": {"credential": True}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
elif 'ruby' in available['modules']:
|
elif 'ruby' in available['modules']:
|
||||||
module = TestApplicationRuby()
|
conf = {
|
||||||
|
"listeners": {"*:7080": {"pass": "applications/empty"}},
|
||||||
|
"applications": {
|
||||||
|
"empty": {
|
||||||
|
"type": "ruby",
|
||||||
|
"processes": {"spare": 0},
|
||||||
|
"working_directory": option.test_dir + "/ruby/empty",
|
||||||
|
"script": option.test_dir + "/ruby/empty/config.ru",
|
||||||
|
"isolation": {"namespaces": {"credential": True}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
elif 'java' in available['modules']:
|
elif 'java' in available['modules']:
|
||||||
module = TestApplicationJava()
|
TestApplicationJava().prepare_env('empty')
|
||||||
|
|
||||||
|
conf = {
|
||||||
|
"listeners": {"*:7080": {"pass": "applications/empty"}},
|
||||||
|
"applications": {
|
||||||
|
"empty": {
|
||||||
|
"unit_jars": option.current_dir + "/build",
|
||||||
|
"type": "java",
|
||||||
|
"processes": {"spare": 0},
|
||||||
|
"working_directory": option.test_dir + "/java/empty/",
|
||||||
|
"webapp": option.temp_dir + "/java",
|
||||||
|
"isolation": {"namespaces": {"credential": True}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
elif 'node' in available['modules']:
|
elif 'node' in available['modules']:
|
||||||
module = TestApplicationNode()
|
TestApplicationNode().prepare_env('basic')
|
||||||
app = 'basic'
|
|
||||||
|
conf = {
|
||||||
|
"listeners": {"*:7080": {"pass": "applications/basic"}},
|
||||||
|
"applications": {
|
||||||
|
"basic": {
|
||||||
|
"type": "external",
|
||||||
|
"processes": {"spare": 0},
|
||||||
|
"working_directory": option.temp_dir + "/node",
|
||||||
|
"executable": "app.js",
|
||||||
|
"isolation": {"namespaces": {"credential": True}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
elif 'perl' in available['modules']:
|
elif 'perl' in available['modules']:
|
||||||
module = TestApplicationPerl()
|
conf = {
|
||||||
app = 'body_empty'
|
"listeners": {"*:7080": {"pass": "applications/body_empty"}},
|
||||||
|
"applications": {
|
||||||
|
"body_empty": {
|
||||||
|
"type": "perl",
|
||||||
|
"processes": {"spare": 0},
|
||||||
|
"working_directory": option.test_dir
|
||||||
|
+ "/perl/body_empty",
|
||||||
|
"script": option.test_dir + "/perl/body_empty/psgi.pl",
|
||||||
|
"isolation": {"namespaces": {"credential": True}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
if not module:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
module.temp_dir = temp_dir
|
if 'success' not in self.conf(conf):
|
||||||
module.load(app)
|
|
||||||
|
|
||||||
resp = module.conf(test_conf, 'applications/' + app + '/isolation')
|
|
||||||
if 'success' not in resp:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
userns = self.getns('user')
|
userns = self.getns('user')
|
||||||
|
|||||||
Reference in New Issue
Block a user