Commit 07eaa133 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: tests modified to correctly use config.json

parent 3183f4d3
...@@ -24,8 +24,7 @@ from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning, ...@@ -24,8 +24,7 @@ from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning,
isSoftwareRunning, startProxy, isSoftwareRunning, startProxy,
isSoftwareReleaseReady, isSoftwareReleaseReady,
runSlapgridUntilSuccess, runSlapgridUntilSuccess,
getBuildAndRunParams, saveBuildAndRunParams, getBuildAndRunParams, saveBuildAndRunParams)
MAX_RUN_INSTANCE, MAX_RUN_SOFTWARE)
from slapos.runner.process import killRunningProcess, isRunning from slapos.runner.process import killRunningProcess, isRunning
from slapos.runner import views from slapos.runner import views
import slapos.slap import slapos.slap
...@@ -98,12 +97,23 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -98,12 +97,23 @@ class SlaprunnerTestCase(unittest.TestCase):
SECRET_KEY="123456", SECRET_KEY="123456",
PERMANENT_SESSION_LIFETIME=datetime.timedelta(days=31), PERMANENT_SESSION_LIFETIME=datetime.timedelta(days=31),
auto_deploy = True, auto_deploy = True,
autorun = False,
) )
self.app = views.app.test_client() self.app = views.app.test_client()
self.app.config = views.app.config self.app.config = views.app.config
#Create password recover code #Create password recover code
with open(os.path.join(views.app.config['etc_dir'], '.rcode'), 'w') as rpwd: with open(os.path.join(views.app.config['etc_dir'], '.rcode'), 'w') as rpwd:
rpwd.write(self.rcode) rpwd.write(self.rcode)
#Create config.json
json_file = os.path.join(views.app.config['etc_dir'], 'config.json')
if not os.path.exists(json_file):
params = {
'run_instance' : True,
'run_software' : True,
'max_run_instance' : 3,
'max_run_software' : 2
}
open(json_file, "w").write(json.dumps(params))
def tearDown(self): def tearDown(self):
"""Remove all test data""" """Remove all test data"""
...@@ -452,6 +462,8 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -452,6 +462,8 @@ class SlaprunnerTestCase(unittest.TestCase):
We directly calls runSlapgridUntilSuccess, because we want We directly calls runSlapgridUntilSuccess, because we want
to test the return code of the function""" to test the return code of the function"""
# Installs a wrong buildout which will fail # Installs a wrong buildout which will fail
MAX_RUN_SOFTWARE = getBuildAndRunParams(self.app.config)['max_run_software']
MAX_RUN_INSTANCE = getBuildAndRunParams(self.app.config)['max_run_instance']
self.test_createSR() self.test_createSR()
newSoftware = self.getCurrentSR() newSoftware = self.getCurrentSR()
softwareRelease = "[buildout]\n\nparts =\n test-application\n" softwareRelease = "[buildout]\n\nparts =\n test-application\n"
...@@ -495,13 +507,13 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -495,13 +507,13 @@ class SlaprunnerTestCase(unittest.TestCase):
project.write(self.software + 'slaprunner-test') project.write(self.software + 'slaprunner-test')
project.close() project.close()
# Build and Run # Build and Run
parameters = getBuildAndRunParams() parameters = getBuildAndRunParams(self.app.config)
parameters['run_instance'] = False parameters['run_instance'] = False
saveBuildAndRunParams(parameters) saveBuildAndRunParams(self.app.config, parameters)
response = runSlapgridUntilSuccess(self.app.config, 'software') response = runSlapgridUntilSuccess(self.app.config, 'software')
self.assertEqual(response, 1) self.assertEqual(response, 1)
parameters['run_instance'] = True parameters['run_instance'] = True
saveBuildAndRunParams(parameters) saveBuildAndRunParams(self.app.config, parameters)
response = runSlapgridUntilSuccess(self.app.config, 'software') response = runSlapgridUntilSuccess(self.app.config, 'software')
self.assertEqual(response, (1, MAX_RUN_INSTANCE)) self.assertEqual(response, (1, MAX_RUN_INSTANCE))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment