Merge lp:~ajkavanagh/charm-helpers/fix-unit-paused-set-functions into lp:charm-helpers

Proposed by Alex Kavanagh
Status: Merged
Merged at revision: 541
Proposed branch: lp:~ajkavanagh/charm-helpers/fix-unit-paused-set-functions
Merge into: lp:charm-helpers
Diff against target: 209 lines (+68/-22)
2 files modified
charmhelpers/contrib/openstack/utils.py (+10/-6)
tests/contrib/openstack/test_openstack_utils.py (+58/-16)
To merge this branch: bzr merge lp:~ajkavanagh/charm-helpers/fix-unit-paused-set-functions
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+288395@code.launchpad.net

Description of the change

Fixes broken *_unit_paused_set() functions in contrib/openstack/utils.py that were merged by mistake.

Also fixes some PEP8 formatting in the utils.py and test_openstack_utils.py files (line lengths).

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

LGTM, thanks for the fixes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/utils.py'
2--- charmhelpers/contrib/openstack/utils.py 2016-03-07 16:44:43 +0000
3+++ charmhelpers/contrib/openstack/utils.py 2016-03-08 12:40:42 +0000
4@@ -772,7 +772,8 @@
5 os.mkdir(parent_dir)
6
7 juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
8- repo_dir = install_remote(repo, dest=parent_dir, branch=branch, depth=depth)
9+ repo_dir = install_remote(
10+ repo, dest=parent_dir, branch=branch, depth=depth)
11
12 venv = os.path.join(parent_dir, 'venv')
13
14@@ -1016,8 +1017,8 @@
15 # Normal case relation ID exists but no related unit
16 # (joining)
17 else:
18- juju_log("{} relations's interface, {}, is related but has "
19- "no units in the relation."
20+ juju_log("{} relations's interface, {}, is related but has"
21+ " no units in the relation."
22 "".format(generic_interface, related_interface),
23 "INFO")
24 # Related unit exists and data missing on the relation
25@@ -1377,7 +1378,8 @@
26 """Set the unit to a paused state in the local kv() store.
27 This does NOT actually pause the unit
28 """
29- with unitdata.HookData()() as kv:
30+ with unitdata.HookData()() as t:
31+ kv = t[0]
32 kv.set('unit-paused', True)
33
34
35@@ -1386,7 +1388,8 @@
36 This does NOT actually restart any services - it only clears the
37 local state.
38 """
39- with unitdata.HookData()() as kv:
40+ with unitdata.HookData()() as t:
41+ kv = t[0]
42 kv.set('unit-paused', False)
43
44
45@@ -1398,7 +1401,8 @@
46 if it excepts, return False
47 """
48 try:
49- with unitdata.HookData()() as kv:
50+ with unitdata.HookData()() as t:
51+ kv = t[0]
52 # transform something truth-y into a Boolean.
53 return not(not(kv.get('unit-paused')))
54 except:
55
56=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
57--- tests/contrib/openstack/test_openstack_utils.py 2016-03-02 13:55:54 +0000
58+++ tests/contrib/openstack/test_openstack_utils.py 2016-03-08 12:40:42 +0000
59@@ -2,6 +2,7 @@
60 import os
61 import subprocess
62 import tempfile
63+import contextlib
64 import unittest
65 from copy import copy
66 from testtools import TestCase
67@@ -196,8 +197,9 @@
68 self.assertEquals(openstack.get_os_codename_install_source('distro'),
69 'essex')
70 # proposed pocket
71- self.assertEquals(openstack.get_os_codename_install_source('distro-proposed'),
72- 'essex')
73+ self.assertEquals(openstack.get_os_codename_install_source(
74+ 'distro-proposed'),
75+ 'essex')
76
77 # various cloud archive pockets
78 src = 'cloud:precise-grizzly'
79@@ -777,7 +779,8 @@
80 repository: 'git://git.openstack.org/openstack/requirements',
81 branch: stable/juno}"""
82 openstack.git_clone_and_install(git_wrong_order_1, 'keystone')
83- error_out.assert_called_with('keystone git repo must be specified last')
84+ error_out.assert_called_with(
85+ 'keystone git repo must be specified last')
86
87 git_wrong_order_2 = """
88 repositories:
89@@ -785,7 +788,8 @@
90 repository: 'git://git.openstack.org/openstack/keystone',
91 branch: stable/juno}"""
92 openstack.git_clone_and_install(git_wrong_order_2, 'keystone')
93- error_out.assert_called_with('requirements git repo must be specified first')
94+ error_out.assert_called_with(
95+ 'requirements git repo must be specified first')
96
97 @patch('os.path.join')
98 @patch.object(openstack, 'charm_dir')
99@@ -839,8 +843,8 @@
100 path_exists.return_value = False
101 install_remote.return_value = dest_dir
102
103- openstack._git_clone_and_install_single(repo, branch, depth, parent_dir,
104- http_proxy, False)
105+ openstack._git_clone_and_install_single(
106+ repo, branch, depth, parent_dir, http_proxy, False)
107 mkdir.assert_called_with(parent_dir)
108 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,
109 branch=branch)
110@@ -855,10 +859,9 @@
111 @patch.object(openstack, 'install_remote')
112 @patch.object(openstack, 'pip_install')
113 @patch.object(openstack, '_git_update_requirements')
114- def test_git_clone_and_install_single_with_update(self, _git_update_reqs,
115- pip_install,
116- install_remote, log,
117- path_exists, mkdir, join):
118+ def test_git_clone_and_install_single_with_update(
119+ self, _git_update_reqs, pip_install, install_remote, log,
120+ path_exists, mkdir, join):
121 repo = 'git://git.openstack.org/openstack/requirements.git'
122 branch = 'master'
123 depth = 1
124@@ -872,8 +875,8 @@
125 path_exists.return_value = False
126 install_remote.return_value = dest_dir
127
128- openstack._git_clone_and_install_single(repo, branch, depth, parent_dir,
129- http_proxy, True)
130+ openstack._git_clone_and_install_single(
131+ repo, branch, depth, parent_dir, http_proxy, True)
132 mkdir.assert_called_with(parent_dir)
133 install_remote.assert_called_with(repo, dest=parent_dir, depth=1,
134 branch=branch)
135@@ -914,7 +917,8 @@
136 'identity': ['identity-service']}
137 expected_result = 'identity'
138
139- result = openstack.incomplete_relation_data(configs, required_interfaces)
140+ result = openstack.incomplete_relation_data(
141+ configs, required_interfaces)
142 self.assertTrue(expected_result in result.keys())
143
144 @patch.object(openstack, 'juju_log')
145@@ -1431,6 +1435,43 @@
146 'Services should be paused but these ports '
147 'which should be closed, but are open: 60')
148
149+ @staticmethod
150+ def _unit_paused_helper(hook_data_mock):
151+ # HookData()() returns a tuple (kv, delta_config, delta_relation)
152+ # but we only want kv in the test.
153+ kv = MagicMock()
154+
155+ @contextlib.contextmanager
156+ def hook_data__call__():
157+ yield (kv, True, False)
158+
159+ hook_data__call__.return_value = (kv, True, False)
160+ hook_data_mock.return_value = hook_data__call__
161+ return kv
162+
163+ @patch('charmhelpers.contrib.openstack.utils.unitdata.HookData')
164+ def test_set_unit_paused(self, hook_data):
165+ kv = self._unit_paused_helper(hook_data)
166+ openstack.set_unit_paused()
167+ kv.set.assert_called_once_with('unit-paused', True)
168+
169+ @patch('charmhelpers.contrib.openstack.utils.unitdata.HookData')
170+ def test_clear_unit_paused(self, hook_data):
171+ kv = self._unit_paused_helper(hook_data)
172+ openstack.clear_unit_paused()
173+ kv.set.assert_called_once_with('unit-paused', False)
174+
175+ @patch('charmhelpers.contrib.openstack.utils.unitdata.HookData')
176+ def test_is_unit_paused_set(self, hook_data):
177+ kv = self._unit_paused_helper(hook_data)
178+ kv.get.return_value = True
179+ r = openstack.is_unit_paused_set()
180+ kv.get.assert_called_once_with('unit-paused')
181+ self.assertEquals(r, True)
182+ kv.get.return_value = False
183+ r = openstack.is_unit_paused_set()
184+ self.assertEquals(r, False)
185+
186 @patch('charmhelpers.contrib.openstack.utils.service_pause')
187 @patch('charmhelpers.contrib.openstack.utils.set_unit_paused')
188 def test_pause_unit_okay(self, set_unit_paused, service_pause):
189@@ -1507,7 +1548,8 @@
190
191 @patch('charmhelpers.contrib.openstack.utils.service_resume')
192 @patch('charmhelpers.contrib.openstack.utils.clear_unit_paused')
193- def test_resume_unit_service_fails(self, clear_unit_paused, service_resume):
194+ def test_resume_unit_service_fails(
195+ self, clear_unit_paused, service_resume):
196 services = ['service1', 'service2']
197 service_resume.side_effect = [True, True]
198 openstack.resume_unit(None, services=services)
199@@ -1519,8 +1561,8 @@
200 openstack.resume_unit(None, services=services)
201 raise Exception("resume_unit should have raised Exception")
202 except Exception as e:
203- self.assertEquals(e.args[0],
204- "Couldn't resume: service2 didn't start cleanly.")
205+ self.assertEquals(
206+ e.args[0], "Couldn't resume: service2 didn't start cleanly.")
207
208 @patch('charmhelpers.contrib.openstack.utils.service_resume')
209 @patch('charmhelpers.contrib.openstack.utils.clear_unit_paused')

Subscribers

People subscribed via source and target branches