diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-03-26 15:49:26 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-03-26 15:49:26 +0000 |
commit | b1a78b3f8bcd51b59f28b03dd6bbb9cb124e89a6 (patch) | |
tree | 1dbb2adeb07915343e1879e7c33836208bdd7cd0 | |
parent | 2f9a0bf27a7b14c86f9c91488ab67239cdda4d74 (diff) | |
download | lorry-controller-b1a78b3f8bcd51b59f28b03dd6bbb9cb124e89a6.tar.gz |
Make sure a JSON error in l-c.conf is reported correctly
-rw-r--r-- | lorrycontroller/readconf.py | 15 | ||||
-rw-r--r-- | yarns.webapp/060-validation.yarn | 7 | ||||
-rw-r--r-- | yarns.webapp/900-implementations.yarn | 5 |
3 files changed, 26 insertions, 1 deletions
diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 704561b..a76a1ad 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -27,6 +27,13 @@ import cliapp import lorrycontroller +class LorryControllerConfParseError(Exception): + + def __init__(self, filename, exc): + Exception.__init__( + self, 'ERROR reading %s: %s' % (filename, str(exc))) + + class ReadConfiguration(lorrycontroller.LorryControllerRoute): http_method = 'POST' @@ -36,7 +43,11 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): logging.info('%s %s called', self.http_method, self.path) self.get_confgit() - conf_obj = self.read_config_file() + + try: + conf_obj = self.read_config_file() + except LorryControllerConfParseError as e: + return str(e) self.fix_up_parsed_fields(conf_obj) statedb = self.open_statedb() @@ -111,6 +122,8 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): # File doesn't exist. Return an empty configuration. return [] bottle.abort(500, 'Error reading %s: %s' % (filename, e)) + except ValueError as e: + raise LorryControllerConfParseError(filename, e) def fix_up_parsed_fields(self, obj): for item in obj: diff --git a/yarns.webapp/060-validation.yarn b/yarns.webapp/060-validation.yarn index 82c957d..144c1a1 100644 --- a/yarns.webapp/060-validation.yarn +++ b/yarns.webapp/060-validation.yarn @@ -58,6 +58,13 @@ Add an empty configuration file. This should still work. THEN response matches "Configuration has been updated" AND STATEDB is empty +Add a syntactically invalid JSON file. + + GIVEN a lorry-controller.conf in CONFGIT containing "blah blah blah" + WHEN admin makes request POST /1.0/read-configuration with dummy=value + THEN response matches "ERROR" + AND STATEDB is empty + Clean up at the end. FINALLY WEBAPP terminates diff --git a/yarns.webapp/900-implementations.yarn b/yarns.webapp/900-implementations.yarn index 29ebef7..c88b6fa 100644 --- a/yarns.webapp/900-implementations.yarn +++ b/yarns.webapp/900-implementations.yarn @@ -96,6 +96,11 @@ an empty list object. IMPLEMENTS GIVEN an empty lorry-controller.conf in (\S+) printf '[]\n' > "$DATADIR/$MATCH_1/lorry-controller.conf" +Set the contents of `lorry-controller.conf` from a textual form. + + IMPLEMENTS GIVEN a lorry-controller.conf in (\S+) containing "(.*)"$ + printf '%s\n' "$MATCH_2" > "$DATADIR/$MATCH_1/lorry-controller.conf" + Add a `.lorry` file to be used by a `lorry-controller.conf`. IMPLEMENTS GIVEN Lorry file (\S+) with (.*) |