Merge lp:~themue/juju-core/037-empty-strings-in-charm-config into lp:~go-bot/juju-core/trunk

Proposed by Frank Mueller
Status: Work in progress
Proposed branch: lp:~themue/juju-core/037-empty-strings-in-charm-config
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~themue/juju-core/036-set-default
Diff against target: 149 lines (+23/-18)
5 files modified
charm/config.go (+2/-2)
charm/config_test.go (+12/-9)
cmd/juju/config_test.go (+7/-0)
state/service_test.go (+0/-4)
state/statecmd/config_test.go (+2/-3)
To merge this branch: bzr merge lp:~themue/juju-core/037-empty-strings-in-charm-config
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+178318@code.launchpad.net

Description of the change

charm: allow empty strings as config values

This is the second CL for lp:1194945. It allows empty strings
as valid values for config options with the type string. Merging
should be done after none has signalled a compatibility problem
as answer to the query mail on the mailing list.

https://codereview.appspot.com/12343045/

To post a comment you must log in.
Revision history for this message
Frank Mueller (themue) wrote :
Download full text (5.7 KiB)

Reviewers: mp+178318_code.launchpad.net,

Message:
Please take a look.

Description:
charm: allow empty strings as config values

This is the second CL for lp:1194945. It allows empty strings
as valid values for config options with the type string. Merging
should be done after none has signalled a compatibility problem
as answer to the query mail on the mailing list.

https://code.launchpad.net/~themue/juju-core/037-empty-strings-in-charm-config/+merge/178318

