Merge lp:~thedac/charms/trusty/neutron-gateway/action-managed-upgrade into lp:~openstack-charmers-archive/charms/trusty/neutron-gateway/next

Proposed by David Ames
Status: Merged
Merged at revision: 141
Proposed branch: lp:~thedac/charms/trusty/neutron-gateway/action-managed-upgrade
Merge into: lp:~openstack-charmers-archive/charms/trusty/neutron-gateway/next
Diff against target: 266 lines (+158/-5)
8 files modified
actions.yaml (+2/-0)
actions/openstack_upgrade.py (+36/-0)
config.yaml (+10/-0)
hooks/charmhelpers/contrib/openstack/utils.py (+51/-0)
hooks/neutron_hooks.py (+2/-3)
hooks/neutron_utils.py (+2/-1)
unit_tests/test_actions_openstack_upgrade.py (+53/-0)
unit_tests/test_neutron_utils.py (+2/-1)
To merge this branch: bzr merge lp:~thedac/charms/trusty/neutron-gateway/action-managed-upgrade
Reviewer Review Type Date Requested Status
David Ames (community) Needs Resubmitting
Billy Olsen Needs Fixing
OpenStack Charmers Pending
Review via email: mp+271183@code.launchpad.net

Description of the change

Action managed upgrades

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #10063 neutron-gateway-next for thedac mp271183
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/10063/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #9228 neutron-gateway-next for thedac mp271183
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/9228/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6449 neutron-gateway-next for thedac mp271183
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12420416/
Build: http://10.245.162.77:8080/job/charm_amulet_test/6449/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #10421 neutron-gateway-next for thedac mp271183
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/10421/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #9611 neutron-gateway-next for thedac mp271183
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/9611/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6566 neutron-gateway-next for thedac mp271183
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/6566/

Revision history for this message
Billy Olsen (billy-olsen) wrote :

David, same comment in this MP as with the openstack-dashboard MP. Quick comment inline which is a fairly simple fix and it should be good to go.

review: Needs Fixing
145. By David Ames

Do not use register_configs import CONFIGS directly

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #10572 neutron-gateway-next for thedac mp271183
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/10572/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #9762 neutron-gateway-next for thedac mp271183
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/9762/

Revision history for this message
David Ames (thedac) wrote :

Resubmit

