Merge lp:~thedac/charms/trusty/openstack-dashboard/action-managed-upgrade into lp:~openstack-charmers-archive/charms/trusty/openstack-dashboard/next
- Trusty Tahr (14.04)
- action-managed-upgrade
- Merge into next
Status: | Merged |
---|---|
Merged at revision: | 87 |
Proposed branch: | lp:~thedac/charms/trusty/openstack-dashboard/action-managed-upgrade |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/openstack-dashboard/next |
Diff against target: |
216 lines (+148/-2) 6 files modified
actions.yaml (+2/-0) actions/openstack_upgrade.py (+34/-0) config.yaml (+10/-1) hooks/charmhelpers/contrib/openstack/utils.py (+48/-0) hooks/horizon_hooks.py (+1/-1) unit_tests/test_actions_openstack_upgrade.py (+53/-0) |
To merge this branch: | bzr merge lp:~thedac/charms/trusty/openstack-dashboard/action-managed-upgrade |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Ames (community) | Needs Resubmitting | ||
Billy Olsen | Needs Fixing | ||
OpenStack Charmers | Pending | ||
Review via email: mp+271027@code.launchpad.net |
Commit message
Description of the change
Add action managed upgrades of OpenStack
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9160 openstack-
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6425 openstack-
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://
Build: http://
- 86. By David Ames
-
Add tests for action managed upgrade
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10062 openstack-
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9229 openstack-
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6448 openstack-
AMULET OK: passed
Build: http://
Corey Bryant (corey.bryant) wrote : | # |
Hey David, inline comment below.
Corey Bryant (corey.bryant) wrote : | # |
Response to my initial comment inline.h
Corey Bryant (corey.bryant) wrote : | # |
Bad wifi, added comment inline again
- 87. By David Ames
-
Specifically call config_changed which has the restart_on_change decorator
- 88. By David Ames
-
Fix tests
David Ames (thedac) wrote : | # |
Agreed. Calling config_changed() on successful upgrade.
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9613 openstack-
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10424 openstack-
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6569 openstack-
AMULET OK: passed
Build: http://
Billy Olsen (billy-olsen) wrote : | # |
David, added an inline comment below. Minor fix and it should be good to go.
- 89. By David Ames
-
Do not use register_configs import CONFIGS directly
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #10574 openstack-
LINT OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #9761 openstack-
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #6706 openstack-
AMULET OK: passed
Build: http://
Preview Diff
1 | === modified file 'actions.yaml' |
2 | --- actions.yaml 2015-04-07 13:58:41 +0000 |
3 | +++ actions.yaml 2015-09-23 14:38:13 +0000 |
4 | @@ -1,2 +1,4 @@ |
5 | git-reinstall: |
6 | description: Reinstall openstack-dashboard 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:38:13 +0000 |
15 | @@ -0,0 +1,34 @@ |
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 horizon_utils import ( |
26 | + do_openstack_upgrade, |
27 | +) |
28 | + |
29 | +from horizon_hooks import ( |
30 | + config_changed, |
31 | + CONFIGS, |
32 | +) |
33 | + |
34 | + |
35 | +def openstack_upgrade(): |
36 | + """Upgrade packages to config-set Openstack version. |
37 | + |
38 | + If the charm was installed from source we cannot upgrade it. |
39 | + For backwards compatibility a config flag must be set for this |
40 | + code to run, otherwise a full service level upgrade will fire |
41 | + on config-changed.""" |
42 | + |
43 | + if do_action_openstack_upgrade('openstack-dashboard', |
44 | + do_openstack_upgrade, |
45 | + CONFIGS): |
46 | + config_changed() |
47 | + |
48 | +if __name__ == '__main__': |
49 | + openstack_upgrade() |
50 | |
51 | === modified file 'config.yaml' |
52 | --- config.yaml 2015-07-10 14:18:48 +0000 |
53 | +++ config.yaml 2015-09-23 14:38:13 +0000 |
54 | @@ -175,4 +175,13 @@ |
55 | description: | |
56 | A comma-separated list of nagios servicegroups. If left empty, the |
57 | nagios_context will be used as the servicegroup. |
58 | - |
59 | + action-managed-upgrade: |
60 | + type: boolean |
61 | + default: False |
62 | + description: | |
63 | + If True enables openstack upgrades for this charm via juju actions. |
64 | + You will still need to set openstack-origin to the new repository but |
65 | + instead of an upgrade running automatically across all units, it will |
66 | + wait for you to execute the openstack-upgrade action for this charm on |
67 | + each unit. If False it will revert to existing behavior of upgrading |
68 | + all units on config change. |
69 | |
70 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' |
71 | --- hooks/charmhelpers/contrib/openstack/utils.py 2015-09-04 13:59:26 +0000 |
72 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2015-09-23 14:38:13 +0000 |
73 | @@ -25,6 +25,7 @@ |
74 | import re |
75 | |
76 | import six |
77 | +import traceback |
78 | import yaml |
79 | |
80 | from charmhelpers.contrib.network import ip |
81 | @@ -34,6 +35,8 @@ |
82 | ) |
83 | |
84 | from charmhelpers.core.hookenv import ( |
85 | + action_fail, |
86 | + action_set, |
87 | config, |
88 | log as juju_log, |
89 | charm_dir, |
90 | @@ -114,6 +117,7 @@ |
91 | ('2.2.1', 'kilo'), |
92 | ('2.2.2', 'kilo'), |
93 | ('2.3.0', 'liberty'), |
94 | + ('2.4.0', 'liberty'), |
95 | ]) |
96 | |
97 | # >= Liberty version->codename mapping |
98 | @@ -748,3 +752,47 @@ |
99 | return projects[key] |
100 | |
101 | return None |
102 | + |
103 | + |
104 | +def do_action_openstack_upgrade(package, upgrade_callback, configs): |
105 | + """Perform action-managed OpenStack upgrade. |
106 | + |
107 | + Upgrades packages to the configured openstack-origin version and sets |
108 | + the corresponding action status as a result. |
109 | + |
110 | + If the charm was installed from source we cannot upgrade it. |
111 | + For backwards compatibility a config flag (action-managed-upgrade) must |
112 | + be set for this code to run, otherwise a full service level upgrade will |
113 | + fire on config-changed. |
114 | + |
115 | + @param package: package name for determining if upgrade available |
116 | + @param upgrade_callback: function callback to charm's upgrade function |
117 | + @param configs: templating object derived from OSConfigRenderer class |
118 | + |
119 | + @return: True if upgrade successful; False if upgrade failed or skipped |
120 | + """ |
121 | + ret = False |
122 | + |
123 | + if git_install_requested(): |
124 | + action_set({'outcome': 'installed from source, skipped upgrade.'}) |
125 | + else: |
126 | + if openstack_upgrade_available(package): |
127 | + if config('action-managed-upgrade'): |
128 | + juju_log('Upgrading OpenStack release') |
129 | + |
130 | + try: |
131 | + upgrade_callback(configs=configs) |
132 | + action_set({'outcome': 'success, upgrade completed.'}) |
133 | + ret = True |
134 | + except: |
135 | + action_set({'outcome': 'upgrade failed, see traceback.'}) |
136 | + action_set({'traceback': traceback.format_exc()}) |
137 | + action_fail('do_openstack_upgrade resulted in an ' |
138 | + 'unexpected error') |
139 | + else: |
140 | + action_set({'outcome': 'action-managed-upgrade config is ' |
141 | + 'False, skipped upgrade.'}) |
142 | + else: |
143 | + action_set({'outcome': 'no upgrade available.'}) |
144 | + |
145 | + return ret |
146 | |
147 | === modified file 'hooks/horizon_hooks.py' |
148 | --- hooks/horizon_hooks.py 2015-09-23 08:07:40 +0000 |
149 | +++ hooks/horizon_hooks.py 2015-09-23 14:38:13 +0000 |
150 | @@ -104,7 +104,7 @@ |
151 | if git_install_requested(): |
152 | if config_value_changed('openstack-origin-git'): |
153 | git_install(config('openstack-origin-git')) |
154 | - else: |
155 | + elif not config('action-managed-upgrade'): |
156 | if openstack_upgrade_available('openstack-dashboard'): |
157 | do_openstack_upgrade(configs=CONFIGS) |
158 | |
159 | |
160 | === added file 'unit_tests/test_actions_openstack_upgrade.py' |
161 | --- unit_tests/test_actions_openstack_upgrade.py 1970-01-01 00:00:00 +0000 |
162 | +++ unit_tests/test_actions_openstack_upgrade.py 2015-09-23 14:38:13 +0000 |
163 | @@ -0,0 +1,53 @@ |
164 | +from mock import patch |
165 | +import os |
166 | + |
167 | +os.environ['JUJU_UNIT_NAME'] = 'openstack-dashboard' |
168 | + |
169 | +with patch('horizon_utils.register_configs') as register_configs: |
170 | + import openstack_upgrade |
171 | + |
172 | +from test_utils import ( |
173 | + CharmTestCase |
174 | +) |
175 | + |
176 | +TO_PATCH = [ |
177 | + 'do_openstack_upgrade', |
178 | + 'config_changed', |
179 | +] |
180 | + |
181 | + |
182 | +class TestHorizonUpgradeActions(CharmTestCase): |
183 | + |
184 | + def setUp(self): |
185 | + super(TestHorizonUpgradeActions, self).setUp(openstack_upgrade, |
186 | + TO_PATCH) |
187 | + |
188 | + @patch('charmhelpers.contrib.openstack.utils.config') |
189 | + @patch('charmhelpers.contrib.openstack.utils.action_set') |
190 | + @patch('charmhelpers.contrib.openstack.utils.git_install_requested') |
191 | + @patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available') |
192 | + def test_openstack_upgrade_true(self, upgrade_avail, git_requested, |
193 | + action_set, config): |
194 | + git_requested.return_value = False |
195 | + upgrade_avail.return_value = True |
196 | + config.return_value = True |
197 | + |
198 | + openstack_upgrade.openstack_upgrade() |
199 | + |
200 | + self.assertTrue(self.do_openstack_upgrade.called) |
201 | + self.assertTrue(self.config_changed.called) |
202 | + |
203 | + @patch('charmhelpers.contrib.openstack.utils.config') |
204 | + @patch('charmhelpers.contrib.openstack.utils.action_set') |
205 | + @patch('charmhelpers.contrib.openstack.utils.git_install_requested') |
206 | + @patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available') |
207 | + def test_openstack_upgrade_false(self, upgrade_avail, git_requested, |
208 | + action_set, config): |
209 | + git_requested.return_value = False |
210 | + upgrade_avail.return_value = True |
211 | + config.return_value = False |
212 | + |
213 | + openstack_upgrade.openstack_upgrade() |
214 | + |
215 | + self.assertFalse(self.do_openstack_upgrade.called) |
216 | + self.assertFalse(self.config_changed.called) |
charm_lint_check #9942 openstack- dashboard- next for thedac mp271027
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/9942/