62
61
Hardcode expected relation_list for tests. Feel free to expand
63
62
as more tests are added.
65
return list(self._relation_list)
64
if relation_id == "website:1":
65
return ["landscape-haproxy/0"]
67
return list(self._relation_list)
67
69
def unit_get(self, *args):
204
206
self.mocker.replay()
205
207
with unittest.TestCase.assertRaises(self, ValueError) as invalid_email:
206
208
hooks.util.create_landscape_admin(db_user, db_password, db_host,
207
admin_name, admin_email, admin_password)
209
admin_name, admin_email,
208
211
self.assertEqual("Invalid administrator email %s" % admin_email,
209
invalid_email.exception.message)
212
invalid_email.exception.message)
211
214
def test_first_admin_not_created_if_account_not_empty(self):
1575
1578
self._service_conf.seek(0)
1576
1579
self.assertFalse(hooks._is_db_up())
1581
def test__get_haproxy_service_name(self):
1583
_get_haproxy_service_name() returns the jinja-ready service name used
1586
haproxy_service_name = hooks._get_haproxy_service_name()
1587
self.assertEqual(haproxy_service_name, "landscapehaproxy")
1589
def test_no_haproxy_service_name_if_not_related_to_haproxy(self):
1591
_get_haproxy_service_name() returns None if we are not related to
1594
def no_website_relation(relation_name):
1597
self.addCleanup(setattr, hooks.juju, "relation_ids",
1598
hooks.juju.relation_ids)
1599
hooks.juju.relation_ids = no_website_relation
1600
haproxy_service_name = hooks._get_haproxy_service_name()
1601
self.assertIsNone(haproxy_service_name)
1603
def test__get_vhost_template(self):
1605
The haproxy prefix in the template variables is replaced by the
1606
name of the actual haproxy service that is part of the deployment.
1608
template_file = "vhostssl.tmpl"
1609
with open("%s/config/%s" % (hooks.ROOT, template_file), "r") as t:
1610
original_template = t.read()
1611
new_template = hooks._get_vhost_template(template_file,
1612
"landscape-haproxy")
1613
self.assertIn("{{ haproxy_msgserver }}", original_template)
1614
self.assertNotIn("{{ landscape-haproxy_msgserver }}",
1616
self.assertIn("{{ landscape-haproxy_msgserver }}", new_template)
1579
1619
class TestHooksServiceMock(TestHooks):
1760
1800
notify the vhost-config relation on a separate ID.
1762
hooks.notify_vhost_config_relation("foo/0")
1802
hooks.notify_vhost_config_relation("haproxy", "foo/0")
1763
1803
with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
1764
1804
vhostssl_template = f.read()
1765
1805
with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:
1773
1813
def test_notify_vhost_config_relation(self):
1774
1814
"""notify the vhost-config relation on the "current" ID."""
1775
hooks.notify_vhost_config_relation()
1815
hooks.notify_vhost_config_relation("haproxy")
1776
1816
with open("%s/config/vhostssl.tmpl" % hooks.ROOT, 'r') as f:
1777
1817
vhostssl_template = f.read()
1778
1818
with open("%s/config/vhost.tmpl" % hooks.ROOT, 'r') as f:
1802
1842
"user": "user",
1803
1843
"password": "password"}})
1804
1844
notify_vhost = self.mocker.replace(hooks.notify_vhost_config_relation)
1845
notify_vhost(hooks._get_haproxy_service_name(), None)
1806
1846
self.mocker.replay()
1807
1847
self.assertRaises(SystemExit, hooks.vhost_config_relation_changed)
1808
1848
self.assertIn('Waiting for data from apache', hooks.juju._logs[-1])
1820
1860
"user": "user",
1821
1861
"password": "password"}})
1822
1862
notify_vhost = self.mocker.replace(hooks.notify_vhost_config_relation)
1863
notify_vhost(hooks._get_haproxy_service_name(), None)
1824
1864
is_db_up = self.mocker.replace(hooks._is_db_up)
1826
1866
self.mocker.result(False)
1843
1883
"user": "user",
1844
1884
"password": "password"}})
1845
1885
notify_vhost = self.mocker.replace(hooks.notify_vhost_config_relation)
1886
notify_vhost(hooks._get_haproxy_service_name(), None)
1847
1887
is_db_up = self.mocker.replace(hooks._is_db_up)
1849
1889
self.mocker.result(True)
1868
1908
"user": "user",
1869
1909
"password": "password"}})
1870
1910
notify_vhost = self.mocker.replace(hooks.notify_vhost_config_relation)
1911
notify_vhost(hooks._get_haproxy_service_name(), None)
1872
1912
mock_conn = self.mocker.mock()
1873
1913
mock_conn.close()
1874
1914
connect_exclusive = self.mocker.replace(hooks.util.connect_exclusive)
1906
1946
"user": "user",
1907
1947
"password": "password"}})
1908
1948
notify_vhost = self.mocker.replace(hooks.notify_vhost_config_relation)
1949
notify_vhost(hooks._get_haproxy_service_name(), None)
1910
1950
is_db_up = self.mocker.replace(hooks._is_db_up)
1912
1952
self.mocker.result(True)
1926
1966
with open(hooks.SSL_CERT_LOCATION, 'r') as f:
1927
1967
self.assertEqual("foobar", f.read())
1969
def test_vhost_config_relation_exits_if_haproxy_not_ready(self):
1971
notify_vhost_config_relation() is not called if the haproxy relation
1974
def should_not_be_here(*args):
1975
raise AssertionError("notify_vhost_config_relation() should not "
1978
self.addCleanup(setattr, hooks, "vhost_config_relation_changed",
1979
hooks.vhost_config_relation_changed)
1980
hooks.notify_vhost_config_relation = should_not_be_here
1981
get_haproxy_service_name = self.mocker.replace(
1982
hooks._get_haproxy_service_name)
1983
get_haproxy_service_name()
1984
self.mocker.result(None)
1985
self.mocker.replay()
1986
hooks.vhost_config_relation_changed()
1930
1989
class TestHooksUtils(TestHooks):
1931
1990
def test__setup_apache(self):