Skip to content

Commit

Permalink
test in UDF
Browse files Browse the repository at this point in the history
  • Loading branch information
kreynoldsf5 committed May 1, 2024
1 parent 238b4fe commit 057b5e6
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 41 deletions.
37 changes: 24 additions & 13 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def eph_ns() -> str:
this_eph_ns = request.cookies.get('eph_ns', None)
return this_eph_ns

def cloudapp_fetch(url, timeout, prop, value, headers = {}):
def cloudapp_fetch(session, url, timeout, prop, value, headers = {}):
"""
Fetch data from URL
Validate prop and value in the JSON response
"""
response = requests.get(url, timeout=timeout, headers=headers)
response = session.get(url, timeout=timeout)
response.raise_for_status()
data = response.json()
if data.get(prop) != value:
Expand Down Expand Up @@ -101,6 +101,7 @@ def arch():
@app.route('/setup', methods=['GET', 'POST'])
def setup():
"""setup page"""
ns = eph_ns()
if request.method == 'POST':
action = request.form['action']
if action == 'save':
Expand All @@ -110,7 +111,7 @@ def setup():
return redirect(url_for('setup'))
response = make_response(redirect('/setup'))
response.set_cookie('eph_ns', this_eph_ns, max_age=60*60*24)
flash("Ephemeral NS successfully set.", "success")
flash('Ephemeral NS successfully set.', "success")
return response
if action == 'clear':
response = make_response(redirect('/setup'))
Expand All @@ -120,7 +121,8 @@ def setup():
html = render_md("markdown/setup.md")
return render_template('setup.html',
title="MCN Practical: Setup",
content=html
content=html,
ns=ns
)

@app.route('/_ce_status')
Expand Down Expand Up @@ -201,8 +203,9 @@ def score():
def ex_test():
"""Example test"""
try:
s = requests.Session()
url = f"https://foo.{app.config['base_url']}/"
data = cloudapp_fetch(url, 5, 'info', 'bar')
data = cloudapp_fetch(s, url, 5, 'info', 'bar')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))
Expand All @@ -211,8 +214,9 @@ def ex_test():
def ex_test2():
"""Example test"""
try:
s = requests.Session()
url = f"https://bar.{app.config['base_url']}/"
data = cloudapp_fetch(url, 5, 'info', 'foo')
data = cloudapp_fetch(s, url, 5, 'info', 'foo')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))
Expand All @@ -222,11 +226,12 @@ def ex_test2():
def lb_aws():
"""Azure LB test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}"
data = cloudapp_fetch(url, 5, 'env', 'AWS')
data = cloudapp_fetch(s, url, 5, 'env', 'AWS')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))
Expand All @@ -235,11 +240,12 @@ def lb_aws():
def lb_azure():
"""Azure LB test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}"
data = cloudapp_fetch(url, 5, 'env', 'Azure')
data = cloudapp_fetch(s, url, 5, 'env', 'Azure')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))
Expand All @@ -248,14 +254,15 @@ def lb_azure():
def route1():
"""First Route Test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
base_url = app.config['base_url']
aws_url = f"https://{ns}.{base_url}/aws/raw"
azure_url = f"https://{ns}.{base_url}/azure/raw"
aws_data = cloudapp_fetch(aws_url, 5, 'env', 'AWS')
azure_data = cloudapp_fetch(azure_url, 5, 'env', 'Azure')
aws_data = cloudapp_fetch(s, aws_url, 5, 'env', 'AWS')
azure_data = cloudapp_fetch(s, azure_url, 5, 'env', 'Azure')
data = {
"aws": aws_data,
"azure": azure_data
Expand All @@ -268,14 +275,17 @@ def route1():
def route2():
"""First Route Test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
base_url = app.config['base_url']
aws_url = f"https://{ns}.{base_url}/"
azure_url = f"https://{ns}.{base_url}/"
aws_data = cloudapp_fetch(aws_url, 5, 'env', 'AWS', headers={"X-MCN-lab": "aws"})
azure_data = cloudapp_fetch(azure_url, 5, 'env', 'Azure', headers={"X-MCN-lab": "azure"})
s.headers["X-MCN-lab"] = "aws"
aws_data = cloudapp_fetch(s, aws_url, 5, 'env', 'AWS')
s.headers["X-MCN-lab"] = "azure"
azure_data = cloudapp_fetch(s, azure_url, 5, 'env', 'Azure', headers={"X-MCN-lab": "azure"})
data = {
"aws": aws_data,
"azure": azure_data
Expand All @@ -288,12 +298,13 @@ def route2():
def manip1():
"""First Manip Test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
base_url = app.config['base_url']
url = f"https://{ns}.{base_url}/"
r_data = cloudapp_fetch(url, 5, 'info[path]', '/')
r_data = cloudapp_fetch(s, url, 5, 'info[path]', '/')
return jsonify(status='success', data=r_data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))
Expand Down
16 changes: 8 additions & 8 deletions labapp/app/markdown/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ Build an origin pool and load balancer based on the exercise requirements.

<ul class="list-group">
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/origin-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
The URL for the cloud app hosted in AWS is <a href="https://aws-cloud-app.mcn-lab.f5demos.com">https://aws-cloud-app.mcn-lab.f5demos.com</a>
</li>
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/origin-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
The cloud app is only reachable from the <strong>student-awsnet</strong> site.
</li>
<li class="list-group-item">
<img src="/static/tls-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/tls-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
The cloud app is TLS only.
</li>
<li class="list-group-item">
<img src="/static/tls-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/tls-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Use the wildcard cert provided in the shared NS, <strong>mcn-lab-wildcard</strong>, to enable TLS on the LB.
</li>
</ul>
Expand Down Expand Up @@ -107,15 +107,15 @@ Create a new origin pool for the Azure cloud app. Reuse your load balancer.

<ul class="list-group">
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/origin-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
The URL for the cloud app hosted in Azure is <a href="https://azure-cloud-app.mcn-lab.f5demos.com">https://aws-cloud-app.mcn-lab.f5demos.com</a>
</li>
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/origin-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
The cloud app is only reachable from the <strong>student-azurenet</strong> site.
</li>
<li class="list-group-item">
<img src="/static/tls-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/tls-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
The cloud app is TLS only.
</li>
</ul>
Expand Down Expand Up @@ -146,5 +146,5 @@ document.getElementById('requestBtn2').addEventListener('click', () => {

<div style="height:25px" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom"></div>

Once you've completed both exercises, move on to the <a href="/route" class="alert-link">http routing</a> exercise.
After completing both exercises, move on to the <strong><a href="/route" class="alert-link">routing</a></strong> exercise.

4 changes: 2 additions & 2 deletions labapp/app/markdown/manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Configure a path <strong>prefix rewrite</strong> to remove part of the request p

<ul class="list-group">
<li class="list-group-item">
<img src="/static/lb-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/lb-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Keep your routing rules from the previous exercise in place.
</li>
<li class="list-group-item">
<img src="/static/lb-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/lb-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Requests to "<u>https://<i>eph-ns</i>.mcn-lab.f5demos.com<strong>/aws/raw</strong></u>" need to arrive at the origin with a path of "<strong>/raw</strong></u>"
</li>
</ul>
Expand Down
10 changes: 5 additions & 5 deletions labapp/app/markdown/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Build routing rules and configure your load balancer to route traffic between th

<ul class="list-group">
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/origin-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Reuse the origin pools from the previous exercise
</li>
<li class="list-group-item">
<img src="/static/lb-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/lb-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Route requests to "<u>https://<i>eph-ns</i>.mcn-lab.f5demos.com/<strong>aws</strong></u>" to the AWS cloud app.
</li>
<li class="list-group-item">
<img src="/static/lb-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/lb-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Route requests to "<u>https://<i>eph-ns</i>.mcn-lab.f5demos.com/<strong>azure</strong></u>" to the Azure cloud app.
</li>
</ul>
Expand Down Expand Up @@ -76,11 +76,11 @@ Build rules to route traffic between the two cloud apps based on an arbitrary HT

<ul class="list-group">
<li class="list-group-item">
<img src="/static/lb-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/lb-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Route requests with an "<strong>X-MCN-Lab: aws</strong>" header to the AWS cloud app.
</li>
<li class="list-group-item">
<img src="/static/lb-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
<img src="/static/lb-icon.png" width="auto" height="50px"> &nbsp; &nbsp;
Route requests with an "<strong>X-MCN-Lab: azure</strong>" header to the Azure cloud app.
</li>
</ul>
Expand Down
10 changes: 6 additions & 4 deletions labapp/app/markdown/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

<div href="/" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom"></div>

Log in to the [lab tenant](https://f5-xc-lab-mcn.console.ves.volterra.io/) and open any namespaced tile (Multi-Cloud App Connect, Distributed Apps, etc.). Your ephemeral namespace is a randomly generated concatenation of _adjective_-_animal_ in the navigation bar towards the top.
Log in to the <strong><a href="https://f5-xc-lab-mcn.console.ves.volterra.io/" target="_blank">lab tenant</a></strong> and open any namespaced tile (Multi-Cloud App Connect, Distributed Apps, etc.). The ephemeral namespace is a randomly generated concatenation of <strong><i>adjective-animal</i></strong> in the navigation bar towards the top.

<img src="/static/eph-ns.png" width="500px" height="auto" alt="eph-ns"/>
<img src="/static/eph-ns.png" width="500px" height="auto" class="rounded" alt="eph-ns"/>

The ephemeral NS name will be used to derive a unique URL for the load balancer used in these exercises.

The ephemeral namespace will be used to derive a unique URL for the load balancer used in the lab exercises.

<form id="setupForm" action="/setup" method="post">
<div class="mb-3">
Expand All @@ -32,4 +33,5 @@ function clearCookie() {
form.appendChild(hiddenInput);
form.submit();
}
</script>
</script>

12 changes: 6 additions & 6 deletions labapp/app/markdown/welcome.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The **site name** is needed when configuring the load balancer advertise policy.

### **Account Provisioning**

Check the email used to launch your UDF deployment for a "welcome" or password reset email to the [lab tenant](https://f5-xc-lab-mcn.console.ves.volterra.io/).
Check the email used to launch your UDF deployment for a "welcome" or password reset email to the <strong><a href="https://f5-xc-lab-mcn.console.ves.volterra.io/" target="_blank">lab tenant</a></strong>.
Update your password and log into the tenant.

<p float="left">
Expand All @@ -49,10 +49,6 @@ Update your password and log into the tenant.
Here's a few things you can do while waiting for the CE to be registered and provisioned:

<ul class="list-group">
<li class="list-group-item">
<i class="bi bi-envelope-exclamation"></i>&nbsp; &nbsp;
Check for the tenant "welcome" email.
</li>
<li class="list-group-item">
<i class="bi bi-book"></i>&nbsp; &nbsp;
Read the lab <strong><a href="/overview">overview</a></strong>.
Expand All @@ -61,6 +57,10 @@ Here's a few things you can do while waiting for the CE to be registered and pro
<i class="bi bi-gear"></i>&nbsp; &nbsp;
Configure lab <strong><a href="/settings">settings</a></strong> after logging into the tenant.
</li>
<li class="list-group-item">
<i class="bi bi-envelope-exclamation"></i>&nbsp; &nbsp;
Check for the tenant "welcome" email.
</li>
<li class="list-group-item">
<i class="bi bi-cup-hot"></i></i>&nbsp; &nbsp;
Get a cup of coffee.
Expand All @@ -70,6 +70,6 @@ Here's a few things you can do while waiting for the CE to be registered and pro

<div style="height:25px" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom"></div>

Welcome to the lab! Next, read an <strong><a href="/overview" class="alert-link">overview</a></strong> that explains the lab environment, tools, and exercises.
Welcome to the lab! Next, read an <strong><a href="/overview">overview</a></strong> that explains the lab environment, tools, and exercises.


9 changes: 6 additions & 3 deletions labapp/app/templates/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
{% block content %}
<div class="markdown-body">
{{ content|safe }}
</div>

<div>
<div class="">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="mt-3">
{% for category, message in messages %}
<div class="alert alert-{{ category }}">{{ message }}</div>
{% endfor %}
</div>
<div>
When ready, start the <strong><a href="/lb" >exercises</a></strong>.
</div>
{% endif %}
{% endwith %}
</div>

</div>

{% endblock %}


0 comments on commit 057b5e6

Please sign in to comment.