def _log(self, url, access_token, logs): num_logs = len(logs) logs_string = json.dumps(logs, sort_keys=True) parameters = { 'access_token': access_token, 'logs': logs_string, } result = requestsJson(url, json=parameters, timeout=300) count_key = 'count' is_good = result != {} and \ count_key in result and \ result[count_key] == num_logs if not is_good: getLogger().error("Submit data to remote server failed") if count_key not in result: getLogger().error("%s is not in request return value", count_key) else: getLogger().error("Sent %d records out of a total of %d", result[count_key], num_logs) else: getLogger().info( "Sent %d records to remote server %s successfully.", num_logs, url) return is_good
def _requestData(self, params): params.update(self.auth_params) result_json = requestsJson(self.benchmark_db_entry, data=params, timeout=NETWORK_TIMEOUT) if "status" not in result_json or result_json['status'] != "success": getLogger().error( "DB post failed, params {}".format(json.dumps(params))) return { "status": "fail", "values": [], } else: return result_json
def upload(self, **kwargs): path = kwargs['file'] if self.server_addr: storage_addr = self.server_addr + "/upload/" getLogger().info("Uploading {} to {}".format(path, storage_addr)) filename = os.path.basename(path) with open(path, "rb") as f: result_json = requestsJson(storage_addr, files={'file': (filename, f.read())}) url = '' if result_json['status'] == 'success': url = os.path.join(self.server_addr, result_json["path"]) getLogger().info("File has been uploaded to {}".format(url)) return url
def _requestData(self, params, retry=True): params.update(self.auth_params) result_json = requestsJson(self.benchmark_db_entry, data=params, timeout=NETWORK_TIMEOUT, retry=retry) if "status" not in result_json or result_json['status'] != "success": getLogger().warning( "DB post failed.\tbenchmark_db_entry: {}\t params: {}".format( self.benchmark_db_entry, json.dumps(params))) for key in result_json: getLogger().error("{}: {}".format(key, result_json[key])) return { "status": "fail", "values": [], } else: return result_json