Merge lp:~hazmat/pyjuju/bool-and-validate-defaults into lp:pyjuju
Proposed by
Kapil Thangavelu
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Benjamin Saller | ||||
Approved revision: | 449 | ||||
Merged at revision: | 473 | ||||
Proposed branch: | lp:~hazmat/pyjuju/bool-and-validate-defaults | ||||
Merge into: | lp:pyjuju | ||||
Diff against target: |
141 lines (+68/-7) 2 files modified
juju/charm/config.py (+16/-5) juju/charm/tests/test_config.py (+52/-2) |
||||
To merge this branch: | bzr merge lp:~hazmat/pyjuju/bool-and-validate-defaults | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Benjamin Saller (community) | Approve | ||
Jim Baker (community) | Approve | ||
Review via email:
|
Description of the change
Validate defaults and add a boolean config type
Defaults previously could be inconsistent to the schema without detection. Per
request also implement a boolean configuration type.
To post a comment you must log in.
Reviewers: mp+89978_ code.launchpad. net,
Message:
Please take a look.
Description:
Defaults previously could be inconsistent to the schema without
detection. Per
request also implement a boolean configuration type.
https:/ /code.launchpad .net/~hazmat/ juju/bool- and-validate- defaults/ +merge/ 89978
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/5572053/
Affected files: config. py tests/test_ config. py
M juju/charm/
M juju/charm/
Index: juju/charm/ config. py config. py' config. py 2011-12-07 02:32:07 +0000 config. py 2012-01-24 18:10:19 +0000 "string" ),
Constant( "str"), # Obsolete
Constant( "int"), "boolean" ),
Constant( "float" )),
"default" : OneOf(String(), Int(), Float()),
"description ": String(),
=== <email address hidden> >
<email address hidden>
=== modified file 'juju/charm/
--- juju/charm/
+++ juju/charm/
@@ -13,6 +13,7 @@
"type": OneOf(Constant(
+ Constant(
@@ -91,6 +92,8 @@
data = self.parse_ serialization_ data(raw_ data, pathname)
self. _data = data
+ # validate defaults
+ self.get_defaults()
def parse_serializa tion_data( self, data, pathname=None):
"""Verify we have sensible option metadata.
@@ -136,7 +139,7 @@
if not valid: lueError(
raise ServiceConfigVa
- "Invalid value for %s: %s" % (name, value))
+ "Invalid value for %s: %r" % (name, value))
return value
def get_defaults(self):
@@ -173,7 +176,9 @@
# Validators return (type mapped value, valid boolean)
def validate_str(value, options):
- return str(value), True
+ if isinstance(value, basestring):
+ return value, True
+ return value, False
def validate_int(value, options):
@@ -184,10 +189,15 @@
def validate_ float(value, options): boolean( value, options):
- try:
+ if isinstance(value, (int, float)):
return float(value), True
- except ValueError:
- return value, False
+ return value, False
+
+
+def validate_
+ if isinstance(value, bool):
+ return value, True
+ return value, False
# maps service option types to callables
validation_kinds = {
@@ -195,4 +205,5 @@
"str": validate_str, # Obsolete
"int": validate_int,
"float": validate_float,
+ "boolean": validate_boolean,
}
Index: juju/charm/ tests/test_ config. py tests/test_ config. py' tests/test_ config. py 2011-12-07 02:32:07 +0000 tests/test_ config. py 2012-01-24 18:42:22 +0000 get_defaults( )
self. assertEqual( defaults, sample_ config_ defaults)
=== <email address hidden> >
<email address hidden>
=== modified file 'juju/charm/
--- juju/charm/
+++ juju/charm/
@@ -78,6 +78,19 @@
defaults = self.config.
+ def test_defaults_ validated( self): lueError,
+ e = self.assertRaises(
+ ServiceConfigVa
+ self.config.parse,
+ yaml.dump(
+ ...