Merge lp:~axino/mojo/mojo-specs into lp:mojo/mojo-specs

Proposed by Junien F
Status: Merged
Approved by: Tom Haddon
Approved revision: 105
Merged at revision: 104
Proposed branch: lp:~axino/mojo/mojo-specs
Merge into: lp:mojo/mojo-specs
Diff against target: 75 lines (+44/-0)
3 files modified
charm-testing/squid-reverseproxy/collect (+1/-0)
charm-testing/squid-reverseproxy/deploy (+5/-0)
charm-testing/squid-reverseproxy/post-deploy (+38/-0)
To merge this branch: bzr merge lp:~axino/mojo/mojo-specs
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Review via email: mp+343702@code.launchpad.net

Commit message

squid-reverseproxy : add test

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 104

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm-testing/squid-reverseproxy/collect'
2--- charm-testing/squid-reverseproxy/collect 2018-04-13 11:24:35 +0000
3+++ charm-testing/squid-reverseproxy/collect 2018-04-20 15:32:56 +0000
4@@ -1,5 +1,6 @@
5 squid-reverseproxy lp:~canonical-sysadmins/canonical-is-charms/squid-reverseproxy
6 nrpe cs:{{ series }}/nrpe
7+apache2 cs:apache2
8
9 squid-reverseproxy/exec.d @
10 squid-reverseproxy/exec.d/basenode lp:~canonical-sysadmins/basenode/trunk
11
12=== modified file 'charm-testing/squid-reverseproxy/deploy'
13--- charm-testing/squid-reverseproxy/deploy 2018-04-13 11:24:35 +0000
14+++ charm-testing/squid-reverseproxy/deploy 2018-04-20 15:32:56 +0000
15@@ -3,8 +3,11 @@
16 services:
17 squid-reverseproxy:
18 charm: squid-reverseproxy
19+ expose: True
20 options:
21 cache_dir: /var/spool/squid
22+ apache2:
23+ charm: apache2
24 nrpe:
25 charm: nrpe
26 {% if series == "xenial" or series == "bionic" %}options:
27@@ -12,3 +15,5 @@
28 swap: '-w 90% -c 75% -n ok'{% endif %}
29 relations:
30 - ['squid-reverseproxy', 'nrpe:nrpe-external-master']
31+ - ['apache2', 'nrpe:nrpe-external-master']
32+ - ['apache2:website', 'squid-reverseproxy']
33
34=== added file 'charm-testing/squid-reverseproxy/post-deploy'
35--- charm-testing/squid-reverseproxy/post-deploy 1970-01-01 00:00:00 +0000
36+++ charm-testing/squid-reverseproxy/post-deploy 2018-04-20 15:32:56 +0000
37@@ -0,0 +1,38 @@
38+#!/usr/bin/python3
39+
40+import subprocess
41+import sys
42+from time import sleep
43+import urllib.request
44+import yaml
45+
46+relation_set = ("relation-set -r website:2 services=\"["
47+ "{{'url': 'http://{apache2}:80',"
48+ "'proxy': [{{'proxy_target': 'http://{apache2}:80',"
49+ "'match': 'http://{apache2}:3128'}}]}}]\"")
50+
51+status = yaml.safe_load(subprocess.check_output(['juju', 'status', '--format', 'yaml']))
52+squid_ip = status['applications']['squid-reverseproxy']['units']['squid-reverseproxy/0']['public-address']
53+apache2_ip = status['applications']['apache2']['units']['apache2/0']['public-address']
54+print("Sending relation data...")
55+subprocess.check_call(['juju', 'run', '--unit', 'apache2/0',
56+ relation_set.format(apache2=apache2_ip, squid=squid_ip)])
57+
58+print("Sleeping 60s to wait for hook completion...")
59+sleep(60)
60+
61+print("Testing the cache...")
62+req = urllib.request.Request('http://{}:3128'.format(squid_ip), headers={'Host': apache2_ip})
63+
64+# First request to warm the cache
65+urllib.request.urlopen(req)
66+
67+# Second to hit the cache
68+res = urllib.request.urlopen(req)
69+
70+if res.getcode() == 200 and res.info()['X-Cache'][0:3] == "HIT":
71+ print("SUCCESS : cache hit")
72+ sys.exit(0)
73+else:
74+ print("ERROR : not 200 or no cache hit")
75+ sys.exit(1)

Subscribers

People subscribed via source and target branches

to all changes: