summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris MacNaughton <chris@centaurisolutions.nl>2019-01-30 15:54:56 +0100
committerChris MacNaughton <chris@centaurisolutions.nl>2019-02-01 11:08:12 +0100
commiteca9d8cd28f7ce6c71c8491e43281a0c0e3bf663 (patch)
tree1523171d9859e2d99a23679823167268eea5ab16
parent2c7836899d16c4ee832f2fef9f84f31c10a756f5 (diff)
Update source/packages if config changes
Also, this change removes the harden decorators as the required configuration for harden is _not_ present in the charm config, rendering it useless. Change-Id: I20c124d9588b8fd6c0e6611725a848eaf892f6af Closes-Bug: #1812219
Notes
Notes (review): Verified+1: Canonical CI <uosci-testing-bot@ubuntu.com> Code-Review+1: sahid <sahid.ferdjaoui@canonical.com> Code-Review+2: James Page <james.page@canonical.com> Workflow+1: James Page <james.page@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 11 Feb 2019 15:48:42 +0000 Reviewed-on: https://review.openstack.org/633969 Project: openstack/charm-ceph-proxy Branch: refs/heads/master
-rwxr-xr-xhooks/ceph_hooks.py15
-rw-r--r--unit_tests/test_ceph_hooks.py34
2 files changed, 41 insertions, 8 deletions
diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py
index 202f654..6347e0e 100755
--- a/hooks/ceph_hooks.py
+++ b/hooks/ceph_hooks.py
@@ -53,7 +53,6 @@ from ceph_broker import (
53) 53)
54 54
55from utils import get_unit_hostname 55from utils import get_unit_hostname
56from charmhelpers.contrib.hardening.harden import harden
57 56
58hooks = Hooks() 57hooks = Hooks()
59 58
@@ -66,17 +65,19 @@ def install_upstart_scripts():
66 65
67 66
68@hooks.hook('install.real') 67@hooks.hook('install.real')
69@harden()
70def install(): 68def install():
71 execd_preinstall() 69 execd_preinstall()
70 package_install()
71 install_upstart_scripts()
72
73
74def package_install():
72 add_source(config('source'), config('key')) 75 add_source(config('source'), config('key'))
73 apt_update(fatal=True) 76 apt_update(fatal=True)
74 apt_install(packages=ceph.PACKAGES, fatal=True) 77 apt_install(packages=ceph.PACKAGES, fatal=True)
75 install_upstart_scripts()
76 78
77 79
78def emit_cephconf(): 80def emit_cephconf():
79
80 cephcontext = { 81 cephcontext = {
81 'auth_supported': config('auth-supported'), 82 'auth_supported': config('auth-supported'),
82 'mon_hosts': config('monitor-hosts'), 83 'mon_hosts': config('monitor-hosts'),
@@ -117,8 +118,11 @@ def emit_cephconf():
117 118
118 119
119@hooks.hook('config-changed') 120@hooks.hook('config-changed')
120@harden()
121def config_changed(): 121def config_changed():
122 c = config()
123 if c.previous('source') != config('source') or \
124 c.previous('key') != config('key'):
125 package_install()
122 emit_cephconf() 126 emit_cephconf()
123 127
124 128
@@ -237,7 +241,6 @@ def assess_status():
237 241
238 242
239@hooks.hook('update-status') 243@hooks.hook('update-status')
240@harden()
241def update_status(): 244def update_status():
242 log('Updating status.') 245 log('Updating status.')
243 246
diff --git a/unit_tests/test_ceph_hooks.py b/unit_tests/test_ceph_hooks.py
index 4f65596..0b394cf 100644
--- a/unit_tests/test_ceph_hooks.py
+++ b/unit_tests/test_ceph_hooks.py
@@ -51,8 +51,8 @@ class TestHooks(test_utils.CharmTestCase):
51 self.log.side_effect = fake_log 51 self.log.side_effect = fake_log
52 52
53 @mock.patch('subprocess.check_output') 53 @mock.patch('subprocess.check_output')
54 def test_radosgw_realtion(self, mock_check_output): 54 @mock.patch('ceph_hooks.apt_install')
55 55 def test_radosgw_relation(self, mock_apt_install, mock_check_output):
56 settings = {'ceph-public-address': '127.0.0.1:1234 [::1]:4321', 56 settings = {'ceph-public-address': '127.0.0.1:1234 [::1]:4321',
57 'radosgw_key': CEPH_KEY, 57 'radosgw_key': CEPH_KEY,
58 'auth': 'cephx', 58 'auth': 'cephx',
@@ -66,6 +66,7 @@ class TestHooks(test_utils.CharmTestCase):
66 hooks.radosgw_relation() 66 hooks.radosgw_relation()
67 self.relation_set.assert_called_with(relation_id=None, 67 self.relation_set.assert_called_with(relation_id=None,
68 relation_settings=settings) 68 relation_settings=settings)
69 mock_apt_install.assert_called_with(packages=[])
69 70
70 @mock.patch('ceph.ceph_user') 71 @mock.patch('ceph.ceph_user')
71 @mock.patch.object(hooks, 'radosgw_relation') 72 @mock.patch.object(hooks, 'radosgw_relation')
@@ -136,3 +137,32 @@ class TestHooks(test_utils.CharmTestCase):
136 137
137 self.relation_set.assert_called_with(relation_id='client:1', 138 self.relation_set.assert_called_with(relation_id='client:1',
138 relation_settings=data) 139 relation_settings=data)
140
141 @mock.patch('ceph_hooks.emit_cephconf')
142 @mock.patch('ceph_hooks.package_install')
143 def test_config_get_skips_package_update(self,
144 mock_package_install,
145 mock_emit_cephconf):
146 previous_test_config = test_utils.TestConfig()
147 previous_test_config.set('source', 'distro')
148 previous_test_config.set('key', '')
149 previous = mock.MagicMock().return_value
150 previous.previous.side_effect = lambda x: previous_test_config.get(x)
151 self.config.side_effect = [previous, "distro", ""]
152 hooks.config_changed()
153 mock_package_install.assert_not_called()
154 mock_emit_cephconf.assert_any_call()
155
156 @mock.patch('ceph_hooks.emit_cephconf')
157 @mock.patch('ceph_hooks.package_install')
158 def test_update_apt_source(self, mock_package_install, mock_emit_cephconf):
159
160 previous_test_config = test_utils.TestConfig()
161 previous_test_config.set('source', 'distro')
162 previous_test_config.set('key', '')
163 previous = mock.MagicMock().return_value
164 previous.previous.side_effect = lambda x: previous_test_config.get(x)
165 self.config.side_effect = [previous, "cloud:cosmic-mimic", ""]
166 hooks.config_changed()
167 mock_package_install.assert_called_with()
168 mock_emit_cephconf.assert_called_with()