diff --git a/test/deploy/linux/python/install/rhel/roles/configure/tasks/main.yml b/test/deploy/linux/python/install/rhel/roles/configure/tasks/main.yml new file mode 100644 index 00000000..ab84bb6e --- /dev/null +++ b/test/deploy/linux/python/install/rhel/roles/configure/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- debug: + msg: Setting up Sample Python application + +- name: Copy files to templates directory + synchronize: + src: "{{ item }}" + dest: ~/ + mode: push + with_fileglob: + - "../templates/*" + become: true + +- name: Install dependencies from requirements.txt + ansible.builtin.pip: + requirements: /home/ec2-user/requirements.txt + umask: "0022" + become: true + diff --git a/test/deploy/linux/python/install/rhel/roles/configure/templates/app.py b/test/deploy/linux/python/install/rhel/roles/configure/templates/app.py new file mode 100644 index 00000000..c5e45876 --- /dev/null +++ b/test/deploy/linux/python/install/rhel/roles/configure/templates/app.py @@ -0,0 +1,100 @@ +import requests +import threading +import time +import uuid +from flask import Flask, jsonify, request +from flask_cors import CORS + +BOOKS = [ + { + 'id': uuid.uuid4().hex, + 'title': 'On the Road', + 'author': 'Jack Kerouac', + 'read': True + }, + { + 'id': uuid.uuid4().hex, + 'title': 'Harry Potter and the Philosopher\'s Stone', + 'author': 'J. K. Rowling', + 'read': False + }, + { + 'id': uuid.uuid4().hex, + 'title': 'Green Eggs and Ham', + 'author': 'Dr. Seuss', + 'read': True + } +] + +# configuration +DEBUG = True + +# instantiate the app +app = Flask(__name__) +app.config.from_object(__name__) + +# enable CORS +CORS(app, resources={r'/*': {'origins': '*'}}) + +# sanity check route +@app.route('/ping', methods=['GET']) +def ping_pong(): + return jsonify('pong!') + +def remove_book(book_id): + for book in BOOKS: + if book['id'] == book_id: + BOOKS.remove(book) + return True + return False + +@app.route('/books', methods=['GET', 'POST']) +def all_books(): + response_object = {'status': 'success'} + if request.method == 'POST': + post_data = request.get_json() + + # break the app here - change to BOOKSSSS + BOOKS.append({ + 'id': uuid.uuid4().hex, + 'title': post_data.get('title'), + 'author': post_data.get('author'), + 'read': post_data.get('read') + }) + response_object['message'] = 'Book added!' + else: + response_object['books'] = BOOKS + return jsonify(response_object) + +@app.route('/books/', methods=['PUT', 'DELETE']) +def single_book(book_id): + response_object = {'status': 'success'} + if request.method == 'PUT': + post_data = request.get_json() + remove_book(book_id) + BOOKS.append({ + 'id': uuid.uuid4().hex, + 'title': post_data.get('title'), + 'author': post_data.get('author'), + 'read': post_data.get('read') + }) + response_object['message'] = 'Book updated!' + if request.method == 'DELETE': + remove_book(book_id) + response_object['message'] = 'Book removed!' + return jsonify(response_object) + +@app.route('/post_book', methods=['POST']) +def somefunction(): + return jsonify('Posted') + +def generate_traffic(): + while True: + requests.get('http://localhost:5000/books') + requests.get('http://localhost:5000/ping') + time.sleep(5) + +if __name__ == '__main__': + traffic_thread = threading.Thread(target=generate_traffic) + traffic_thread.start() + app.run(threaded=True) diff --git a/test/deploy/linux/python/install/rhel/roles/configure/templates/requirements.txt b/test/deploy/linux/python/install/rhel/roles/configure/templates/requirements.txt new file mode 100644 index 00000000..fceec3bf --- /dev/null +++ b/test/deploy/linux/python/install/rhel/roles/configure/templates/requirements.txt @@ -0,0 +1,3 @@ +Flask>=2.2.2 +Flask-Cors==3.0.10 +requests==2.28.1 diff --git a/test/manual/definitions/apm/python/python-al2.json b/test/manual/definitions/apm/python/python-al2.json new file mode 100644 index 00000000..df0fcf7e --- /dev/null +++ b/test/manual/definitions/apm/python/python-al2.json @@ -0,0 +1,27 @@ +{ + "global_tags": { + "owning_team": "virtuoso", + "Environment": "development", + "Department": "product", + "Product": "virtuoso" + }, + "resources": [ + { + "id": "pythonHost", + "provider": "aws", + "type": "ec2", + "size": "t3.small", + "ami_name": "amzn2-ami-hvm-2.0.????????.?-x86_64-gp2", + "user_name": "ec2-user" + } + ], + "services": [ + { + "id": "pythonApp", + "source_repository": "https://github.com/newrelic/open-install-library.git", + "deploy_script_path": "test/deploy/linux/python/install/rhel/roles/", + "port": 80, + "destinations": ["pythonHost"] + } + ] +}