Merge lp:~teknico/charms/precise/juju-gui/cleanup-charm-code into lp:~juju-gui/charms/precise/juju-gui/trunk

Proposed by Nicola Larosa
Status: Merged
Merged at revision: 57
Proposed branch: lp:~teknico/charms/precise/juju-gui/cleanup-charm-code
Merge into: lp:~juju-gui/charms/precise/juju-gui/trunk
Diff against target: 330 lines (+41/-47)
6 files modified
hooks/backend.py (+7/-7)
hooks/config-changed (+2/-5)
hooks/start (+3/-7)
hooks/utils.py (+5/-5)
hooks/web-relation-joined (+3/-4)
tests/test_utils.py (+21/-19)
To merge this branch: bzr merge lp:~teknico/charms/precise/juju-gui/cleanup-charm-code
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+162315@code.launchpad.net

Description of the change

More charm code cleanup.

Most of these changes were split from the former branch that added
backend unit tests, it was getting too big and unreadable.

No behavior changes, only formatting and two occasions of different
expressions of the same meaning.

https://codereview.appspot.com/9125046/

To post a comment you must log in.
Revision history for this message
Nicola Larosa (teknico) wrote :

Reviewers: mp+162315_code.launchpad.net,

Message:
Please take a look.

Description:
More charm code cleanup.

Most of these changes were split from the former branch that added
backend unit tests, it was getting too big and unreadable.

No behavior changes, only formatting and two occasions of different
expressions of the same meaning.

https://code.launchpad.net/~teknico/charms/precise/juju-gui/cleanup-charm-code/+merge/162315

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/9125046/

Affected files:
   A [revision details]
   M hooks/backend.py
   M hooks/config-changed
   M hooks/start
   M hooks/utils.py
   M hooks/web-relation-joined
   M tests/test_utils.py

54. By Nicola Larosa

Merge from trunk.

Revision history for this message
Nicola Larosa (teknico) wrote :
Revision history for this message
Francesco Banconi (frankban) wrote :

LGTM, thank you!

https://codereview.appspot.com/9125046/diff/3001/tests/test_utils.py
File tests/test_utils.py (right):

https://codereview.appspot.com/9125046/diff/3001/tests/test_utils.py#newcode51
tests/test_utils.py:51: class TestAttrDict(unittest.TestCase):
Just curious: why this change in all testcase names?

https://codereview.appspot.com/9125046/

Revision history for this message
Nicola Larosa (teknico) wrote :

Thanks for the review!

https://codereview.appspot.com/9125046/diff/3001/tests/test_utils.py
File tests/test_utils.py (right):

https://codereview.appspot.com/9125046/diff/3001/tests/test_utils.py#newcode51
tests/test_utils.py:51: class TestAttrDict(unittest.TestCase):
frankban wrote:
> Just curious: why this change in all testcase names?

Because having "Test" as a prefix is the convention usually followed by
unittest testcases, and also because that way it is easier to
distinguish between actual testcases and support classes.

https://codereview.appspot.com/9125046/

Revision history for this message
Gary Poster (gary) wrote :

LGTM. Thank you.

https://codereview.appspot.com/9125046/diff/3001/hooks/backend.py
File hooks/backend.py (right):

