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): ...@@ -646,27 +646,47 @@ def getSoftwareReleaseName(config):
return software.replace(' ', '_') return software.replace(' ', '_')
return "No_name" return "No_name"
def removeSoftwareRootDirectory(config, md5, folder_name):
def removeSoftwareByName(config, md5, folderName): """
"""Remove all content of the software release specified by md5 Removes all content in the filesystem of the software release specified by md5
Args: Args:
config: slaprunner configuration config: slaprunner configuration
foldername: the link name given to the software release folder_name: the link name given to the software release
md5: the md5 filename given by slapgrid to SR folder""" 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")
path = os.path.join(config['software_root'], md5) 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): 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): if not os.path.exists(linkpath):
raise Exception("Cannot remove software Release: No such file or directory %s" % return (0, "Cannot remove software Release: No such file or directory %s" %
('software_root/' + folderName)) ('software_root/' + folder_name))
svcStopAll(config)
os.unlink(linkpath) os.unlink(linkpath)
shutil.rmtree(path) 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): def tail(f, lines=20):
......
...@@ -367,12 +367,9 @@ def removeFile(): ...@@ -367,12 +367,9 @@ def removeFile():
def removeSoftwareDir(): def removeSoftwareDir():
try: status, message = removeSoftwareByName(app.config, request.form['md5'],
data = removeSoftwareByName(app.config, request.form['md5'], request.form['title'])
request.form['title']) return jsonify(code=status, result=message)
return jsonify(code=1, result=data)
except Exception as e:
return jsonify(code=0, result=str(e))
#read file and return content to ajax #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