Commit b2fcffce authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: factorizes code from runSoftwareWithLock and runInstanceWithLock

parent a15ab535
......@@ -278,33 +278,55 @@ def waitProcess(config, process, step):
date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
slapgridResultToFile(config, step, process.returncode, date)
def runSoftwareWithLock(config, lock=False):
def runSlapgridWithLock(config, step, process_name, lock=False):
"""
Use Slapgrid to compile current Software Release and wait until
compilation is done
* process_name is the name of the process given to supervisord, which will
run the software or the instance
* step is one of ('software', 'instance')
* lock allows to make this function asynchronous or not
"""
if sup_process.isRunning(config, 'slapgrid-sr'):
if sup_process.isRunning(config, process_name):
return 1
if not os.path.exists(config['software_root']):
os.mkdir(config['software_root'])
root_folder = config["%s_root" % step]
log_file = config["%s_log" % step]
if not os.path.exists(root_folder):
os.mkdir(root_folder)
# XXX Hackish and unreliable
if os.path.exists(config['software_log']):
os.remove(config['software_log'])
if os.path.exists(log_file):
os.remove(log_file)
if not updateProxy(config):
return 1
try:
sup_process.runProcess(config, "slapgrid-sr")
sup_process.runProcess(config, process_name)
if lock:
sup_process.waitForProcessEnd(config, "slapgrid-sr")
sup_process.waitForProcessEnd(config, process_name)
#Saves the current compile software for re-use
config_SR_folder(config)
return sup_process.returnCode(config, "slapgrid-sr")
if step == 'software':
config_SR_folder(config)
return sup_process.returnCode(config, process_name)
except xmlrpclib.Fault:
return 1
def runSoftwareWithLock(config, lock=False):
"""
Use Slapgrid to compile current Software Release and wait until
compilation is done
"""
return runSlapgridWithLock(config, 'software', 'slapgrid-sr', lock)
def runInstanceWithLock(config, lock=False):
"""
Use Slapgrid to deploy current Software Release and wait until
deployment is done.
"""
return runSlapgridWithLock(config, 'instance', 'slapgrid-cp', lock)
def config_SR_folder(config):
"""Create a symbolik link for each folder in software folder. That allows
the user to customize software release folder"""
......@@ -373,29 +395,6 @@ def isInstanceRunning(config):
return sup_process.isRunning(config, 'slapgrid-cp')
def runInstanceWithLock(config, lock=False):
"""
Use Slapgrid to deploy current Software Release and wait until
deployment is done.
"""
if sup_process.isRunning(config, 'slapgrid-cp'):
return 1
startProxy(config)
# XXX Hackish and unreliable
if os.path.exists(config['instance_log']):
os.remove(config['instance_log'])
if not (updateProxy(config) and requestInstance(config)):
return 1
try:
sup_process.runProcess(config, "slapgrid-cp")
if lock:
sup_process.waitForProcessEnd(config, "slapgrid-cp")
return sup_process.returnCode(config, "slapgrid-cp")
except xmlrpclib.Fault:
return 1
def getProfilePath(projectDir, profile):
"""
Return the path of the current Software Release `profile`
......
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