Merge lp:~free.ekanayaka/landscape-charm/no-combo-loader-support into lp:~landscape/landscape-charm/stable

Proposed by Free Ekanayaka
Status: Merged
Approved by: Free Ekanayaka
Approved revision: 219
Merged at revision: 218
Proposed branch: lp:~free.ekanayaka/landscape-charm/no-combo-loader-support
Merge into: lp:~landscape/landscape-charm/stable
Diff against target: 289 lines (+105/-26)
3 files modified
hooks/hooks.py (+28/-7)
hooks/test_hooks.py (+77/-5)
tests/01-begin.py (+0/-14)
To merge this branch: bzr merge lp:~free.ekanayaka/landscape-charm/no-combo-loader-support
Reviewer Review Type Date Requested Status
Данило Шеган (community) Approve
Geoff Teale (community) Approve
Chad Smith Pending
Review via email: mp+248524@code.launchpad.net

Commit message

Support both LDS packages with and and without combo-loader.

Description of the change

Support both LDS packages with and and without combo-loader.

Packages with combo-loader are the ones currently released, while packages without the combo-loader are then ones built after:

https://code.launchpad.net/~free.ekanayaka/landscape/consolidate-combo-loader/+merge/248254

lands.

To post a comment you must log in.
219. By Free Ekanayaka

Fix combo-loader apache rule

Revision history for this message
Geoff Teale (tealeg) wrote :

+1 All looks good.

review: Approve
Revision history for this message
Данило Шеган (danilo) wrote :

