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

Proposed by David Ames on 2015-09-22
Status: Merged
Merged at revision: 83
Proposed branch: lp:~thedac/charms/trusty/swift-storage/action-managed-upgrade
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-storage/next
Diff against target: 215 lines (+153/-2)
6 files modified
actions.yaml (+2/-1)
actions/openstack_upgrade.py (+34/-0)
charmhelpers/contrib/openstack/utils.py (+47/-0)
config.yaml (+10/-0)
hooks/swift_storage_hooks.py (+2/-1)
unit_tests/test_actions_openstack_upgrade.py (+58/-0)
To merge this branch: bzr merge lp:~thedac/charms/trusty/swift-storage/action-managed-upgrade
Reviewer Review Type Date Requested Status
OpenStack Charmers 2015-09-22 Pending
Review via email: mp+272046@code.launchpad.net

Description of the Change

Action managed upgrades

To post a comment you must log in.

charm_lint_check #10473 swift-storage-next for thedac mp272046
    LINT OK: passed

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

charm_unit_test #9664 swift-storage-next for thedac mp272046
    UNIT OK: passed

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

charm_amulet_test #6616 swift-storage-next for thedac mp272046
    AMULET OK: passed

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

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-08-11 09:55:31 +0000
3+++ actions.yaml 2015-09-22 23:01:36 +0000
4@@ -2,4 +2,5 @@
5 description: Pause the swift-storage unit. This action will stop Swift services.
6 resume:
7 description: Resume the swift-storage unit. This action will start Swift services.
8-
9+openstack-upgrade:
10+ description: Perform openstack upgrades. Config option action-managed-upgrade must be set to True.
11
12=== added symlink 'actions/openstack-upgrade'
13=== target is u'openstack_upgrade.py'
14=== added file 'actions/openstack_upgrade.py'
15--- actions/openstack_upgrade.py 1970-01-01 00:00:00 +0000
16+++ actions/openstack_upgrade.py 2015-09-22 23:01:36 +0000
17@@ -0,0 +1,34 @@
18+#!/usr/bin/python
19+import sys
20+
21+sys.path.append('hooks/')
22+
23+from charmhelpers.contrib.openstack.utils import (
24+ do_action_openstack_upgrade,
25+)
26+
27+from swift_storage_hooks import (
28+ config_changed,
29+ CONFIGS,
30+)
31+
32+from lib.swift_storage_utils import (
33+ do_openstack_upgrade,
34+)
35+
36+
37+def openstack_upgrade():
38+ """Upgrade packages to config-set Openstack version.
39+
40+ If the charm was installed from source we cannot upgrade it.
41+ For backwards compatibility a config flag must be set for this
42+ code to run, otherwise a full service level upgrade will fire
43+ on config-changed."""
44+
45+ if (do_action_openstack_upgrade('swift',
46+ do_openstack_upgrade,
47+ CONFIGS)):
48+ config_changed()
49+
50+if __name__ == '__main__':
51+ openstack_upgrade()
52
53=== modified file 'charmhelpers/contrib/openstack/utils.py'
54--- charmhelpers/contrib/openstack/utils.py 2015-09-14 11:43:35 +0000
55+++ charmhelpers/contrib/openstack/utils.py 2015-09-22 23:01:36 +0000
56@@ -25,6 +25,7 @@
57 import re
58
59 import six
60+import traceback
61 import yaml
62
63 from charmhelpers.contrib.network import ip
64@@ -34,6 +35,8 @@
65 )
66
67 from charmhelpers.core.hookenv import (
68+ action_fail,
69+ action_set,
70 config,
71 log as juju_log,
72 charm_dir,
73@@ -749,3 +752,47 @@
74 return projects[key]
75
76 return None
77+
78+
79+def do_action_openstack_upgrade(package, upgrade_callback, configs):
80+ """Perform action-managed OpenStack upgrade.
81+
82+ Upgrades packages to the configured openstack-origin version and sets
83+ the corresponding action status as a result.
84+
85+ If the charm was installed from source we cannot upgrade it.
86+ For backwards compatibility a config flag (action-managed-upgrade) must
87+ be set for this code to run, otherwise a full service level upgrade will
88+ fire on config-changed.
89+
90+ @param package: package name for determining if upgrade available
91+ @param upgrade_callback: function callback to charm's upgrade function
92+ @param configs: templating object derived from OSConfigRenderer class
93+
94+ @return: True if upgrade successful; False if upgrade failed or skipped
95+ """
96+ ret = False
97+
98+ if git_install_requested():
99+ action_set({'outcome': 'installed from source, skipped upgrade.'})
100+ else:
101+ if openstack_upgrade_available(package):
102+ if config('action-managed-upgrade'):
103+ juju_log('Upgrading OpenStack release')
104+
105+ try:
106+ upgrade_callback(configs=configs)
107+ action_set({'outcome': 'success, upgrade completed.'})
108+ ret = True
109+ except:
110+ action_set({'outcome': 'upgrade failed, see traceback.'})
111+ action_set({'traceback': traceback.format_exc()})
112+ action_fail('do_openstack_upgrade resulted in an '
113+ 'unexpected error')
114+ else:
115+ action_set({'outcome': 'action-managed-upgrade config is '
116+ 'False, skipped upgrade.'})
117+ else:
118+ action_set({'outcome': 'no upgrade available.'})
119+
120+ return ret
121
122=== modified file 'config.yaml'
123--- config.yaml 2015-07-10 14:13:35 +0000
124+++ config.yaml 2015-09-22 23:01:36 +0000
125@@ -125,3 +125,13 @@
126 description: |
127 A comma-separated list of nagios servicegroups.
128 If left empty, the nagios_context will be used as the servicegroup
129+ action-managed-upgrade:
130+ type: boolean
131+ default: False
132+ description: |
133+ If True enables openstack upgrades for this charm via juju actions.
134+ You will still need to set openstack-origin to the new repository but
135+ instead of an upgrade running automatically across all units, it will
136+ wait for you to execute the openstack-upgrade action for this charm on
137+ each unit. If False it will revert to existing behavior of upgrading
138+ all units on config change.
139
140=== modified file 'hooks/swift_storage_hooks.py'
141--- hooks/swift_storage_hooks.py 2015-08-28 10:21:17 +0000
142+++ hooks/swift_storage_hooks.py 2015-09-22 23:01:36 +0000
143@@ -73,7 +73,8 @@
144 ensure_swift_directories()
145 setup_rsync()
146
147- if openstack_upgrade_available('swift'):
148+ if not config('action-managed-upgrade') and \
149+ openstack_upgrade_available('swift'):
150 do_openstack_upgrade(configs=CONFIGS)
151 CONFIGS.write_all()
152
153
154=== added file 'unit_tests/test_actions_openstack_upgrade.py'
155--- unit_tests/test_actions_openstack_upgrade.py 1970-01-01 00:00:00 +0000
156+++ unit_tests/test_actions_openstack_upgrade.py 2015-09-22 23:01:36 +0000
157@@ -0,0 +1,58 @@
158+from mock import patch
159+import os
160+
161+os.environ['JUJU_UNIT_NAME'] = 'swift-storge'
162+
163+with patch('charmhelpers.core.hookenv.config') as config:
164+ config.return_value = 'swift-storage'
165+ import actions.openstack_upgrade as openstack_upgrade
166+
167+from test_utils import (
168+ CharmTestCase
169+)
170+
171+TO_PATCH = [
172+ 'config_changed',
173+ 'do_openstack_upgrade',
174+]
175+
176+
177+class TestSwiftStorageUpgradeActions(CharmTestCase):
178+
179+ def setUp(self):
180+ super(TestSwiftStorageUpgradeActions, self).setUp(openstack_upgrade,
181+ TO_PATCH)
182+
183+ @patch('actions.charmhelpers.contrib.openstack.utils.config')
184+ @patch('actions.charmhelpers.contrib.openstack.utils.action_set')
185+ @patch('actions.charmhelpers.contrib.openstack.utils.'
186+ 'git_install_requested')
187+ @patch('actions.charmhelpers.contrib.openstack.utils.'
188+ 'openstack_upgrade_available')
189+ def test_openstack_upgrade_true(self, upgrade_avail, git_requested,
190+ action_set, config):
191+ git_requested.return_value = False
192+ upgrade_avail.return_value = True
193+ config.return_value = True
194+
195+ openstack_upgrade.openstack_upgrade()
196+
197+ self.assertTrue(self.do_openstack_upgrade.called)
198+ self.assertTrue(self.config_changed.called)
199+
200+ @patch('actions.charmhelpers.contrib.openstack.utils.config')
201+ @patch('actions.charmhelpers.contrib.openstack.utils.action_set')
202+ @patch('actions.charmhelpers.contrib.openstack.utils.'
203+ 'git_install_requested')
204+ @patch('actions.charmhelpers.contrib.openstack.utils.'
205+ 'openstack_upgrade_available')
206+ def test_openstack_upgrade_false(self, upgrade_avail, git_requested,
207+ action_set, config):
208+ git_requested.return_value = False
209+ upgrade_avail.return_value = True
210+ config.return_value = False
211+
212+ openstack_upgrade.openstack_upgrade()
213+
214+ self.assertFalse(self.do_openstack_upgrade.called)
215+ self.assertFalse(self.config_changed.called)

Subscribers

People subscribed via source and target branches