diff options
author | Will Holland <william.holland@codethink.co.uk> | 2015-09-16 22:11:16 +0100 |
---|---|---|
committer | Will Holland <william.holland@codethink.co.uk> | 2015-09-16 22:11:16 +0100 |
commit | 27b0acaa45f6bf27a5ad1dd44c20041a08957387 (patch) | |
tree | 67008d5e4644fa7e1057d9ca511b3b568a433b97 /source | |
parent | 3bfb2aeef694b433de010d569c607d954fe16625 (diff) | |
download | orchestration-27b0acaa45f6bf27a5ad1dd44c20041a08957387.tar.gz |
Redo bottlerock
To make it use the same terminology as master.cfg and cut out the intermediate
scripts
Diffstat (limited to 'source')
-rw-r--r-- | source/bottlerock.py | 122 |
1 files changed, 70 insertions, 52 deletions
diff --git a/source/bottlerock.py b/source/bottlerock.py index 07ea0ef..7a25954 100644 --- a/source/bottlerock.py +++ b/source/bottlerock.py @@ -9,7 +9,7 @@ LOGFILE = '../orch.log' DEFINITIONS = 'ssh://git@cu010-trove.codethink.com/baserock/baserock/definitions' TEST_REPO = 'ssh://git@cu010-trove.codethink.com/cu010-trove/br6/ciat-tester' -trigger_names = [ +categories = [ 'repo_update', 'definitions_update', 'build_complete', @@ -21,78 +21,96 @@ def log(msg): ''' write message to log file with timestamp and script name ''' import datetime global log_file + msg = str(msg) dt = str(datetime.datetime.now()).split('.')[0] to_log = "[%s] Bottlerock: %s" % (dt, msg) print to_log log_file.write('%s\n' % to_log) -def call_trigger(trigger_name,*args): - global trigger_names - assert trigger_name in trigger_names +def sendchange(category,properties): + ''' sendchange to buildbot with category and a dictionary of property names + and their values ''' + + global categories + assert category in categories import subprocess - log('%s trigger' % trigger_name) - trigger_cmd = ['sh','../source/%s.sh' % trigger_name] - for arg in args: trigger_cmd.append(arg) - if subprocess.call(trigger_cmd): + IP=127.0.0.1 + port=9999 + user='orchestration' + password='orchestration' + cmd = [ + '../orchenv-master/bin/buildbot', + 'sendchange', + '-m%s:%d' % (IP,port), + '-a%s:%s' % (user,passwd), + '-Wscriptbot', + '-C%s' % category] + for property in properties.items(): + cmd.append('-p%s:%s' % property) + log(cmd) + if subprocess.call(cmd): return HTTPResponse(status=500) else: return 0 +class Status400(Exception): pass + +def get_form(*properties): + ''' get properties from POST form and return as a dict, if property not + sent in form raise Status400 ''' + + property_dict = {} + for property in properties: + p = request.forms.get(property) + if p: + attr_dict[property] = p + else: + raise Status400(property) + +def missing_property_response(property): + return HTTPResponse( + status=400, + body="400: A %s is required" % property) + @post('/repo_update') def repo_update(): - repo_name = request.forms.get("repo_name") - if not repo_name: - return HTTPResponse( - status=400, - body="400: A repo_name is required") - elif repo_name == DEFINITIONS: - return call_trigger('definitions_update') - elif repo_name == TEST_REPO: - return call_trigger('definitions_update',"force") + try: + properties = get_form("repo_name") + except Status400 as p: + return missing_property_response(p) + if properties['repo_name'] == DEFINITIONS: + return sendchange('definitions_update') + elif properties['repo_name'] == TEST_REPO: + force = {"force":"force"} + return sendchange('definitions_update',force) else: - return call_trigger('repo_update',repo_name) + return sendchange('repo_update',properties) @post('/force_build') def force_build(): - return call_trigger('definitions_update',"force") + force = {"force":"force"} + return sendchange('definitions_update',force) @post('/build_complete') def build_complete(): - system = request.forms.get("system") - if not system: - return HTTPResponse( - status=400, - body="400: A system name is required") - buildslave_scripts_sha = request.forms.get("buildslave_scripts_sha") - if not buildslave_scripts_sha: - return HTTPResponse( - status=400, - body="400: A buildslave_scripts_sha is required") - definitions_sha = request.forms.get("definitions_sha") - if not definitions_sha: - return HTTPResponse( - status=400, - body="400: A definitions_sha is required") - testing_sha = request.forms.get("testing_sha") - if not testing_sha: - return HTTPResponse( - status=400, - body="400: A testing_sha is required") - return call_trigger('build_complete',system,buildslave_scripts_sha,definitions_sha,testing_sha) + try: + properties = get_form( + "system", + "buildslave_scripts_sha", + "definitions_sha", + "testing_sha") + except Status400 as p: + return missing_property_response(p) + return sendchange('build_complete',properties) @post('/deploy_complete') def deploy_complete(): - artefact = request.forms.get("artefact") - if not artefact: - return HTTPResponse( - status=400, - body="400: An artefact name is required") - testing_sha = request.forms.get("testing_sha") - if not testing_sha: - return HTTPResponse( - status=400, - body="400: A testing SHA is required") - return call_trigger('deploy_complete',artefact,testing_sha) + try: + properties = get_form( + 'artefact', + 'testing_sha') + except Status400 as p: + return missing_property_response(p) + return sendchange('deploy_complete',properties) if __name__ == '__main__': run(host='0.0.0.0', port=8080, debug=True) - |