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
=== modified file 'charmtools/bundles.py'
--- charmtools/bundles.py 2014-01-08 22:43:34 +0000
+++ charmtools/bundles.py 2014-02-18 16:35:09 +0000
@@ -1,12 +1,16 @@
1import glob
2import json
1import os3import os
4import re
2import yaml5import yaml
3import glob
4import json
56
6from linter import Linter7from linter import Linter
7from charmworldlib import bundle as cw_bundle8from charmworldlib import bundle as cw_bundle
89
910
11charm_url_includes_id = re.compile(r'-\d+$').search
12
13
10class BundleLinter(Linter):14class BundleLinter(Linter):
11 def validate(self, contents):15 def validate(self, contents):
12 for name, bdata in contents.items():16 for name, bdata in contents.items():
@@ -19,9 +23,13 @@
1923
20 if 'services' in bdata:24 if 'services' in bdata:
21 for svc, sdata in bdata['services'].items():25 for svc, sdata in bdata['services'].items():
22 if not 'annotations' in sdata:26 if 'annotations' not in sdata:
23 self.warn('%s: %s: No annotations found, will render '27 self.warn('%s: %s: No annotations found, will render '
24 'bad in GUI' % (name, svc))28 'poorly in GUI' % (name, svc))
29 if not charm_url_includes_id(sdata['charm']):
30 self.warn(
31 '%s: charm URL should include a revision' % svc)
32
25 else:33 else:
26 if 'inherits' not in bdata:34 if 'inherits' not in bdata:
27 self.err("%s: No services defined" % name)35 self.err("%s: No services defined" % name)
2836
=== modified file 'scripts/test'
--- scripts/test 2013-12-02 20:19:24 +0000
+++ scripts/test 2014-02-18 16:35:09 +0000
@@ -4,4 +4,4 @@
4then4then
5 extra_args="--pdb-failures"5 extra_args="--pdb-failures"
6fi6fi
7bin/nosetests --exe --with-id $extra_args $@7bin/nosetests --nocapture --exe --with-id $extra_args $@
88
=== added file 'tests/test_bundle_proof.py'
--- tests/test_bundle_proof.py 1970-01-01 00:00:00 +0000
+++ tests/test_bundle_proof.py 2014-02-18 16:35:09 +0000
@@ -0,0 +1,91 @@
1#!/usr/bin/python
2
3# Copyright (C) 2013 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18import charmtools.bundles
19import os.path
20import shutil
21import sys
22import tempfile
23import textwrap
24import unittest
25
26
27class TestCharmProof(unittest.TestCase):
28 def setUp(self):
29 self.linter = charmtools.bundles.BundleLinter()
30
31 def test_warn_on_charm_urls_without_revisions(self):
32 self.linter.validate({
33 'my-service': {
34 'services': {
35 'memcached': {
36 'charm': 'cs:precise/memcached',
37 'num_units': 1,
38 },
39 },
40 }})
41 self.assertIn(
42 'W: memcached: charm URL should include a revision',
43 self.linter.lint)
44
45 def test_no_warning_when_charm_urls_include_revisions(self):
46 self.linter.validate({
47 'my-service': {
48 'services': {
49 'memcached': {
50 'charm': 'cs:precise/memcached-99',
51 'num_units': 1,
52 },
53 },
54 }})
55 self.assertNotIn(
56 'W: memcached: charm URL should include a revision',
57 self.linter.lint)
58
59 def test_warn_on_missing_annotations(self):
60 self.linter.validate({
61 'my-service': {
62 'services': {
63 'memcached': {
64 'charm': 'cs:precise/memcached',
65 'num_units': 1,
66 },
67 },
68 }})
69 self.assertIn(
70 'W: my-service: memcached: No annotations found, will render '
71 'poorly in GUI',
72 self.linter.lint)
73
74 def test_no_warning_when_annotations_are_included(self):
75 self.linter.validate({
76 'my-service': {
77 'services': {
78 'memcached': {
79 'charm': 'cs:precise/memcached',
80 'num_units': 1,
81 'annotations': {
82 'gui-x': '821.5',
83 'gui-y': '669.2698359714502',
84 },
85 },
86 },
87 }})
88 self.assertNotIn(
89 'W: my-service: memcached: No annotations found, will render '
90 'poorly in GUI',
91 self.linter.lint)
092
=== modified file 'tests/test_charm_proof.py'
--- tests/test_charm_proof.py 2014-01-10 03:41:58 +0000
+++ tests/test_charm_proof.py 2014-02-18 16:35:09 +0000
@@ -34,7 +34,6 @@
34class TestCharmProof(TestCase):34class TestCharmProof(TestCase):
35 def setUp(self):35 def setUp(self):
36 self.charm_dir = mkdtemp()36 self.charm_dir = mkdtemp()
37 self.config_path = join(self.charm_dir, 'config.yaml')
38 self.linter = Linter()37 self.linter = Linter()
3938
40 def tearDown(self):39 def tearDown(self):
@@ -255,5 +254,6 @@
255 "for the tag 'tag:yaml.org,2002:python/name:__builtin__.int'")254 "for the tag 'tag:yaml.org,2002:python/name:__builtin__.int'")
256 self.assertTrue(self.linter.lint[0].startswith(expected))255 self.assertTrue(self.linter.lint[0].startswith(expected))
257256
257
258if __name__ == '__main__':258if __name__ == '__main__':
259 main()259 main()

Subscribers

People subscribed via source and target branches

to all changes: