Commit f64c6451 authored by Matthieu Lamalle's avatar Matthieu Lamalle

catch errors and pass

parent 67cca5bd
......@@ -190,9 +190,9 @@ class ServerRunner(ZephirCommonController):
@register_wamp('v1.server.exec.command', notification_uri='v1.server.executed', database=True)
async def exec_cmd_on_server(self, cursor, server_id, command):
return self._exec_cmd_on_server(cursor, server_id, command)
return await self._exec_cmd_on_server(cursor, server_id, command)
def _exec_cmd_on_server(self, cursor, server_id, command):
async def _exec_cmd_on_server(self, cursor, server_id, command):
"""
Transfer command transmitted to automation (salt, ...)
"""
......@@ -531,9 +531,19 @@ class ServerRunner(ZephirCommonController):
"""
servers = self.serverselection.describe_serverselection(cursor, serverselection_id)['serverselectionserversid']
ret = []
for server_id in servers:
ret.append(self._exec_cmd_on_server(cursor, server_id, command))
try:
ret.append(await self._exec_cmd_on_server(cursor, server_id, command))
except ServerErrorUnknownServerId as err:
ret.append({'job_id': '',
'server_id': server_id,
'command': command,
'automation': 'salt',
'executed': True,
'success': False,
'retcode': 1,
'return': str(err)})
return ret
......
......@@ -160,7 +160,7 @@ def fetch_server_dict(cursor, serverid: int):
def fetch_server(cursor, serverid: int):
fetched = fetchone(cursor, FETCH_SERVER, (serverid,))
if fetched is None:
raise Exception(_('unable to find a server with ID {}').format(serverid))
raise ServerErrorUnknownServerId(_('unable to find a server with ID {}').format(serverid))
return fetched
......
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