Merge lp:~tvansteenburgh/charm-tools/proof-tags into lp:charm-tools/1.4

Proposed by Tim Van Steenburgh
Status: Merged
Merged at revision: 342
Proposed branch: lp:~tvansteenburgh/charm-tools/proof-tags
Merge into: lp:charm-tools/1.4
Diff against target: 453 lines (+129/-48)
22 files modified
charmtools/charms.py (+47/-30)
charmtools/templates/ansible/files/metadata.yaml (+3/-1)
charmtools/templates/bash/files/metadata.yaml (+3/-1)
charmtools/templates/python/files/metadata.yaml (+3/-1)
charmtools/templates/python_services/files/metadata.yaml (+3/-1)
tests/test_charm_proof.py (+47/-0)
tests_functional/charms/broken-config/metadata.yaml (+1/-1)
tests_functional/charms/broken-maintainer/metadata.yaml (+1/-1)
tests_functional/charms/broken-subordinate/metadata.yaml (+1/-1)
tests_functional/charms/broken-subordinate2/metadata.yaml (+1/-1)
tests_functional/charms/empty-requires/metadata.yaml (+1/-1)
tests_functional/charms/icon-template/metadata.yaml (+1/-1)
tests_functional/charms/missing-maintainer/metadata.yaml (+1/-1)
tests_functional/charms/mod-spdy/metadata.yaml (+1/-1)
tests_functional/charms/unknown-metadata/metadata.yaml (+1/-1)
tests_functional/create/no-package-exists/metadata.yaml (+3/-1)
tests_functional/create/python-apt/metadata.yaml (+3/-1)
tests_functional/create/test_ansible_create.py (+3/-0)
tests_functional/create/test_python_create.py (+1/-0)
tests_functional/proof/expected/broken-categories (+1/-0)
tests_functional/proof/expected/icon-template (+1/-1)
tests_functional/proof/expected/test (+2/-2)
To merge this branch: bzr merge lp:~tvansteenburgh/charm-tools/proof-tags
Reviewer Review Type Date Requested Status
Charm Toolers Pending
Review via email: mp+239295@code.launchpad.net

Description of the change

Updated proof to handle tags in metadata.yaml

- metadata must have either categories or tags, both of which must
  be a non-empty list