https://codereview.appspot.com/9125046/diff/3001/hooks/backend.py#newcode66
hooks/backend.py:66: charmhelpers.log('Setting up haproxy and Apache
start up scripts.')
Heh, benji and I were just commenting on this yesterday. Thank you.

https://codereview.appspot.com/9125046/

Revision history for this message
Nicola Larosa (teknico) wrote :

*** Submitted:

More charm code cleanup.

Most of these changes were split from the former branch that added
backend unit tests, it was getting too big and unreadable.

No behavior changes, only formatting and two occasions of different
expressions of the same meaning.

R=frankban, gary.poster
CC=
https://codereview.appspot.com/9125046

https://codereview.appspot.com/9125046/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/backend.py'
2--- hooks/backend.py 2013-05-02 16:51:14 +0000
3+++ hooks/backend.py 2013-05-03 10:39:24 +0000
4@@ -1,5 +1,5 @@
5 """
6-A composition system for creating backend object.
7+A composition system for creating backend objects.
8
9 Backends implement start(), stop() and install() methods. A backend is composed
10 of many mixins and each mixin will implement any/all of those methods and all
11@@ -57,13 +57,13 @@
12 class UpstartMixin(object):
13 """Manage (install, start, stop, etc.) some service via Upstart."""
14
15- upstart_scripts = ('haproxy.conf', )
16+ upstart_scripts = ('haproxy.conf',)
17 debs = ('curl', 'openssl', 'haproxy', 'apache2')
18
19 def install(self, backend):
20- """Set up haproxy and nginx upstart configuration files."""
21+ """Set up haproxy and Apache upstart configuration files."""
22 utils.setup_apache()
23- charmhelpers.log('Setting up haproxy and nginx start up scripts.')
24+ charmhelpers.log('Setting up haproxy and Apache start up scripts.')
25 config = backend.config
26 if backend.different(
27 'ssl-cert-path', 'ssl-cert-contents', 'ssl-key-contents'):
28@@ -120,7 +120,7 @@
29
30
31 class ImprovMixin(object):
32- debs = ('zookeeper', )
33+ debs = ('zookeeper',)
34
35 def install(self, backend):
36 config = backend.config
37@@ -138,7 +138,7 @@
38
39
40 class GoMixin(object):
41- debs = ('python-yaml', )
42+ debs = ('python-yaml',)
43
44
45 class Backend(object):
46@@ -185,7 +185,7 @@
47 mixins.append(GuiMixin)
48 mixins.append(UpstartMixin)
49
50- # record our choice mapping classes to instances
51+ # Record our choice mapping classes to instances.
52 for i, b in enumerate(mixins):
53 if callable(b):
54 mixins[i] = b()
55
56=== modified file 'hooks/config-changed'
57--- hooks/config-changed 2013-04-30 10:14:57 +0000
58+++ hooks/config-changed 2013-05-03 10:39:24 +0000
59@@ -10,17 +10,14 @@
60 get_config,
61 log,
62 )
63-from shelltoolbox import (
64- DictDiffer,
65-)
66+from shelltoolbox import DictDiffer
67
68+from backend import Backend
69 from utils import (
70 config_json,
71 log_hook,
72 )
73
74-from backend import Backend
75-
76
77 def main():
78 config = get_config()
79
80=== modified file 'hooks/start'
81--- hooks/start 2013-04-30 10:14:57 +0000
82+++ hooks/start 2013-05-03 10:39:24 +0000
83@@ -1,15 +1,10 @@
84 #!/usr/bin/env python2
85 #-*- python -*-
86
87-from charmhelpers import (
88- get_config,
89-)
90-
91-from utils import (
92- log_hook,
93-)
94+from charmhelpers import get_config
95
96 from backend import Backend
97+from utils import log_hook
98
99
100 def main():
101@@ -17,6 +12,7 @@
102 backend = Backend(config)
103 backend.start()
104
105+
106 if __name__ == '__main__':
107 with log_hook():
108 main()
109
110=== modified file 'hooks/utils.py'
111--- hooks/utils.py 2013-05-03 08:50:46 +0000
112+++ hooks/utils.py 2013-05-03 10:39:24 +0000
113@@ -49,6 +49,9 @@
114 import tempfile
115 from urlparse import urlparse
116
117+import apt
118+import tempita
119+
120 from launchpadlib.launchpad import Launchpad
121 from shelltoolbox import (
122 Serializer,
123@@ -69,9 +72,6 @@
124 unit_get,
125 )
126
127-import apt
128-import tempita
129-
130
131 AGENT = 'juju-api-agent'
132 APACHE = 'apache2'
133@@ -574,7 +574,7 @@
134 Each method is called in the context of its mixin instance, and its
135 argument is the Backend instance.
136 """
137- # chain method calls through all implementing mixins
138+ # Chain method calls through all implementing mixins.
139 def method(self):
140 for mixin in self.mixins:
141 a_callable = getattr(type(mixin), name, None)
142@@ -589,7 +589,7 @@
143 """Helper to merge a property from a set of strategy objects
144 into a unified set.
145 """
146- # return merged property from every providing backend as a set
147+ # Return merged property from every providing mixin as a set.
148 @property
149 def method(self):
150 result = set()
151
152=== modified file 'hooks/web-relation-joined'
153--- hooks/web-relation-joined 2013-04-30 10:14:57 +0000
154+++ hooks/web-relation-joined 2013-05-03 10:39:24 +0000
155@@ -2,6 +2,7 @@
156 #-*- python -*-
157
158 import socket
159+
160 from charmhelpers import (
161 get_config,
162 relation_set,
163@@ -12,12 +13,10 @@
164 def main():
165 hostname = socket.getfqdn()
166 config = get_config()
167- if config['secure']:
168- port = 443
169- else:
170- port = 80
171+ port = 443 if config['secure'] else 80
172 relation_set(port=port, hostname=hostname)
173
174+
175 if __name__ == '__main__':
176 with log_hook():
177 main()
178
179=== modified file 'tests/test_utils.py'
180--- tests/test_utils.py 2013-05-03 08:50:46 +0000
181+++ tests/test_utils.py 2013-05-03 10:39:24 +0000
182@@ -6,10 +6,10 @@
183 from simplejson import dumps
184 from subprocess import CalledProcessError
185 import tempfile
186-import tempita
187 import unittest
188
189 import charmhelpers
190+import tempita
191 import yaml
192
193 from backend import InstallMixin
194@@ -42,12 +42,13 @@
195 """A dict with the ability to access keys as attributes."""
196
197 def __getattr__(self, attr):
198- if attr in self:
199+ try:
200 return self[attr]
201- raise AttributeError
202-
203-
204-class AttrDictTest(unittest.TestCase):
205+ except KeyError:
206+ raise AttributeError
207+
208+
209+class TestAttrDict(unittest.TestCase):
210
211 def test_key_as_attribute(self):
212 # Ensure attributes can be used to retrieve dict values.
213@@ -61,7 +62,7 @@
214 AttrDict().myattr
215
216
217-class FirstPathInDirTest(unittest.TestCase):
218+class TestFirstPathInDir(unittest.TestCase):
219
220 def setUp(self):
221 self.directory = tempfile.mkdtemp()
222@@ -83,7 +84,7 @@
223 self.assertRaises(IndexError, first_path_in_dir, self.directory)
224
225
226-class GetApiAddressTest(unittest.TestCase):
227+class TestGetApiAddress(unittest.TestCase):
228
229 def setUp(self):
230 self.base_dir = tempfile.mkdtemp()
231@@ -109,7 +110,7 @@
232 self.assertRaises(IOError, get_api_address, self.unit_dir)
233
234
235-class LegacyJujuTest(unittest.TestCase):
236+class TestLegacyJuju(unittest.TestCase):
237
238 def setUp(self):
239 self.base_dir = tempfile.mkdtemp()
240@@ -142,7 +143,7 @@
241 return [AttrDict({attr: value}) for value in values]
242
243
244-class MakeCollectionTest(unittest.TestCase):
245+class TestMakeCollection(unittest.TestCase):
246
247 def test_factory(self):
248 # Ensure the factory returns the expected object instances.
249@@ -152,7 +153,7 @@
250 self.assertEqual(num, instance.myattr)
251
252
253-class GetByAttrTest(unittest.TestCase):
254+class TestGetByAttr(unittest.TestCase):
255
256 attr = 'myattr'
257 collection = make_collection(attr, range(5))
258@@ -186,7 +187,7 @@
259 return self.file_link
260
261
262-class GetReleaseFileUrlTest(unittest.TestCase):
263+class TestGetReleaseFileUrl(unittest.TestCase):
264
265 project = AttrDict(
266 series=(
267@@ -307,7 +308,7 @@
268 self.assertEqual('http://example.com/0.1.0.tgz', url)
269
270
271-class GetZookeeperAddressTest(unittest.TestCase):
272+class TestGetZookeeperAddress(unittest.TestCase):
273
274 def setUp(self):
275 self.zookeeper_address = 'example.com:2000'
276@@ -323,7 +324,7 @@
277 self.assertEqual(self.zookeeper_address, address)
278
279
280-class LogHookTest(unittest.TestCase):
281+class TestLogHook(unittest.TestCase):
282
283 def setUp(self):
284 # Monkeypatch the charmhelpers log function.
285@@ -366,7 +367,7 @@
286 self.assertIn('<<< Exiting', self.output[-1])
287
288
289-class ParseSourceTest(unittest.TestCase):
290+class TestParseSource(unittest.TestCase):
291
292 def setUp(self):
293 # Monkey patch utils.CURRENT_DIR.
294@@ -417,7 +418,7 @@
295 self.assertTupleEqual(expected, parse_source('url:foo/bar'))
296
297
298-class RenderToFileTest(unittest.TestCase):
299+class TestRenderToFile(unittest.TestCase):
300
301 def setUp(self):
302 self.destination_file = tempfile.NamedTemporaryFile()
303@@ -436,7 +437,7 @@
304 self.assertEqual(expected, self.destination_file.read())
305
306
307-class SaveOrCreateCertificatesTest(unittest.TestCase):
308+class TestSaveOrCreateCertificates(unittest.TestCase):
309
310 def setUp(self):
311 base_dir = tempfile.mkdtemp()
312@@ -465,7 +466,8 @@
313 self.assertEqual('KeyCertificate', open(pem_file).read())
314
315
316-class CmdLogTest(unittest.TestCase):
317+class TestCmdLog(unittest.TestCase):
318+
319 def setUp(self):
320 # Patch the charmhelpers 'command', which powers get_config. The
321 # result of this is the mock_config dictionary will be returned.
322@@ -485,7 +487,7 @@
323 self.assertTrue(line.endswith(': juju-gui@INFO \nfoo\n'))
324
325
326-class StartStopTest(unittest.TestCase):
327+class TestStartStop(unittest.TestCase):
328
329 def setUp(self):
330 self.service_names = []

Subscribers

People subscribed via source and target branches