diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-03-31 16:11:15 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-03-31 16:11:15 +0000 |
commit | 215b7086a6d0e7ba94a2f6c1a9448c2baed38d3b (patch) | |
tree | 3610f19329f099862c8e8c11b64fa6b9ae9e04ff | |
parent | f57cb74a5b541d1b34c7af66a564794ef3edb0da (diff) | |
download | lorry-controller-215b7086a6d0e7ba94a2f6c1a9448c2baed38d3b.tar.gz |
Store remote Trove access details in STATEDB
-rw-r--r-- | lorrycontroller/givemejob.py | 15 | ||||
-rw-r--r-- | lorrycontroller/lstroves.py | 10 | ||||
-rw-r--r-- | lorrycontroller/readconf.py | 10 | ||||
-rw-r--r-- | lorrycontroller/route.py | 8 | ||||
-rw-r--r-- | lorrycontroller/statedb.py | 33 | ||||
-rw-r--r-- | yarns.webapp/900-implementations.yarn | 1 |
6 files changed, 54 insertions, 23 deletions
diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py index f620734..590973a 100644 --- a/lorrycontroller/givemejob.py +++ b/lorrycontroller/givemejob.py @@ -41,9 +41,10 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): now = statedb.get_current_time() for lorry_info in lorry_infos: if self.ready_to_run(lorry_info, now): - self.create_repository_in_local_trove(lorry_info) + self.create_repository_in_local_trove( + statedb, lorry_info) if lorry_info['from_trovehost']: - self.copy_repository_metadata(lorry_info) + self.copy_repository_metadata(statedb, lorry_info) self.give_job_to_minion(statedb, lorry_info, now) logging.info( 'Giving job %s to lorry %s to MINION %s:%s', @@ -67,12 +68,12 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): due = lorry_info['last_run'] + lorry_info['interval'] return (lorry_info['running_job'] is None and due <= now) - def create_repository_in_local_trove(self, lorry_info): + def create_repository_in_local_trove(self, statedb, lorry_info): # Create repository on local Trove. If it fails, assume # it failed because the repository already existed, and # ignore the failure (but log message). - local = lorrycontroller.GitanoCommand('localhost') + local = lorrycontroller.GitanoCommand('localhost', 'ssh', None, None) try: local.create(lorry_info['path']) except lorrycontroller.GitanoCommandFailure as e: @@ -82,14 +83,14 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute): else: logging.info('Created %s on local repo', lorry_info['path']) - def copy_repository_metadata(self, lorry_info): + def copy_repository_metadata(self, statedb, lorry_info): '''Copy project.head and project.description to the local Trove.''' assert lorry_info['from_trovehost'] assert lorry_info['from_path'] - remote = lorrycontroller.GitanoCommand(lorry_info['from_trovehost']) - local = lorrycontroller.GitanoCommand('localhost') + remote = self.new_gitano_command(statedb, lorry_info['from_trovehost']) + local = self.new_gitano_command(statedb, 'localhost') try: remote_config = remote.get_gitano_config(lorry_info['from_path']) diff --git a/lorrycontroller/lstroves.py b/lorrycontroller/lstroves.py index 1f18a17..8c80907 100644 --- a/lorrycontroller/lstroves.py +++ b/lorrycontroller/lstroves.py @@ -40,7 +40,7 @@ class TroveRepositoryLister(object): self.app_settings = app_settings def list_trove_into_statedb(self, statedb, trove_info): - remote_paths = self.ls(trove_info) + remote_paths = self.ls(statedb, trove_info) remote_paths = self.skip_ignored_repos(trove_info, remote_paths) repo_map = self.map_remote_repos_to_local_ones( trove_info, remote_paths) @@ -50,11 +50,11 @@ class TroveRepositoryLister(object): now = statedb.get_current_time() statedb.set_trove_ls_last_run(trove_info['trovehost'], now) - def ls(self, trove_info): + def ls(self, statedb, trove_info): if self.app_settings['debug-fake-trove']: repo_paths = self.get_fake_ls_output(trove_info) else: - repo_paths = self.get_real_ls_output(trove_info) + repo_paths = self.get_real_ls_output(statedb, trove_info) return repo_paths @@ -68,8 +68,8 @@ class TroveRepositoryLister(object): return obj['ls-output'] return None - def get_real_ls_output(self, trove_info): - gitano = lorrycontroller.GitanoCommand(trove_info['trovehost']) + def get_real_ls_output(self, statedb, trove_info): + gitano = self.new_gitano_command(statedb, trove_info['trovehost']) output = gitano.ls() return self.parse_ls_output(output) diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 9bbc579..867261a 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -266,8 +266,18 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): return json.dumps(obj, indent=4) def add_trove(self, statedb, section): + username = None + password = None + if 'auth' in section: + auth = section['auth'] + username = auth.get('username') + password = auth.get('password') + statedb.add_trove( trovehost=section['trovehost'], + protocol=section['protocol'], + username=username, + password=password, lorry_interval=section['interval'], lorry_timeout=section.get( 'lorry-timeout', self.DEFAULT_LORRY_TIMEOUT), diff --git a/lorrycontroller/route.py b/lorrycontroller/route.py index 91a406e..1eb4e5b 100644 --- a/lorrycontroller/route.py +++ b/lorrycontroller/route.py @@ -41,5 +41,13 @@ class LorryControllerRoute(object): def open_statedb(self): return lorrycontroller.StateDB(self.app_settings['statedb']) + def new_gitano_command(self, statedb, trovehost): + trove_info = statedb.get_trove_info(trovehost) + return lorrycontroller.GitanoCommand( + trovehost, + trove_info['protocol'], + trove_info['username'], + trove_info['password']) + def run(self, **kwargs): raise NotImplementedError() diff --git a/lorrycontroller/statedb.py b/lorrycontroller/statedb.py index f393e07..b34b736 100644 --- a/lorrycontroller/statedb.py +++ b/lorrycontroller/statedb.py @@ -96,6 +96,9 @@ class StateDB(object): c.execute( 'CREATE TABLE troves (' 'trovehost TEXT PRIMARY KEY, ' + 'protocol TEXT, ' + 'username TEXT, ' + 'password TEXT, ' 'lorry_interval INT, ' 'lorry_timeout INT, ' 'ls_interval INT, ' @@ -206,7 +209,8 @@ class StateDB(object): def get_trove_info(self, trovehost): c = self.get_cursor() c.execute( - 'SELECT lorry_interval, lorry_timeout, ls_interval, ls_last_run, ' + 'SELECT protocol, username, password, lorry_interval, ' + 'lorry_timeout, ls_interval, ls_last_run, ' 'prefixmap, ignore ' 'FROM troves WHERE trovehost IS ?', (trovehost,)) @@ -215,15 +219,19 @@ class StateDB(object): raise lorrycontroller.TroveNotFoundError(trovehost) return { 'trovehost': trovehost, - 'lorry_interval': row[0], - 'lorry_timeout': row[1], - 'ls_interval': row[2], - 'ls_last_run': row[3], - 'prefixmap': row[4], - 'ignore': row[5], + 'protocol': row[0], + 'username': row[1], + 'password': row[2], + 'lorry_interval': row[3], + 'lorry_timeout': row[4], + 'ls_interval': row[5], + 'ls_last_run': row[6], + 'prefixmap': row[7], + 'ignore': row[8], } - def add_trove(self, trovehost=None, lorry_interval=None, + def add_trove(self, trovehost=None, protocol=None, username=None, + password=None, lorry_interval=None, lorry_timeout=None, ls_interval=None, prefixmap=None, ignore=None): logging.debug( @@ -232,6 +240,7 @@ class StateDB(object): prefixmap, ignore) assert trovehost is not None + assert protocol is not None assert lorry_interval is not None assert lorry_timeout is not None assert ls_interval is not None @@ -245,11 +254,13 @@ class StateDB(object): c = self.get_cursor() c.execute( 'INSERT INTO troves ' - '(trovehost, lorry_interval, lorry_timeout, ' + '(trovehost, protocol, username, password, ' + 'lorry_interval, lorry_timeout, ' 'ls_interval, ls_last_run, ' 'prefixmap, ignore) ' - 'VALUES (?, ?, ?, ?, ?, ?, ?)', - (trovehost, lorry_interval, lorry_timeout, ls_interval, 0, + 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + (trovehost, protocol, username, password, + lorry_interval, lorry_timeout, ls_interval, 0, prefixmap, ignore)) else: c = self.get_cursor() diff --git a/yarns.webapp/900-implementations.yarn b/yarns.webapp/900-implementations.yarn index 600f8d0..4f87be9 100644 --- a/yarns.webapp/900-implementations.yarn +++ b/yarns.webapp/900-implementations.yarn @@ -159,6 +159,7 @@ most of the configuration. new = { "type": "troves", "trovehost": MATCH_3, + "protocol": "ssh", "interval": "0s", "ls-interval": "0s", "prefixmap": {}, |