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']
33 def upload_result(self, case_name, raw_data):
35 print('No target was set, so no data will be posted.')
37 self.result["case_name"] = case_name
38 self.result["details"] = raw_data
41 print('Result to be uploaded:\n %s' % json.dumps(self.result))
42 res = requests.post(self.target,
43 data=json.dumps(self.result),
46 print('Test result posting finished with status code %d.' % res.status_code)
47 except Exception as err:
48 print ('Failed to record result data: %s', err)
53 #data = '{"details": [{"client": 200, "throughput": 20}, {"client": 300, "throughput": 20}], "case_name": "rubbos"}'
55 print ("no argumens input!!")
58 with open(sys.argv[1],'r') as stream:
59 data = json.load(stream)
60 Uploader().upload_result(data)
62 if __name__ == "__main__":