diff options
author | Sastry Isukapalli <sastry@research.att.com> | 2018-03-28 22:21:30 -0400 |
---|---|---|
committer | Sastry Isukapalli <sastry@research.att.com> | 2018-03-28 22:57:12 -0400 |
commit | ab7a87456538e561d60d209fe534c175ddd0269c (patch) | |
tree | 1724b218d148f989cf8e3647bc1bd703526f08c8 /test/functest/simulators/oof_dependencies_simulators.py | |
parent | ad29f38cbcb164a7f328b26daf789dbff90deb98 (diff) |
Functest scripts, simulators, and payloads
osdf/adapters/policy/utils.py:
Removed duplicated code (group_policies and group_policies_gen are very similar,
and group_policies seems to be not used
osdf/optimizers/placementopt/conductor/api_builder.py:
changed param name from "grouped_policies" to "flat_policies"
tox.ini
added starup and shutdown of simulators (flask app with mock payloads) in tox tests
rest all files/changes in "test/" folder
quite a few payload files
Patch set 2: removed a "print()" statement from simulator code
Issue-ID: OPTFRA-22
Change-Id: I0006c577fc459c7c884b55e8316c689afd151780
Signed-off-by: Sastry Isukapalli <sastry@research.att.com>
Diffstat (limited to 'test/functest/simulators/oof_dependencies_simulators.py')
-rwxr-xr-x | test/functest/simulators/oof_dependencies_simulators.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/functest/simulators/oof_dependencies_simulators.py b/test/functest/simulators/oof_dependencies_simulators.py new file mode 100755 index 0000000..bdb552d --- /dev/null +++ b/test/functest/simulators/oof_dependencies_simulators.py @@ -0,0 +1,84 @@ +# ------------------------------------------------------------------------- +# Copyright (c) 2018 AT&T Intellectual Property +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +""" +Simulators for dependencies of OSDF (e.g. HAS-API, Policy, SO-callback, etc.) +""" +import glob + +from osdf.utils.interfaces import json_from_file +from flask import Flask, jsonify, request + +app = Flask(__name__) + + +@app.route("/simulated/ERROR/<component>", methods=["GET", "POST"]) +@app.route("/simulated/unhealthy/<component>", methods=["GET", "POST"]) +def error_for_component(component): + """Send an HTTP error for component""" + return jsonify({"error": "{} error".format(component)}), 503 + + +@app.route("/simulated/healthy/<component>", methods=["GET", "POST"]) +def healthy_status_for_component(component): + """Send a health-OK response for component""" + return jsonify({"success": "Passed Health Check for Component {}".format(component)}) + + +@app.route("/simulated/success/<component>", methods=["GET", "POST"]) +def successful_call_for_component(component): + """Send a message about successful call to component""" + return jsonify({"success": "made a call to Component: {}".format(component)}) + + +@app.route("/simulated/oof/has-api/<path:mainpath>", methods=["GET", "POST"]) +def has_api_calls(mainpath): + data, status = get_payload_for_simulated_component('has-api', mainpath) + if not status: + return jsonify(data) + return jsonify(data), 503 + + +def get_payload_for_simulated_component(component, mainpath): + """ + Get the payload for the given path for the given component + :param component: Component we are using (e.g. HAS-API, Policy, SO-callback, etc.) + :param mainpath: path within the URL (e.g. /main/X1/y1/) + :return: Content if file exists, or else 503 error + """ + file_name = "{}/response-payloads/{}".format(component, mainpath) + data = json_from_file(file_name) + if not data: + return {"Error": "Unable to read File {}".format(file_name)}, 503 + return data, None + + +@app.route("/simulated/policy/<sub_component>/getConfig", methods=["POST"]) +def get_policies(sub_component): + """ + Get all policies for this folder + :param sub_component: The folder we are interested in (e.g. "pdp-has-vcpe-good", "pdp-has-vcpe-bad") + :return: A list of policies as a json object (each element is one policy) + """ + main_dir = "policy/response-payloads/" + sub_component + files = glob.glob("{}/*.json".format(main_dir)) + return jsonify([json_from_file(x) for x in files]) + + +if __name__ == "__main__": + app.run(debug=True) |