Merge ~niedbalski/charm-prometheus-openstack-exporter/+git/charm-prometheus-openstack-exporter:reconfig-on-change into ~prometheus-charmers/charm-prometheus-openstack-exporter/+git/prometheus-openstack-exporter-charm:master

Proposed by Jorge Niedbalski
Status: Merged
Approved by: Stuart Bishop
Approved revision: 186e23bf1dd6327b95d4b1da1f4ee5945b50affb
Merged at revision: 6a6b506384c65f327c906078a21b3146e2183fb3
Proposed branch: ~niedbalski/charm-prometheus-openstack-exporter/+git/charm-prometheus-openstack-exporter:reconfig-on-change
Merge into: ~prometheus-charmers/charm-prometheus-openstack-exporter/+git/prometheus-openstack-exporter-charm:master
Diff against target: 74 lines (+26/-7)
2 files modified
reactive/openstack_exporter.py (+11/-4)
unit_tests/test_reactive_openstack_exporter.py (+15/-3)
Reviewer Review Type Date Requested Status
Jorge Niedbalski (community) Approve
Stuart Bishop (community) Approve
Felipe Reyes (community) Approve
Review via email: mp+369730@code.launchpad.net

Commit message

This patch implements a reconfig_on_change method that validates that the event/relation data has changed prior to execute a reconfig and a subsequent service restart.

This fixes the behavior described on LP: #1835277

Description of the change

This patch implements a reconfig_on_change method that validates that the event/relation data has changed prior to execute a reconfig and a subsequent service restart.

This fixes the behavior described on LP: #1835277

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Felipe Reyes (freyes) wrote :

On top of the comment I left inline, your patch was committed on top of a very old commit, please could you rebase your commit of the HEAD of the master repo?, I merged it locally and there are no conflicts, but still an extra testing would be appropriate.

review: Needs Fixing
Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

@freyes,

Thanks for reviewing, I've rebased it against the proper branch and fixed the observations about logging INFO levels.

I'd appreciate your review.

Thanks.

Revision history for this message
Felipe Reyes (freyes) wrote :

LGTM, thanks for the patch, @niedbalski.

review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good. I think the first test could be improved per inline comment, which can be updated before landing if you agree.

review: Approve
Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

@stub,

Yes, sure. Please add the inline comment before merging.

Thanks!

Revision history for this message
Stuart Bishop (stub) wrote :

Mergebot will land this branch when the merge proposal status is set to Approved. I can't make updates to the branch as I don't own it.

Revision history for this message
Jorge Niedbalski (niedbalski) :
review: Approve
Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

OK, reviewed @stub comments on the tests, should be ready for merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 6a6b506384c65f327c906078a21b3146e2183fb3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/openstack_exporter.py b/reactive/openstack_exporter.py
2index a654797..aa88150 100644
3--- a/reactive/openstack_exporter.py
4+++ b/reactive/openstack_exporter.py
5@@ -63,6 +63,15 @@ def config_paths(key):
6 return config_path
7
8
9+def reconfig_on_change(key, data):
10+ if not data_changed(key, data):
11+ hookenv.log('{} data unchanged, skipping reconfig'.format(key), level=hookenv.DEBUG)
12+ return
13+ unitdata.kv().set(key, data)
14+ hookenv.log('{} data changed, triggering reconfig'.format(key), level=hookenv.DEBUG)
15+ set_state('exporter.do-reconfig')
16+
17+
18 @when_not('exporter.installed')
19 def install_packages():
20 hookenv.status_set('maintenance', 'Installing software')
21@@ -80,8 +89,7 @@ def save_swift_hosts(swift):
22 functools.reduce(lambda x, y: x + y,
23 [s['hosts'] for s in services])]
24 hookenv.log('services => {}, hosts => {}'.format(services, swift_hosts))
25- unitdata.kv().set('swift_hosts', swift_hosts)
26- set_state('exporter.do-reconfig')
27+ reconfig_on_change('swift_hosts', swift_hosts)
28
29
30 @when('identity-credentials.connected')
31@@ -92,8 +100,7 @@ def configure_keystone_username(keystone):
32
33 @when('identity-credentials.available')
34 def save_creds(keystone):
35- unitdata.kv().set('keystone-relation-creds', keystone.get_creds())
36- set_state('exporter.do-reconfig')
37+ reconfig_on_change('keystone-relation-creds', keystone.get_creds())
38
39
40 @when_any('exporter.installed', 'exporter.do-check-reconfig')
41diff --git a/unit_tests/test_reactive_openstack_exporter.py b/unit_tests/test_reactive_openstack_exporter.py
42index 5691426..470d0b2 100644
43--- a/unit_tests/test_reactive_openstack_exporter.py
44+++ b/unit_tests/test_reactive_openstack_exporter.py
45@@ -32,10 +32,7 @@ class SimpleConfigMock(dict):
46 @mock.patch('os.chmod')
47 @mock.patch('os.fchown')
48 @mock.patch('reactive.openstack_exporter.hookenv.status_set')
49-# @mock.patch('reactive.openstack_exporter.host.service_restart')
50 @mock.patch('reactive.openstack_exporter.configure_keystone_username')
51-@mock.patch('reactive.openstack_exporter.set_state')
52-@mock.patch('reactive.openstack_exporter.data_changed')
53 @mock.patch('reactive.openstack_exporter.hookenv.unit_get')
54 @mock.patch('reactive.openstack_exporter.hookenv.config')
55 class TestOpenstackExporterContext(unittest.TestCase):
56@@ -118,3 +115,18 @@ class TestOpenstackExporterContext(unittest.TestCase):
57 def test_restart(self, _mock_service_restart, *args):
58 openstack_exporter.do_restart()
59 _mock_service_restart.assert_called_once()
60+
61+ @mock.patch('reactive.openstack_exporter.set_state')
62+ @mock.patch('reactive.openstack_exporter.data_changed')
63+ def test_reconfig_on_change(self, data_changed, set_state, *args):
64+ data_changed.return_value = True
65+ openstack_exporter.reconfig_on_change('foo', "{'bar': 'foo'}")
66+ data_changed.assert_called_once_with('foo', "{'bar': 'foo'}")
67+ set_state.assert_called_once_with('exporter.do-reconfig')
68+
69+ @mock.patch('reactive.openstack_exporter.set_state')
70+ @mock.patch('reactive.openstack_exporter.data_changed')
71+ def test_reconfig_on_change_unchanged(self, data_changed, set_state, *args):
72+ data_changed.return_value = False
73+ openstack_exporter.reconfig_on_change('foo', "bar")
74+ set_state.assert_not_called()

Subscribers

People subscribed via source and target branches