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
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2015-01-27 04:05:15 +0000
+++ hooks/hooks.py 2015-02-04 12:18:28 +0000
@@ -119,11 +119,21 @@
119 haproxy_service = re.sub("\W", "", haproxy_service)119 haproxy_service = re.sub("\W", "", haproxy_service)
120 return haproxy_service120 return haproxy_service
121121
122COMBO_LOADER_VHOST_ENTRY = (
123 " RewriteRule ^/combo http://{{ haproxy_comboloader }}/ [P,L]\n")
124
125NO_COMBO_LOADER_VHOST_ENTRY = (
126 " RewriteRule "
127 "^/combo(.*) http://{{ haproxy_appserver }}/combo$1 [P,L]\n")
128
122129
123def _get_vhost_template(template_filename, haproxy_service_name):130def _get_vhost_template(template_filename, haproxy_service_name):
124 """Expand the template with the provided haproxy service name."""131 """Expand the template with the provided haproxy service name."""
125 with open("%s/config/%s" % (ROOT, template_filename), "r") as handle:132 with open("%s/config/%s" % (ROOT, template_filename), "r") as handle:
126 contents = handle.read()133 contents = handle.read()
134 if not HAS_COMBO_LOADER:
135 contents = contents.replace(
136 COMBO_LOADER_VHOST_ENTRY, NO_COMBO_LOADER_VHOST_ENTRY)
127 contents = re.sub(r"{{ haproxy_([^}]+) }}", r"{{ %s_\1 }}" %137 contents = re.sub(r"{{ haproxy_([^}]+) }}", r"{{ %s_\1 }}" %
128 haproxy_service_name, contents)138 haproxy_service_name, contents)
129 return contents139 return contents
@@ -654,6 +664,8 @@
654 count = service_count664 count = service_count
655 if re.match(r"^.*:\d+$", service_count):665 if re.match(r"^.*:\d+$", service_count):
656 (service, count) = service_count.split(":")666 (service, count) = service_count.split(":")
667 if service == "combo-loader" and not HAS_COMBO_LOADER:
668 continue
657 result[service] = count669 result[service] = count
658 return result670 return result
659671
@@ -668,6 +680,8 @@
668 result = {}680 result = {}
669 requested = _get_requested_service_count()681 requested = _get_requested_service_count()
670 for service in _get_requested_services():682 for service in _get_requested_services():
683 if service == "combo-loader" and not HAS_COMBO_LOADER:
684 continue
671 args = [service]685 args = [service]
672 args.extend(SERVICE_COUNT[service])686 args.extend(SERVICE_COUNT[service])
673 args.append(requested[service])687 args.append(requested[service])
@@ -752,6 +766,8 @@
752 config = juju.config_get()766 config = juju.config_get()
753 if "services" in config:767 if "services" in config:
754 for service in config["services"].split():768 for service in config["services"].split():
769 if service == "combo-loader" and not HAS_COMBO_LOADER:
770 continue
755 if service not in SERVICE_DEFAULT:771 if service not in SERVICE_DEFAULT:
756 juju.juju_log("Invalid Service: %s" % service)772 juju.juju_log("Invalid Service: %s" % service)
757 raise Exception("Invalid Service: %s" % service)773 raise Exception("Invalid Service: %s" % service)
@@ -857,10 +873,6 @@
857 "pingserver": {873 "pingserver": {
858 "port": "8070", "httpchk": "HEAD /ping HTTP/1.0"874 "port": "8070", "httpchk": "HEAD /ping HTTP/1.0"
859 },875 },
860 "combo-loader": {
861 "port": "9070",
862 "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
863 },
864 "async-frontend": {876 "async-frontend": {
865 "port": "9090",877 "port": "9090",
866 "service_options": ["timeout client 300000",878 "service_options": ["timeout client 300000",
@@ -869,6 +881,14 @@
869 "package-upload": {"port": "9100"},881 "package-upload": {"port": "9100"},
870 "package-search": {"port": "9090"}}882 "package-search": {"port": "9090"}}
871883
884HAS_COMBO_LOADER = os.path.exists("/etc/init.d/landscape-combo-loader")
885if HAS_COMBO_LOADER:
886 SERVICE_PROXY["combo-loader"] = {
887 "port": "9070",
888 "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
889 }
890
891
872# Format is:892# Format is:
873# [min, auto_max, hard_max]893# [min, auto_max, hard_max]
874# min = minimum number of daemons to launch894# min = minimum number of daemons to launch
@@ -879,7 +899,6 @@
879 "msgserver": [2, 8, 9],899 "msgserver": [2, 8, 9],
880 "pingserver": [1, 4, 9],900 "pingserver": [1, 4, 9],
881 "apiserver": [1, 2, 9],901 "apiserver": [1, 2, 9],
882 "combo-loader": [1, 1, 1],
883 "async-frontend": [1, 1, 1],902 "async-frontend": [1, 1, 1],
884 "jobhandler": [1, 1, 1],903 "jobhandler": [1, 1, 1],
885 "package-upload": [1, 1, 1],904 "package-upload": [1, 1, 1],
@@ -887,13 +906,13 @@
887 "juju-sync": [1, 1, 1],906 "juju-sync": [1, 1, 1],
888 "cron": [1, 1, 1],907 "cron": [1, 1, 1],
889 "static": [1, 1, 1]}908 "static": [1, 1, 1]}
890909if HAS_COMBO_LOADER:
910 SERVICE_COUNT["combo-loader"] = [1, 1, 1]
891911
892SERVICE_DEFAULT = {912SERVICE_DEFAULT = {
893 "appserver": "RUN_APPSERVER",913 "appserver": "RUN_APPSERVER",
894 "msgserver": "RUN_MSGSERVER",914 "msgserver": "RUN_MSGSERVER",
895 "pingserver": "RUN_PINGSERVER",915 "pingserver": "RUN_PINGSERVER",
896 "combo-loader": "RUN_COMBO_LOADER",
897 "async-frontend": "RUN_ASYNC_FRONTEND",916 "async-frontend": "RUN_ASYNC_FRONTEND",
898 "apiserver": "RUN_APISERVER",917 "apiserver": "RUN_APISERVER",
899 "package-upload": "RUN_PACKAGEUPLOADSERVER",918 "package-upload": "RUN_PACKAGEUPLOADSERVER",
@@ -902,6 +921,8 @@
902 "juju-sync": "RUN_JUJU_SYNC",921 "juju-sync": "RUN_JUJU_SYNC",
903 "cron": "RUN_CRON",922 "cron": "RUN_CRON",
904 "static": None}923 "static": None}
924if HAS_COMBO_LOADER:
925 SERVICE_DEFAULT["combo-loader"] = "RUN_COMBO_LOADER"
905926
906LANDSCAPE_DEFAULT_FILE = "/etc/default/landscape-server"927LANDSCAPE_DEFAULT_FILE = "/etc/default/landscape-server"
907LANDSCAPE_APACHE_SITE = "/etc/apache2/sites-available/landscape.conf"928LANDSCAPE_APACHE_SITE = "/etc/apache2/sites-available/landscape.conf"
908929
=== modified file 'hooks/test_hooks.py'
--- hooks/test_hooks.py 2015-01-27 04:05:15 +0000
+++ hooks/test_hooks.py 2015-02-04 12:18:28 +0000
@@ -162,6 +162,25 @@
162UPGRADE_SCHEMA="no"162UPGRADE_SCHEMA="no"
163 """)163 """)
164164
165 def with_combo_loader(self):
166 """Tweak globals so they match a deployment with combo-loader."""
167 self.addCleanup(
168 setattr, hooks, "HAS_COMBO_LOADER", hooks.HAS_COMBO_LOADER)
169 self.addCleanup(
170 setattr, hooks, "SERVICE_PROXY", hooks.SERVICE_PROXY)
171 self.addCleanup(
172 setattr, hooks, "SERVICE_COUNT", hooks.SERVICE_COUNT)
173 self.addCleanup(
174 setattr, hooks, "SERVICE_DEFAULT", hooks.SERVICE_DEFAULT)
175
176 hooks.HAS_COMBO_LOADER = True
177 hooks.SERVICE_PROXY["combo-loader"] = {
178 "port": "9070",
179 "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
180 }
181 hooks.SERVICE_COUNT["combo-loader"] = [1, 1, 1]
182 hooks.SERVICE_DEFAULT["combo-loader"] = "RUN_COMBO_LOADER"
183
165184
166class TestHooksService(TestHooks):185class TestHooksService(TestHooks):
167186
@@ -1399,7 +1418,7 @@
1399 """1418 """
1400 hooks.juju.config["service-count"] = "0"1419 hooks.juju.config["service-count"] = "0"
1401 result = hooks._get_requested_service_count()1420 result = hooks._get_requested_service_count()
1402 self.assertEqual(len(result), 12)1421 self.assertEqual(len(result), 11)
1403 self.assertEqual(result["appserver"], "0")1422 self.assertEqual(result["appserver"], "0")
14041423
1405 hooks.juju.config["service-count"] = "foo"1424 hooks.juju.config["service-count"] = "foo"
@@ -1425,12 +1444,23 @@
1425 hooks.juju.config["service-count"] = (1444 hooks.juju.config["service-count"] = (
1426 "juju-sync:-8 cron:XYZ BLAh BLAh:X")1445 "juju-sync:-8 cron:XYZ BLAh BLAh:X")
1427 result = hooks._get_requested_service_count()1446 result = hooks._get_requested_service_count()
1428 self.assertEqual(len(result), 12)1447 self.assertEqual(len(result), 11)
1429 self.assertEqual(result["juju-sync"], "AUTO")1448 self.assertEqual(result["juju-sync"], "AUTO")
1430 self.assertEqual(result["cron"], "AUTO")1449 self.assertEqual(result["cron"], "AUTO")
1431 self.assertEqual(result["appserver"], "AUTO")1450 self.assertEqual(result["appserver"], "AUTO")
1432 self.assertNotIn("BLAh", result)1451 self.assertNotIn("BLAh", result)
14331452
1453 def test_get_requested_service_with_combo_loader(self):
1454 """
1455 If the installed landscape-server package has the combo-loader service,
1456 that _get_requested_service_count() includes it.
1457 """
1458 self.with_combo_loader()
1459 hooks.juju.config["service-count"] = "1"
1460 result = hooks._get_requested_service_count()
1461 self.assertEqual(len(result), 12)
1462 self.assertEqual(result["combo-loader"], "1")
1463
1434 def test_get_services_dict(self):1464 def test_get_services_dict(self):
1435 """1465 """
1436 The services dict contains service names as keys1466 The services dict contains service names as keys
@@ -1454,6 +1484,22 @@
1454 result = hooks._get_services_dict()1484 result = hooks._get_services_dict()
1455 self.assertEqual(result, {"appserver": 3, "cron": 1})1485 self.assertEqual(result, {"appserver": 3, "cron": 1})
14561486
1487 # The combo-loader is skipped if not available.
1488 hooks.juju.config["services"] = "appserver combo-loader"
1489 hooks.juju.config["service-count"] = "AUTO"
1490 result = hooks._get_services_dict()
1491 self.assertEqual(result, {"appserver": 3})
1492
1493 def test_get_services_dict_with_combo_loader(self):
1494 """
1495 The services dict contains the combo-loader if available.
1496 """
1497 self.with_combo_loader()
1498 hooks.juju.config["services"] = "appserver"
1499 hooks.juju.config["service-count"] = "2"
1500 result = hooks._get_services_dict()
1501 self.assertEqual(result, {"appserver": 2})
1502
1457 def test_get_requested_services(self):1503 def test_get_requested_services(self):
1458 """1504 """
1459 "services" config is parsed into list. Exceptions are raised for1505 "services" config is parsed into list. Exceptions are raised for
@@ -1467,6 +1513,11 @@
1467 result = hooks._get_requested_services()1513 result = hooks._get_requested_services()
1468 self.assertEqual(["appserver", "pingserver", "cron"], result)1514 self.assertEqual(["appserver", "pingserver", "cron"], result)
14691515
1516 # The combo-loader is skipped if not available
1517 hooks.juju.config["services"] = "appserver combo-loader"
1518 result = hooks._get_requested_services()
1519 self.assertEqual(["appserver"], result)
1520
1470 hooks.juju.config["services"] = "appserver pingserver cron foo"1521 hooks.juju.config["services"] = "appserver pingserver cron foo"
1471 self.assertRaises(Exception, hooks._get_requested_services)1522 self.assertRaises(Exception, hooks._get_requested_services)
14721523
@@ -1860,9 +1911,28 @@
1860 """1911 """
1861 notify the vhost-config relation on a separate ID.1912 notify the vhost-config relation on a separate ID.
1862 """1913 """
1863 hooks.notify_vhost_config_relation("haproxy", "foo/0")1914 self.with_combo_loader()
1864 with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:1915 hooks.notify_vhost_config_relation("haproxy", "foo/0")
1865 vhostssl_template = f.read()1916 with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
1917 vhostssl_template = f.read()
1918 with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:
1919 vhost_template = f.read()
1920 baseline = yaml.dump(
1921 [{"port": "443", "template": base64.b64encode(vhostssl_template)},
1922 {"port": "80", "template": base64.b64encode(vhost_template)}])
1923 self.assertEqual(
1924 (("vhosts", baseline),), hooks.juju._outgoing_relation_data)
1925
1926 def test_notify_vhost_config_relation_specify_id_no_combo_loader(self):
1927 """
1928 If there's no combo-loader the relevant vhost entry is skipped.
1929 """
1930 hooks.notify_vhost_config_relation("haproxy", "foo/0")
1931 with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
1932 vhostssl_template = f.read()
1933 vhostssl_template = vhostssl_template.replace(
1934 hooks.COMBO_LOADER_VHOST_ENTRY,
1935 hooks.NO_COMBO_LOADER_VHOST_ENTRY)
1866 with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:1936 with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:
1867 vhost_template = f.read()1937 vhost_template = f.read()
1868 baseline = yaml.dump(1938 baseline = yaml.dump(
@@ -1876,6 +1946,7 @@
1876 If the landscape-server package being installed has offline pages1946 If the landscape-server package being installed has offline pages
1877 under the static dir, the legacy templates are used.1947 under the static dir, the legacy templates are used.
1878 """1948 """
1949 self.with_combo_loader()
1879 self.addCleanup(1950 self.addCleanup(
1880 setattr, hooks, "HAS_OLD_ERROR_PATH", hooks.HAS_OLD_ERROR_PATH)1951 setattr, hooks, "HAS_OLD_ERROR_PATH", hooks.HAS_OLD_ERROR_PATH)
1881 hooks.HAS_OLD_ERROR_PATH = True1952 hooks.HAS_OLD_ERROR_PATH = True
@@ -1892,6 +1963,7 @@
18921963
1893 def test_notify_vhost_config_relation(self):1964 def test_notify_vhost_config_relation(self):
1894 """notify the vhost-config relation on the "current" ID."""1965 """notify the vhost-config relation on the "current" ID."""
1966 self.with_combo_loader()
1895 hooks.notify_vhost_config_relation("haproxy")1967 hooks.notify_vhost_config_relation("haproxy")
1896 with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:1968 with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
1897 vhostssl_template = f.read()1969 vhostssl_template = f.read()
18981970
=== modified file 'tests/01-begin.py'
--- tests/01-begin.py 2015-01-19 18:32:57 +0000
+++ tests/01-begin.py 2015-02-04 12:18:28 +0000
@@ -379,8 +379,6 @@
379 cls.juju_status, "pingserver")379 cls.juju_status, "pingserver")
380 cls.async_unit = find_landscape_unit_with_service(380 cls.async_unit = find_landscape_unit_with_service(
381 cls.juju_status, "async-frontend")381 cls.juju_status, "async-frontend")
382 cls.combo_unit = find_landscape_unit_with_service(
383 cls.juju_status, "combo-loader")
384382
385 def run_command_on_unit(self, cmd, unit):383 def run_command_on_unit(self, cmd, unit):
386 output = check_output(["juju", "ssh", unit, cmd], stderr=PIPE)384 output = check_output(["juju", "ssh", unit, cmd], stderr=PIPE)
@@ -441,18 +439,6 @@
441 url = "https://{}/ajax".format(self.frontend)439 url = "https://{}/ajax".format(self.frontend)
442 check_url(url, good_content)440 check_url(url, good_content)
443441
444 def test_combo_unavailable_page(self):
445 """
446 Verify that the frontend shows the unstyled unavailable page for combo.
447 """
448 self.addCleanup(self.start_server, "landscape-combo-loader",
449 self.combo_unit)
450 self.stop_server("landscape-combo-loader", self.combo_unit)
451 good_content = ["503 Service Unavailable",
452 "No server is available to handle this request."]
453 url = "http://{}/combo".format(self.frontend)
454 check_url(url, good_content)
455
456442
457class LandscapeCronTests(BaseLandscapeTests):443class LandscapeCronTests(BaseLandscapeTests):
458444

Subscribers

People subscribed via source and target branches