+++ /dev/null
-##############################################################################\r
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd. and others\r
-#\r
-# All rights reserved. This program and the accompanying materials\r
-# are made available under the terms of the Apache License, Version 2.0\r
-# which accompanies this distribution, and is available at\r
-# http://www.apache.org/licenses/LICENSE-2.0\r
-##############################################################################\r
-import os\r
-import argparse\r
-import json\r
-import requests\r
-import logging\r
-__author__ = "qwyang0126@gmail.com"\r
-__date__ = "2016-01-11"\r
-LOG = logging.getLogger(__name__)\r
-\r
-\r
-class Uploader(object):\r
- def __init__(self, conf):\r
- self.headers = {'Content-type': 'application/json'}\r
- self.timeout = 5\r
- self.result = {\r
- "project_name": "bottlenecks",\r
- "description": "bottlenecks test cases result"}\r
-\r
- with open(conf) as stream:\r
- dashboard_conf = json.load(stream)\r
- self.result['pod_name'] = dashboard_conf['pod_name']\r
- self.result['installer'] = dashboard_conf['installer']\r
- self.result['version'] = dashboard_conf['version']\r
- self.target = dashboard_conf['target']\r
-\r
- def upload_result(self, case_name, raw_data):\r
- if self.target == '':\r
- LOG.error('No target was set, so no data will be posted.')\r
- return\r
- self.result["case_name"] = case_name\r
- self.result["details"] = raw_data\r
- try:\r
- LOG.debug('Result to be uploaded:\n %s' % json.dumps(self.result, indent=4))\r
- res = requests.post(self.target,\r
- data=json.dumps(self.result),\r
- headers=self.headers,\r
- timeout=self.timeout)\r
- print('Test result posting finished with status code %d.' % res.status_code)\r
- except Exception as err:\r
- LOG.error('Failed to record result data: %s', err)\r
-\r
-\r
-if __name__ == "__main__":\r
- logging.basicConfig(level=logging.DEBUG)\r
- parser = argparse.ArgumentParser()\r
- parser.add_argument('--config', required=True, help="basic config file for uploader, json format.")\r
- parser.add_argument('--dir', required=True, help="result files for test cases")\r
- args = parser.parse_args()\r
- realpath = os.path.realpath(args.dir)\r
- for filename in os.listdir(args.dir):\r
- filepath = os.path.join(realpath, filename)\r
- LOG.debug("uploading test result from file:%s", filepath)\r
- with open(filepath) as stream:\r
- result = eval(stream.read())\r
- Uploader(args.config).upload_result(filename.lower().replace('-', ''), result)\r