Commit 0fbb9119 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: factorizes the Software Releases removal code

It makes tests easiers and lighten the code in view.py
parent 086a9951
......@@ -646,27 +646,47 @@ def getSoftwareReleaseName(config):
return software.replace(' ', '_')
return "No_name"
def removeSoftwareByName(config, md5, folderName):
"""Remove all content of the software release specified by md5
def removeSoftwareRootDirectory(config, md5, folder_name):
"""
Removes all content in the filesystem of the software release specified by md5
Args:
config: slaprunner configuration
foldername: the link name given to the software release
md5: the md5 filename given by slapgrid to SR folder"""
if isSoftwareRunning(config) or isInstanceRunning(config):
raise Exception("Software installation or instantiation in progress, cannot remove")
folder_name: the link name given to the software release
md5: the md5 filename given by slapgrid to SR folder
"""
path = os.path.join(config['software_root'], md5)
linkpath = os.path.join(config['software_link'], folderName)
linkpath = os.path.join(config['software_link'], folder_name)
if not os.path.exists(path):
raise Exception("Cannot remove software Release: No such file or directory")
return (0, "Cannot remove software Release: No such file or directory")
if not os.path.exists(linkpath):
raise Exception("Cannot remove software Release: No such file or directory %s" %
('software_root/' + folderName))
svcStopAll(config)
return (0, "Cannot remove software Release: No such file or directory %s" %
('software_root/' + folder_name))
os.unlink(linkpath)
shutil.rmtree(path)
return loadSoftwareRList(config)
return
def removeSoftwareByName(config, md5, folder_name):
"""
Removes a software release specified by its md5 and its name from the webrunner.
If the software release is the one of the current running instance, then
the instance should be stopped.
Args:
config: slaprunner configuration
folder_name: the link name given to the software release
md5: the md5 filename given by slapgrid to SR folder
"""
if isSoftwareRunning(config) or isInstanceRunning(config):
return (0, "Software installation or instantiation in progress, cannot remove")
if getSoftwareReleaseName(config) == folder_name:
removeCurrentInstance(config)
result = removeSoftwareRootDirectory(config, md5, folder_name)
if result is not None:
return result
return 1, loadSoftwareRList(config)
def tail(f, lines=20):
......
......@@ -367,12 +367,9 @@ def removeFile():
def removeSoftwareDir():
try:
data = removeSoftwareByName(app.config, request.form['md5'],
request.form['title'])
return jsonify(code=1, result=data)
except Exception as e:
return jsonify(code=0, result=str(e))
status, message = removeSoftwareByName(app.config, request.form['md5'],
request.form['title'])
return jsonify(code=status, result=message)
#read file and return content to ajax
......
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