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
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2013-02-13 23:57:05 +0000
+++ hooks/hooks.py 2013-02-15 04:36:21 +0000
@@ -11,6 +11,7 @@
11import sys11import sys
12import yaml12import yaml
13import nrpe13import nrpe
14import time
1415
1516
16###############################################################################17###############################################################################
@@ -84,6 +85,17 @@
84 finally:85 finally:
85 return(relation_data)86 return(relation_data)
8687
88def relation_set(arguments, relation_id=None):
89 """
90 Wrapper around relation-set
91 @param arguments: list of command line arguments
92 @param relation_id: optional relation-id (passed to -r parameter) to use
93 """
94 set_args = ["relation-set"]
95 if relation_id is not None:
96 set_args.extend(["-r", str(relation_id)])
97 set_args.extend(arguments)
98 subprocess.check_call(set_args)
8799
88#------------------------------------------------------------------------------100#------------------------------------------------------------------------------
89# apt_get_install( package ): Installs a package101# apt_get_install( package ): Installs a package
@@ -601,6 +613,16 @@
601 else:613 else:
602 return(False)614 return(False)
603615
616def website_notify():
617 """
618 Notify any webiste relations of any configuration changes.
619 """
620 juju_log("Notifying all website relations of change")
621 all_relations = relation_get_all("website")
622 if hasattr(all_relations, "iteritems"):
623 for relid, reldata in all_relations.iteritems():
624 relation_set(["time=%s" % time.time()], relation_id=relid)
625
604626
605###############################################################################627###############################################################################
606# Hook functions628# Hook functions
@@ -652,10 +674,12 @@
652def reverseproxy_interface(hook_name=None):674def reverseproxy_interface(hook_name=None):
653 if hook_name is None:675 if hook_name is None:
654 return(None)676 return(None)
655 if hook_name == "changed":677 elif hook_name == "changed":
656 config_changed()678 config_changed()
657 if hook_name=="departed":679 website_notify()
658 config_changed()680 elif hook_name=="departed":
681 config_changed()
682 website_notify()
659683
660def website_interface(hook_name=None):684def website_interface(hook_name=None):
661 if hook_name is None:685 if hook_name is None:
662686
=== modified file 'hooks/test_hooks.py'
--- hooks/test_hooks.py 2013-02-13 23:57:05 +0000
+++ hooks/test_hooks.py 2013-02-15 04:36:21 +0000
@@ -109,15 +109,6 @@
109 self.mocker.result(result)109 self.mocker.result(result)
110 self.mocker.count(1, None)110 self.mocker.count(1, None)
111111
112 def _expect_relation_set(self, args):
113 """
114 @param args: list of arguments expected to be passed to relation_set
115 """
116 obj = self.mocker.replace("hooks.relation_set")
117 obj(args)
118 self.relation_set = args
119 self.mocker.count(1,None)
120
121 def test_create_services(self):112 def test_create_services(self):
122 """113 """
123 Simplest use case, config stanza seeded in config file, server line114 Simplest use case, config stanza seeded in config file, server line
124115
=== modified file 'revision'
--- revision 2013-02-13 23:57:05 +0000
+++ revision 2013-02-15 04:36:21 +0000
@@ -1,1 +1,1 @@
139142

Subscribers

People subscribed via source and target branches