162
162
UPGRADE_SCHEMA="no"
165
def with_combo_loader(self):
166
"""Tweak globals so they match a deployment with combo-loader."""
168
setattr, hooks, "HAS_COMBO_LOADER", hooks.HAS_COMBO_LOADER)
170
setattr, hooks, "SERVICE_PROXY", hooks.SERVICE_PROXY)
172
setattr, hooks, "SERVICE_COUNT", hooks.SERVICE_COUNT)
174
setattr, hooks, "SERVICE_DEFAULT", hooks.SERVICE_DEFAULT)
176
hooks.HAS_COMBO_LOADER = True
177
hooks.SERVICE_PROXY["combo-loader"] = {
179
"httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
181
hooks.SERVICE_COUNT["combo-loader"] = [1, 1, 1]
182
hooks.SERVICE_DEFAULT["combo-loader"] = "RUN_COMBO_LOADER"
166
185
class TestHooksService(TestHooks):
1400
1419
hooks.juju.config["service-count"] = "0"
1401
1420
result = hooks._get_requested_service_count()
1402
self.assertEqual(len(result), 12)
1421
self.assertEqual(len(result), 11)
1403
1422
self.assertEqual(result["appserver"], "0")
1405
1424
hooks.juju.config["service-count"] = "foo"
1425
1444
hooks.juju.config["service-count"] = (
1426
1445
"juju-sync:-8 cron:XYZ BLAh BLAh:X")
1427
1446
result = hooks._get_requested_service_count()
1428
self.assertEqual(len(result), 12)
1447
self.assertEqual(len(result), 11)
1429
1448
self.assertEqual(result["juju-sync"], "AUTO")
1430
1449
self.assertEqual(result["cron"], "AUTO")
1431
1450
self.assertEqual(result["appserver"], "AUTO")
1432
1451
self.assertNotIn("BLAh", result)
1453
def test_get_requested_service_with_combo_loader(self):
1455
If the installed landscape-server package has the combo-loader service,
1456
that _get_requested_service_count() includes it.
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")
1434
1464
def test_get_services_dict(self):
1436
1466
The services dict contains service names as keys
1454
1484
result = hooks._get_services_dict()
1455
1485
self.assertEqual(result, {"appserver": 3, "cron": 1})
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})
1493
def test_get_services_dict_with_combo_loader(self):
1495
The services dict contains the combo-loader if available.
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})
1457
1503
def test_get_requested_services(self):
1459
1505
"services" config is parsed into list. Exceptions are raised for
1467
1513
result = hooks._get_requested_services()
1468
1514
self.assertEqual(["appserver", "pingserver", "cron"], result)
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)
1470
1521
hooks.juju.config["services"] = "appserver pingserver cron foo"
1471
1522
self.assertRaises(Exception, hooks._get_requested_services)
1861
1912
notify the vhost-config relation on a separate ID.
1863
hooks.notify_vhost_config_relation("haproxy", "foo/0")
1864
with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
1865
vhostssl_template = f.read()
1914
self.with_combo_loader()
1915
hooks.notify_vhost_config_relation("haproxy", "foo/0")
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)}])
1924
(("vhosts", baseline),), hooks.juju._outgoing_relation_data)
1926
def test_notify_vhost_config_relation_specify_id_no_combo_loader(self):
1928
If there's no combo-loader the relevant vhost entry is skipped.
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
1936
with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:
1867
1937
vhost_template = f.read()
1868
1938
baseline = yaml.dump(
1876
1946
If the landscape-server package being installed has offline pages
1877
1947
under the static dir, the legacy templates are used.
1949
self.with_combo_loader()
1879
1950
self.addCleanup(
1880
1951
setattr, hooks, "HAS_OLD_ERROR_PATH", hooks.HAS_OLD_ERROR_PATH)
1881
1952
hooks.HAS_OLD_ERROR_PATH = True
1893
1964
def test_notify_vhost_config_relation(self):
1894
1965
"""notify the vhost-config relation on the "current" ID."""
1966
self.with_combo_loader()
1895
1967
hooks.notify_vhost_config_relation("haproxy")
1896
1968
with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
1897
1969
vhostssl_template = f.read()