~landscape/landscape-charm/stable

« back to all changes in this revision

Viewing changes to hooks/test_hooks.py

  • Committer: Landscape Builder
  • Author(s): Free Ekanayaka
  • Date: 2015-02-05 16:07:10 UTC
  • mfrom: (217.1.2 no-combo-loader-support)
  • Revision ID: landscape_builder-20150205160710-jjl4nsa29v0orx24
Merge no-combo-loader-support [f=1417971] [r=danilo,tealeg] [a=Free Ekanayaka]
Support both LDS packages with and and without combo-loader.

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
UPGRADE_SCHEMA="no"
163
163
            """)
164
164
 
 
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
 
165
184
 
166
185
class TestHooksService(TestHooks):
167
186
 
1399
1418
        """
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")
1404
1423
 
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)
1433
1452
 
 
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
1464
    def test_get_services_dict(self):
1435
1465
        """
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})
1456
1486
 
 
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
1503
    def test_get_requested_services(self):
1458
1504
        """
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)
1469
1515
 
 
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
1521
        hooks.juju.config["services"] = "appserver pingserver cron foo"
1471
1522
        self.assertRaises(Exception, hooks._get_requested_services)
1472
1523
 
1860
1911
        """
1861
1912
        notify the vhost-config relation on a separate ID.
1862
1913
        """
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)}])
 
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
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.
1878
1948
        """
 
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
1892
1963
 
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()