summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-08 14:46:38 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-08 14:46:38 +0100
commit4cff3a3ec8b9bf88f31449f2a52f9c4de2d7d77e (patch)
treefce8611b19ac9b2804f6dfb9ac30c0e7c03b12e3
parent6ad3ba51287b1578d8882f3645dfa75c0a7d256f (diff)
downloadlorry-controller-4cff3a3ec8b9bf88f31449f2a52f9c4de2d7d77e.tar.gz
Cope with lorries changing uuid and being destroyed in the same run
-rwxr-xr-xlorry-controller8
-rw-r--r--lorrycontroller/workingstate.py3
2 files changed, 7 insertions, 4 deletions
diff --git a/lorry-controller b/lorry-controller
index b1f4d86..ba793ad 100755
--- a/lorry-controller
+++ b/lorry-controller
@@ -91,7 +91,11 @@ class LorryController(cliapp.Application):
for dead_lorry in prev_lorries - cur_lorries:
logging.info("Dead lorry: %s" % dead_lorry)
conf_uuid = mgr.lorry_state[dead_lorry]['conf']
- should_delete = self.conf.configs[conf_uuid]['destroy']
+ if conf_uuid in self.conf.configs:
+ should_delete = self.conf.configs[conf_uuid]['destroy']
+ else:
+ # Could not find UUID in config, switch to 'never'
+ should_delete = "never"
# TODO: also handle 'unchanged'
if should_delete == "always":
logging.warning("TODO: Delete from Trove")
@@ -121,6 +125,7 @@ class LorryController(cliapp.Application):
store_state = False
if store_state:
mgr.lorry_state[new_lorry] = {
+ 'destroy': conf['destroy'],
'conf': conf_uuid,
'lorry': lorry,
'next-due': nextdue,
@@ -140,6 +145,7 @@ class LorryController(cliapp.Application):
conf_uuid = lorry['controller-uuid']
nextdue = self.conf.duetimes[upd_lorry]
mgr.lorry_state[upd_lorry] = {
+ 'destroy': conf['destroy'],
'conf': conf_uuid,
'lorry': lorry,
'next-due': nextdue,
diff --git a/lorrycontroller/workingstate.py b/lorrycontroller/workingstate.py
index f6f8128..1812ad5 100644
--- a/lorrycontroller/workingstate.py
+++ b/lorrycontroller/workingstate.py
@@ -65,9 +65,6 @@ class WorkingStateManager(object):
self.lorry_state_file)
with open(self.lorry_state_file, "r") as fh:
self.lorry_state = json.load(fh)
- for lorry_name, dct in self.lorry_state.iteritems():
- if type(dct['conf']) == dict:
- dct['conf'] = dct['uuid']
else:
self.lorry_state = dict()