1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
16 class Uploader(object):
18 def __init__(self, conf):
19 self.headers = {'Content-type': 'application/json'}
22 "project_name": "bottlenecks",
23 "description": "bottlenecks test cases result"}
25 with open(conf) as stream:
26 dashboard_conf = yaml.load(stream)
27 self.result['pod_name'] = dashboard_conf['pod_name']
28 self.result['installer'] = dashboard_conf['installer']
29 self.result['version'] = dashboard_conf['version']
30 self.target = dashboard_conf['target']
32 def upload_result(self, case_name, raw_data):
34 print('No target was set, so no data will be posted.')
36 self.result["case_name"] = case_name
37 self.result["details"] = raw_data
40 print('Result to be uploaded:\n %s' % json.dumps(self.result))
41 res = requests.post(self.target,
42 data=json.dumps(self.result),
46 'Test result posting finished with status code %d.' %
48 except Exception as err:
49 print ('Failed to record result data: %s', err)
54 # data = '{"details": [{"client": 200, "throughput": 20},
55 # {"client": 300, "throughput": 20}], "case_name": "rubbos"}'
57 print ("no argumens input!!")
60 with open(sys.argv[1], 'r') as stream:
61 data = json.load(stream)
62 Uploader().upload_result(data)
65 if __name__ == "__main__":