from flask_socketio import SocketIO
import json
+from log import LOG
import Queue
import traceback
from utils import byteify
app.root_path = root_path
socketio = SocketIO(app, async_mode='threading')
busy_json = result_json(STATUS_ERROR, 'there is already an NFVbench request running')
+ config_is_null_json = result_json(STATUS_ERROR, 'configuration is missing')
not_busy_json = result_json(STATUS_ERROR, 'no pending NFVbench run')
not_found_msg = 'results not found'
pending_msg = 'NFVbench run still pending'
@app.route('/start_run', methods=['POST'])
def start_run():
config = load_json(request.json)
- if Ctx.is_busy():
- return jsonify(busy_json)
+ if config:
+ if Ctx.is_busy():
+ return jsonify(busy_json)
+ else:
+ request_id = get_uuid()
+ Ctx.enqueue(config, request_id)
+ return jsonify(result_json(STATUS_PENDING, pending_msg, request_id))
else:
- request_id = get_uuid()
- Ctx.enqueue(config, request_id)
- return jsonify(result_json(STATUS_PENDING, pending_msg, request_id))
+ return jsonify(config_is_null_json)
@app.route('/status', defaults={'request_id': None}, methods=['GET'])
@app.route('/status/<request_id>', methods=['GET'])
notifications using websocket events (send_ methods). Caller should simply create an instance
of this class and pass a runner object then invoke the run method
"""
- def __init__(self, http_root, runner):
+ def __init__(self, http_root, runner, logger):
self.nfvbench_runner = runner
setup_flask(http_root)
+ self.fluent_logger = logger
def run(self, host='127.0.0.1', port=7556):
# wait for run requests
# the runner must be executed from the main thread (Trex client library requirement)
while True:
+
# print 'main thread waiting for requests...'
config = Ctx.dequeue()
# print 'main thread processing request...'
# 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}
with RunLock():
- results = self.nfvbench_runner.run(config)
+ results = self.nfvbench_runner.run(config, config)
except Exception as exc:
print 'NFVbench runner exception:'
traceback.print_exc()
results = result_json(STATUS_ERROR, str(exc))
+ LOG.exception()
if Ctx.request_from_socketio:
socketio.emit('run_end', results)
# this might overwrite a previously unfetched result
Ctx.set_result(results)
Ctx.release()
+ self.fluent_logger.send_run_summary(True)
def send_interval_stats(self, time_ms, tx_pps, rx_pps, drop_pct):
stats = {'time_ms': time_ms, 'tx_pps': tx_pps, 'rx_pps': rx_pps, 'drop_pct': drop_pct}