2 ################################################################################
3 # Copyright (c) 2020 AT&T Intellectual Property. #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
24 from flask import Flask, jsonify, send_file
25 from tests.constants import config_file, controls_schema_file, helm_repo_index_response
26 from xapp_onboarder.server import settings
29 logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
30 logging.config.fileConfig(logger_config)
31 log = logging.getLogger(__name__)
33 listen_address = '0.0.0.0:8080'
35 app.config['SERVER_NAME'] = listen_address
42 return {'health': 'OK'}
44 @app.route('/index.yaml')
46 return yaml.dump(helm_repo_index_response)
48 @app.route('/api/charts', methods=['POST'])
50 return {"saved": True}, 201
52 @app.route('/api/charts/test_xapp/1.0.0', methods=['DELETE'])
54 return {"deleted":True}, 200
56 @app.route('/api/charts/test_xapp', methods=['GET'])
57 def get_all_xapp_version():
58 test_xapp = helm_repo_index_response['entries']['test_xapp']
59 return jsonify(test_xapp), 200
61 @app.route('/api/charts', methods=['GET'])
63 return jsonify(helm_repo_index_response['entries']), 200
65 @app.route('/charts/test_xapp-1.0.0.tgz', methods=['GET'])
66 def download_xapp_helm_package():
67 if not os.path.exists(settings.MOCK_TEST_HELM_REPO_TEMP_DIR):
68 os.makedirs(settings.MOCK_TEST_HELM_REPO_TEMP_DIR)
69 with open(settings.MOCK_TEST_HELM_REPO_TEMP_DIR + '/values.yaml', 'w') as file:
70 file.write(json.dumps(helm_repo_index_response))
72 with tarfile.open(settings.MOCK_TEST_HELM_REPO_TEMP_DIR + '/test_xapp-1.0.0.tgz', "w:gz") as tar:
73 tar.addfile(tarfile.TarInfo("test_xapp/values.yaml"), open(settings.MOCK_TEST_HELM_REPO_TEMP_DIR + '/values.yaml'))
75 return send_file(settings.MOCK_TEST_HELM_REPO_TEMP_DIR + '/test_xapp-1.0.0.tgz', mimetype='application/zip')
79 @app.route('/schema.json', methods=['GET'])
83 return controls_schema_file, 200
85 @app.route('/config-file.json', methods=['GET'])
86 def get_config_file():
89 return config_file, 200
92 log.info('>>>>> Starting mock helm_repo at http://{}<<<<<'.format(listen_address))
95 if __name__ == '__main__':