- if categories present, output INFO msg to change to tags
- all icon proof output is now info-only
- updated charm-create templates to use tags instead of
  categories, with a link to list of whitelisted tags in the docs

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/charms.py'
2--- charmtools/charms.py 2014-08-28 18:10:06 +0000
3+++ charmtools/charms.py 2014-10-22 20:07:30 +0000
4@@ -11,17 +11,20 @@
5 from linter import Linter
6 from launchpadlib.launchpad import Launchpad
7
8-KNOWN_METADATA_KEYS = ['name',
9- 'summary',
10- 'maintainer',
11- 'maintainers',
12- 'description',
13- 'categories',
14- 'subordinate',
15- 'provides',
16- 'requires',
17- 'format',
18- 'peers']
19+KNOWN_METADATA_KEYS = [
20+ 'name',
21+ 'summary',
22+ 'maintainer',
23+ 'maintainers',
24+ 'description',
25+ 'categories',
26+ 'subordinate',
27+ 'provides',
28+ 'requires',
29+ 'format',
30+ 'peers',
31+ 'tags',
32+]
33
34 KNOWN_RELATION_KEYS = ['interface', 'scope', 'limit', 'optional']
35
36@@ -247,32 +250,21 @@
37
38 charm_basename = os.path.basename(charm_path)
39 if charm['name'] != charm_basename:
40- warn_msg = ("metadata name (%s) must match directory name (%s)"
41- " exactly for local deployment.") % (
42- charm['name'], charm_basename)
43+ warn_msg = (
44+ "metadata name (%s) must match directory name (%s)"
45+ " exactly for local deployment.") % (charm['name'],
46+ charm_basename)
47 lint.warn(warn_msg)
48
49 # summary should be short
50 if len(charm['summary']) > 72:
51 lint.warn('summary sould be less than 72')
52
53- # validate maintainer info
54 validate_maintainer(charm, lint)
55-
56- if 'categories' not in charm:
57- lint.warn('Metadata is missing categories.')
58- else:
59- categories = charm['categories']
60- if type(categories) != list or categories == []:
61- # The category names are not validated because they may
62- # change.
63- lint.warn(
64- 'Categories metadata must be a list of one or more of:'
65- ' applications, app-servers, databases, file-servers, '
66- 'cache-proxy, misc')
67+ validate_categories_and_tags(charm, lint)
68
69 if not os.path.exists(os.path.join(charm_path, 'icon.svg')):
70- lint.warn("No icon.svg file.")
71+ lint.info("No icon.svg file.")
72 else:
73 # should have an icon.svg
74 template_sha1 = hashlib.sha1()
75@@ -283,9 +275,9 @@
76 with open(os.path.join(charm_path, 'icon.svg')) as ci:
77 icon_sha1.update(ci.read())
78 if template_sha1.hexdigest() == icon_sha1.hexdigest():
79- lint.warn("Includes template icon.svg file.")
80+ lint.info("Includes template icon.svg file.")
81 except IOError as e:
82- lint.warn(
83+ lint.info(
84 "Error while opening %s (%s)" %
85 (e.filename, e.strerror))
86
87@@ -459,6 +451,31 @@
88 'not "%s"' % formatted)
89
90
91+def validate_categories_and_tags(charm, linter):
92+ if 'categories' not in charm and 'tags' not in charm:
93+ linter.warn('Metadata missing required field "tags"')
94+ return
95+
96+ if 'tags' in charm:
97+ tags = charm['tags']
98+ if type(tags) != list or tags == []:
99+ linter.warn('Metadata field "tags" must be a non-empty list')
100+
101+ if 'categories' in charm:
102+ categories = charm['categories']
103+ if type(categories) != list or categories == []:
104+ # The category names are not validated because they may
105+ # change.
106+ linter.warn(
107+ 'Categories metadata must be a list of one or more of: '
108+ 'applications, app-servers, databases, file-servers, '
109+ 'cache-proxy, misc')
110+ linter.info(
111+ 'Categories are being deprecated in favor of tags. '
112+ 'Please rename the "categories" field to "tags".'
113+ )
114+
115+
116 def remote():
117 lp = Launchpad.login_anonymously('charm-tools', 'production',
118 version='devel')
119
120=== modified file 'charmtools/templates/ansible/files/metadata.yaml'
121--- charmtools/templates/ansible/files/metadata.yaml 2014-06-25 16:31:59 +0000
122+++ charmtools/templates/ansible/files/metadata.yaml 2014-10-22 20:07:30 +0000
123@@ -3,7 +3,9 @@
124 maintainer: $metadata.maintainer
125 description: |
126 $metadata.description
127-categories:
128+tags:
129+ # Replace "misc" with one or more whitelisted tags from this list:
130+ # https://juju.ubuntu.com/docs/authors-charm-metadata.html#charm-metadata
131 - misc
132 subordinate: false
133 provides:
134
135=== modified file 'charmtools/templates/bash/files/metadata.yaml'
136--- charmtools/templates/bash/files/metadata.yaml 2014-05-22 20:28:08 +0000
137+++ charmtools/templates/bash/files/metadata.yaml 2014-10-22 20:07:30 +0000
138@@ -3,7 +3,9 @@
139 maintainer: $metadata.maintainer
140 description: |
141 $metadata.description
142-categories:
143+tags:
144+ # Replace "misc" with one or more whitelisted tags from this list:
145+ # https://juju.ubuntu.com/docs/authors-charm-metadata.html#charm-metadata
146 - misc
147 subordinate: false
148 provides:
149
150=== modified file 'charmtools/templates/python/files/metadata.yaml'
151--- charmtools/templates/python/files/metadata.yaml 2014-05-23 20:10:24 +0000
152+++ charmtools/templates/python/files/metadata.yaml 2014-10-22 20:07:30 +0000
153@@ -3,7 +3,9 @@
154 maintainer: $metadata.maintainer
155 description: |
156 $metadata.description
157-categories:
158+tags:
159+ # Replace "misc" with one or more whitelisted tags from this list:
160+ # https://juju.ubuntu.com/docs/authors-charm-metadata.html#charm-metadata
161 - misc
162 subordinate: false
163 provides:
164
165=== modified file 'charmtools/templates/python_services/files/metadata.yaml'
166--- charmtools/templates/python_services/files/metadata.yaml 2014-09-10 18:38:30 +0000
167+++ charmtools/templates/python_services/files/metadata.yaml 2014-10-22 20:07:30 +0000
168@@ -3,7 +3,9 @@
169 maintainer: $metadata.maintainer
170 description: |
171 $metadata.description
172-categories:
173+tags:
174+ # Replace "misc" with one or more whitelisted tags from this list:
175+ # https://juju.ubuntu.com/docs/authors-charm-metadata.html#charm-metadata
176 - misc
177 subordinate: false
178 provides:
179
180=== modified file 'tests/test_charm_proof.py'
181--- tests/test_charm_proof.py 2014-08-28 18:10:06 +0000
182+++ tests/test_charm_proof.py 2014-10-22 20:07:30 +0000
183@@ -31,6 +31,7 @@
184
185 from charmtools.charms import CharmLinter as Linter
186 from charmtools.charms import validate_maintainer
187+from charmtools.charms import validate_categories_and_tags
188
189
190 class TestCharmProof(TestCase):
191@@ -342,6 +343,52 @@
192 self.assertTrue(self.linter.lint[0].startswith(expected))
193
194
195+class CategoriesTagsValidationTest(TestCase):
196+ def test_no_categories_or_tags(self):
197+ """Charm has neither categories nor tags."""
198+ linter = Mock()
199+ charm = {}
200+ validate_categories_and_tags(charm, linter)
201+ linter.warn.assert_called_once_with(
202+ 'Metadata missing required field "tags"')
203+
204+ def test_invalid_tags(self):
205+ """Charm has invalid tags field"""
206+ warning = 'Metadata field "tags" must be a non-empty list'
207+ linter = Mock()
208+ validate_categories_and_tags({'tags': 'foo'}, linter)
209+ linter.warn.assert_called_once_with(warning)
210+ linter.reset_mock()
211+ validate_categories_and_tags({'tags': []}, linter)
212+ linter.warn.assert_called_once_with(warning)
213+
214+ def test_invalid_categories(self):
215+ """Charm has invalid categories field"""
216+ warning = (
217+ 'Categories metadata must be a list of one or more of: '
218+ 'applications, app-servers, databases, file-servers, '
219+ 'cache-proxy, misc'
220+ )
221+ linter = Mock()
222+ validate_categories_and_tags({'categories': 'foo'}, linter)
223+ linter.warn.assert_called_once_with(warning)
224+ linter.reset_mock()
225+ validate_categories_and_tags({'categories': []}, linter)
226+ linter.warn.assert_called_once_with(warning)
227+
228+ def test_valid_categories(self):
229+ """Charm has valid categories, which should be changed to tags"""
230+ info = (
231+ 'Categories are being deprecated in favor of tags. '
232+ 'Please rename the "categories" field to "tags".'
233+ )
234+ linter = Mock()
235+ validate_categories_and_tags({'categories': ['misc']}, linter)
236+ linter.info.assert_called_once_with(info)
237+ self.assertFalse(linter.warn.called)
238+ self.assertFalse(linter.err.called)
239+
240+
241 class MaintainerValidationTest(TestCase):
242 def test_two_maintainer_fields(self):
243 """Charm has maintainer AND maintainers."""
244
245=== modified file 'tests_functional/charms/broken-config/metadata.yaml'
246--- tests_functional/charms/broken-config/metadata.yaml 2013-11-11 19:08:11 +0000
247+++ tests_functional/charms/broken-config/metadata.yaml 2014-10-22 20:07:30 +0000
248@@ -1,7 +1,7 @@
249 name: broken-config
250 summary: <Fill in summary here>
251 maintainer: test@testhost
252-categories:
253+tags:
254 - misc
255 description: |
256 <Multi-line description here>
257
258=== modified file 'tests_functional/charms/broken-maintainer/metadata.yaml'
259--- tests_functional/charms/broken-maintainer/metadata.yaml 2013-11-11 19:08:11 +0000
260+++ tests_functional/charms/broken-maintainer/metadata.yaml 2014-10-22 20:07:30 +0000
261@@ -3,7 +3,7 @@
262 maintainer: test@testhost>
263 description: |
264 <Multi-line description here>
265-categories:
266+tags:
267 - misc
268 provides:
269 relation-name:
270
271=== modified file 'tests_functional/charms/broken-subordinate/metadata.yaml'
272--- tests_functional/charms/broken-subordinate/metadata.yaml 2013-11-11 19:08:11 +0000
273+++ tests_functional/charms/broken-subordinate/metadata.yaml 2014-10-22 20:07:30 +0000
274@@ -4,5 +4,5 @@
275 maintainer: test@testhost
276 description: |
277 <Multi-line description here>
278-categories:
279+tags:
280 - misc
281
282=== modified file 'tests_functional/charms/broken-subordinate2/metadata.yaml'
283--- tests_functional/charms/broken-subordinate2/metadata.yaml 2013-11-11 19:08:11 +0000
284+++ tests_functional/charms/broken-subordinate2/metadata.yaml 2014-10-22 20:07:30 +0000
285@@ -4,7 +4,7 @@
286 maintainer: test@testhost
287 description: |
288 <Multi-line description here>
289-categories:
290+tags:
291 - misc
292 requires:
293 foo:
294
295=== modified file 'tests_functional/charms/empty-requires/metadata.yaml'
296--- tests_functional/charms/empty-requires/metadata.yaml 2013-11-11 19:08:11 +0000
297+++ tests_functional/charms/empty-requires/metadata.yaml 2014-10-22 20:07:30 +0000
298@@ -6,5 +6,5 @@
299 provides:
300 requires:
301 peers:
302-categories:
303+tags:
304 - misc
305
306=== modified file 'tests_functional/charms/icon-template/metadata.yaml'
307--- tests_functional/charms/icon-template/metadata.yaml 2013-11-11 19:08:11 +0000
308+++ tests_functional/charms/icon-template/metadata.yaml 2014-10-22 20:07:30 +0000
309@@ -3,7 +3,7 @@
310 maintainer: test@testhost
311 description: |
312 <Multi-line description here>
313-categories:
314+tags:
315 - misc
316 provides:
317 relation-name:
318
319=== modified file 'tests_functional/charms/missing-maintainer/metadata.yaml'
320--- tests_functional/charms/missing-maintainer/metadata.yaml 2013-11-11 19:08:11 +0000
321+++ tests_functional/charms/missing-maintainer/metadata.yaml 2014-10-22 20:07:30 +0000
322@@ -2,7 +2,7 @@
323 summary: <Fill in summary here>
324 description: |
325 <Multi-line description here>
326-categories:
327+tags:
328 - misc
329 provides:
330 relation-name:
331
332=== modified file 'tests_functional/charms/mod-spdy/metadata.yaml'
333--- tests_functional/charms/mod-spdy/metadata.yaml 2013-11-11 19:08:11 +0000
334+++ tests_functional/charms/mod-spdy/metadata.yaml 2014-10-22 20:07:30 +0000
335@@ -6,7 +6,7 @@
336 mod_spdy is a SPDY module for Apache 2.2 that allows your web server
337 to take advantage of SPDY features like stream multiplexing and header
338 compression.
339-categories:
340+tags:
341 - misc
342 requires:
343 juju-info:
344
345=== modified file 'tests_functional/charms/unknown-metadata/metadata.yaml'
346--- tests_functional/charms/unknown-metadata/metadata.yaml 2013-11-11 19:08:11 +0000
347+++ tests_functional/charms/unknown-metadata/metadata.yaml 2014-10-22 20:07:30 +0000
348@@ -4,7 +4,7 @@
349 maintainer: test@testhost
350 description: |
351 <Multi-line description here>
352-categories:
353+tags:
354 - misc
355 provides:
356 relation-name:
357
358=== modified file 'tests_functional/create/no-package-exists/metadata.yaml'
359--- tests_functional/create/no-package-exists/metadata.yaml 2013-11-11 19:08:11 +0000
360+++ tests_functional/create/no-package-exists/metadata.yaml 2014-10-22 20:07:30 +0000
361@@ -3,7 +3,9 @@
362 maintainer: tester <test@testhost>
363 description: |
364 <Multi-line description here>
365-categories:
366+tags:
367+ # Replace "misc" with one or more whitelisted tags from this list:
368+ # https://juju.ubuntu.com/docs/authors-charm-metadata.html#charm-metadata
369 - misc
370 subordinate: false
371 provides:
372
373=== modified file 'tests_functional/create/python-apt/metadata.yaml'
374--- tests_functional/create/python-apt/metadata.yaml 2013-11-11 19:08:11 +0000
375+++ tests_functional/create/python-apt/metadata.yaml 2014-10-22 20:07:30 +0000
376@@ -10,7 +10,9 @@
377 structure The included 'aptsources' Python interface provides an
378 abstraction of the sources.list configuration on the repository and
379 the distro level.
380-categories:
381+tags:
382+ # Replace "misc" with one or more whitelisted tags from this list:
383+ # https://juju.ubuntu.com/docs/authors-charm-metadata.html#charm-metadata
384 - misc
385 subordinate: false
386 provides:
387
388=== modified file 'tests_functional/create/test_ansible_create.py'
389--- tests_functional/create/test_ansible_create.py 2014-09-09 18:55:59 +0000
390+++ tests_functional/create/test_ansible_create.py 2014-10-22 20:07:30 +0000
391@@ -40,6 +40,7 @@
392
393 class AnsibleCreateTest(TestCase):
394 maxDiff = None
395+
396 def setUp(self):
397 self.tempdir = tempfile.mkdtemp()
398
399@@ -67,10 +68,12 @@
400 'lib/charmhelpers/core/services/__init__.py',
401 'lib/charmhelpers/core/services/base.py',
402 'lib/charmhelpers/core/services/helpers.py',
403+ 'lib/charmhelpers/core/sysctl.py',
404 'lib/charmhelpers/core/templating.py',
405 'lib/charmhelpers/fetch/__init__.py',
406 'lib/charmhelpers/fetch/archiveurl.py',
407 'lib/charmhelpers/fetch/bzrurl.py',
408+ 'lib/charmhelpers/fetch/giturl.py',
409 ]
410 return sorted(static_files + dynamic_files)
411
412
413=== modified file 'tests_functional/create/test_python_create.py'
414--- tests_functional/create/test_python_create.py 2014-09-26 15:09:14 +0000
415+++ tests_functional/create/test_python_create.py 2014-10-22 20:07:30 +0000
416@@ -59,6 +59,7 @@
417 'lib/charmhelpers/core/services/__init__.py',
418 'lib/charmhelpers/core/services/base.py',
419 'lib/charmhelpers/core/services/helpers.py',
420+ 'lib/charmhelpers/core/sysctl.py',
421 'lib/charmhelpers/core/templating.py',
422 ]
423 return sorted(static_files + dynamic_files)
424
425=== modified file 'tests_functional/proof/expected/broken-categories'
426--- tests_functional/proof/expected/broken-categories 2014-05-16 06:06:43 +0000
427+++ tests_functional/proof/expected/broken-categories 2014-10-22 20:07:30 +0000
428@@ -1,2 +1,3 @@
429 W: Categories metadata must be a list of one or more of: applications, app-servers, databases, file-servers, cache-proxy, misc
430+I: Categories are being deprecated in favor of tags. Please rename the "categories" field to "tags".
431 I: missing recommended hook config-changed
432
433=== modified file 'tests_functional/proof/expected/icon-template'
434--- tests_functional/proof/expected/icon-template 2014-05-16 06:06:43 +0000
435+++ tests_functional/proof/expected/icon-template 2014-10-22 20:07:30 +0000
436@@ -1,4 +1,4 @@
437-W: Includes template icon.svg file.
438+I: Includes template icon.svg file.
439 W: no copyright file
440 W: Includes template README.ex file
441 W: README.ex includes line 1 of boilerplate README.ex
442
443=== modified file 'tests_functional/proof/expected/test'
444--- tests_functional/proof/expected/test 2014-05-16 06:06:43 +0000
445+++ tests_functional/proof/expected/test 2014-10-22 20:07:30 +0000
446@@ -1,5 +1,5 @@
447-W: Metadata is missing categories.
448-W: No icon.svg file.
449+W: Metadata missing required field "tags"
450+I: No icon.svg file.
451 W: no copyright file
452 W: Includes template README.ex file
453 W: README.ex includes line 1 of boilerplate README.ex

Subscribers

People subscribed via source and target branches