diff options
author | Lars Wirzenius <lwirzenius@wikimedia.org> | 2019-07-19 21:01:21 +0300 |
---|---|---|
committer | Lars Wirzenius <lwirzenius@wikimedia.org> | 2019-07-19 21:01:21 +0300 |
commit | a27b819cd5d75018d2798b54793530c87d7a3914 (patch) | |
tree | 749f68574d723a1806d0fe728990200d3ddbb9c5 | |
parent | 37311766b488a6325abd3a8f486072e0d0e6485c (diff) | |
download | wmf-ci-arch-a27b819cd5d75018d2798b54793530c87d7a3914.tar.gz |
Change: make controller's /trigger call VCSWorker's /updaterepo
-rwxr-xr-x | api.py | 38 |
1 files changed, 33 insertions, 5 deletions
@@ -23,6 +23,7 @@ # which forwards requests to localhost. +import json import logging import os import shutil @@ -372,9 +373,14 @@ class Controller(API): '''A dummy controller API''' - def __init__(self): + VCSWORKER = 'https://wmf2-vcsworker.vm.liw.fi' + DEPLOYER = 'https://wmf2-deployer.vm.liw.fi' + MAX_TRIGGER_TIME = 60 + + def __init__(self, token): super().__init__() - self.builds = [] + self._token = token + self._builds = [] def get_routes(self): return [ @@ -394,11 +400,32 @@ class Controller(API): def _status(self): return { - 'builds': list(self.builds), + 'builds': list(self._builds), } def _trigger(self): - return 'trigger?' + spec = bottle.request.json + if spec is None: + logging.error('Request has null as spec') + logging.debug('Request: %r', dict(bottle.request.headers)) + logging.debug('Request: %r', bottle.request.body.read()) + raise bottle.HTTPError(400) + + logging.info('Triggering build of %r', spec) + self._builds.append(spec) + + url = '{}/updaterepo'.format(self.VCSWORKER) + argv = [ + 'curl', + '-HAuthorization: Bearer {}'.format(self._token), + '-HContent-Type: application/json', + '--data-binary', json.dumps(spec), + url, + ] + ok = runcmd('.', argv, self.MAX_TRIGGER_TIME) + if not ok: + raise bottle.HTTPError(500, 'Error triggering build') + return 'Triggered build' def runcmd(cwd, argv, timeout): @@ -450,7 +477,8 @@ def main(): setup_logging() if cmd == 'controller': - api = Controller() + token = get_token_from_file(args.pop(0)) + api = Controller(token) elif cmd == 'vcsworker': gitlab_token = get_token_from_file(args.pop(0)) artifact_token = get_token_from_file(args.pop(0)) |