Requires:
https://code.launchpad.net/~themue/juju-core/036-set-default/+merge/178279

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M charm/config.go
   M charm/config_test.go
   M cmd/juju/config_test.go
   M state/service_test.go
   M state/statecmd/config_test.go

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: charm/config.go
=== modified file 'charm/config.go'
--- charm/config.go 2013-08-02 12:16:22 +0000
+++ charm/config.go 2013-08-02 14:54:09 +0000
@@ -45,7 +45,7 @@
   if checker := optionTypeCheckers[option.Type]; checker != nil {
    if value, err = checker.Coerce(value, nil); err != nil {
     return nil, err
- } else if value == "" {
+ } else if option.Type != "string" && value == "" {
     value = nil
    }
    return value, nil
@@ -64,7 +64,7 @@
  // returns an error if it cannot be parsed to the correct type. Empty
  // string values are returned as nil.
  func (option Option) parse(name, str string) (_ interface{}, err error) {
- if str == "" {
+ if option.Type != "string" && str == "" {
    return nil, nil
   }
   defer option.error(&err, name, str)

Index: charm/config_test.go
=== modified file 'charm/config_test.go'
--- charm/config_test.go 2013-07-19 14:49:06 +0000
+++ charm/config_test.go 2013-08-02 14:54:09 +0000
@@ -112,7 +112,7 @@
   c.Assert(settings, DeepEquals, charm.Settings{
    "title": "something valid",
    "username": nil,
- "outlook": nil,
+ "outlook": "",
   })
  }

@@ -149,10 +149,6 @@
     "reticulate-splines": true,
    },
   }, {
- info: "empty string-typed values become nil",
- input: charm.Settings{"outlook": ""},
- expect: charm.Settings{"outlook": nil},
- }, {
    info: "almost-correctly-typed values are valid",
    input: charm.Settings{
     "skill-level": 123,
@@ -201,6 +197,13 @@
   "reticulate-splines": nil,
  }

+var settingsWithEmptyString = charm.Settings{
+ "outlook": "",
+ "skill-level": nil,
+ "agility-ratio": nil,
+ "reticulate-splines": nil,
+}
+
  var settingsWithValues = charm.Settings{
   "outlook": "whatever",
   "skill-level": int64(123),
@@ -279,14 +282,14 @@
    key: "blah",
    expect: settingsWithNils,
   }, {
- info: "empty strings are considered nil",
+ info: "empty strings are considered nil for non-string types",
    yaml: `blah:
              outlook: ""
           ...

Read more...

Revision history for this message
Dimiter Naydenov (dimitern) wrote :
Revision history for this message
John A Meinel (jameinel) wrote :
Revision history for this message
William Reade (fwereade) wrote :

Sorry, NOT LGTM without explanation. The API has lost/changed
functionality, I think, because we can no longer set string values to
defaults; and we've now got two ways to set defaults for non-string
types. How is all this going to work in the imminent CLI-API world?

https://codereview.appspot.com/12343045/diff/1/charm/config.go
File charm/config.go (right):

https://codereview.appspot.com/12343045/diff/1/charm/config.go#newcode39
charm/config.go:39: // are always considered valid, and empty string
values are converted to nil.
This isn't true any more.

https://codereview.appspot.com/12343045/diff/1/charm/config.go#newcode48
charm/config.go:48: } else if option.Type != "string" && value == "" {
Why are we keeping this behaviour? Having `value=` mean different things
depending on type seems like a bad idea to me. Can't we just delete this
whole special-case block?

https://codereview.appspot.com/12343045/diff/1/charm/config.go#newcode67
charm/config.go:67: if option.Type != "string" && str == "" {
Similarly.

https://codereview.appspot.com/12343045/diff/1/charm/config_test.go
File charm/config_test.go (right):

https://codereview.appspot.com/12343045/diff/1/charm/config_test.go#newcode337
charm/config_test.go:337: info: "empty strings are nil values for
non-string types",
Yeah -- why do we now have two ways of specifying set-to-default? I
don't think this is a good idea *unless* we have to support `value=` for
python compatibility.

https://codereview.appspot.com/12343045/diff/1/state/statecmd/config_test.go
File state/statecmd/config_test.go (right):

https://codereview.appspot.com/12343045/diff/1/state/statecmd/config_test.go#newcode90
state/statecmd/config_test.go:90: "value": "",
So how do we set defaults over the API?

https://codereview.appspot.com/12343045/

Unmerged revisions

1572. By Frank Mueller

charm: allowing empty strings as valid config value for string types

1571. By Frank Mueller

cmd/set: corrected the reset of an invalid change to be exact like before

1570. By Frank Mueller

cmd/set: merged trunk

1569. By Frank Mueller

cmd/set: removed setting to empty string until clearance

1568. By Frank Mueller

cmd/set: add option --default to set to default value

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm/config.go'
2--- charm/config.go 2013-07-19 14:49:06 +0000
3+++ charm/config.go 2013-08-02 15:03:22 +0000
4@@ -45,7 +45,7 @@
5 if checker := optionTypeCheckers[option.Type]; checker != nil {
6 if value, err = checker.Coerce(value, nil); err != nil {
7 return nil, err
8- } else if value == "" {
9+ } else if option.Type != "string" && value == "" {
10 value = nil
11 }
12 return value, nil
13@@ -64,7 +64,7 @@
14 // returns an error if it cannot be parsed to the correct type. Empty
15 // string values are returned as nil.
16 func (option Option) parse(name, str string) (_ interface{}, err error) {
17- if str == "" {
18+ if option.Type != "string" && str == "" {
19 return nil, nil
20 }
21 defer option.error(&err, name, str)
22
23=== modified file 'charm/config_test.go'
24--- charm/config_test.go 2013-07-19 14:49:06 +0000
25+++ charm/config_test.go 2013-08-02 15:03:22 +0000
26@@ -112,7 +112,7 @@
27 c.Assert(settings, DeepEquals, charm.Settings{
28 "title": "something valid",
29 "username": nil,
30- "outlook": nil,
31+ "outlook": "",
32 })
33 }
34
35@@ -149,10 +149,6 @@
36 "reticulate-splines": true,
37 },
38 }, {
39- info: "empty string-typed values become nil",
40- input: charm.Settings{"outlook": ""},
41- expect: charm.Settings{"outlook": nil},
42- }, {
43 info: "almost-correctly-typed values are valid",
44 input: charm.Settings{
45 "skill-level": 123,
46@@ -201,6 +197,13 @@
47 "reticulate-splines": nil,
48 }
49
50+var settingsWithEmptyString = charm.Settings{
51+ "outlook": "",
52+ "skill-level": nil,
53+ "agility-ratio": nil,
54+ "reticulate-splines": nil,
55+}
56+
57 var settingsWithValues = charm.Settings{
58 "outlook": "whatever",
59 "skill-level": int64(123),
60@@ -279,14 +282,14 @@
61 key: "blah",
62 expect: settingsWithNils,
63 }, {
64- info: "empty strings are considered nil",
65+ info: "empty strings are considered nil for non-string types",
66 yaml: `blah:
67 outlook: ""
68 skill-level: ""
69 agility-ratio: ""
70 reticulate-splines: ""`,
71 key: "blah",
72- expect: settingsWithNils,
73+ expect: settingsWithEmptyString,
74 }, {
75 info: "appropriate strings are valid",
76 yaml: `blah:
77@@ -331,14 +334,14 @@
78 input: map[string]string{},
79 expect: charm.Settings{},
80 }, {
81- info: "empty strings are nil values",
82+ info: "empty strings are nil values for non-string types",
83 input: map[string]string{
84 "outlook": "",
85 "skill-level": "",
86 "agility-ratio": "",
87 "reticulate-splines": "",
88 },
89- expect: settingsWithNils,
90+ expect: settingsWithEmptyString,
91 }, {
92 info: "strings are converted",
93 input: map[string]string{
94
95=== modified file 'cmd/juju/config_test.go'
96--- cmd/juju/config_test.go 2013-08-02 15:03:22 +0000
97+++ cmd/juju/config_test.go 2013-08-02 15:03:22 +0000
98@@ -123,6 +123,13 @@
99 "outlook": "hello@world.tld",
100 },
101 }, {
102+ about: "set an option to an empty string",
103+ args: []string{"username="},
104+ expect: charm.Settings{
105+ "username": "",
106+ "outlook": "hello@world.tld",
107+ },
108+}, {
109 about: "set to default value",
110 args: []string{"--default", "username"},
111 expect: charm.Settings{
112
113=== modified file 'state/service_test.go'
114--- state/service_test.go 2013-07-18 16:46:59 +0000
115+++ state/service_test.go 2013-08-02 15:03:22 +0000
116@@ -344,10 +344,6 @@
117 about: "unset missing string",
118 update: charm.Settings{"outlook": nil},
119 }, {
120- about: `empty strings unset string values`,
121- initial: charm.Settings{"outlook": "positive"},
122- update: charm.Settings{"outlook": "", "title": ""},
123-}, {
124 about: "preserve existing value",
125 initial: charm.Settings{"title": "sir"},
126 update: charm.Settings{"username": "admin001"},
127
128=== modified file 'state/statecmd/config_test.go'
129--- state/statecmd/config_test.go 2013-06-11 00:58:34 +0000
130+++ state/statecmd/config_test.go 2013-08-02 15:03:22 +0000
131@@ -73,7 +73,7 @@
132 about: "deployed service #2",
133 charm: "dummy",
134 config: map[string]string{
135- // Empty string gives default
136+ // Empty string sets to empty string
137 "title": "",
138 // Value when there's a default
139 "username": "foobie",
140@@ -87,8 +87,7 @@
141 "title": map[string]interface{}{
142 "description": "A descriptive title used for the service.",
143 "type": "string",
144- "value": "My Title",
145- "default": true,
146+ "value": "",
147 },
148 "outlook": map[string]interface{}{
149 "description": "No default outlook.",

Subscribers

People subscribed via source and target branches

to status/vote changes: