Skip to content
Snippets Groups Projects
Commit 7143d98b authored by Chris Hines's avatar Chris Hines
Browse files

throw more useful error messages when the remote server is down

parent 4e35d1d8
No related branches found
No related tags found
2 merge requests!11Dev,!6Dev
Pipeline #7125 passed
...@@ -8,7 +8,7 @@ from flask import render_template ...@@ -8,7 +8,7 @@ from flask import render_template
import flask_restful import flask_restful
from . import api, app from . import api, app
from .sshwrapper import Ssh, SshAgentException, SftpPermissionException, SftpException from .sshwrapper import Ssh, SshAgentException, SftpPermissionException, SftpException, SshCtrlException
from .tunnelstat import SSHSession from .tunnelstat import SSHSession
...@@ -224,6 +224,8 @@ class JobStat(Resource): ...@@ -224,6 +224,8 @@ class JobStat(Resource):
except SshAgentException as e: except SshAgentException as e:
logger.error(e) logger.error(e)
flask_restful.abort(400, message="Identity error {}".format(e)) flask_restful.abort(400, message="Identity error {}".format(e))
except SshCtrlException as e:
flask_restful.abort(400,message="We're having difficultly contacting {}. Could there be an outage in effect?".format(params['identity']['site']['host']))
if not (res['stderr'] == '' or res['stderr'] is None or res['stderr'] == b''): if not (res['stderr'] == '' or res['stderr'] is None or res['stderr'] == b''):
logger.error(res['stderr']) logger.error(res['stderr'])
flask_restful.abort(400, message=res['stderr'].decode()) flask_restful.abort(400, message=res['stderr'].decode())
...@@ -284,21 +286,24 @@ class DirList(Resource): ...@@ -284,21 +286,24 @@ class DirList(Resource):
path = "." path = "."
if cd == "": if cd == "":
cd = "." cd = "."
if 'lscmd' in site and site['lscmd'] is not None and site['lscmd'] is not "": try:
logger.debug('using ssh.execute with lscmd') if 'lscmd' in site and site['lscmd'] is not None and site['lscmd'] is not "":
res = Ssh.execute(sshsess, host=params['identity']['site']['host'], user=params['identity']['username'], logger.debug('using ssh.execute with lscmd')
sshport=sshport, res = Ssh.execute(sshsess, host=params['identity']['site']['host'], user=params['identity']['username'],
cmd="{} {} {}".format(site['lscmd'],path,cd)) sshport=sshport,
try: cmd="{} {} {}".format(site['lscmd'],path,cd))
dirls = json.loads(res['stdout'].decode()) try:
except: dirls = json.loads(res['stdout'].decode())
flask_restful.abort(404,message="You don't have permission to view that directory") except:
else: flask_restful.abort(404,message="You don't have permission to view that directory")
logger.debug('using ssh.sftpls') else:
logger.debug('using ssh.sftpls')
dirls = Ssh.sftpls(sshsess, host=params['identity']['site']['host'],
user=params['identity']['username'], path=params['path'],changepath=params['cd'], sshport=sshport) dirls = Ssh.sftpls(sshsess, host=params['identity']['site']['host'],
return dirls user=params['identity']['username'], path=params['path'],changepath=params['cd'], sshport=sshport)
return dirls
except SshCtrlException as e:
flask_restful.abort(400,message="We're having difficultly contacting {}. Could there be an outage in effect?".format(params['identity']['site']['host']))
class JobCancel(Resource): class JobCancel(Resource):
""" """
...@@ -310,11 +315,14 @@ class JobCancel(Resource): ...@@ -310,11 +315,14 @@ class JobCancel(Resource):
""" """
params = get_conn_params() params = get_conn_params()
sshsess = SSHSession.get_sshsession() sshsess = SSHSession.get_sshsession()
res = Ssh.execute(sshsess, host=params['identity']['site']['host'], user=params['identity']['username'], try:
cmd=params['interface']['cancelcmd'].format(jobid=jobid)) res = Ssh.execute(sshsess, host=params['identity']['site']['host'], user=params['identity']['username'],
if not (res['stderr'] == '' or res['stderr'] is None or res['stderr'] == b''): cmd=params['interface']['cancelcmd'].format(jobid=jobid))
flask_restful.abort(400, message=res['stderr'].decode()) if not (res['stderr'] == '' or res['stderr'] is None or res['stderr'] == b''):
return res['stdout'].decode() flask_restful.abort(400, message=res['stderr'].decode())
return res['stdout'].decode()
except SshCtrlException as e:
flask_restful.abort(400,message="We're having difficultly contacting {}. Could there be an outage in effect?".format(params['identity']['site']['host']))
class JobSubmit(Resource): class JobSubmit(Resource):
...@@ -345,8 +353,11 @@ class JobSubmit(Resource): ...@@ -345,8 +353,11 @@ class JobSubmit(Resource):
flask_restful.abort(400, message='Incomplete job information was passed to the backend.') flask_restful.abort(400, message='Incomplete job information was passed to the backend.')
logger.debug('script formated to {}'.format(script)) logger.debug('script formated to {}'.format(script))
res = Ssh.execute(sshsess, host=params['identity']['site']['host'], user=params['identity']['username'], try:
res = Ssh.execute(sshsess, host=params['identity']['site']['host'], user=params['identity']['username'],
cmd=params['interface']['submitcmd'], stdin=script) cmd=params['interface']['submitcmd'], stdin=script)
except SshCtrlException as e:
flask_restful.abort(400,message="We're having difficultly contacting {}. Could there be an outage in effect?".format(params['identity']['site']['host']))
if not (res['stderr'] == '' or res['stderr'] is None or res['stderr'] == b''): if not (res['stderr'] == '' or res['stderr'] is None or res['stderr'] == b''):
logger.debug('failed to submit job') logger.debug('failed to submit job')
logger.debug(res['stderr']) logger.debug(res['stderr'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment