Merge lp:~benji/charms/precise/juju-gui/fix-cache-headers into lp:~charmers/charms/precise/juju-gui/trunk

Proposed by Benji York
Status: Merged
Merge reported by: Marco Ceppi
Merged at revision: not available
Proposed branch: lp:~benji/charms/precise/juju-gui/fix-cache-headers
Merge into: lp:~charmers/charms/precise/juju-gui/trunk
Prerequisite: lp:~juju-gui/charms/precise/juju-gui/trunk
Diff against target: 199 lines (+64/-23) (has conflicts)
6 files modified
HACKING.md (+5/-2)
Makefile (+8/-2)
config/apache-site.template (+3/-0)
hooks/utils.py (+1/-0)
revision (+4/-0)
tests/20-functional.test (+43/-19)
Text conflict in revision
To merge this branch: bzr merge lp:~benji/charms/precise/juju-gui/fix-cache-headers
Reviewer Review Type Date Requested Status
Francesco Banconi (community) Approve
Gary Poster (community) Approve
charmers Pending
Review via email: mp+177958@code.launchpad.net

Commit message

Add good cache headers to the GUI when served by Apache.

Description of the change

Add good cache headers to the GUI when served by Apache.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

Great, thanks Benji! Thanks also for writing the test: that is very cool.

Nice flyby change to Makefile. Nice approach to juju_deploy.

LGTM

Gary

review: Approve
Revision history for this message
Gary Poster (gary) wrote :

Please land this change in ~juju-gui-charmers *and* ~juju-gui. I would suggest landing it in ~juju-gui-charmers and merging that branch back to ~juju-gui. Your MP is against ~juju-gui: please don't merge other ~juju-gui stuff into ~juju-gui-charmers! Only your fix.

Beware that when you land this against ~juju-gui-charmers *you are making a release of the official charm*. Please qa your changes with that branch before landing.

Revision history for this message
Francesco Banconi (frankban) wrote :

This branch looks good Benji, thank you!
I am doing QA now.
Please take a look at the comment below.

113 + if is_legacy_juju:
114 + hostname = unit_info['public-address']
115 + self.addCleanup(
116 + self.stop_services,
117 + hostname, ['haproxy', 'apache2', 'juju-api-agent'])

It's nice to have this logic abstracted in its own method.
However, while this is correct for test_api_agent, test_cache_headers
and test_branch_source, for test_staging we need to replace
'juju-api-agent' with 'juju-api-improv' in the list of services:

146 - hostname, ['haproxy', 'apache2', 'juju-api-improv'])

Revision history for this message
Francesco Banconi (frankban) wrote :

QA: everything seems to work well.
Started with 0.8.0, played with the GUI and charm browser,
switched to 0.8.1, the GUI looks good.
Thank you!

review: Approve
Revision history for this message
Benji York (benji) wrote :

> It's nice to have this logic abstracted in its own method.
> However, while this is correct for test_api_agent, test_cache_headers
> and test_branch_source, for test_staging we need to replace
> 'juju-api-agent' with 'juju-api-improv' in the list of services:

Good catch. I guess this is one reason I like to remove repetition like
this, it can trick you by not really being repetitious. :)

I've tweaked the juju_deploy method to fix this problem.

Thanks for the review.

72. By Benji York

fix service cleanup

Revision history for this message
Gary Poster (gary) wrote :

Sorry, this branch is against the wrong target!

Benji, the official branch is

lp:~juju-gui-charmers/charms/precise/juju-gui/trunk

Please land on that one, and then merge to lp:~juju-gui/charms/precise/juju-gui/trunk

The target of this MP (lp:~charmers/charms/precise/juju-gui/trunk) is not used for anything much. It is a decoy.

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

This appears to have been merged in to the proper charmstore version of the charm

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING.md'
2--- HACKING.md 2013-07-17 21:30:28 +0000
3+++ HACKING.md 2013-08-01 13:01:28 +0000
4@@ -39,9 +39,12 @@
5 it locally, e.g.:
6
7 bzr checkout --lightweight lp:juju-plugins
8+ ln -s juju-plugins/plugins/juju_test.py juju-test
9+ export PATH="$PATH":`pwd`
10
11-At this point, link "juju-plugins/plugins/juju_test.py" as "juju-test"
12-somewhere in your PATH, so that it is possible to execute "juju-test".
13+Alternatively you may check out lp:juju-plugins and link
14+"juju-plugins/plugins/juju_test.py" as "juju-test" somewhere in your PATH, so
15+that it is possible to execute "juju-test".
16
17 Before being able to run the suite, test requirements need to be installed
18 running the command:
19
20=== modified file 'Makefile'
21--- Makefile 2013-08-01 13:01:27 +0000
22+++ Makefile 2013-08-01 13:01:28 +0000
23@@ -26,7 +26,12 @@
24 ./tests/10-unit.test
25 ./tests/11-server.test
26
27-ftest: setup
28+ensure-juju-test:
29+ @which juju-test > /dev/null \
30+ || (echo 'The "juju-test" command is missing. See HACKING.md.' \
31+ ; false)
32+
33+ftest: setup ensure-juju-test
34 $(JUJUTEST) 20-functional.test
35
36 # This will be eventually removed when we have juju-test --clean-state.
37@@ -62,4 +67,5 @@
38 @echo ' service to be started. If JUJU_ENV is not passed, the charm will'
39 @echo ' be deployed in the default Juju environment.'
40
41-.PHONY: all clean deploy ftest help jujutest lint setup test unittest
42+.PHONY: all clean deploy ensure-juju-test ftest help jujutest lint setup test \
43+ unittest
44
45=== modified file 'config/apache-site.template'
46--- config/apache-site.template 2013-04-23 20:15:28 +0000
47+++ config/apache-site.template 2013-08-01 13:01:28 +0000
48@@ -27,4 +27,7 @@
49
50 FallbackResource /index.html
51
52+ Header unset Cache-Control
53+ Header set Cache-Control "max-age=0, public, must-revalidate"
54+
55 </VirtualHost>
56
57=== modified file 'hooks/utils.py'
58--- hooks/utils.py 2013-08-01 13:01:27 +0000
59+++ hooks/utils.py 2013-08-01 13:01:28 +0000
60@@ -561,6 +561,7 @@
61 with su('root'):
62 run('a2dissite', 'default')
63 run('a2ensite', 'juju-gui')
64+ run('a2enmod', 'headers')
65
66
67 def save_or_create_certificates(
68
69=== modified file 'revision'
70--- revision 2013-07-31 17:30:56 +0000
71+++ revision 2013-08-01 13:01:28 +0000
72@@ -1,1 +1,5 @@
73+<<<<<<< TREE
74 62
75+=======
76+63
77+>>>>>>> MERGE-SOURCE
78
79=== modified file 'tests/20-functional.test'
80--- tests/20-functional.test 2013-06-12 09:07:29 +0000
81+++ tests/20-functional.test 2013-08-01 13:01:28 +0000
82@@ -16,6 +16,7 @@
83 # You should have received a copy of the GNU Affero General Public License
84 # along with this program. If not, see <http://www.gnu.org/licenses/>.
85
86+import httplib
87 import unittest
88 import urlparse
89
90@@ -23,6 +24,8 @@
91 from selenium.webdriver.support import ui
92 from xvfbwrapper import Xvfb
93
94+# XXX 2013-07-30 benji bug=872264: Don't use juju_deploy directly, use
95+# DeployTestMixin.juju_deploy instead. See comment in stop_services.
96 from deploy import juju_deploy
97 from helpers import (
98 juju_destroy_service,
99@@ -129,24 +132,36 @@
100 # Just invoking ``juju destroy-service juju-gui`` in tearDown
101 # should execute the ``stop`` hook, stopping all the services
102 # started by the charm in the machine. Right now this does not
103- # work in pyJuju, so the same behavior is accomplished keeping
104+ # work in pyJuju, so the desired effect is achieved by keeping
105 # track of started services and manually stopping them here.
106 target = 'ubuntu@{0}'.format(hostname)
107 for service in services:
108 ssh(target, 'sudo', 'service', service, 'stop')
109
110+ def juju_deploy(self, *args, **kws):
111+ """Shim in our additional cleanup for pyJuju."""
112+ # XXX 2012-11-29 frankban bug=872264: see *stop_services* above.
113+ # Once pyJuju works correctly or we drop support for it altogether, we
114+ # can remove this shim.
115+ unit_info = juju_deploy(*args, **kws)
116+ if is_legacy_juju:
117+ hostname = unit_info['public-address']
118+ services = ['haproxy', 'apache2']
119+ # Staging uses improv, otherwise the API agent is used.
120+ if kws.get('options').get('staging') == 'true':
121+ services.append('juju-api-improv')
122+ else:
123+ services.append('juju-api-agent')
124+ self.addCleanup(self.stop_services, hostname, services)
125+ return unit_info
126+
127
128 class DeployTest(DeployTestMixin, unittest.TestCase):
129
130 def test_api_agent(self):
131 # Ensure the Juju GUI and API agent services are correctly set up.
132- unit_info = juju_deploy(self.charm)
133+ unit_info = self.juju_deploy(self.charm)
134 hostname = unit_info['public-address']
135- if is_legacy_juju:
136- # XXX 2012-11-29 frankban bug=872264: see *stop_services* above.
137- self.addCleanup(
138- self.stop_services,
139- hostname, ['haproxy', 'apache2', 'juju-api-agent'])
140 self.navigate_to(hostname)
141 self.handle_browser_warning()
142 self.assertEnvironmentIsConnected()
143@@ -154,12 +169,8 @@
144 @unittest.skipUnless(is_legacy_juju, 'staging only works in pyJuju')
145 def test_staging(self):
146 # Ensure the Juju GUI and improv services are correctly set up.
147- unit_info = juju_deploy(self.charm, options={'staging': 'true'})
148+ unit_info = self.juju_deploy(self.charm, options={'staging': 'true'})
149 hostname = unit_info['public-address']
150- # XXX 2012-11-29 frankban bug=872264: see *stop_services* above.
151- self.addCleanup(
152- self.stop_services,
153- hostname, ['haproxy', 'apache2', 'juju-api-improv'])
154 self.navigate_to(hostname)
155 self.handle_browser_warning()
156 self.assertEnvironmentIsConnected()
157@@ -168,22 +179,35 @@
158
159 def test_branch_source(self):
160 # Ensure the Juju GUI is correctly deployed from a Bazaar branch.
161- unit_info = juju_deploy(
162+ unit_info = self.juju_deploy(
163 self.charm, options={'juju-gui-source': JUJU_GUI_TEST_BRANCH})
164 hostname = unit_info['public-address']
165- if is_legacy_juju:
166- # XXX 2012-11-29 frankban bug=872264: see *stop_services* above.
167- self.addCleanup(
168- self.stop_services,
169- hostname, ['haproxy', 'apache2', 'juju-api-agent'])
170 self.navigate_to(hostname)
171 self.handle_browser_warning()
172 self.assertEnvironmentIsConnected()
173
174+ def test_cache_headers(self):
175+ # Make sure the correct cache headers are sent.
176+ unit_info = self.juju_deploy(
177+ self.charm, options={'juju-gui-source': JUJU_GUI_TEST_BRANCH})
178+ hostname = unit_info['public-address']
179+ conn = httplib.HTTPSConnection(hostname)
180+ conn.request('GET', '/')
181+ headers = conn.getresponse().getheaders()
182+ # There is only one Cache-Control header.
183+ self.assertEqual(zip(*headers)[0].count('cache-control'), 1)
184+ # The right cache directives are in Cache-Control.
185+ cache_control = dict(headers)['cache-control']
186+ cache_directives = [s.strip() for s in cache_control.split(',')]
187+ self.assertIn('max-age=0', cache_directives)
188+ self.assertIn('public', cache_directives)
189+ self.assertIn('must-revalidate', cache_directives)
190+
191+
192 @unittest.skipIf(is_legacy_juju, 'force-machine only works in juju-core')
193 def test_force_machine(self):
194 # Ensure the Juju GUI is correctly set up in the Juju bootstrap node.
195- unit_info = juju_deploy(self.charm, force_machine=0)
196+ unit_info = self.juju_deploy(self.charm, force_machine=0)
197 self.assertEqual('0', unit_info['machine'])
198 self.navigate_to(unit_info['public-address'])
199 self.handle_browser_warning()

Subscribers

People subscribed via source and target branches

to all changes: