summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2020-01-13 19:31:51 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commita306b8b9d8cc3248f05dd4b5971a6ddd97ab1cde (patch)
tree8cb171b77cc0f9c93e16657f0694fe9f32ec20e0
parent1ced3dd0693fc6d88c0d5ec8432102454e10075e (diff)
Catch execution errors during restore image command
This patch allows us to send feedback to the server in case of error during the execution of the command. In case of error, ogClient will send an "Internal Error" http message.
-rw-r--r--src/linux/ogOperations.py6
-rw-r--r--src/ogRest.py14
2 files changed, 14 insertions, 6 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py
index 447f188..1aa454f 100644
--- a/src/linux/ogOperations.py
+++ b/src/linux/ogOperations.py
@@ -74,5 +74,9 @@ def procirestore(httpparser):
profile = httpparser.getProfile()
cid = httpparser.getId()
- result = subprocess.check_output([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], shell=True)
+ try:
+ result = subprocess.check_output([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], shell=True)
+ except:
+ raise ValueError('Error: Incorrect command value')
+
return result.decode('utf-8')
diff --git a/src/ogRest.py b/src/ogRest.py
index 99ecdbc..5119eea 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -106,9 +106,14 @@ class ogThread():
ogOperations.procsetup(httpparser)
# Process image restore
- def procirestore(msgqueue, httpparser):
- msgqueue.queue.clear()
- msgqueue.put(ogOperations.procirestore(httpparser))
+ def procirestore(httpparser):
+ try:
+ ogOperations.procirestore(httpparser)
+ except ValueError as err:
+ client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR))
+ return
+
+ client.send(restResponse.getResponse(ogResponses.OK))
class ogResponses(Enum):
BAD_REQUEST=0
@@ -211,5 +216,4 @@ class ogRest():
client.send(restResponse.getResponse(ogResponses.OK))
def process_irestore(self, client, httpparser):
- threading.Thread(target=ogThread.procirestore, args=(self.msgqueue, httpparser,)).start()
- client.send(restResponse.getResponse(ogResponses.OK))
+ threading.Thread(target=ogThread.procirestore, args=(client, httpparser,)).start()