Merge lp:~sidnei/charms/precise/haproxy/restore-services-from-relation into lp:charms/haproxy

Proposed by Sidnei da Silva
Status: Merged
Merged at revision: 70
Proposed branch: lp:~sidnei/charms/precise/haproxy/restore-services-from-relation
Merge into: lp:charms/haproxy
Diff against target: 120 lines (+24/-12)
2 files modified
hooks/hooks.py (+14/-6)
hooks/tests/test_website_hooks.py (+10/-6)
To merge this branch: bzr merge lp:~sidnei/charms/precise/haproxy/restore-services-from-relation
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+193773@code.launchpad.net

Commit message

Actually fix tests.

Description of the change

Actually fix tests.

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

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 2013-10-25 21:33:52 +0000
3+++ hooks/hooks.py 2013-11-04 13:11:24 +0000
4@@ -342,7 +342,11 @@
5
6
7 def parse_services_yaml(services, yaml_data):
8- for service in yaml.safe_load(yaml_data):
9+ yaml_services = yaml.safe_load(yaml_data)
10+ if yaml_services is None:
11+ return services
12+
13+ for service in yaml_services:
14 service_name = service["service_name"]
15 if not services:
16 # 'None' is used as a marker for the first service defined, which
17@@ -365,6 +369,7 @@
18
19 services[service_name] = merge_service(
20 services.get(service_name, {}), service)
21+
22 return services
23
24
25@@ -435,6 +440,7 @@
26
27 # Augment services_dict with service definitions from relation data.
28 relation_data = relations_of_type("reverseproxy")
29+
30 for relation_info in relation_data:
31 if "services" in relation_info:
32 services_dict = parse_services_yaml(services_dict,
33@@ -444,8 +450,6 @@
34 log("No services configured, exiting.")
35 return
36
37- relation_data = relations_of_type("reverseproxy")
38-
39 for relation_info in relation_data:
40 unit = relation_info['__unit__']
41
42@@ -785,7 +789,6 @@
43
44
45 def notify_relation(relation, changed=False, relation_ids=None):
46- config_data = config_get()
47 default_host = get_hostname()
48 default_port = 80
49
50@@ -809,7 +812,7 @@
51 if len(service_names) == 1:
52 service_name = service_names.pop()
53 elif len(service_names) > 1:
54- log("Remote units requested than a single service name."
55+ log("Remote units requested more than a single service name."
56 "Falling back to default host/port.")
57
58 if service_name is not None:
59@@ -822,9 +825,14 @@
60 my_host = default_host
61 my_port = default_port
62
63+ all_services = ""
64+ services_dict = create_services()
65+ if services_dict is not None:
66+ all_services = yaml.safe_dump(sorted(services_dict.itervalues()))
67+
68 relation_set(relation_id=rid, port=str(my_port),
69 hostname=my_host,
70- all_services=config_data['services'])
71+ all_services=all_services)
72
73
74 def notify_website(changed=False, relation_ids=None):
75
76=== modified file 'hooks/tests/test_website_hooks.py'
77--- hooks/tests/test_website_hooks.py 2013-05-10 17:36:36 +0000
78+++ hooks/tests/test_website_hooks.py 2013-11-04 13:11:24 +0000
79@@ -36,13 +36,14 @@
80 def setUp(self):
81 super(NotifyRelationTest, self).setUp()
82
83+ self.relations_of_type = self.patch_hook("relations_of_type")
84 self.relations_for_id = self.patch_hook("relations_for_id")
85 self.relation_set = self.patch_hook("relation_set")
86 self.config_get = self.patch_hook("config_get")
87 self.get_relation_ids = self.patch_hook("get_relation_ids")
88 self.get_hostname = self.patch_hook("get_hostname")
89 self.log = self.patch_hook("log")
90- self.get_config_services = self.patch_hook("get_config_service")
91+ self.get_config_service = self.patch_hook("get_config_service")
92
93 def patch_hook(self, hook_name):
94 mock_controller = patch.object(hooks, hook_name)
95@@ -114,9 +115,12 @@
96 relation_id="website:1", port="80", hostname="foo.local",
97 all_services=""),
98 ])
99- self.log.assert_called_once_with(
100- "Remote units requested than a single service name."
101- "Falling back to default host/port.")
102+ self.log.assert_has_calls([
103+ call.log(
104+ "Remote units requested more than a single service name."
105+ "Falling back to default host/port."),
106+ call.log("No services configured, exiting."),
107+ ])
108
109 def test_notify_website_relation_with_same_sitenames(self):
110 self.get_relation_ids.return_value = ("website:1",)
111@@ -124,8 +128,8 @@
112 self.relations_for_id.return_value = [{"service_name": "bar"},
113 {"service_name": "bar"}]
114 self.config_get.return_value = {"services": ""}
115- self.get_config_services.return_value = {"service_host": "bar.local",
116- "service_port": "4242"}
117+ self.get_config_service.return_value = {"service_host": "bar.local",
118+ "service_port": "4242"}
119
120 hooks.notify_relation("website")
121

Subscribers

People subscribed via source and target branches