Commit bea2a72f authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Updated tests for new process way

parent e459a6c1
...@@ -7,11 +7,13 @@ import datetime ...@@ -7,11 +7,13 @@ import datetime
import json import json
import os import os
import shutil import shutil
import time
import unittest import unittest
import hashlib import hashlib
from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning, isSoftwareRunning, readPid, from slapos.runner.utils import (getProfilePath, getSession, isInstanceRunning,
startProxy, killRunningProcess) isSoftwareRunning, startProxy)
from slapos.runner.process import killRunningProcess, isRunning
from slapos.runner import views from slapos.runner import views
import slapos.slap import slapos.slap
...@@ -108,9 +110,9 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -108,9 +110,9 @@ class SlaprunnerTestCase(unittest.TestCase):
shutil.rmtree(self.app.config['software_link']) shutil.rmtree(self.app.config['software_link'])
self.logout() self.logout()
#Stop process #Stop process
killRunningProcess(self.app.config, 'proxy.pid') killRunningProcess('slapproxy', recursive=True)
killRunningProcess(self.app.config, 'slapgrid-cp.pid') killRunningProcess('slapgrid-cp', recursive=True)
killRunningProcess(self.app.config, 'slapgrid-sr.pid') killRunningProcess('slapgrid-sr', recursive=True)
def configAccount(self, username, password, email, name, rcode): def configAccount(self, username, password, email, name, rcode):
"""Helper for configAccount""" """Helper for configAccount"""
...@@ -154,17 +156,13 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -154,17 +156,13 @@ class SlaprunnerTestCase(unittest.TestCase):
def getCurrentSR(self): def getCurrentSR(self):
return getProfilePath(self.app.config['etc_dir'], return getProfilePath(self.app.config['etc_dir'],
self.app.config['software_profile']) self.app.config['software_profile'])
def proxyStatus(self, status=True):
def proxyStatus(self, status=True, sleep_time=0):
"""Helper for testslapproxy status""" """Helper for testslapproxy status"""
proxy_pid = os.path.join(self.app.config['run_dir'], 'proxy.pid') proxy = isRunning('slapproxy')
pid = readPid(proxy_pid) if proxy != status and sleep_time != 0:
proxy = False time.sleep(sleep_time)
if pid: proxy = isRunning('slapproxy')
try:
os.kill(pid, 0)
proxy = True
except Exception:
pass
self.assertEqual(proxy, status) self.assertEqual(proxy, status)
def setupProjectFolder(self, withSoftware=False): def setupProjectFolder(self, withSoftware=False):
...@@ -207,8 +205,7 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -207,8 +205,7 @@ class SlaprunnerTestCase(unittest.TestCase):
def stopSlapproxy(self): def stopSlapproxy(self):
"""Kill slapproxy process""" """Kill slapproxy process"""
killRunningProcess(self.app.config, 'proxy.pid') killRunningProcess('slapproxy', recursive=True)
#Begin test case here #Begin test case here
...@@ -262,7 +259,7 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -262,7 +259,7 @@ class SlaprunnerTestCase(unittest.TestCase):
startProxy(self.app.config) startProxy(self.app.config)
self.proxyStatus(True) self.proxyStatus(True)
self.stopSlapproxy() self.stopSlapproxy()
self.proxyStatus(False) self.proxyStatus(False, sleep_time=1)
def test_cloneProject(self): def test_cloneProject(self):
"""Start scenario 1 for deploying SR: Clone a project from git repository""" """Start scenario 1 for deploying SR: Clone a project from git repository"""
...@@ -319,7 +316,8 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -319,7 +316,8 @@ class SlaprunnerTestCase(unittest.TestCase):
assert software in currentSR assert software in currentSR
self.assertFalse(isInstanceRunning(self.app.config)) self.assertFalse(isInstanceRunning(self.app.config))
self.assertFalse(isSoftwareRunning(self.app.config)) self.assertFalse(isSoftwareRunning(self.app.config))
#Slapproxy process is supose to be startednewSoftware = os.path.join(self.software, 'slaprunner-test') #Slapproxy process is supose to be started
#newSoftware = os.path.join(self.software, 'slaprunner-test')
self.proxyStatus(True) self.proxyStatus(True)
self.stopSlapproxy() self.stopSlapproxy()
self.logout() self.logout()
...@@ -411,7 +409,7 @@ class SlaprunnerTestCase(unittest.TestCase): ...@@ -411,7 +409,7 @@ class SlaprunnerTestCase(unittest.TestCase):
self.test_updateInstanceParameter() self.test_updateInstanceParameter()
#Login #Login
self.login(self.users[0], self.users[1]) self.login(self.users[0], self.users[1])
self.proxyStatus(False) self.proxyStatus(False, sleep_time=1)
#run Software profile #run Software profile
response = loadJson(self.app.post('/runSoftwareProfile', response = loadJson(self.app.post('/runSoftwareProfile',
data=dict(), data=dict(),
......
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