Merge lp:~davidpbritton/charms/precise/haproxy/reverseproxy-notify-website into lp:charms/haproxy

Proposed by David Britton on 2013-02-15
Status: Merged
Merged at revision: 65
Proposed branch: lp:~davidpbritton/charms/precise/haproxy/reverseproxy-notify-website
Merge into: lp:charms/haproxy
Prerequisite: lp:~davidpbritton/charms/precise/haproxy/fixes
Diff against target: 90 lines (+29/-14)
3 files modified
hooks/hooks.py (+28/-4)
hooks/test_hooks.py (+0/-9)
revision (+1/-1)
To merge this branch: bzr merge lp:~davidpbritton/charms/precise/haproxy/reverseproxy-notify-website
Reviewer Review Type Date Requested Status
Juan L. Negron (community) 2013-02-15 Approve on 2013-02-15
Review via email: mp+148605@code.launchpad.net

Description of the change

When the reverseproxy relation changes, the website proxy will likely need to be updated, so trigger a config-changed to notify the other side of the relation that it will need to update.

I'm not sure if this the appropriate way to handle this situation, but in practice it seems to work. Please let me know if there is a more accurate or correct way to do it.

To post a comment you must log in.
Juan L. Negron (negronjl) wrote :

Reviewing this now.

-Juan

Juan L. Negron (negronjl) wrote :

This seems to be working as intended and I think it's a good idea.

Approved.

Merging.

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-02-13 23:57:05 +0000
3+++ hooks/hooks.py 2013-02-15 04:36:21 +0000
4@@ -11,6 +11,7 @@
5 import sys
6 import yaml
7 import nrpe
8+import time
9
10
11 ###############################################################################
12@@ -84,6 +85,17 @@
13 finally:
14 return(relation_data)
15
16+def relation_set(arguments, relation_id=None):
17+ """
18+ Wrapper around relation-set
19+ @param arguments: list of command line arguments
20+ @param relation_id: optional relation-id (passed to -r parameter) to use
21+ """
22+ set_args = ["relation-set"]
23+ if relation_id is not None:
24+ set_args.extend(["-r", str(relation_id)])
25+ set_args.extend(arguments)
26+ subprocess.check_call(set_args)
27
28 #------------------------------------------------------------------------------
29 # apt_get_install( package ): Installs a package
30@@ -601,6 +613,16 @@
31 else:
32 return(False)
33
34+def website_notify():
35+ """
36+ Notify any webiste relations of any configuration changes.
37+ """
38+ juju_log("Notifying all website relations of change")
39+ all_relations = relation_get_all("website")
40+ if hasattr(all_relations, "iteritems"):
41+ for relid, reldata in all_relations.iteritems():
42+ relation_set(["time=%s" % time.time()], relation_id=relid)
43+
44
45 ###############################################################################
46 # Hook functions
47@@ -652,10 +674,12 @@
48 def reverseproxy_interface(hook_name=None):
49 if hook_name is None:
50 return(None)
51- if hook_name == "changed":
52- config_changed()
53- if hook_name=="departed":
54- config_changed()
55+ elif hook_name == "changed":
56+ config_changed()
57+ website_notify()
58+ elif hook_name=="departed":
59+ config_changed()
60+ website_notify()
61
62 def website_interface(hook_name=None):
63 if hook_name is None:
64
65=== modified file 'hooks/test_hooks.py'
66--- hooks/test_hooks.py 2013-02-13 23:57:05 +0000
67+++ hooks/test_hooks.py 2013-02-15 04:36:21 +0000
68@@ -109,15 +109,6 @@
69 self.mocker.result(result)
70 self.mocker.count(1, None)
71
72- def _expect_relation_set(self, args):
73- """
74- @param args: list of arguments expected to be passed to relation_set
75- """
76- obj = self.mocker.replace("hooks.relation_set")
77- obj(args)
78- self.relation_set = args
79- self.mocker.count(1,None)
80-
81 def test_create_services(self):
82 """
83 Simplest use case, config stanza seeded in config file, server line
84
85=== modified file 'revision'
86--- revision 2013-02-13 23:57:05 +0000
87+++ revision 2013-02-15 04:36:21 +0000
88@@ -1,1 +1,1 @@
89-39
90+42

Subscribers

People subscribed via source and target branches