Skip to content
Snippets Groups Projects
Commit ff8f888b authored by John Chilton's avatar John Chilton
Browse files

Improved handling of missing files.

parent 24b340bb
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ from webob import Response
from webob import exc
import inspect
from os.path import exists
import re
from simplejson import dumps
......@@ -94,7 +95,11 @@ class Controller(object):
resp = Response(body=dumps(result))
elif self.response_type == 'file':
resp = Response()
resp.app_iter = FileIterator(result)
path = result
if exists(path):
resp.app_iter = FileIterator(path)
else:
raise exc.HTTPNotFound("No file found with path %s." % path)
else:
resp = Response(body='OK')
return resp(environ, start_response)
......
......@@ -19,6 +19,15 @@ class parseJson(object):
return replacement
class OutputNotFoundException(Exception):
def __init__(self, path):
self.path = path
def __str__(self):
return "No remote output found for path %s" % self.path
class Client(object):
"""
Objects of this client class perform low-level communication with a remote LWR server.
......@@ -163,7 +172,7 @@ class Client(object):
elif output_type == "task":
output_path = os.path.join(working_directory, name)
else:
raise Exception("No remote output found for dataset with path %s" % path)
raise OutputNotFoundException("No remote output found for dataset with path %s" % path)
self.__raw_download_output(name, self.job_id, output_type, output_path)
def __raw_download_output(self, name, job_id, output_type, output_path):
......
......@@ -21,6 +21,7 @@ def main():
parser = optparse.OptionParser()
parser.add_option('--url', dest='url', default='http://localhost:8913/')
parser.add_option('--private_token', default=None)
parser.add_option('--test_errors', default=False, action="store_true")
(options, args) = parser.parse_args()
try:
......@@ -70,6 +71,11 @@ finally:
client.launch(new_command)
client.wait()
client.download_output(temp_output_path, temp_directory)
if options.test_errors:
try:
client.download_output(temp_output_path + "x", temp_directory)
except BaseException, e:
traceback.print_exc(e)
output_file = open(temp_output_path, 'r')
try:
output_contents = output_file.read()
......
......@@ -46,6 +46,12 @@ def test_app():
download_response = test_app.get("/download_output?job_id=%s&name=test_output" % job_id)
assert download_response.body == "Hello World!"
try:
test_app.get("/download_output?job_id=%s&name=test_output2" % job_id)
assert False # Should throw exception
except:
pass
command_line = urllib.quote("""python -c "import sys; sys.stdout.write('test_out')" """)
launch_response = test_app.get("/launch?job_id=%s&command_line=%s" % (job_id, command_line))
assert launch_response.body == 'OK'
......
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