review: Needs Resubmitting
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6707 neutron-gateway-next for thedac mp271183
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/6707/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'actions.yaml'
2--- actions.yaml 2015-04-10 14:22:04 +0000
3+++ actions.yaml 2015-09-23 14:40:28 +0000
4@@ -1,2 +1,4 @@
5 git-reinstall:
6 description: Reinstall quantum-gateway from the openstack-origin-git repositories.
7+openstack-upgrade:
8+ description: Perform openstack upgrades. Config option action-managed-upgrade must be set to True.
9
10=== added symlink 'actions/openstack-upgrade'
11=== target is u'openstack_upgrade.py'
12=== added file 'actions/openstack_upgrade.py'
13--- actions/openstack_upgrade.py 1970-01-01 00:00:00 +0000
14+++ actions/openstack_upgrade.py 2015-09-23 14:40:28 +0000
15@@ -0,0 +1,36 @@
16+#!/usr/bin/python
17+import sys
18+
19+sys.path.append('hooks/')
20+
21+from charmhelpers.contrib.openstack.utils import (
22+ do_action_openstack_upgrade,
23+)
24+
25+from neutron_utils import (
26+ do_openstack_upgrade,
27+ get_common_package,
28+)
29+
30+from neutron_hooks import (
31+ config_changed,
32+ CONFIGS,
33+)
34+
35+
36+def openstack_upgrade():
37+ """Upgrade packages to config-set Openstack version.
38+
39+ If the charm was installed from source we cannot upgrade it.
40+ For backwards compatibility a config flag must be set for this
41+ code to run, otherwise a full service level upgrade will fire
42+ on config-changed."""
43+
44+ if do_action_openstack_upgrade(get_common_package(),
45+ do_openstack_upgrade,
46+ CONFIGS):
47+ config_changed()
48+
49+
50+if __name__ == '__main__':
51+ openstack_upgrade()
52
53=== modified file 'config.yaml'
54--- config.yaml 2015-09-15 20:26:06 +0000
55+++ config.yaml 2015-09-23 14:40:28 +0000
56@@ -216,3 +216,13 @@
57 description: |
58 Default multicast port number that will be used to communicate between
59 HA Cluster nodes.
60+ action-managed-upgrade:
61+ type: boolean
62+ default: False
63+ description: |
64+ If True enables openstack upgrades for this charm via juju actions.
65+ You will still need to set openstack-origin to the new repository but
66+ instead of an upgrade running automatically across all units, it will
67+ wait for you to execute the openstack-upgrade action for this charm on
68+ each unit. If False it will revert to existing behavior of upgrading
69+ all units on config change.
70
71=== modified file 'hooks/charmhelpers/contrib/openstack/utils.py'
72--- hooks/charmhelpers/contrib/openstack/utils.py 2015-09-03 09:43:15 +0000
73+++ hooks/charmhelpers/contrib/openstack/utils.py 2015-09-23 14:40:28 +0000
74@@ -25,6 +25,7 @@
75 import re
76
77 import six
78+import traceback
79 import yaml
80
81 from charmhelpers.contrib.network import ip
82@@ -34,6 +35,8 @@
83 )
84
85 from charmhelpers.core.hookenv import (
86+ action_fail,
87+ action_set,
88 config,
89 log as juju_log,
90 charm_dir,
91@@ -114,6 +117,7 @@
92 ('2.2.1', 'kilo'),
93 ('2.2.2', 'kilo'),
94 ('2.3.0', 'liberty'),
95+ ('2.4.0', 'liberty'),
96 ])
97
98 # >= Liberty version->codename mapping
99@@ -142,6 +146,9 @@
100 'glance-common': OrderedDict([
101 ('11.0.0', 'liberty'),
102 ]),
103+ 'openstack-dashboard': OrderedDict([
104+ ('8.0.0', 'liberty'),
105+ ]),
106 }
107
108 DEFAULT_LOOPBACK_SIZE = '5G'
109@@ -745,3 +752,47 @@
110 return projects[key]
111
112 return None
113+
114+
115+def do_action_openstack_upgrade(package, upgrade_callback, configs):
116+ """Perform action-managed OpenStack upgrade.
117+
118+ Upgrades packages to the configured openstack-origin version and sets
119+ the corresponding action status as a result.
120+
121+ If the charm was installed from source we cannot upgrade it.
122+ For backwards compatibility a config flag (action-managed-upgrade) must
123+ be set for this code to run, otherwise a full service level upgrade will
124+ fire on config-changed.
125+
126+ @param package: package name for determining if upgrade available
127+ @param upgrade_callback: function callback to charm's upgrade function
128+ @param configs: templating object derived from OSConfigRenderer class
129+
130+ @return: True if upgrade successful; False if upgrade failed or skipped
131+ """
132+ ret = False
133+
134+ if git_install_requested():
135+ action_set({'outcome': 'installed from source, skipped upgrade.'})
136+ else:
137+ if openstack_upgrade_available(package):
138+ if config('action-managed-upgrade'):
139+ juju_log('Upgrading OpenStack release')
140+
141+ try:
142+ upgrade_callback(configs=configs)
143+ action_set({'outcome': 'success, upgrade completed.'})
144+ ret = True
145+ except:
146+ action_set({'outcome': 'upgrade failed, see traceback.'})
147+ action_set({'traceback': traceback.format_exc()})
148+ action_fail('do_openstack_upgrade resulted in an '
149+ 'unexpected error')
150+ else:
151+ action_set({'outcome': 'action-managed-upgrade config is '
152+ 'False, skipped upgrade.'})
153+ else:
154+ action_set({'outcome': 'no upgrade available.'})
155+
156+ return ret
157
158=== modified file 'hooks/neutron_hooks.py'
159--- hooks/neutron_hooks.py 2015-09-22 13:46:41 +0000
160+++ hooks/neutron_hooks.py 2015-09-23 14:40:28 +0000
161@@ -102,10 +102,9 @@
162 if config_value_changed('openstack-origin-git'):
163 git_install(config('openstack-origin-git'))
164 CONFIGS.write_all()
165- else:
166+ elif not config('action-managed-upgrade'):
167 if openstack_upgrade_available(get_common_package()):
168- do_openstack_upgrade()
169- CONFIGS.write_all()
170+ do_openstack_upgrade(CONFIGS)
171
172 update_nrpe_config()
173
174
175=== modified file 'hooks/neutron_utils.py'
176--- hooks/neutron_utils.py 2015-09-10 12:35:59 +0000
177+++ hooks/neutron_utils.py 2015-09-23 14:40:28 +0000
178@@ -652,7 +652,7 @@
179 return list(set(_services))
180
181
182-def do_openstack_upgrade():
183+def do_openstack_upgrade(configs):
184 """
185 Perform an upgrade. Takes care of upgrading packages, rewriting
186 configs, database migrations and potentially any other post-upgrade
187@@ -672,6 +672,7 @@
188 fatal=True, dist=True)
189 apt_install(get_early_packages(), fatal=True)
190 apt_install(get_packages(), fatal=True)
191+ configs.write_all()
192
193
194 def configure_ovs():
195
196=== added file 'unit_tests/test_actions_openstack_upgrade.py'
197--- unit_tests/test_actions_openstack_upgrade.py 1970-01-01 00:00:00 +0000
198+++ unit_tests/test_actions_openstack_upgrade.py 2015-09-23 14:40:28 +0000
199@@ -0,0 +1,53 @@
200+from mock import patch
201+import os
202+
203+os.environ['JUJU_UNIT_NAME'] = 'neutron-gateway'
204+
205+with patch('neutron_utils.register_configs') as register_configs:
206+ import openstack_upgrade
207+
208+from test_utils import (
209+ CharmTestCase
210+)
211+
212+TO_PATCH = [
213+ 'do_openstack_upgrade',
214+ 'config_changed',
215+]
216+
217+
218+class TestNeutronGWUpgradeActions(CharmTestCase):
219+
220+ def setUp(self):
221+ super(TestNeutronGWUpgradeActions, self).setUp(openstack_upgrade,
222+ TO_PATCH)
223+
224+ @patch('charmhelpers.contrib.openstack.utils.config')
225+ @patch('charmhelpers.contrib.openstack.utils.action_set')
226+ @patch('charmhelpers.contrib.openstack.utils.git_install_requested')
227+ @patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available')
228+ def test_openstack_upgrade_true(self, upgrade_avail, git_requested,
229+ action_set, config):
230+ git_requested.return_value = False
231+ upgrade_avail.return_value = True
232+ config.return_value = True
233+
234+ openstack_upgrade.openstack_upgrade()
235+
236+ self.assertTrue(self.do_openstack_upgrade.called)
237+ self.assertTrue(self.config_changed.called)
238+
239+ @patch('charmhelpers.contrib.openstack.utils.config')
240+ @patch('charmhelpers.contrib.openstack.utils.action_set')
241+ @patch('charmhelpers.contrib.openstack.utils.git_install_requested')
242+ @patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available')
243+ def test_openstack_upgrade_false(self, upgrade_avail, git_requested,
244+ action_set, config):
245+ git_requested.return_value = False
246+ upgrade_avail.return_value = True
247+ config.return_value = False
248+
249+ openstack_upgrade.openstack_upgrade()
250+
251+ self.assertFalse(self.do_openstack_upgrade.called)
252+ self.assertFalse(self.config_changed.called)
253
254=== modified file 'unit_tests/test_neutron_utils.py'
255--- unit_tests/test_neutron_utils.py 2015-09-10 12:35:59 +0000
256+++ unit_tests/test_neutron_utils.py 2015-09-23 14:40:28 +0000
257@@ -244,7 +244,8 @@
258 self.test_config.set('openstack-origin', 'cloud:precise-havana')
259 self.test_config.set('plugin', 'ovs')
260 self.get_os_codename_install_source.return_value = 'havana'
261- neutron_utils.do_openstack_upgrade()
262+ configs = neutron_utils.register_configs()
263+ neutron_utils.do_openstack_upgrade(configs)
264 self.assertTrue(self.log.called)
265 self.apt_update.assert_called_with(fatal=True)
266 dpkg_opts = [

Subscribers

People subscribed via source and target branches