summaryrefslogtreecommitdiff
path: root/lorrycontroller/givemejob.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/givemejob.py')
-rw-r--r--lorrycontroller/givemejob.py98
1 files changed, 19 insertions, 79 deletions
diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py
index 9d4d4d2..85f1818 100644
--- a/lorrycontroller/givemejob.py
+++ b/lorrycontroller/givemejob.py
@@ -36,9 +36,16 @@ 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(statedb, lorry_info)
if lorry_info['from_host']:
- self.copy_repository_metadata(statedb, lorry_info)
+ metadata = self.get_repo_metadata(statedb,
+ lorry_info)
+ else:
+ metadata = {}
+ downstream_type = lorrycontroller.downstream_types[
+ self.app_settings['git-server-type']]
+ downstream_type(self.app_settings) \
+ .prepare_repo(lorry_info['path'], metadata)
+
self.give_job_to_minion(statedb, lorry_info, now)
logging.info(
'Giving job %s to lorry %s to MINION %s:%s',
@@ -62,92 +69,23 @@ 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(self, statedb, lorry_info):
- api = self.app_settings['git-server-type']
- if api == 'gitano':
- self.create_repository_in_local_trove(statedb, lorry_info)
- elif api == 'gerrit':
- self.create_gerrit_project(statedb, lorry_info)
- elif api == 'gitlab':
- self.create_gitlab_project(statedb, lorry_info)
- elif api == 'local':
- pass
-
- 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.LocalTroveGitanoCommand()
- try:
- local.create(lorry_info['path'])
- except lorrycontroller.GitanoCommandFailure as e:
- logging.debug(
- 'Ignoring error creating %s on local Trove: %s',
- lorry_info['path'], e)
- else:
- logging.info('Created %s on local repo', lorry_info['path'])
-
- def create_gerrit_project(self, statedb, lorry_info):
- '''Create a project in the local Gerrit server.
-
- The 'lorry' user must have createProject capability in the Gerrit.
-
- '''
- gerrit = lorrycontroller.Gerrit(
- host='localhost', user='lorry')
- project_name = lorry_info['path']
-
- if gerrit.has_project(project_name):
- logging.info('Project %s exists in local Gerrit already.',
- project_name)
- else:
- gerrit.create_project(project_name)
- logging.info('Created %s project in local Gerrit.', project_name)
-
- def create_gitlab_project(self, statedb, lorry_info):
- gitlab = lorrycontroller.Gitlab(
- 'localhost', self.app_settings['gitlab-private-token'])
- project_name = lorry_info['path']
-
- if gitlab.has_project(project_name):
- logging.info('Project %s exists in local GitLab already.',
- project_name)
- else:
- gitlab.create_project(lorry_info['path'])
- logging.info('Created %s project in local GitLab.', project_name)
-
- def copy_repository_metadata(self, statedb, lorry_info):
- '''Copy project.head and project.description to the local Trove.'''
+ def get_repo_metadata(self, statedb, lorry_info):
+ '''Get repository head and description.'''
assert lorry_info['from_host']
assert lorry_info['from_path']
- if self.app_settings['git-server-type'] != 'gitano':
- # FIXME: would be good to have this info in Gerrit too
- return
+ # XXX We don't know whether upstream is Trove
+ metadata = {}
remote = lorrycontroller.new_gitano_command(statedb, lorry_info['from_host'])
- local = lorrycontroller.LocalTroveGitanoCommand()
try:
remote_config = remote.get_gitano_config(lorry_info['from_path'])
- local_config = local.get_gitano_config(lorry_info['path'])
-
- if remote_config['project.head'] != local_config['project.head']:
- local.set_gitano_config(
- lorry_info['path'],
- 'project.head',
- remote_config['project.head'])
-
- if not local_config['project.description']:
- desc = '{host}: {desc}'.format(
- host=lorry_info['from_host'],
- desc=remote_config['project.description'])
- local.set_gitano_config(
- lorry_info['path'],
- 'project.description',
- desc)
+ metadata['head'] = remote_config['project.head']
+ metadata['description'] = '{host}: {desc}'.format(
+ host=lorry_info['from_host'],
+ desc=remote_config['project.description'])
except lorrycontroller.GitanoCommandFailure as e:
logging.error('ERROR: %s' % str(e))
# FIXME: We need a good way to report these errors to the
@@ -155,6 +93,8 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute):
# request, so that's not the way to do this. Needs
# thinking.
+ return metadata
+
def give_job_to_minion(self, statedb, lorry_info, now):
path = lorry_info['path']
minion_host = bottle.request.forms.host