Looks good. I haven't noticed that this is against the stable charm at first, so I was worried that we'd be dragging compatibility code with us forever, but since we are re-working the charm altogether, nothing to worry about.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2015-01-27 04:05:15 +0000
3+++ hooks/hooks.py 2015-02-04 12:18:28 +0000
4@@ -119,11 +119,21 @@
5 haproxy_service = re.sub("\W", "", haproxy_service)
6 return haproxy_service
7
8+COMBO_LOADER_VHOST_ENTRY = (
9+ " RewriteRule ^/combo http://{{ haproxy_comboloader }}/ [P,L]\n")
10+
11+NO_COMBO_LOADER_VHOST_ENTRY = (
12+ " RewriteRule "
13+ "^/combo(.*) http://{{ haproxy_appserver }}/combo$1 [P,L]\n")
14+
15
16 def _get_vhost_template(template_filename, haproxy_service_name):
17 """Expand the template with the provided haproxy service name."""
18 with open("%s/config/%s" % (ROOT, template_filename), "r") as handle:
19 contents = handle.read()
20+ if not HAS_COMBO_LOADER:
21+ contents = contents.replace(
22+ COMBO_LOADER_VHOST_ENTRY, NO_COMBO_LOADER_VHOST_ENTRY)
23 contents = re.sub(r"{{ haproxy_([^}]+) }}", r"{{ %s_\1 }}" %
24 haproxy_service_name, contents)
25 return contents
26@@ -654,6 +664,8 @@
27 count = service_count
28 if re.match(r"^.*:\d+$", service_count):
29 (service, count) = service_count.split(":")
30+ if service == "combo-loader" and not HAS_COMBO_LOADER:
31+ continue
32 result[service] = count
33 return result
34
35@@ -668,6 +680,8 @@
36 result = {}
37 requested = _get_requested_service_count()
38 for service in _get_requested_services():
39+ if service == "combo-loader" and not HAS_COMBO_LOADER:
40+ continue
41 args = [service]
42 args.extend(SERVICE_COUNT[service])
43 args.append(requested[service])
44@@ -752,6 +766,8 @@
45 config = juju.config_get()
46 if "services" in config:
47 for service in config["services"].split():
48+ if service == "combo-loader" and not HAS_COMBO_LOADER:
49+ continue
50 if service not in SERVICE_DEFAULT:
51 juju.juju_log("Invalid Service: %s" % service)
52 raise Exception("Invalid Service: %s" % service)
53@@ -857,10 +873,6 @@
54 "pingserver": {
55 "port": "8070", "httpchk": "HEAD /ping HTTP/1.0"
56 },
57- "combo-loader": {
58- "port": "9070",
59- "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
60- },
61 "async-frontend": {
62 "port": "9090",
63 "service_options": ["timeout client 300000",
64@@ -869,6 +881,14 @@
65 "package-upload": {"port": "9100"},
66 "package-search": {"port": "9090"}}
67
68+HAS_COMBO_LOADER = os.path.exists("/etc/init.d/landscape-combo-loader")
69+if HAS_COMBO_LOADER:
70+ SERVICE_PROXY["combo-loader"] = {
71+ "port": "9070",
72+ "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
73+ }
74+
75+
76 # Format is:
77 # [min, auto_max, hard_max]
78 # min = minimum number of daemons to launch
79@@ -879,7 +899,6 @@
80 "msgserver": [2, 8, 9],
81 "pingserver": [1, 4, 9],
82 "apiserver": [1, 2, 9],
83- "combo-loader": [1, 1, 1],
84 "async-frontend": [1, 1, 1],
85 "jobhandler": [1, 1, 1],
86 "package-upload": [1, 1, 1],
87@@ -887,13 +906,13 @@
88 "juju-sync": [1, 1, 1],
89 "cron": [1, 1, 1],
90 "static": [1, 1, 1]}
91-
92+if HAS_COMBO_LOADER:
93+ SERVICE_COUNT["combo-loader"] = [1, 1, 1]
94
95 SERVICE_DEFAULT = {
96 "appserver": "RUN_APPSERVER",
97 "msgserver": "RUN_MSGSERVER",
98 "pingserver": "RUN_PINGSERVER",
99- "combo-loader": "RUN_COMBO_LOADER",
100 "async-frontend": "RUN_ASYNC_FRONTEND",
101 "apiserver": "RUN_APISERVER",
102 "package-upload": "RUN_PACKAGEUPLOADSERVER",
103@@ -902,6 +921,8 @@
104 "juju-sync": "RUN_JUJU_SYNC",
105 "cron": "RUN_CRON",
106 "static": None}
107+if HAS_COMBO_LOADER:
108+ SERVICE_DEFAULT["combo-loader"] = "RUN_COMBO_LOADER"
109
110 LANDSCAPE_DEFAULT_FILE = "/etc/default/landscape-server"
111 LANDSCAPE_APACHE_SITE = "/etc/apache2/sites-available/landscape.conf"
112
113=== modified file 'hooks/test_hooks.py'
114--- hooks/test_hooks.py 2015-01-27 04:05:15 +0000
115+++ hooks/test_hooks.py 2015-02-04 12:18:28 +0000
116@@ -162,6 +162,25 @@
117 UPGRADE_SCHEMA="no"
118 """)
119
120+ def with_combo_loader(self):
121+ """Tweak globals so they match a deployment with combo-loader."""
122+ self.addCleanup(
123+ setattr, hooks, "HAS_COMBO_LOADER", hooks.HAS_COMBO_LOADER)
124+ self.addCleanup(
125+ setattr, hooks, "SERVICE_PROXY", hooks.SERVICE_PROXY)
126+ self.addCleanup(
127+ setattr, hooks, "SERVICE_COUNT", hooks.SERVICE_COUNT)
128+ self.addCleanup(
129+ setattr, hooks, "SERVICE_DEFAULT", hooks.SERVICE_DEFAULT)
130+
131+ hooks.HAS_COMBO_LOADER = True
132+ hooks.SERVICE_PROXY["combo-loader"] = {
133+ "port": "9070",
134+ "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
135+ }
136+ hooks.SERVICE_COUNT["combo-loader"] = [1, 1, 1]
137+ hooks.SERVICE_DEFAULT["combo-loader"] = "RUN_COMBO_LOADER"
138+
139
140 class TestHooksService(TestHooks):
141
142@@ -1399,7 +1418,7 @@
143 """
144 hooks.juju.config["service-count"] = "0"
145 result = hooks._get_requested_service_count()
146- self.assertEqual(len(result), 12)
147+ self.assertEqual(len(result), 11)
148 self.assertEqual(result["appserver"], "0")
149
150 hooks.juju.config["service-count"] = "foo"
151@@ -1425,12 +1444,23 @@
152 hooks.juju.config["service-count"] = (
153 "juju-sync:-8 cron:XYZ BLAh BLAh:X")
154 result = hooks._get_requested_service_count()
155- self.assertEqual(len(result), 12)
156+ self.assertEqual(len(result), 11)
157 self.assertEqual(result["juju-sync"], "AUTO")
158 self.assertEqual(result["cron"], "AUTO")
159 self.assertEqual(result["appserver"], "AUTO")
160 self.assertNotIn("BLAh", result)
161
162+ def test_get_requested_service_with_combo_loader(self):
163+ """
164+ If the installed landscape-server package has the combo-loader service,
165+ that _get_requested_service_count() includes it.
166+ """
167+ self.with_combo_loader()
168+ hooks.juju.config["service-count"] = "1"
169+ result = hooks._get_requested_service_count()
170+ self.assertEqual(len(result), 12)
171+ self.assertEqual(result["combo-loader"], "1")
172+
173 def test_get_services_dict(self):
174 """
175 The services dict contains service names as keys
176@@ -1454,6 +1484,22 @@
177 result = hooks._get_services_dict()
178 self.assertEqual(result, {"appserver": 3, "cron": 1})
179
180+ # The combo-loader is skipped if not available.
181+ hooks.juju.config["services"] = "appserver combo-loader"
182+ hooks.juju.config["service-count"] = "AUTO"
183+ result = hooks._get_services_dict()
184+ self.assertEqual(result, {"appserver": 3})
185+
186+ def test_get_services_dict_with_combo_loader(self):
187+ """
188+ The services dict contains the combo-loader if available.
189+ """
190+ self.with_combo_loader()
191+ hooks.juju.config["services"] = "appserver"
192+ hooks.juju.config["service-count"] = "2"
193+ result = hooks._get_services_dict()
194+ self.assertEqual(result, {"appserver": 2})
195+
196 def test_get_requested_services(self):
197 """
198 "services" config is parsed into list. Exceptions are raised for
199@@ -1467,6 +1513,11 @@
200 result = hooks._get_requested_services()
201 self.assertEqual(["appserver", "pingserver", "cron"], result)
202
203+ # The combo-loader is skipped if not available
204+ hooks.juju.config["services"] = "appserver combo-loader"
205+ result = hooks._get_requested_services()
206+ self.assertEqual(["appserver"], result)
207+
208 hooks.juju.config["services"] = "appserver pingserver cron foo"
209 self.assertRaises(Exception, hooks._get_requested_services)
210
211@@ -1860,9 +1911,28 @@
212 """
213 notify the vhost-config relation on a separate ID.
214 """
215- hooks.notify_vhost_config_relation("haproxy", "foo/0")
216- with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
217- vhostssl_template = f.read()
218+ self.with_combo_loader()
219+ hooks.notify_vhost_config_relation("haproxy", "foo/0")
220+ with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
221+ vhostssl_template = f.read()
222+ with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:
223+ vhost_template = f.read()
224+ baseline = yaml.dump(
225+ [{"port": "443", "template": base64.b64encode(vhostssl_template)},
226+ {"port": "80", "template": base64.b64encode(vhost_template)}])
227+ self.assertEqual(
228+ (("vhosts", baseline),), hooks.juju._outgoing_relation_data)
229+
230+ def test_notify_vhost_config_relation_specify_id_no_combo_loader(self):
231+ """
232+ If there's no combo-loader the relevant vhost entry is skipped.
233+ """
234+ hooks.notify_vhost_config_relation("haproxy", "foo/0")
235+ with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
236+ vhostssl_template = f.read()
237+ vhostssl_template = vhostssl_template.replace(
238+ hooks.COMBO_LOADER_VHOST_ENTRY,
239+ hooks.NO_COMBO_LOADER_VHOST_ENTRY)
240 with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:
241 vhost_template = f.read()
242 baseline = yaml.dump(
243@@ -1876,6 +1946,7 @@
244 If the landscape-server package being installed has offline pages
245 under the static dir, the legacy templates are used.
246 """
247+ self.with_combo_loader()
248 self.addCleanup(
249 setattr, hooks, "HAS_OLD_ERROR_PATH", hooks.HAS_OLD_ERROR_PATH)
250 hooks.HAS_OLD_ERROR_PATH = True
251@@ -1892,6 +1963,7 @@
252
253 def test_notify_vhost_config_relation(self):
254 """notify the vhost-config relation on the "current" ID."""
255+ self.with_combo_loader()
256 hooks.notify_vhost_config_relation("haproxy")
257 with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
258 vhostssl_template = f.read()
259
260=== modified file 'tests/01-begin.py'
261--- tests/01-begin.py 2015-01-19 18:32:57 +0000
262+++ tests/01-begin.py 2015-02-04 12:18:28 +0000
263@@ -379,8 +379,6 @@
264 cls.juju_status, "pingserver")
265 cls.async_unit = find_landscape_unit_with_service(
266 cls.juju_status, "async-frontend")
267- cls.combo_unit = find_landscape_unit_with_service(
268- cls.juju_status, "combo-loader")
269
270 def run_command_on_unit(self, cmd, unit):
271 output = check_output(["juju", "ssh", unit, cmd], stderr=PIPE)
272@@ -441,18 +439,6 @@
273 url = "https://{}/ajax".format(self.frontend)
274 check_url(url, good_content)
275
276- def test_combo_unavailable_page(self):
277- """
278- Verify that the frontend shows the unstyled unavailable page for combo.
279- """
280- self.addCleanup(self.start_server, "landscape-combo-loader",
281- self.combo_unit)
282- self.stop_server("landscape-combo-loader", self.combo_unit)
283- good_content = ["503 Service Unavailable",
284- "No server is available to handle this request."]
285- url = "http://{}/combo".format(self.frontend)
286- check_url(url, good_content)
287-
288
289 class LandscapeCronTests(BaseLandscapeTests):
290

Subscribers

People subscribed via source and target branches