#
import json
-import Queue
+import queue
from threading import Thread
import uuid
from flask import jsonify
from flask import request
-from summarizer import NFVBenchSummarizer
+from .summarizer import NFVBenchSummarizer
-from log import LOG
-from utils import byteify
-from utils import RunLock
+from .log import LOG
+from .utils import RunLock
-from __init__ import __version__
+from .__init__ import __version__
STATUS_OK = 'OK'
STATUS_ERROR = 'ERROR'
def load_json(data):
- return json.loads(json.dumps(data), object_hook=byteify)
+ return json.loads(json.dumps(data))
def get_uuid():
class Ctx(object):
MAXLEN = 5
- run_queue = Queue.Queue()
+ run_queue = queue.Queue()
busy = False
result = None
results = {}
res = Ctx.results[request_id]
except KeyError:
return None
-
+ # pylint: disable=unsubscriptable-object
if Ctx.result and request_id == Ctx.result['request_id']:
Ctx.result = None
-
- return res
- else:
- res = Ctx.result
- if res:
- Ctx.result = None
return res
+ # pylint: enable=unsubscriptable-object
+ res = Ctx.result
+ if res:
+ Ctx.result = None
+ return res
@staticmethod
def is_busy():
return jsonify(res)
# result for given request_id not found
return jsonify(result_json(STATUS_NOT_FOUND, not_found_msg, request_id))
- else:
- if Ctx.is_busy():
- # task still pending, return with request_id
- return jsonify(result_json(STATUS_PENDING,
- pending_msg,
- Ctx.get_current_request_id()))
-
- res = Ctx.get_result()
- if res:
- return jsonify(res)
- return jsonify(not_busy_json)
+ if Ctx.is_busy():
+ # task still pending, return with request_id
+ return jsonify(result_json(STATUS_PENDING,
+ pending_msg,
+ Ctx.get_current_request_id()))
- return app
+ res = Ctx.get_result()
+ if res:
+ return jsonify(res)
+ return jsonify(not_busy_json)
+ return app
class WebServer(object):
"""This class takes care of the web server. Caller should simply create an instance
# print config
try:
# remove unfilled values as we do not want them to override default values with None
- config = {k: v for k, v in config.items() if v is not None}
+ config = {k: v for k, v in list(config.items()) if v is not None}
with RunLock():
if self.fluent_logger:
self.fluent_logger.start_new_run()
try:
summary = NFVBenchSummarizer(results['result'], self.fluent_logger)
LOG.info(str(summary))
+ if 'json' in config and 'result' in results and results['status']:
+ self.nfvbench_runner.save(results['result'])
except KeyError:
# in case of error, 'result' might be missing
if 'error_message' in results: