def cancel_test(): """Cancel a scheduled test""" test_id = request.form['test_id'] test = db.get_test(test_id) # If test is scheduled, we can immediately cancel. # If test is already in progress, we need to mark as # cancel_pending to await the client to cancel the job itself. new_status = 'cancelled' if test['status'] == 'in_progress' or test['status'] == 'cancel_pending': new_status = 'cancel_pending' if user_in_role('admin'): db.update_test_status(test_id, new_status) else: # Check if the test is owned by the user: if test['user'] == get_user_id(): db.update_test_status(test_id, new_status) else: return make_response( jsonify({ 'error': 'Access Denied to modify test {test_id}'.format( test_id=test_id) }), 401) return jsonify({'success': 'Test cancelled'})
def get_test(test_id): """Retrieve the definition for a scheduled test""" try: test = db.get_test(test_id) return jsonify(test) except UnknownTestError: return make_response(jsonify({'error':'Unknown Test {test_id}.'.format(test_id=test_id)}), 404)
def view_test(test_id): try: test = db.get_test(test_id) except UnknownTestError: return make_response('Unknown Test {test_id}.'.format(test_id=test_id), 404) artifacts = db.get_test_artifacts(test_id) has_chart = False for a in artifacts: if a['artifact_type'] in ['failure','link']: # Proactively fetch non-blob artifacts: a['artifact'] = db.get_test_artifact_data(test_id, a['artifact_type'], a['name']) if a['artifact_type'] == 'stats': has_chart = True return render_template('view_test.jinja2.html', test=test, artifacts=artifacts, has_chart=has_chart)
def view_test(test_id): try: test = db.get_test(test_id) except UnknownTestError: return make_response("Unknown Test {test_id}.".format(test_id=test_id), 404) artifacts = db.get_test_artifacts(test_id) has_chart = False for a in artifacts: if a["artifact_type"] in ["failure", "link"]: # Proactively fetch non-blob artifacts: a["artifact"] = db.get_test_artifact_data(test_id, a["artifact_type"], a["name"]) if a["artifact_type"] == "stats": has_chart = True return render_template("view_test.jinja2.html", test=test, artifacts=artifacts, has_chart=has_chart)
def cancel_test(): """Cancel a scheduled test""" test_id = request.form['test_id'] test = db.get_test(test_id) # If test is scheduled, we can immediately cancel. # If test is already in progress, we need to mark as # cancel_pending to await the client to cancel the job itself. new_status = 'cancelled' if test['status'] == 'in_progress' or test['status'] == 'cancel_pending': new_status = 'cancel_pending' if user_in_role('admin'): db.update_test_status(test_id, new_status) else: # Check if the test is owned by the user: if test['user'] == get_user_id(): db.update_test_status(test_id, new_status) else: return make_response(jsonify({'error':'Access Denied to modify test {test_id}' .format(test_id=test_id)}), 401) return jsonify({'success':'Test cancelled'})
def cancel_test(): """Cancel a scheduled test""" test_id = request.form["test_id"] test = db.get_test(test_id) # If test is scheduled, we can immediately cancel. # If test is already in progress, we need to mark as # cancel_pending to await the client to cancel the job itself. new_status = "cancelled" if test["status"] == "in_progress" or test["status"] == "cancel_pending": new_status = "cancel_pending" if user_in_role("admin"): db.update_test_status(test_id, new_status) else: # Check if the test is owned by the user: if test["user"] == get_user_id(): db.update_test_status(test_id, new_status) else: return make_response( jsonify({"error": "Access Denied to modify test {test_id}".format(test_id=test_id)}), 401 ) return jsonify({"success": "Test cancelled"})
except zmq.error.ZMQError, e: if e.errno == zmq.POLLERR: log.error(e) # Interrupted zmq socket code, reinitialize: # I get this when I resize my terminal.. WTF? zmq_socket = setup_zmq() finally: tests = db.get_scheduled_tests(context['cluster'], limit=1) if len(tests) > 0: test_id = tests[0]['test_id'] break else: # Send no-work-yet message: console_publish(context['cluster'], {'ctl':'WAIT'}) command.respond(action='wait', follow_up=False) test = db.get_test(test_id) # Give the test to the client: response = command.respond(test=test) # Expect an prepared status message back: assert response['test_id'] == test['test_id'] and \ response['status'] == 'prepared' # Update the test status: db.update_test_status(test['test_id'], 'in_progress') # Let the client know they can start it: response.respond(test_id=test['test_id'], status="in_progress", done=True) def test_done(command): """Receive completed test artifacts from client""" db.update_test_status(command['test_id'], command['status']) # Record test failure message, if any: if command['status'] == 'failed':
except zmq.error.ZMQError, e: if e.errno == zmq.POLLERR: log.error(e) # Interrupted zmq socket code, reinitialize: # I get this when I resize my terminal.. WTF? zmq_socket = setup_zmq() finally: tests = db.get_scheduled_tests(context['cluster'], limit=1) if len(tests) > 0: test_id = tests[0]['test_id'] break else: # Send no-work-yet message: console_publish(context['cluster'], {'ctl': 'WAIT'}) command.respond(action='wait', follow_up=False) test = db.get_test(test_id) # Give the test to the client: response = command.respond(test=test) # Expect an prepared status message back: assert response['test_id'] == test['test_id'] and \ response['status'] == 'prepared' # Update the test status: db.update_test_status(test['test_id'], 'in_progress') # Let the client know they can start it: response.respond(test_id=test['test_id'], status="in_progress", done=True) def test_done(command): """Receive completed test artifacts from client""" db.update_test_status(command['test_id'], command['status'])