Merge lp:~benji/charm-tools/add-versionless-charm-in-bundle-warning into lp:charm-tools/1.2

Proposed by Benji York
Status: Merged
Merged at revision: 315
Proposed branch: lp:~benji/charm-tools/add-versionless-charm-in-bundle-warning
Merge into: lp:charm-tools/1.2
Diff against target: 163 lines (+105/-6)
4 files modified
charmtools/bundles.py (+12/-4)
scripts/test (+1/-1)
tests/test_bundle_proof.py (+91/-0)
tests/test_charm_proof.py (+1/-1)
To merge this branch: bzr merge lp:~benji/charm-tools/add-versionless-charm-in-bundle-warning
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+206986@code.launchpad.net

Commit message

Add a bundle lint warning about revisionless charm URLs

Also:
  - added tests for the bundle linter
  - fixed some whitespace to be PEP-8 complient
  - turned a "not XXX in YYY" into the more idomatic "XXX not in YYY"

Description of the change

Add a bundle lint warning about revisionless charm URLs

Also:
  - added tests for the bundle linter
  - fixed some whitespace to be PEP-8 complient
  - turned a "not XXX in YYY" into the more idomatic "XXX not in YYY"

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/bundles.py'
2--- charmtools/bundles.py 2014-01-08 22:43:34 +0000
3+++ charmtools/bundles.py 2014-02-18 16:35:09 +0000
4@@ -1,12 +1,16 @@
5+import glob
6+import json
7 import os
8+import re
9 import yaml
10-import glob
11-import json
12
13 from linter import Linter
14 from charmworldlib import bundle as cw_bundle
15
16
17+charm_url_includes_id = re.compile(r'-\d+$').search
18+
19+
20 class BundleLinter(Linter):
21 def validate(self, contents):
22 for name, bdata in contents.items():
23@@ -19,9 +23,13 @@
24
25 if 'services' in bdata:
26 for svc, sdata in bdata['services'].items():
27- if not 'annotations' in sdata:
28+ if 'annotations' not in sdata:
29 self.warn('%s: %s: No annotations found, will render '
30- 'bad in GUI' % (name, svc))
31+ 'poorly in GUI' % (name, svc))
32+ if not charm_url_includes_id(sdata['charm']):
33+ self.warn(
34+ '%s: charm URL should include a revision' % svc)
35+
36 else:
37 if 'inherits' not in bdata:
38 self.err("%s: No services defined" % name)
39
40=== modified file 'scripts/test'
41--- scripts/test 2013-12-02 20:19:24 +0000
42+++ scripts/test 2014-02-18 16:35:09 +0000
43@@ -4,4 +4,4 @@
44 then
45 extra_args="--pdb-failures"
46 fi
47-bin/nosetests --exe --with-id $extra_args $@
48+bin/nosetests --nocapture --exe --with-id $extra_args $@
49
50=== added file 'tests/test_bundle_proof.py'
51--- tests/test_bundle_proof.py 1970-01-01 00:00:00 +0000
52+++ tests/test_bundle_proof.py 2014-02-18 16:35:09 +0000
53@@ -0,0 +1,91 @@
54+#!/usr/bin/python
55+
56+# Copyright (C) 2013 Canonical Ltd.
57+#
58+# This program is free software: you can redistribute it and/or modify
59+# it under the terms of the GNU General Public License as published by
60+# the Free Software Foundation, either version 3 of the License, or
61+# (at your option) any later version.
62+#
63+# This program is distributed in the hope that it will be useful,
64+# but WITHOUT ANY WARRANTY; without even the implied warranty of
65+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66+# GNU General Public License for more details.
67+#
68+# You should have received a copy of the GNU General Public License
69+# along with this program. If not, see <http://www.gnu.org/licenses/>.
70+
71+import charmtools.bundles
72+import os.path
73+import shutil
74+import sys
75+import tempfile
76+import textwrap
77+import unittest
78+
79+
80+class TestCharmProof(unittest.TestCase):
81+ def setUp(self):
82+ self.linter = charmtools.bundles.BundleLinter()
83+
84+ def test_warn_on_charm_urls_without_revisions(self):
85+ self.linter.validate({
86+ 'my-service': {
87+ 'services': {
88+ 'memcached': {
89+ 'charm': 'cs:precise/memcached',
90+ 'num_units': 1,
91+ },
92+ },
93+ }})
94+ self.assertIn(
95+ 'W: memcached: charm URL should include a revision',
96+ self.linter.lint)
97+
98+ def test_no_warning_when_charm_urls_include_revisions(self):
99+ self.linter.validate({
100+ 'my-service': {
101+ 'services': {
102+ 'memcached': {
103+ 'charm': 'cs:precise/memcached-99',
104+ 'num_units': 1,
105+ },
106+ },
107+ }})
108+ self.assertNotIn(
109+ 'W: memcached: charm URL should include a revision',
110+ self.linter.lint)
111+
112+ def test_warn_on_missing_annotations(self):
113+ self.linter.validate({
114+ 'my-service': {
115+ 'services': {
116+ 'memcached': {
117+ 'charm': 'cs:precise/memcached',
118+ 'num_units': 1,
119+ },
120+ },
121+ }})
122+ self.assertIn(
123+ 'W: my-service: memcached: No annotations found, will render '
124+ 'poorly in GUI',
125+ self.linter.lint)
126+
127+ def test_no_warning_when_annotations_are_included(self):
128+ self.linter.validate({
129+ 'my-service': {
130+ 'services': {
131+ 'memcached': {
132+ 'charm': 'cs:precise/memcached',
133+ 'num_units': 1,
134+ 'annotations': {
135+ 'gui-x': '821.5',
136+ 'gui-y': '669.2698359714502',
137+ },
138+ },
139+ },
140+ }})
141+ self.assertNotIn(
142+ 'W: my-service: memcached: No annotations found, will render '
143+ 'poorly in GUI',
144+ self.linter.lint)
145
146=== modified file 'tests/test_charm_proof.py'
147--- tests/test_charm_proof.py 2014-01-10 03:41:58 +0000
148+++ tests/test_charm_proof.py 2014-02-18 16:35:09 +0000
149@@ -34,7 +34,6 @@
150 class TestCharmProof(TestCase):
151 def setUp(self):
152 self.charm_dir = mkdtemp()
153- self.config_path = join(self.charm_dir, 'config.yaml')
154 self.linter = Linter()
155
156 def tearDown(self):
157@@ -255,5 +254,6 @@
158 "for the tag 'tag:yaml.org,2002:python/name:__builtin__.int'")
159 self.assertTrue(self.linter.lint[0].startswith(expected))
160
161+
162 if __name__ == '__main__':
163 main()

Subscribers

People subscribed via source and target branches

to all changes: