Merge lp:~james-page/charm-helpers/disable-hookenv-config-save into lp:charm-helpers

Proposed by James Page
Status: Merged
Merge reported by: Tim Van Steenburgh
Merged at revision: not available
Proposed branch: lp:~james-page/charm-helpers/disable-hookenv-config-save
Merge into: lp:charm-helpers
Diff against target: 51 lines (+17/-4)
2 files modified
charmhelpers/core/hookenv.py (+6/-4)
tests/core/test_hookenv.py (+11/-0)
To merge this branch: bzr merge lp:~james-page/charm-helpers/disable-hookenv-config-save
Reviewer Review Type Date Requested Status
Tim Van Steenburgh Approve
charmers Pending
Review via email: mp+235607@code.launchpad.net

Description of the change

Add option to allow override in hookenv of configuration implicit save.

The introduction of the implicit save in Hooks broken pretty much all unit tests
in the openstack charms which exercise hook registration directly to ensure
hooks are correctly registered.

This change allows the save to be by-passed completely.

To post a comment you must log in.
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1 LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/hookenv.py'
2--- charmhelpers/core/hookenv.py 2014-09-08 02:28:10 +0000
3+++ charmhelpers/core/hookenv.py 2014-09-23 10:45:34 +0000
4@@ -486,9 +486,10 @@
5 hooks.execute(sys.argv)
6 """
7
8- def __init__(self):
9+ def __init__(self, config_save=True):
10 super(Hooks, self).__init__()
11 self._hooks = {}
12+ self._config_save = config_save
13
14 def register(self, name, function):
15 """Register a hook"""
16@@ -499,9 +500,10 @@
17 hook_name = os.path.basename(args[0])
18 if hook_name in self._hooks:
19 self._hooks[hook_name]()
20- cfg = config()
21- if cfg.implicit_save:
22- cfg.save()
23+ if self._config_save:
24+ cfg = config()
25+ if cfg.implicit_save:
26+ cfg.save()
27 else:
28 raise UnregisteredHookError(hook_name)
29
30
31=== modified file 'tests/core/test_hookenv.py'
32--- tests/core/test_hookenv.py 2014-09-05 16:31:44 +0000
33+++ tests/core/test_hookenv.py 2014-09-23 10:45:34 +0000
34@@ -972,6 +972,17 @@
35
36 self.assertFalse(config.save.called)
37
38+ def test_config_save_disabled(self):
39+ config = hookenv.config()
40+ config.implicit_save = True
41+
42+ foo = MagicMock()
43+ hooks = hookenv.Hooks(config_save=False)
44+ hooks.register('foo', foo)
45+ hooks.execute(['foo', 'some', 'other', 'args'])
46+
47+ self.assertFalse(config.save.called)
48+
49 def test_runs_a_registered_function(self):
50 foo = MagicMock()
51 hooks = hookenv.Hooks()

Subscribers

People subscribed via source and target branches