Tests: Added rootfs tests.

This commit is contained in:
Tiago Natel de Moura
2020-05-28 14:59:52 +01:00
parent e2b53e16c6
commit 08b765ae42
12 changed files with 542 additions and 34 deletions

View File

@@ -19,26 +19,36 @@ class TestApplicationGo(TestApplicationProto):
return unit if not complete_check else unit.complete()
def prepare_env(self, script, name):
def prepare_env(self, script, name, static=False):
if not os.path.exists(self.testdir + '/go'):
os.mkdir(self.testdir + '/go')
env = os.environ.copy()
env['GOPATH'] = self.pardir + '/build/go'
try:
process = subprocess.Popen(
[
'go',
'build',
'-o',
self.testdir + '/go/' + name,
self.current_dir + '/go/' + script + '/' + name + '.go',
],
env=env,
stderr=subprocess.STDOUT,
)
if static:
args = [
'go',
'build',
'-tags',
'netgo',
'-ldflags',
'-extldflags "-static"',
'-o',
self.testdir + '/go/' + name,
self.current_dir + '/go/' + script + '/' + name + '.go',
]
else:
args = [
'go',
'build',
'-o',
self.testdir + '/go/' + name,
self.current_dir + '/go/' + script + '/' + name + '.go',
]
try:
process = subprocess.Popen(args, env=env)
process.communicate()
except:
@@ -47,21 +57,28 @@ class TestApplicationGo(TestApplicationProto):
return process
def load(self, script, name='app', **kwargs):
self.prepare_env(script, name)
static_build = False
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
"type": "external",
"processes": {"spare": 0},
"working_directory": self.current_dir
+ "/go/"
+ script,
"executable": self.testdir + "/go/" + name,
}
wdir = self.current_dir + "/go/" + script
executable = self.testdir + "/go/" + name
if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']:
wdir = "/go/"
executable = "/go/" + name
static_build = True
self.prepare_env(script, name, static=static_build)
conf = {
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
"type": "external",
"processes": {"spare": 0},
"working_directory": wdir,
"executable": executable,
},
},
**kwargs
)
}
self._load_conf(conf, **kwargs)

View File

@@ -1,3 +1,6 @@
import shutil
import os
from unit.applications.proto import TestApplicationProto
@@ -8,7 +11,21 @@ class TestApplicationPython(TestApplicationProto):
if name is None:
name = script
script_path = self.current_dir + '/python/' + script
if script[0] == '/':
script_path = script
else:
script_path = self.current_dir + '/python/' + script
if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
rootfs = kwargs['isolation']['rootfs']
if not os.path.exists(rootfs + '/app/python/'):
os.makedirs(rootfs + '/app/python/')
if not os.path.exists(rootfs + '/app/python/' + name):
shutil.copytree(script_path, rootfs + '/app/python/' + name)
script_path = '/app/python/' + name
self._load_conf(
{