Improve hardware command response behavior

This patch give us a better support in case of error or success execution.
In error cases, the new behavior is to send an Internal Error http message (500).
Otherwise, the server will receive a message with a json with this format:

    { "hardware" : "xyz" }

"xyz" is the output saved in a specific path during the execution of
InventarioHardware.
more_events
Alvaro Neira Ayuso 2020-01-13 19:20:13 +01:00 committed by Alvaro Neira Ayuso
parent 683afa6465
commit 1ced3dd069
2 changed files with 19 additions and 6 deletions

View File

@ -48,7 +48,11 @@ def procsoftware(httpparser, path):
return result.decode('utf-8') return result.decode('utf-8')
def prochardware(path): def prochardware(path):
result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioHardware', path], shell=True) try:
result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioHardware', path], shell=True)
except:
raise ValueError('Error: Incorrect command value')
return result.decode('utf-8') return result.decode('utf-8')
def procsetup(httpparser): def procsetup(httpparser):

View File

@ -87,9 +87,19 @@ class ogThread():
client.send(restResponse.getResponse(ogResponses.OK, jsonResp)) client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
# Process hardware # Process hardware
def prochardware(msgqueue, path): def prochardware(client, path):
msgqueue.queue.clear() try:
msgqueue.put(ogOperations.prochardware(path)) ogOperations.prochardware(path)
except ValueError as err:
client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR))
return
jsonResp = jsonResponse()
f = open(path, "r")
lines = f.readlines()
f.close()
jsonResp.addElement('hardware', lines[0])
client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
# Process setup # Process setup
def procsetup(msgqueue, httpparser): def procsetup(msgqueue, httpparser):
@ -191,8 +201,7 @@ class ogRest():
def process_hardware(self, client): def process_hardware(self, client):
path = '/tmp/Chrd-' + client.ip path = '/tmp/Chrd-' + client.ip
threading.Thread(target=ogThread.prochardware, args=(self.msgqueue, path,)).start() threading.Thread(target=ogThread.prochardware, args=(client, path,)).start()
client.send(restResponse.getResponse(ogResponses.OK))
def process_schedule(self, client): def process_schedule(self, client):
client.send(restResponse.getResponse(ogResponses.OK)) client.send(restResponse.getResponse(ogResponses.OK))