diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-02-20 18:08:21 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-02-20 18:08:21 +0000 |
commit | 9e9b30252a87a307646080882251edc63615956a (patch) | |
tree | 5d39907ad3509afc1dfb3c9cfccbdc3db221c60a | |
parent | 93859df18806f4edc1f225ebddd804d6e81d2c58 (diff) | |
download | lorry-controller-9e9b30252a87a307646080882251edc63615956a.tar.gz |
Add yarn for no lorry-controller.conf
-rwxr-xr-x | lorry-controller-webapp | 11 | ||||
-rw-r--r-- | yarns.webapp/030-queue-management.yarn | 33 | ||||
-rw-r--r-- | yarns.webapp/900-implementations.yarn | 25 | ||||
-rw-r--r-- | yarns.webapp/yarn.sh | 12 |
4 files changed, 79 insertions, 2 deletions
diff --git a/lorry-controller-webapp b/lorry-controller-webapp index a8c7fdd..6a3b0e2 100755 --- a/lorry-controller-webapp +++ b/lorry-controller-webapp @@ -16,6 +16,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import errno import logging import json import os @@ -206,8 +207,14 @@ class ReadConfiguration(LorryControllerRoute): filename = os.path.join( self.app_settings['configuration-directory'], 'lorry-controller.conf') - with open(filename) as f: - return json.load(f) + try: + with open(filename) as f: + return json.load(f) + except IOError as e: + if e.errno == errno.ENOENT: + # File doesn't exist. Return an empty configuration. + return [] + bottle.abort(500, 'Error reading %s: %s' % (filename, e)) class ListQueue(LorryControllerRoute): diff --git a/yarns.webapp/030-queue-management.yarn b/yarns.webapp/030-queue-management.yarn index b58a63f..32ad7cd 100644 --- a/yarns.webapp/030-queue-management.yarn +++ b/yarns.webapp/030-queue-management.yarn @@ -33,3 +33,36 @@ new one, and verify that the `running-queue` status is still `true`. Finally, clean up. FINALLY WEBAPP terminates + + +Read CONFGIT +------------ + +We need to be able to get Lorry Controller, specifically WEBAPP, to +update its configuration and run-queue from CONFGIT using the +`/1.0/read-configuration` HTTP API request. + +First, set up WEBAPP. + + SCENARIO WEBAPP updates its configuration from CONFGIT + GIVEN a new git repository in CONFGIT + AND WEBAPP uses CONFGIT as its configuration directory + AND a running WEBAPP + +We'll start with an empty configuration. This is the default state +when WEBAPP has never read its configuration. + + WHEN admin makes request GET /1.0/list-queue + THEN response has queue set to [] + +Make WEBAPP read an empty configuration. Or rather, a configuration +that does not match any existing `.lorry` files. + + GIVEN an empty lorry-controller.conf in CONFGIT + WHEN admin makes request GET /1.0/read-configuration + AND admin makes request GET /1.0/list-queue + THEN response has queue set to [] + +Finally, clean up. + + FINALLY WEBAPP terminates diff --git a/yarns.webapp/900-implementations.yarn b/yarns.webapp/900-implementations.yarn index 01c6fbe..003096f 100644 --- a/yarns.webapp/900-implementations.yarn +++ b/yarns.webapp/900-implementations.yarn @@ -30,6 +30,7 @@ be running until it crashes or is explicitly killed. start-stop-daemon -S -x "$SRCDIR/lorry-controller-webapp" \ -b -p "$DATADIR/webapp.pid" -m --verbose \ -- \ + --configuration-directory "$DATADIR/confgit" \ --statedb "$DATADIR/webapp.db" \ --status-html "$DATADIR/lc-status.html" \ --log-level debug \ @@ -64,6 +65,30 @@ Also test that WEBAPP isn't running. exit 1 fi +Managing Lorry Controller configuration +--------------------------------------- + +We need to be able to create, and change, the `lorry-controller.conf` +file, and other files, in CONFGIT. First of all, we need to create +CONFGIT. + + IMPLEMENTS GIVEN a new git repository in (\S+) + git init "$DATADIR/$MATCH_1" + +Then we need to create an empty `lorry-controller.conf` file there. +This is not just an empty file, it must be a JSON file that contains +an empty list object. + + IMPLEMENTS GIVEN an empty lorry-controller.conf in (\S+) + printf '[]\n' > "$DATADIR/$MATCH_1/lorry-controller.conf" + +Further, we need to be able to tell WEBAPP, when it runs, where the +configuration directory is. + + IMPLEMENTS GIVEN WEBAPP uses (\S+) as its configuration directory + add_to_config_file "$DATADIR/webapp.conf" \ + configuration-directory "$DATADIR/$MATCH_1" + Making and analysing GET requests --------------------------------- diff --git a/yarns.webapp/yarn.sh b/yarns.webapp/yarn.sh index 58af354..a5f22b5 100644 --- a/yarns.webapp/yarn.sh +++ b/yarns.webapp/yarn.sh @@ -30,3 +30,15 @@ kill_daemon_using_pid_file() echo "Error killing daemon running as pid $pid" fi } + + +# Add a configuration item to a cliapp-style configuration file. + +add_to_config_file() +{ + if [ ! -e "$1" ] + then + printf '[config]\n' > "$1" + fi + printf '%s = %s\n' "$2" "$3" >> "$1" +} |