Merge lp:~bac/charm-tools/1321316 into lp:charm-tools/1.2

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 322
Proposed branch: lp:~bac/charm-tools/1321316
Merge into: lp:charm-tools/1.2
Diff against target: 46 lines (+16/-2)
2 files modified
charmtools/charms.py (+2/-2)
tests/test_charm_proof.py (+14/-0)
To merge this branch: bzr merge lp:~bac/charm-tools/1321316
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+220286@code.launchpad.net

Description of the change

Don't die if an option has no type.

If a config option doesn't specify a type, a warning was issued
but the process failed with KeyError. This fix allows it to proceed, using
'string' if not type is given.

This bug affects charmworld ingest, so getting it released soonish would be
great.

https://codereview.appspot.com/98390047/

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Reviewers: mp+220286_code.launchpad.net,

Message:
Please take a look.

Description:
Don't die if an option has no type.

If a config option doesn't specify a type, a warning was issued
but the process failed with KeyError. This fix allows it to proceed,
using
'string' if not type is given.

This bug affects charmworld ingest, so getting it released soonish would
be
great.

https://code.launchpad.net/~bac/charm-tools/1321316/+merge/220286

(do not edit description out of merge proposal)

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

Affected files (+18, -2 lines):
   A [revision details]
   M charmtools/charms.py
   M tests/test_charm_proof.py

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: charmtools/charms.py
=== modified file 'charmtools/charms.py'
--- charmtools/charms.py 2014-05-16 15:52:09 +0000
+++ charmtools/charms.py 2014-05-20 14:59:35 +0000
@@ -185,7 +185,7 @@
                  self.warn('config.yaml: option %s has an invalid type (%s)'
                            % (option_name, option_type))
              elif 'default' in option_value:
- expected_type = KNOWN_OPTION_TYPES[option_value['type']]
+ expected_type = KNOWN_OPTION_TYPES[option_type]
                  actual_value = option_value['default']
                  if actual_value is None:
                      notify = (self.info if expected_type in
ALLOW_NONE_DEFAULT
@@ -197,7 +197,7 @@
                      self.err(
                          'config.yaml: type of option %s is specified as '
                          '%s, but the type of the default value is %s'
- % (option_name, option_value['type'],
+ % (option_name, option_type,
                             type(actual_value).__name__))
              else:
                  # Nothing to do: the option type is valid but no default

Index: tests/test_charm_proof.py
=== modified file 'tests/test_charm_proof.py'
--- tests/test_charm_proof.py 2014-05-16 15:52:09 +0000
+++ tests/test_charm_proof.py 2014-05-20 14:59:35 +0000
@@ -71,6 +71,20 @@
          self.linter.check_config_file(self.charm_dir)
          self.assertEqual([], self.linter.lint)

+ def test_missing_type_defaults_to_string(self):
+ # A warning is issued but no failure.
+ self.write_config("""
+ options:
+ string_opt:
+ description: A string option
+ default: some text
+ """)
+ self.linter.check_config_file(self.charm_dir)
+ self.assertEqual(
+ ['W: config.yaml: option string_opt does not have the keys: '
+ 'type'],
+ self.linter.lint)
+
      def test_config_with_invalid_yaml(self):
          self.write_config("""
              options:

Revision history for this message
Marco Ceppi (marcoceppi) wrote :
Revision history for this message
Brad Crittenden (bac) wrote :

*** Submitted:

Don't die if an option has no type.

If a config option doesn't specify a type, a warning was issued
but the process failed with KeyError. This fix allows it to proceed,
using
'string' if not type is given.

This bug affects charmworld ingest, so getting it released soonish would
be
great.

R=Marco Ceppi
CC=
https://codereview.appspot.com/98390047

https://codereview.appspot.com/98390047/

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-05-16 15:52:09 +0000
3+++ charmtools/charms.py 2014-05-20 15:08:06 +0000
4@@ -185,7 +185,7 @@
5 self.warn('config.yaml: option %s has an invalid type (%s)'
6 % (option_name, option_type))
7 elif 'default' in option_value:
8- expected_type = KNOWN_OPTION_TYPES[option_value['type']]
9+ expected_type = KNOWN_OPTION_TYPES[option_type]
10 actual_value = option_value['default']
11 if actual_value is None:
12 notify = (self.info if expected_type in ALLOW_NONE_DEFAULT
13@@ -197,7 +197,7 @@
14 self.err(
15 'config.yaml: type of option %s is specified as '
16 '%s, but the type of the default value is %s'
17- % (option_name, option_value['type'],
18+ % (option_name, option_type,
19 type(actual_value).__name__))
20 else:
21 # Nothing to do: the option type is valid but no default
22
23=== modified file 'tests/test_charm_proof.py'
24--- tests/test_charm_proof.py 2014-05-16 15:52:09 +0000
25+++ tests/test_charm_proof.py 2014-05-20 15:08:06 +0000
26@@ -71,6 +71,20 @@
27 self.linter.check_config_file(self.charm_dir)
28 self.assertEqual([], self.linter.lint)
29
30+ def test_missing_type_defaults_to_string(self):
31+ # A warning is issued but no failure.
32+ self.write_config("""
33+ options:
34+ string_opt:
35+ description: A string option
36+ default: some text
37+ """)
38+ self.linter.check_config_file(self.charm_dir)
39+ self.assertEqual(
40+ ['W: config.yaml: option string_opt does not have the keys: '
41+ 'type'],
42+ self.linter.lint)
43+
44 def test_config_with_invalid_yaml(self):
45 self.write_config("""
46 options:

Subscribers

People subscribed via source and target branches

to all changes: