summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-02 14:51:00 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-10-02 14:59:50 +0100
commit704695b55eedc77eec565719faa11f404754a5af (patch)
treead62d50cf40c49b8d5a8afdc17c34741dfd8f660
parentb896af73870c4cf4027b8d997b78cb50ef1fdf0f (diff)
downloadlorry-controller-704695b55eedc77eec565719faa11f404754a5af.tar.gz
Parse and validate trove config and maintain some state
-rwxr-xr-xlorry-controller10
-rw-r--r--lorry-controller.conf1
-rw-r--r--lorrycontroller/confparser.py38
-rw-r--r--lorrycontroller/workingstate.py13
4 files changed, 58 insertions, 4 deletions
diff --git a/lorry-controller b/lorry-controller
index 9d96b9a..ce60989 100755
--- a/lorry-controller
+++ b/lorry-controller
@@ -79,6 +79,8 @@ class LorryController(cliapp.Application):
'git/lorry-controller.conf')
with WorkingStateManager(self) as mgr:
+ # Update any troves
+ self.conf.update_troves(mgr)
prev_lorries = set(mgr.lorry_state.keys())
cur_lorries = set(self.conf.lorries.keys())
logging.debug("Starting processing. Previously %d lorries "
@@ -155,9 +157,11 @@ class LorryController(cliapp.Application):
if earliest_due is None or due < earliest_due:
earliest_due = due
what_early_due = lorry
-
- logging.debug("Lorried %d. %s due in %d seconds" % (
- lorried, what_early_due, int(earliest_due - now)))
+ if earliest_due is None:
+ logging.debug("Lorried %d. No idea what's next." % lorried)
+ else:
+ logging.debug("Lorried %d. %s due in %d seconds" % (
+ lorried, what_early_due, int(earliest_due - now)))
logging.debug("All done.")
def rungit(self, args):
self.runcmd(['git']+args, cwd=os.path.join(self.settings['work-area'],
diff --git a/lorry-controller.conf b/lorry-controller.conf
index 0600608..378f45a 100644
--- a/lorry-controller.conf
+++ b/lorry-controller.conf
@@ -1,6 +1,7 @@
[
{
"type": "trove",
+ "uuid": "SomethingUniqueToIdentifyThisStanzaShouldItChange",
"serial": 1,
"trovehost": "git.baserock.org",
"ls-interval": "1H",
diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py
index d23cf4c..cc8f0e5 100644
--- a/lorrycontroller/confparser.py
+++ b/lorrycontroller/confparser.py
@@ -65,6 +65,8 @@ class LorryControllerConfig(object):
def _validate__generics(self, entry):
'''Validate the generic entries such as 'serial'.'''
+ if type(entry.get('uuid', None)) != unicode:
+ self._give_up("UUID missing, cannot reconcile without it!")
for key, defval in default_values:
if type(defval) != type(entry[key]):
self._give_up("Invalid type for '%s': %r" % (key, entry[key]))
@@ -73,6 +75,9 @@ class LorryControllerConfig(object):
self._give_up("Invalid value for create: unchanged")
self._validate__when(entry, 'destroy')
entry['interval-parsed'] = self._parse_interval(entry['interval'])
+ if 'ls-interval' in entry:
+ entry['ls-interval-parsed'] = \
+ self._parse_interval(entry['ls-interval'])
def _validate__when(self, entry, key):
if entry[key] not in valid_whens:
@@ -142,7 +147,38 @@ class LorryControllerConfig(object):
starttime += step
logging.debug("Now loaded %d lorries" % len(self.lorries.keys()))
-
+
+ def _validate_trove(self, entry):
+ # Validate top levels
+ if type(entry.get('trovehost', None)) != unicode:
+ self._give_up("Trove host %r is not a string" %
+ entry.get('trovehost', None))
+ if 'ls-interval-parsed' not in entry:
+ self._give_up("No ls-interval specified for %s" %
+ entry['trovehost'])
+ if type(entry.get('prefixmap', None)) != dict:
+ self._give_up("Prefixmap not a dict for %s" %
+ entry['trovehost'])
+ if type(entry.get('ignore', [])) != list:
+ self._give_up("Ignore is not a list for %s" %
+ entry['trovehost'])
+ # Validate prefixmap
+ for local, remote in entry['prefixmap'].iteritems():
+ if type(local) != unicode:
+ self._give_up("Local part of prefixmap is not a string: %r" %
+ local)
+ if type(remote) != unicode:
+ self._give_up("Remote part of prefixmap is not a string: %r" %
+ remote)
+ # Validate ignore
+ for ign in entry.get('ignore', []):
+ if type(ign) != unicode:
+ self._give_up("Part of ignore list is not a string: %r" % ign)
+
+ def update_troves(self, statemgr):
+ # Now that we have a state manager we can look at the trove data.
+ pass
+
def _give_up(self, *args, **kwargs):
logging.error(*args, **kwargs)
raise SystemExit(5)
diff --git a/lorrycontroller/workingstate.py b/lorrycontroller/workingstate.py
index 2064005..c4b031f 100644
--- a/lorrycontroller/workingstate.py
+++ b/lorrycontroller/workingstate.py
@@ -58,6 +58,8 @@ class WorkingStateManager(object):
def _load_state(self):
self.lorry_state_file = os.path.join(self.workdir,
"last-lorry-state.json")
+ self.trove_state_file = os.path.join(self.workdir,
+ "last-trove-state.json")
if os.path.exists(self.lorry_state_file):
logging.debug("Loading state file: %s" % self.lorry_state_file)
with open(self.lorry_state_file, "r") as fh:
@@ -65,11 +67,22 @@ class WorkingStateManager(object):
else:
self.lorry_state = dict()
+ if os.path.exists(self.trove_state_file):
+ logging.debug("Loading state file: %s" % self.trove_state_file)
+ with open(self.trove_state_file, "r") as fh:
+ self.trove_state = json.load(fh)
+ else:
+ self.trove_state = dict()
+
def save_state(self):
logging.debug("Serialising state: %s" % self.lorry_state_file)
with open(self.lorry_state_file, "w") as fh:
json.dump(self.lorry_state, fh, sort_keys=True, indent=4)
fh.write("\n")
+ logging.debug("Serialising state: %s" % self.trove_state_file)
+ with open(self.trove_state_file, "w") as fh:
+ json.dump(self.trove_state, fh, sort_keys=True, indent=4)
+ fh.write("\n")
def runner(self, lorryname):
return LorryFileRunner(self, lorryname)