Merge lp:~dimitern/juju-core/148-apiuniter-fix-configsettings into lp:~go-bot/juju-core/trunk
- 148-apiuniter-fix-configsettings
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Dimiter Naydenov | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 1893 | ||||
Proposed branch: | lp:~dimitern/juju-core/148-apiuniter-fix-configsettings | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Prerequisite: | lp:~dimitern/juju-core/147-apiprovisioner-blank-env-secrets | ||||
Diff against target: |
747 lines (+177/-113) 16 files modified
state/api/params/internal.go (+37/-22) state/api/provisioner/provisioner.go (+1/-1) state/api/uniter/relationunit.go (+3/-3) state/api/uniter/relationunit_test.go (+2/-2) state/api/uniter/settings.go (+6/-6) state/api/uniter/settings_test.go (+11/-11) state/api/uniter/unit.go (+2/-10) state/apiserver/provisioner/provisioner.go (+2/-2) state/apiserver/provisioner/provisioner_test.go (+1/-1) state/apiserver/uniter/uniter.go (+24/-19) state/apiserver/uniter/uniter_test.go (+64/-12) worker/uniter/context.go (+2/-2) worker/uniter/context_test.go (+15/-15) worker/uniter/jujuc/context.go (+2/-2) worker/uniter/jujuc/relation-get.go (+1/-1) worker/uniter/jujuc/util_test.go (+4/-4) |
||||
To merge this branch: | bzr merge lp:~dimitern/juju-core/148-apiuniter-fix-configsettings | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+187824@code.launchpad.net |
Commit message
apiuniter: Fix lp:1231457
This changes several params types, while keeping
the field names for backward compatibility.
And changes the result of ConfigSettings() call
to return map[string]
settings are different from relation settings
(which are always strings), and coercing charm
settings to stings discards non-string config
settings, so this is fixed here.
https:/
R=fwereade
Description of the change
apiuniter: Fix lp:1231457
This changes several params types, while keeping
the field names for backward compatibility.
And changes the result of ConfigSettings() call
to return map[string]
settings are different from relation settings
(which are always strings), and coercing charm
settings to stings discards non-string config
settings, so this is fixed here.
Dimiter Naydenov (dimitern) wrote : | # |
William Reade (fwereade) wrote : | # |
LGTM with an error return on unexpected relation settings.
https:/
File state/api/
https:/
state/api/
configuration.
Man, our vocabulary is still kinda screwed up here... "Config" means too
many things. Not much we can do about it right now though.
https:/
File state/api/
https:/
state/api/
map[string]
can you not do charm.Settings(
https:/
File state/apiserver
https:/
state/apiserver
strings.
Hmm. This is almost legitimate-panic territory. Best not, since we're
running in the API server and will cause a lot of collateral damage, but
I think we should at least error out -- if it happens, we're clearly not
in Kansas any more.
Dimiter Naydenov (dimitern) wrote : | # |
Please take a look.
https:/
File state/api/
https:/
state/api/
map[string]
On 2013/09/26 16:11:52, fwereade wrote:
> can you not do charm.Settings(
Done.
https:/
File state/apiserver
https:/
state/apiserver
strings.
On 2013/09/26 16:11:52, fwereade wrote:
> Hmm. This is almost legitimate-panic territory. Best not, since we're
running in
> the API server and will cause a lot of collateral damage, but I think
we should
> at least error out -- if it happens, we're clearly not in Kansas any
more.
Done. Also added a couple of tests for the error.
Preview Diff
1 | === modified file 'state/api/params/internal.go' | |||
2 | --- state/api/params/internal.go 2013-09-24 08:55:01 +0000 | |||
3 | +++ state/api/params/internal.go 2013-09-26 17:24:28 +0000 | |||
4 | @@ -105,28 +105,43 @@ | |||
5 | 105 | Results []BoolResult | 105 | Results []BoolResult |
6 | 106 | } | 106 | } |
7 | 107 | 107 | ||
28 | 108 | // Settings holds charm config options names and values. | 108 | // RelationSettings holds relation settings names and values. |
29 | 109 | type Settings map[string]string | 109 | type RelationSettings map[string]string |
30 | 110 | 110 | ||
31 | 111 | // SettingsResult holds a charm settings map or an error. | 111 | // RelationSettingsResult holds a relation settings map or an error. |
32 | 112 | type SettingsResult struct { | 112 | type RelationSettingsResult struct { |
33 | 113 | Error *Error | 113 | Error *Error |
34 | 114 | Settings Settings | 114 | Settings RelationSettings |
35 | 115 | } | 115 | } |
36 | 116 | 116 | ||
37 | 117 | // SettingsResults holds the result of an API calls that returns | 117 | // RelationSettingsResults holds the result of an API calls that |
38 | 118 | // settings for multiple entities. | 118 | // returns settings for multiple relations. |
39 | 119 | type SettingsResults struct { | 119 | type RelationSettingsResults struct { |
40 | 120 | Results []SettingsResult | 120 | Results []RelationSettingsResult |
41 | 121 | } | 121 | } |
42 | 122 | 122 | ||
43 | 123 | // Config holds configuration with string keys and arbitrary values. | 123 | // ConfigSettings holds unit, service or cham configuration settings |
44 | 124 | type Config map[string]interface{} | 124 | // with string keys and arbitrary values. |
45 | 125 | 125 | type ConfigSettings map[string]interface{} | |
46 | 126 | // ConfigResult holds a configuration map or an error. | 126 | |
47 | 127 | type ConfigResult struct { | 127 | // ConfigSettingsResult holds a configuration map or an error. |
48 | 128 | type ConfigSettingsResult struct { | ||
49 | 129 | Error *Error | ||
50 | 130 | Settings ConfigSettings | ||
51 | 131 | } | ||
52 | 132 | |||
53 | 133 | // ConfigSettingsResults holds multiple configuration maps or errors. | ||
54 | 134 | type ConfigSettingsResults struct { | ||
55 | 135 | Results []ConfigSettingsResult | ||
56 | 136 | } | ||
57 | 137 | |||
58 | 138 | // EnvironConfig holds an environment configuration. | ||
59 | 139 | type EnvironConfig map[string]interface{} | ||
60 | 140 | |||
61 | 141 | // EnvironConfigResult holds environment configuration or an error. | ||
62 | 142 | type EnvironConfigResult struct { | ||
63 | 128 | Error *Error | 143 | Error *Error |
65 | 129 | Config Config | 144 | Config EnvironConfig |
66 | 130 | } | 145 | } |
67 | 131 | 146 | ||
68 | 132 | // RelationUnit holds a relation and a unit tag. | 147 | // RelationUnit holds a relation and a unit tag. |
69 | @@ -164,7 +179,7 @@ | |||
70 | 164 | type RelationUnitSettings struct { | 179 | type RelationUnitSettings struct { |
71 | 165 | Relation string | 180 | Relation string |
72 | 166 | Unit string | 181 | Unit string |
74 | 167 | Settings Settings | 182 | Settings RelationSettings |
75 | 168 | } | 183 | } |
76 | 169 | 184 | ||
77 | 170 | // RelationUnitsSettings holds the arguments for making a EnterScope | 185 | // RelationUnitsSettings holds the arguments for making a EnterScope |
78 | 171 | 186 | ||
79 | === modified file 'state/api/provisioner/provisioner.go' | |||
80 | --- state/api/provisioner/provisioner.go 2013-09-26 10:38:59 +0000 | |||
81 | +++ state/api/provisioner/provisioner.go 2013-09-26 17:24:28 +0000 | |||
82 | @@ -71,7 +71,7 @@ | |||
83 | 71 | 71 | ||
84 | 72 | // EnvironConfig returns the current environment configuration. | 72 | // EnvironConfig returns the current environment configuration. |
85 | 73 | func (st *State) EnvironConfig() (*config.Config, error) { | 73 | func (st *State) EnvironConfig() (*config.Config, error) { |
87 | 74 | var result params.ConfigResult | 74 | var result params.EnvironConfigResult |
88 | 75 | err := st.caller.Call("Provisioner", "", "EnvironConfig", nil, &result) | 75 | err := st.caller.Call("Provisioner", "", "EnvironConfig", nil, &result) |
89 | 76 | if err != nil { | 76 | if err != nil { |
90 | 77 | return nil, err | 77 | return nil, err |
91 | 78 | 78 | ||
92 | === modified file 'state/api/uniter/relationunit.go' | |||
93 | --- state/api/uniter/relationunit.go 2013-09-10 17:00:19 +0000 | |||
94 | +++ state/api/uniter/relationunit.go 2013-09-26 17:24:28 +0000 | |||
95 | @@ -105,7 +105,7 @@ | |||
96 | 105 | // Settings returns a Settings which allows access to the unit's settings | 105 | // Settings returns a Settings which allows access to the unit's settings |
97 | 106 | // within the relation. | 106 | // within the relation. |
98 | 107 | func (ru *RelationUnit) Settings() (*Settings, error) { | 107 | func (ru *RelationUnit) Settings() (*Settings, error) { |
100 | 108 | var results params.SettingsResults | 108 | var results params.RelationSettingsResults |
101 | 109 | args := params.RelationUnits{ | 109 | args := params.RelationUnits{ |
102 | 110 | RelationUnits: []params.RelationUnit{{ | 110 | RelationUnits: []params.RelationUnit{{ |
103 | 111 | Relation: ru.relation.tag, | 111 | Relation: ru.relation.tag, |
104 | @@ -133,9 +133,9 @@ | |||
105 | 133 | // unit is not grounds for an error, because the unit settings are | 133 | // unit is not grounds for an error, because the unit settings are |
106 | 134 | // guaranteed to persist for the lifetime of the relation, regardless | 134 | // guaranteed to persist for the lifetime of the relation, regardless |
107 | 135 | // of the lifetime of the unit. | 135 | // of the lifetime of the unit. |
109 | 136 | func (ru *RelationUnit) ReadSettings(uname string) (params.Settings, error) { | 136 | func (ru *RelationUnit) ReadSettings(uname string) (params.RelationSettings, error) { |
110 | 137 | tag := names.UnitTag(uname) | 137 | tag := names.UnitTag(uname) |
112 | 138 | var results params.SettingsResults | 138 | var results params.RelationSettingsResults |
113 | 139 | args := params.RelationUnitPairs{ | 139 | args := params.RelationUnitPairs{ |
114 | 140 | RelationUnitPairs: []params.RelationUnitPair{{ | 140 | RelationUnitPairs: []params.RelationUnitPair{{ |
115 | 141 | Relation: ru.relation.tag, | 141 | Relation: ru.relation.tag, |
116 | 142 | 142 | ||
117 | === modified file 'state/api/uniter/relationunit_test.go' | |||
118 | --- state/api/uniter/relationunit_test.go 2013-09-13 11:35:33 +0000 | |||
119 | +++ state/api/uniter/relationunit_test.go 2013-09-26 17:24:28 +0000 | |||
120 | @@ -196,7 +196,7 @@ | |||
121 | 196 | 196 | ||
122 | 197 | gotSettings, err := apiRelUnit.Settings() | 197 | gotSettings, err := apiRelUnit.Settings() |
123 | 198 | c.Assert(err, gc.IsNil) | 198 | c.Assert(err, gc.IsNil) |
125 | 199 | c.Assert(gotSettings.Map(), gc.DeepEquals, params.Settings{ | 199 | c.Assert(gotSettings.Map(), gc.DeepEquals, params.RelationSettings{ |
126 | 200 | "some": "settings", | 200 | "some": "settings", |
127 | 201 | "other": "things", | 201 | "other": "things", |
128 | 202 | }) | 202 | }) |
129 | @@ -230,7 +230,7 @@ | |||
130 | 230 | s.assertInScope(c, myRelUnit, true) | 230 | s.assertInScope(c, myRelUnit, true) |
131 | 231 | gotSettings, err = apiRelUnit.ReadSettings("mysql/0") | 231 | gotSettings, err = apiRelUnit.ReadSettings("mysql/0") |
132 | 232 | c.Assert(err, gc.IsNil) | 232 | c.Assert(err, gc.IsNil) |
134 | 233 | c.Assert(gotSettings, gc.DeepEquals, params.Settings{ | 233 | c.Assert(gotSettings, gc.DeepEquals, params.RelationSettings{ |
135 | 234 | "some": "settings", | 234 | "some": "settings", |
136 | 235 | "other": "things", | 235 | "other": "things", |
137 | 236 | }) | 236 | }) |
138 | 237 | 237 | ||
139 | === modified file 'state/api/uniter/settings.go' | |||
140 | --- state/api/uniter/settings.go 2013-09-06 16:22:34 +0000 | |||
141 | +++ state/api/uniter/settings.go 2013-09-26 17:24:28 +0000 | |||
142 | @@ -15,12 +15,12 @@ | |||
143 | 15 | st *State | 15 | st *State |
144 | 16 | relationTag string | 16 | relationTag string |
145 | 17 | unitTag string | 17 | unitTag string |
147 | 18 | settings params.Settings | 18 | settings params.RelationSettings |
148 | 19 | } | 19 | } |
149 | 20 | 20 | ||
151 | 21 | func newSettings(st *State, relationTag, unitTag string, settings params.Settings) *Settings { | 21 | func newSettings(st *State, relationTag, unitTag string, settings params.RelationSettings) *Settings { |
152 | 22 | if settings == nil { | 22 | if settings == nil { |
154 | 23 | settings = make(params.Settings) | 23 | settings = make(params.RelationSettings) |
155 | 24 | } | 24 | } |
156 | 25 | return &Settings{ | 25 | return &Settings{ |
157 | 26 | st: st, | 26 | st: st, |
158 | @@ -36,8 +36,8 @@ | |||
159 | 36 | // not return map[string]interface{}, but since all values are | 36 | // not return map[string]interface{}, but since all values are |
160 | 37 | // expected to be strings anyway, we need to fix the uniter code | 37 | // expected to be strings anyway, we need to fix the uniter code |
161 | 38 | // accordingly when migrating to the API. | 38 | // accordingly when migrating to the API. |
164 | 39 | func (s *Settings) Map() params.Settings { | 39 | func (s *Settings) Map() params.RelationSettings { |
165 | 40 | settingsCopy := make(params.Settings) | 40 | settingsCopy := make(params.RelationSettings) |
166 | 41 | for k, v := range s.settings { | 41 | for k, v := range s.settings { |
167 | 42 | if v != "" { | 42 | if v != "" { |
168 | 43 | // Skip deleted keys. | 43 | // Skip deleted keys. |
169 | @@ -75,7 +75,7 @@ | |||
170 | 75 | // without overwritting. | 75 | // without overwritting. |
171 | 76 | func (s *Settings) Write() error { | 76 | func (s *Settings) Write() error { |
172 | 77 | // First make a copy of the map, including deleted keys. | 77 | // First make a copy of the map, including deleted keys. |
174 | 78 | settingsCopy := make(params.Settings) | 78 | settingsCopy := make(params.RelationSettings) |
175 | 79 | for k, v := range s.settings { | 79 | for k, v := range s.settings { |
176 | 80 | settingsCopy[k] = v | 80 | settingsCopy[k] = v |
177 | 81 | } | 81 | } |
178 | 82 | 82 | ||
179 | === modified file 'state/api/uniter/settings_test.go' | |||
180 | --- state/api/uniter/settings_test.go 2013-09-06 15:39:38 +0000 | |||
181 | +++ state/api/uniter/settings_test.go 2013-09-26 17:24:28 +0000 | |||
182 | @@ -34,7 +34,7 @@ | |||
183 | 34 | c.Assert(theMap, gc.HasLen, 0) | 34 | c.Assert(theMap, gc.HasLen, 0) |
184 | 35 | 35 | ||
185 | 36 | // And also accepts a populated map, and returns a converted map. | 36 | // And also accepts a populated map, and returns a converted map. |
187 | 37 | rawSettings := params.Settings{ | 37 | rawSettings := params.RelationSettings{ |
188 | 38 | "some": "settings", | 38 | "some": "settings", |
189 | 39 | "other": "stuff", | 39 | "other": "stuff", |
190 | 40 | } | 40 | } |
191 | @@ -47,15 +47,15 @@ | |||
192 | 47 | settings := uniter.NewSettings(s.uniter, "blah", "foo", nil) | 47 | settings := uniter.NewSettings(s.uniter, "blah", "foo", nil) |
193 | 48 | 48 | ||
194 | 49 | settings.Set("foo", "bar") | 49 | settings.Set("foo", "bar") |
196 | 50 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 50 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
197 | 51 | "foo": "bar", | 51 | "foo": "bar", |
198 | 52 | }) | 52 | }) |
199 | 53 | settings.Set("foo", "qaz") | 53 | settings.Set("foo", "qaz") |
201 | 54 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 54 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
202 | 55 | "foo": "qaz", | 55 | "foo": "qaz", |
203 | 56 | }) | 56 | }) |
204 | 57 | settings.Set("bar", "Cheers") | 57 | settings.Set("bar", "Cheers") |
206 | 58 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 58 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
207 | 59 | "foo": "qaz", | 59 | "foo": "qaz", |
208 | 60 | "bar": "Cheers", | 60 | "bar": "Cheers", |
209 | 61 | }) | 61 | }) |
210 | @@ -67,27 +67,27 @@ | |||
211 | 67 | settings.Set("foo", "qaz") | 67 | settings.Set("foo", "qaz") |
212 | 68 | settings.Set("abc", "tink") | 68 | settings.Set("abc", "tink") |
213 | 69 | settings.Set("bar", "tonk") | 69 | settings.Set("bar", "tonk") |
215 | 70 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 70 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
216 | 71 | "foo": "qaz", | 71 | "foo": "qaz", |
217 | 72 | "abc": "tink", | 72 | "abc": "tink", |
218 | 73 | "bar": "tonk", | 73 | "bar": "tonk", |
219 | 74 | }) | 74 | }) |
220 | 75 | settings.Delete("abc") | 75 | settings.Delete("abc") |
222 | 76 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 76 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
223 | 77 | "foo": "qaz", | 77 | "foo": "qaz", |
224 | 78 | "bar": "tonk", | 78 | "bar": "tonk", |
225 | 79 | }) | 79 | }) |
226 | 80 | settings.Delete("bar") | 80 | settings.Delete("bar") |
228 | 81 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 81 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
229 | 82 | "foo": "qaz", | 82 | "foo": "qaz", |
230 | 83 | }) | 83 | }) |
231 | 84 | settings.Set("abc", "123") | 84 | settings.Set("abc", "123") |
233 | 85 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 85 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
234 | 86 | "foo": "qaz", | 86 | "foo": "qaz", |
235 | 87 | "abc": "123", | 87 | "abc": "123", |
236 | 88 | }) | 88 | }) |
237 | 89 | settings.Delete("missing") | 89 | settings.Delete("missing") |
239 | 90 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 90 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
240 | 91 | "foo": "qaz", | 91 | "foo": "qaz", |
241 | 92 | "abc": "123", | 92 | "abc": "123", |
242 | 93 | }) | 93 | }) |
243 | @@ -112,7 +112,7 @@ | |||
244 | 112 | c.Assert(err, gc.IsNil) | 112 | c.Assert(err, gc.IsNil) |
245 | 113 | settings, err := apiRelUnit.Settings() | 113 | settings, err := apiRelUnit.Settings() |
246 | 114 | c.Assert(err, gc.IsNil) | 114 | c.Assert(err, gc.IsNil) |
248 | 115 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 115 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
249 | 116 | "some": "stuff", | 116 | "some": "stuff", |
250 | 117 | "other": "things", | 117 | "other": "things", |
251 | 118 | }) | 118 | }) |
252 | @@ -126,7 +126,7 @@ | |||
253 | 126 | c.Assert(err, gc.IsNil) | 126 | c.Assert(err, gc.IsNil) |
254 | 127 | settings, err = apiRelUnit.Settings() | 127 | settings, err = apiRelUnit.Settings() |
255 | 128 | c.Assert(err, gc.IsNil) | 128 | c.Assert(err, gc.IsNil) |
257 | 129 | c.Assert(settings.Map(), gc.DeepEquals, params.Settings{ | 129 | c.Assert(settings.Map(), gc.DeepEquals, params.RelationSettings{ |
258 | 130 | "foo": "qaz", | 130 | "foo": "qaz", |
259 | 131 | "other": "days", | 131 | "other": "days", |
260 | 132 | }) | 132 | }) |
261 | 133 | 133 | ||
262 | === modified file 'state/api/uniter/unit.go' | |||
263 | --- state/api/uniter/unit.go 2013-09-17 18:18:44 +0000 | |||
264 | +++ state/api/uniter/unit.go 2013-09-26 17:24:28 +0000 | |||
265 | @@ -120,20 +120,12 @@ | |||
266 | 120 | return service, nil | 120 | return service, nil |
267 | 121 | } | 121 | } |
268 | 122 | 122 | ||
269 | 123 | func convertSettings(input params.Settings) charm.Settings { | ||
270 | 124 | result := make(charm.Settings) | ||
271 | 125 | for k, v := range input { | ||
272 | 126 | result[k] = v | ||
273 | 127 | } | ||
274 | 128 | return result | ||
275 | 129 | } | ||
276 | 130 | |||
277 | 131 | // ConfigSettings returns the complete set of service charm config settings | 123 | // ConfigSettings returns the complete set of service charm config settings |
278 | 132 | // available to the unit. Unset values will be replaced with the default | 124 | // available to the unit. Unset values will be replaced with the default |
279 | 133 | // value for the associated option, and may thus be nil when no default is | 125 | // value for the associated option, and may thus be nil when no default is |
280 | 134 | // specified. | 126 | // specified. |
281 | 135 | func (u *Unit) ConfigSettings() (charm.Settings, error) { | 127 | func (u *Unit) ConfigSettings() (charm.Settings, error) { |
283 | 136 | var results params.SettingsResults | 128 | var results params.ConfigSettingsResults |
284 | 137 | args := params.Entities{ | 129 | args := params.Entities{ |
285 | 138 | Entities: []params.Entity{{Tag: u.tag}}, | 130 | Entities: []params.Entity{{Tag: u.tag}}, |
286 | 139 | } | 131 | } |
287 | @@ -148,7 +140,7 @@ | |||
288 | 148 | if result.Error != nil { | 140 | if result.Error != nil { |
289 | 149 | return nil, result.Error | 141 | return nil, result.Error |
290 | 150 | } | 142 | } |
292 | 151 | return convertSettings(result.Settings), nil | 143 | return charm.Settings(result.Settings), nil |
293 | 152 | } | 144 | } |
294 | 153 | 145 | ||
295 | 154 | // ServiceName returns the service name. | 146 | // ServiceName returns the service name. |
296 | 155 | 147 | ||
297 | === modified file 'state/apiserver/provisioner/provisioner.go' | |||
298 | --- state/apiserver/provisioner/provisioner.go 2013-09-26 16:01:47 +0000 | |||
299 | +++ state/apiserver/provisioner/provisioner.go 2013-09-26 17:24:28 +0000 | |||
300 | @@ -152,8 +152,8 @@ | |||
301 | 152 | } | 152 | } |
302 | 153 | 153 | ||
303 | 154 | // EnvironConfig returns the current environment's configuration. | 154 | // EnvironConfig returns the current environment's configuration. |
306 | 155 | func (p *ProvisionerAPI) EnvironConfig() (params.ConfigResult, error) { | 155 | func (p *ProvisionerAPI) EnvironConfig() (params.EnvironConfigResult, error) { |
307 | 156 | result := params.ConfigResult{} | 156 | result := params.EnvironConfigResult{} |
308 | 157 | config, err := p.st.EnvironConfig() | 157 | config, err := p.st.EnvironConfig() |
309 | 158 | if err != nil { | 158 | if err != nil { |
310 | 159 | return result, err | 159 | return result, err |
311 | 160 | 160 | ||
312 | === modified file 'state/apiserver/provisioner/provisioner_test.go' | |||
313 | --- state/apiserver/provisioner/provisioner_test.go 2013-09-26 11:15:31 +0000 | |||
314 | +++ state/apiserver/provisioner/provisioner_test.go 2013-09-26 17:24:28 +0000 | |||
315 | @@ -421,7 +421,7 @@ | |||
316 | 421 | result, err := s.provisioner.EnvironConfig() | 421 | result, err := s.provisioner.EnvironConfig() |
317 | 422 | c.Assert(err, gc.IsNil) | 422 | c.Assert(err, gc.IsNil) |
318 | 423 | c.Assert(result.Error, gc.IsNil) | 423 | c.Assert(result.Error, gc.IsNil) |
320 | 424 | c.Assert(result.Config, gc.DeepEquals, params.Config(envConfig.AllAttrs())) | 424 | c.Assert(result.Config, gc.DeepEquals, params.EnvironConfig(envConfig.AllAttrs())) |
321 | 425 | 425 | ||
322 | 426 | // Now test it with a non-environment manager and make sure | 426 | // Now test it with a non-environment manager and make sure |
323 | 427 | // the secret attributes are masked. | 427 | // the secret attributes are masked. |
324 | 428 | 428 | ||
325 | === modified file 'state/apiserver/uniter/uniter.go' | |||
326 | --- state/apiserver/uniter/uniter.go 2013-09-12 14:58:40 +0000 | |||
327 | +++ state/apiserver/uniter/uniter.go 2013-09-26 17:24:28 +0000 | |||
328 | @@ -6,6 +6,8 @@ | |||
329 | 6 | package uniter | 6 | package uniter |
330 | 7 | 7 | ||
331 | 8 | import ( | 8 | import ( |
332 | 9 | "fmt" | ||
333 | 10 | |||
334 | 9 | "launchpad.net/juju-core/charm" | 11 | "launchpad.net/juju-core/charm" |
335 | 10 | "launchpad.net/juju-core/environs" | 12 | "launchpad.net/juju-core/environs" |
336 | 11 | "launchpad.net/juju-core/errors" | 13 | "launchpad.net/juju-core/errors" |
337 | @@ -489,13 +491,13 @@ | |||
338 | 489 | 491 | ||
339 | 490 | // ConfigSettings returns the complete set of service charm config | 492 | // ConfigSettings returns the complete set of service charm config |
340 | 491 | // settings available to each given unit. | 493 | // settings available to each given unit. |
344 | 492 | func (u *UniterAPI) ConfigSettings(args params.Entities) (params.SettingsResults, error) { | 494 | func (u *UniterAPI) ConfigSettings(args params.Entities) (params.ConfigSettingsResults, error) { |
345 | 493 | result := params.SettingsResults{ | 495 | result := params.ConfigSettingsResults{ |
346 | 494 | Results: make([]params.SettingsResult, len(args.Entities)), | 496 | Results: make([]params.ConfigSettingsResult, len(args.Entities)), |
347 | 495 | } | 497 | } |
348 | 496 | canAccess, err := u.accessUnit() | 498 | canAccess, err := u.accessUnit() |
349 | 497 | if err != nil { | 499 | if err != nil { |
351 | 498 | return params.SettingsResults{}, err | 500 | return params.ConfigSettingsResults{}, err |
352 | 499 | } | 501 | } |
353 | 500 | for i, entity := range args.Entities { | 502 | for i, entity := range args.Entities { |
354 | 501 | err := common.ErrPerm | 503 | err := common.ErrPerm |
355 | @@ -506,7 +508,7 @@ | |||
356 | 506 | var settings charm.Settings | 508 | var settings charm.Settings |
357 | 507 | settings, err = unit.ConfigSettings() | 509 | settings, err = unit.ConfigSettings() |
358 | 508 | if err == nil { | 510 | if err == nil { |
360 | 509 | result.Results[i].Settings = convertSettings(settings) | 511 | result.Results[i].Settings = params.ConfigSettings(settings) |
361 | 510 | } | 512 | } |
362 | 511 | } | 513 | } |
363 | 512 | } | 514 | } |
364 | @@ -791,25 +793,28 @@ | |||
365 | 791 | return result, nil | 793 | return result, nil |
366 | 792 | } | 794 | } |
367 | 793 | 795 | ||
370 | 794 | func convertSettings(settings map[string]interface{}) params.Settings { | 796 | func convertRelationSettings(settings map[string]interface{}) (params.RelationSettings, error) { |
371 | 795 | result := make(params.Settings) | 797 | result := make(params.RelationSettings) |
372 | 796 | for k, v := range settings { | 798 | for k, v := range settings { |
373 | 797 | // All relation settings should be strings. | 799 | // All relation settings should be strings. |
375 | 798 | sval, _ := v.(string) | 800 | sval, ok := v.(string) |
376 | 801 | if !ok { | ||
377 | 802 | return nil, fmt.Errorf("unexpected relation setting %q: expected string, got %T", k, v) | ||
378 | 803 | } | ||
379 | 799 | result[k] = sval | 804 | result[k] = sval |
380 | 800 | } | 805 | } |
382 | 801 | return result | 806 | return result, nil |
383 | 802 | } | 807 | } |
384 | 803 | 808 | ||
385 | 804 | // ReadSettings returns the local settings of each given set of | 809 | // ReadSettings returns the local settings of each given set of |
386 | 805 | // relation/unit. | 810 | // relation/unit. |
390 | 806 | func (u *UniterAPI) ReadSettings(args params.RelationUnits) (params.SettingsResults, error) { | 811 | func (u *UniterAPI) ReadSettings(args params.RelationUnits) (params.RelationSettingsResults, error) { |
391 | 807 | result := params.SettingsResults{ | 812 | result := params.RelationSettingsResults{ |
392 | 808 | Results: make([]params.SettingsResult, len(args.RelationUnits)), | 813 | Results: make([]params.RelationSettingsResult, len(args.RelationUnits)), |
393 | 809 | } | 814 | } |
394 | 810 | canAccess, err := u.accessUnit() | 815 | canAccess, err := u.accessUnit() |
395 | 811 | if err != nil { | 816 | if err != nil { |
397 | 812 | return params.SettingsResults{}, err | 817 | return params.RelationSettingsResults{}, err |
398 | 813 | } | 818 | } |
399 | 814 | for i, arg := range args.RelationUnits { | 819 | for i, arg := range args.RelationUnits { |
400 | 815 | relUnit, err := u.getRelationUnit(canAccess, arg.Relation, arg.Unit) | 820 | relUnit, err := u.getRelationUnit(canAccess, arg.Relation, arg.Unit) |
401 | @@ -817,7 +822,7 @@ | |||
402 | 817 | var settings *state.Settings | 822 | var settings *state.Settings |
403 | 818 | settings, err = relUnit.Settings() | 823 | settings, err = relUnit.Settings() |
404 | 819 | if err == nil { | 824 | if err == nil { |
406 | 820 | result.Results[i].Settings = convertSettings(settings.Map()) | 825 | result.Results[i].Settings, err = convertRelationSettings(settings.Map()) |
407 | 821 | } | 826 | } |
408 | 822 | } | 827 | } |
409 | 823 | result.Results[i].Error = common.ServerError(err) | 828 | result.Results[i].Error = common.ServerError(err) |
410 | @@ -845,13 +850,13 @@ | |||
411 | 845 | 850 | ||
412 | 846 | // ReadRemoteSettings returns the remote settings of each given set of | 851 | // ReadRemoteSettings returns the remote settings of each given set of |
413 | 847 | // relation/local unit/remote unit. | 852 | // relation/local unit/remote unit. |
417 | 848 | func (u *UniterAPI) ReadRemoteSettings(args params.RelationUnitPairs) (params.SettingsResults, error) { | 853 | func (u *UniterAPI) ReadRemoteSettings(args params.RelationUnitPairs) (params.RelationSettingsResults, error) { |
418 | 849 | result := params.SettingsResults{ | 854 | result := params.RelationSettingsResults{ |
419 | 850 | Results: make([]params.SettingsResult, len(args.RelationUnitPairs)), | 855 | Results: make([]params.RelationSettingsResult, len(args.RelationUnitPairs)), |
420 | 851 | } | 856 | } |
421 | 852 | canAccess, err := u.accessUnit() | 857 | canAccess, err := u.accessUnit() |
422 | 853 | if err != nil { | 858 | if err != nil { |
424 | 854 | return params.SettingsResults{}, err | 859 | return params.RelationSettingsResults{}, err |
425 | 855 | } | 860 | } |
426 | 856 | for i, arg := range args.RelationUnitPairs { | 861 | for i, arg := range args.RelationUnitPairs { |
427 | 857 | relUnit, err := u.getRelationUnit(canAccess, arg.Relation, arg.LocalUnit) | 862 | relUnit, err := u.getRelationUnit(canAccess, arg.Relation, arg.LocalUnit) |
428 | @@ -862,7 +867,7 @@ | |||
429 | 862 | var settings map[string]interface{} | 867 | var settings map[string]interface{} |
430 | 863 | settings, err = relUnit.ReadSettings(remoteUnit) | 868 | settings, err = relUnit.ReadSettings(remoteUnit) |
431 | 864 | if err == nil { | 869 | if err == nil { |
433 | 865 | result.Results[i].Settings = convertSettings(settings) | 870 | result.Results[i].Settings, err = convertRelationSettings(settings) |
434 | 866 | } | 871 | } |
435 | 867 | } | 872 | } |
436 | 868 | } | 873 | } |
437 | 869 | 874 | ||
438 | === modified file 'state/apiserver/uniter/uniter_test.go' | |||
439 | --- state/apiserver/uniter/uniter_test.go 2013-09-18 15:57:30 +0000 | |||
440 | +++ state/apiserver/uniter/uniter_test.go 2013-09-26 17:24:28 +0000 | |||
441 | @@ -808,10 +808,10 @@ | |||
442 | 808 | }} | 808 | }} |
443 | 809 | result, err := s.uniter.ConfigSettings(args) | 809 | result, err := s.uniter.ConfigSettings(args) |
444 | 810 | c.Assert(err, gc.IsNil) | 810 | c.Assert(err, gc.IsNil) |
447 | 811 | c.Assert(result, gc.DeepEquals, params.SettingsResults{ | 811 | c.Assert(result, gc.DeepEquals, params.ConfigSettingsResults{ |
448 | 812 | Results: []params.SettingsResult{ | 812 | Results: []params.ConfigSettingsResult{ |
449 | 813 | {Error: apiservertesting.ErrUnauthorized}, | 813 | {Error: apiservertesting.ErrUnauthorized}, |
451 | 814 | {Settings: params.Settings{"blog-title": "My Title"}}, | 814 | {Settings: params.ConfigSettings{"blog-title": "My Title"}}, |
452 | 815 | {Error: apiservertesting.ErrUnauthorized}, | 815 | {Error: apiservertesting.ErrUnauthorized}, |
453 | 816 | }, | 816 | }, |
454 | 817 | }) | 817 | }) |
455 | @@ -1097,10 +1097,10 @@ | |||
456 | 1097 | }} | 1097 | }} |
457 | 1098 | result, err := s.uniter.ReadSettings(args) | 1098 | result, err := s.uniter.ReadSettings(args) |
458 | 1099 | c.Assert(err, gc.IsNil) | 1099 | c.Assert(err, gc.IsNil) |
461 | 1100 | c.Assert(result, gc.DeepEquals, params.SettingsResults{ | 1100 | c.Assert(result, gc.DeepEquals, params.RelationSettingsResults{ |
462 | 1101 | Results: []params.SettingsResult{ | 1101 | Results: []params.RelationSettingsResult{ |
463 | 1102 | {Error: apiservertesting.ErrUnauthorized}, | 1102 | {Error: apiservertesting.ErrUnauthorized}, |
465 | 1103 | {Settings: params.Settings{ | 1103 | {Settings: params.RelationSettings{ |
466 | 1104 | "some": "settings", | 1104 | "some": "settings", |
467 | 1105 | }}, | 1105 | }}, |
468 | 1106 | {Error: apiservertesting.ErrUnauthorized}, | 1106 | {Error: apiservertesting.ErrUnauthorized}, |
469 | @@ -1116,6 +1116,31 @@ | |||
470 | 1116 | }) | 1116 | }) |
471 | 1117 | } | 1117 | } |
472 | 1118 | 1118 | ||
473 | 1119 | func (s *uniterSuite) TestReadSettingsWithNonStringValuesFails(c *gc.C) { | ||
474 | 1120 | rel := s.addRelation(c, "wordpress", "mysql") | ||
475 | 1121 | relUnit, err := rel.Unit(s.wordpressUnit) | ||
476 | 1122 | c.Assert(err, gc.IsNil) | ||
477 | 1123 | settings := map[string]interface{}{ | ||
478 | 1124 | "other": "things", | ||
479 | 1125 | "invalid-bool": false, | ||
480 | 1126 | } | ||
481 | 1127 | err = relUnit.EnterScope(settings) | ||
482 | 1128 | c.Assert(err, gc.IsNil) | ||
483 | 1129 | s.assertInScope(c, relUnit, true) | ||
484 | 1130 | |||
485 | 1131 | args := params.RelationUnits{RelationUnits: []params.RelationUnit{ | ||
486 | 1132 | {Relation: rel.Tag(), Unit: "unit-wordpress-0"}, | ||
487 | 1133 | }} | ||
488 | 1134 | expectErr := `unexpected relation setting "invalid-bool": expected string, got bool` | ||
489 | 1135 | result, err := s.uniter.ReadSettings(args) | ||
490 | 1136 | c.Assert(err, gc.IsNil) | ||
491 | 1137 | c.Assert(result, gc.DeepEquals, params.RelationSettingsResults{ | ||
492 | 1138 | Results: []params.RelationSettingsResult{ | ||
493 | 1139 | {Error: ¶ms.Error{Message: expectErr}}, | ||
494 | 1140 | }, | ||
495 | 1141 | }) | ||
496 | 1142 | } | ||
497 | 1143 | |||
498 | 1119 | func (s *uniterSuite) TestReadRemoteSettings(c *gc.C) { | 1144 | func (s *uniterSuite) TestReadRemoteSettings(c *gc.C) { |
499 | 1120 | rel := s.addRelation(c, "wordpress", "mysql") | 1145 | rel := s.addRelation(c, "wordpress", "mysql") |
500 | 1121 | relUnit, err := rel.Unit(s.wordpressUnit) | 1146 | relUnit, err := rel.Unit(s.wordpressUnit) |
501 | @@ -1146,8 +1171,8 @@ | |||
502 | 1146 | // We don't set the remote unit settings on purpose to test the error. | 1171 | // We don't set the remote unit settings on purpose to test the error. |
503 | 1147 | expectErr := `cannot read settings for unit "mysql/0" in relation "wordpress:db mysql:server": settings not found` | 1172 | expectErr := `cannot read settings for unit "mysql/0" in relation "wordpress:db mysql:server": settings not found` |
504 | 1148 | c.Assert(err, gc.IsNil) | 1173 | c.Assert(err, gc.IsNil) |
507 | 1149 | c.Assert(result, gc.DeepEquals, params.SettingsResults{ | 1174 | c.Assert(result, gc.DeepEquals, params.RelationSettingsResults{ |
508 | 1150 | Results: []params.SettingsResult{ | 1175 | Results: []params.RelationSettingsResult{ |
509 | 1151 | {Error: apiservertesting.ErrUnauthorized}, | 1176 | {Error: apiservertesting.ErrUnauthorized}, |
510 | 1152 | {Error: apiservertesting.ErrUnauthorized}, | 1177 | {Error: apiservertesting.ErrUnauthorized}, |
511 | 1153 | {Error: ¶ms.Error{Message: expectErr}}, | 1178 | {Error: ¶ms.Error{Message: expectErr}}, |
512 | @@ -1182,15 +1207,42 @@ | |||
513 | 1182 | }}} | 1207 | }}} |
514 | 1183 | result, err = s.uniter.ReadRemoteSettings(args) | 1208 | result, err = s.uniter.ReadRemoteSettings(args) |
515 | 1184 | c.Assert(err, gc.IsNil) | 1209 | c.Assert(err, gc.IsNil) |
519 | 1185 | c.Assert(result, gc.DeepEquals, params.SettingsResults{ | 1210 | c.Assert(result, gc.DeepEquals, params.RelationSettingsResults{ |
520 | 1186 | Results: []params.SettingsResult{ | 1211 | Results: []params.RelationSettingsResult{ |
521 | 1187 | {Settings: params.Settings{ | 1212 | {Settings: params.RelationSettings{ |
522 | 1188 | "other": "things", | 1213 | "other": "things", |
523 | 1189 | }}, | 1214 | }}, |
524 | 1190 | }, | 1215 | }, |
525 | 1191 | }) | 1216 | }) |
526 | 1192 | } | 1217 | } |
527 | 1193 | 1218 | ||
528 | 1219 | func (s *uniterSuite) TestReadRemoteSettingsWithNonStringValuesFails(c *gc.C) { | ||
529 | 1220 | rel := s.addRelation(c, "wordpress", "mysql") | ||
530 | 1221 | relUnit, err := rel.Unit(s.mysqlUnit) | ||
531 | 1222 | c.Assert(err, gc.IsNil) | ||
532 | 1223 | settings := map[string]interface{}{ | ||
533 | 1224 | "other": "things", | ||
534 | 1225 | "invalid-bool": false, | ||
535 | 1226 | } | ||
536 | 1227 | err = relUnit.EnterScope(settings) | ||
537 | 1228 | c.Assert(err, gc.IsNil) | ||
538 | 1229 | s.assertInScope(c, relUnit, true) | ||
539 | 1230 | |||
540 | 1231 | args := params.RelationUnitPairs{RelationUnitPairs: []params.RelationUnitPair{{ | ||
541 | 1232 | Relation: rel.Tag(), | ||
542 | 1233 | LocalUnit: "unit-wordpress-0", | ||
543 | 1234 | RemoteUnit: "unit-mysql-0", | ||
544 | 1235 | }}} | ||
545 | 1236 | expectErr := `unexpected relation setting "invalid-bool": expected string, got bool` | ||
546 | 1237 | result, err := s.uniter.ReadRemoteSettings(args) | ||
547 | 1238 | c.Assert(err, gc.IsNil) | ||
548 | 1239 | c.Assert(result, gc.DeepEquals, params.RelationSettingsResults{ | ||
549 | 1240 | Results: []params.RelationSettingsResult{ | ||
550 | 1241 | {Error: ¶ms.Error{Message: expectErr}}, | ||
551 | 1242 | }, | ||
552 | 1243 | }) | ||
553 | 1244 | } | ||
554 | 1245 | |||
555 | 1194 | func (s *uniterSuite) TestUpdateSettings(c *gc.C) { | 1246 | func (s *uniterSuite) TestUpdateSettings(c *gc.C) { |
556 | 1195 | rel := s.addRelation(c, "wordpress", "mysql") | 1247 | rel := s.addRelation(c, "wordpress", "mysql") |
557 | 1196 | relUnit, err := rel.Unit(s.wordpressUnit) | 1248 | relUnit, err := rel.Unit(s.wordpressUnit) |
558 | @@ -1202,7 +1254,7 @@ | |||
559 | 1202 | err = relUnit.EnterScope(settings) | 1254 | err = relUnit.EnterScope(settings) |
560 | 1203 | s.assertInScope(c, relUnit, true) | 1255 | s.assertInScope(c, relUnit, true) |
561 | 1204 | 1256 | ||
563 | 1205 | newSettings := params.Settings{ | 1257 | newSettings := params.RelationSettings{ |
564 | 1206 | "some": "different", | 1258 | "some": "different", |
565 | 1207 | "other": "", | 1259 | "other": "", |
566 | 1208 | } | 1260 | } |
567 | 1209 | 1261 | ||
568 | === modified file 'worker/uniter/context.go' | |||
569 | --- worker/uniter/context.go 2013-09-13 10:38:02 +0000 | |||
570 | +++ worker/uniter/context.go 2013-09-26 17:24:28 +0000 | |||
571 | @@ -275,7 +275,7 @@ | |||
572 | 275 | } | 275 | } |
573 | 276 | 276 | ||
574 | 277 | // SettingsMap is a map from unit name to relation settings. | 277 | // SettingsMap is a map from unit name to relation settings. |
576 | 278 | type SettingsMap map[string]params.Settings | 278 | type SettingsMap map[string]params.RelationSettings |
577 | 279 | 279 | ||
578 | 280 | // ContextRelation is the implementation of jujuc.ContextRelation. | 280 | // ContextRelation is the implementation of jujuc.ContextRelation. |
579 | 281 | type ContextRelation struct { | 281 | type ContextRelation struct { |
580 | @@ -367,7 +367,7 @@ | |||
581 | 367 | return ctx.settings, nil | 367 | return ctx.settings, nil |
582 | 368 | } | 368 | } |
583 | 369 | 369 | ||
585 | 370 | func (ctx *ContextRelation) ReadSettings(unit string) (settings params.Settings, err error) { | 370 | func (ctx *ContextRelation) ReadSettings(unit string) (settings params.RelationSettings, err error) { |
586 | 371 | settings, member := ctx.members[unit] | 371 | settings, member := ctx.members[unit] |
587 | 372 | if settings == nil { | 372 | if settings == nil { |
588 | 373 | if settings = ctx.cache[unit]; settings == nil { | 373 | if settings = ctx.cache[unit]; settings == nil { |
589 | 374 | 374 | ||
590 | === modified file 'worker/uniter/context_test.go' | |||
591 | --- worker/uniter/context_test.go 2013-09-17 03:12:12 +0000 | |||
592 | +++ worker/uniter/context_test.go 2013-09-26 17:24:28 +0000 | |||
593 | @@ -275,10 +275,10 @@ | |||
594 | 275 | // Check that the changes to the local settings nodes have been discarded. | 275 | // Check that the changes to the local settings nodes have been discarded. |
595 | 276 | node0, err = s.relctxs[0].Settings() | 276 | node0, err = s.relctxs[0].Settings() |
596 | 277 | c.Assert(err, gc.IsNil) | 277 | c.Assert(err, gc.IsNil) |
598 | 278 | c.Assert(node0.Map(), gc.DeepEquals, params.Settings{"relation-name": "db0"}) | 278 | c.Assert(node0.Map(), gc.DeepEquals, params.RelationSettings{"relation-name": "db0"}) |
599 | 279 | node1, err = s.relctxs[1].Settings() | 279 | node1, err = s.relctxs[1].Settings() |
600 | 280 | c.Assert(err, gc.IsNil) | 280 | c.Assert(err, gc.IsNil) |
602 | 281 | c.Assert(node1.Map(), gc.DeepEquals, params.Settings{"relation-name": "db1"}) | 281 | c.Assert(node1.Map(), gc.DeepEquals, params.RelationSettings{"relation-name": "db1"}) |
603 | 282 | 282 | ||
604 | 283 | // Check that the changes have been written to state. | 283 | // Check that the changes have been written to state. |
605 | 284 | settings0, err := s.relunits[0].ReadSettings("u/0") | 284 | settings0, err := s.relunits[0].ReadSettings("u/0") |
606 | @@ -303,13 +303,13 @@ | |||
607 | 303 | // Check that the changes to the local settings nodes are still there. | 303 | // Check that the changes to the local settings nodes are still there. |
608 | 304 | node0, err = s.relctxs[0].Settings() | 304 | node0, err = s.relctxs[0].Settings() |
609 | 305 | c.Assert(err, gc.IsNil) | 305 | c.Assert(err, gc.IsNil) |
611 | 306 | c.Assert(node0.Map(), gc.DeepEquals, params.Settings{ | 306 | c.Assert(node0.Map(), gc.DeepEquals, params.RelationSettings{ |
612 | 307 | "relation-name": "db0", | 307 | "relation-name": "db0", |
613 | 308 | "baz": "3", | 308 | "baz": "3", |
614 | 309 | }) | 309 | }) |
615 | 310 | node1, err = s.relctxs[1].Settings() | 310 | node1, err = s.relctxs[1].Settings() |
616 | 311 | c.Assert(err, gc.IsNil) | 311 | c.Assert(err, gc.IsNil) |
618 | 312 | c.Assert(node1.Map(), gc.DeepEquals, params.Settings{ | 312 | c.Assert(node1.Map(), gc.DeepEquals, params.RelationSettings{ |
619 | 313 | "relation-name": "db1", | 313 | "relation-name": "db1", |
620 | 314 | "qux": "4", | 314 | "qux": "4", |
621 | 315 | }) | 315 | }) |
622 | @@ -383,13 +383,13 @@ | |||
623 | 383 | "u/4": {"qux": "4"}, | 383 | "u/4": {"qux": "4"}, |
624 | 384 | }) | 384 | }) |
625 | 385 | c.Assert(ctx.UnitNames(), gc.DeepEquals, []string{"u/2", "u/4"}) | 385 | c.Assert(ctx.UnitNames(), gc.DeepEquals, []string{"u/2", "u/4"}) |
627 | 386 | assertSettings := func(unit string, expect params.Settings) { | 386 | assertSettings := func(unit string, expect params.RelationSettings) { |
628 | 387 | actual, err := ctx.ReadSettings(unit) | 387 | actual, err := ctx.ReadSettings(unit) |
629 | 388 | c.Assert(err, gc.IsNil) | 388 | c.Assert(err, gc.IsNil) |
630 | 389 | c.Assert(actual, gc.DeepEquals, expect) | 389 | c.Assert(actual, gc.DeepEquals, expect) |
631 | 390 | } | 390 | } |
634 | 391 | assertSettings("u/2", params.Settings{"baz": "2"}) | 391 | assertSettings("u/2", params.RelationSettings{"baz": "2"}) |
635 | 392 | assertSettings("u/4", params.Settings{"qux": "4"}) | 392 | assertSettings("u/4", params.RelationSettings{"qux": "4"}) |
636 | 393 | 393 | ||
637 | 394 | // Send a second update; check that members are only added, not removed. | 394 | // Send a second update; check that members are only added, not removed. |
638 | 395 | ctx.UpdateMembers(uniter.SettingsMap{ | 395 | ctx.UpdateMembers(uniter.SettingsMap{ |
639 | @@ -400,10 +400,10 @@ | |||
640 | 400 | c.Assert(ctx.UnitNames(), gc.DeepEquals, []string{"u/1", "u/2", "u/3", "u/4"}) | 400 | c.Assert(ctx.UnitNames(), gc.DeepEquals, []string{"u/1", "u/2", "u/3", "u/4"}) |
641 | 401 | 401 | ||
642 | 402 | // Check that all settings remain cached. | 402 | // Check that all settings remain cached. |
647 | 403 | assertSettings("u/1", params.Settings{"foo": "1"}) | 403 | assertSettings("u/1", params.RelationSettings{"foo": "1"}) |
648 | 404 | assertSettings("u/2", params.Settings{"abc": "2"}) | 404 | assertSettings("u/2", params.RelationSettings{"abc": "2"}) |
649 | 405 | assertSettings("u/3", params.Settings{"bar": "3"}) | 405 | assertSettings("u/3", params.RelationSettings{"bar": "3"}) |
650 | 406 | assertSettings("u/4", params.Settings{"qux": "4"}) | 406 | assertSettings("u/4", params.RelationSettings{"qux": "4"}) |
651 | 407 | 407 | ||
652 | 408 | // Delete a member, and check that it is no longer a member... | 408 | // Delete a member, and check that it is no longer a member... |
653 | 409 | ctx.DeleteMember("u/2") | 409 | ctx.DeleteMember("u/2") |
654 | @@ -454,7 +454,7 @@ | |||
655 | 454 | ctx.UpdateMembers(uniter.SettingsMap{"u/1": {"entirely": "different"}}) | 454 | ctx.UpdateMembers(uniter.SettingsMap{"u/1": {"entirely": "different"}}) |
656 | 455 | m, err = ctx.ReadSettings("u/1") | 455 | m, err = ctx.ReadSettings("u/1") |
657 | 456 | c.Assert(err, gc.IsNil) | 456 | c.Assert(err, gc.IsNil) |
659 | 457 | c.Assert(m, gc.DeepEquals, params.Settings{"entirely": "different"}) | 457 | c.Assert(m, gc.DeepEquals, params.RelationSettings{"entirely": "different"}) |
660 | 458 | } | 458 | } |
661 | 459 | 459 | ||
662 | 460 | func (s *ContextRelationSuite) TestNonMemberCaching(c *gc.C) { | 460 | func (s *ContextRelationSuite) TestNonMemberCaching(c *gc.C) { |
663 | @@ -700,7 +700,7 @@ | |||
664 | 700 | return context | 700 | return context |
665 | 701 | } | 701 | } |
666 | 702 | 702 | ||
668 | 703 | func convertSettings(settings params.Settings) map[string]interface{} { | 703 | func convertSettings(settings params.RelationSettings) map[string]interface{} { |
669 | 704 | result := make(map[string]interface{}) | 704 | result := make(map[string]interface{}) |
670 | 705 | for k, v := range settings { | 705 | for k, v := range settings { |
671 | 706 | result[k] = v | 706 | result[k] = v |
672 | @@ -708,8 +708,8 @@ | |||
673 | 708 | return result | 708 | return result |
674 | 709 | } | 709 | } |
675 | 710 | 710 | ||
678 | 711 | func convertMap(settingsMap map[string]interface{}) params.Settings { | 711 | func convertMap(settingsMap map[string]interface{}) params.RelationSettings { |
679 | 712 | result := make(params.Settings) | 712 | result := make(params.RelationSettings) |
680 | 713 | for k, v := range settingsMap { | 713 | for k, v := range settingsMap { |
681 | 714 | result[k] = v.(string) | 714 | result[k] = v.(string) |
682 | 715 | } | 715 | } |
683 | 716 | 716 | ||
684 | === modified file 'worker/uniter/jujuc/context.go' | |||
685 | --- worker/uniter/jujuc/context.go 2013-09-12 16:29:52 +0000 | |||
686 | +++ worker/uniter/jujuc/context.go 2013-09-26 17:24:28 +0000 | |||
687 | @@ -77,12 +77,12 @@ | |||
688 | 77 | UnitNames() []string | 77 | UnitNames() []string |
689 | 78 | 78 | ||
690 | 79 | // ReadSettings returns the settings of any remote unit in the relation. | 79 | // ReadSettings returns the settings of any remote unit in the relation. |
692 | 80 | ReadSettings(unit string) (params.Settings, error) | 80 | ReadSettings(unit string) (params.RelationSettings, error) |
693 | 81 | } | 81 | } |
694 | 82 | 82 | ||
695 | 83 | // Settings is implemented by types that manipulate unit settings. | 83 | // Settings is implemented by types that manipulate unit settings. |
696 | 84 | type Settings interface { | 84 | type Settings interface { |
698 | 85 | Map() params.Settings | 85 | Map() params.RelationSettings |
699 | 86 | Set(string, string) | 86 | Set(string, string) |
700 | 87 | Delete(string) | 87 | Delete(string) |
701 | 88 | } | 88 | } |
702 | 89 | 89 | ||
703 | === modified file 'worker/uniter/jujuc/relation-get.go' | |||
704 | --- worker/uniter/jujuc/relation-get.go 2013-09-12 16:29:52 +0000 | |||
705 | +++ worker/uniter/jujuc/relation-get.go 2013-09-26 17:24:28 +0000 | |||
706 | @@ -78,7 +78,7 @@ | |||
707 | 78 | if !found { | 78 | if !found { |
708 | 79 | return fmt.Errorf("unknown relation id") | 79 | return fmt.Errorf("unknown relation id") |
709 | 80 | } | 80 | } |
711 | 81 | var settings params.Settings | 81 | var settings params.RelationSettings |
712 | 82 | if c.UnitName == c.ctx.UnitName() { | 82 | if c.UnitName == c.ctx.UnitName() { |
713 | 83 | node, err := r.Settings() | 83 | node, err := r.Settings() |
714 | 84 | if err != nil { | 84 | if err != nil { |
715 | 85 | 85 | ||
716 | === modified file 'worker/uniter/jujuc/util_test.go' | |||
717 | --- worker/uniter/jujuc/util_test.go 2013-09-12 16:29:52 +0000 | |||
718 | +++ worker/uniter/jujuc/util_test.go 2013-09-26 17:24:28 +0000 | |||
719 | @@ -166,7 +166,7 @@ | |||
720 | 166 | return s | 166 | return s |
721 | 167 | } | 167 | } |
722 | 168 | 168 | ||
724 | 169 | func (r *ContextRelation) ReadSettings(name string) (params.Settings, error) { | 169 | func (r *ContextRelation) ReadSettings(name string) (params.RelationSettings, error) { |
725 | 170 | s, found := r.units[name] | 170 | s, found := r.units[name] |
726 | 171 | if !found { | 171 | if !found { |
727 | 172 | return nil, fmt.Errorf("unknown unit %s", name) | 172 | return nil, fmt.Errorf("unknown unit %s", name) |
728 | @@ -174,7 +174,7 @@ | |||
729 | 174 | return s.Map(), nil | 174 | return s.Map(), nil |
730 | 175 | } | 175 | } |
731 | 176 | 176 | ||
733 | 177 | type Settings params.Settings | 177 | type Settings params.RelationSettings |
734 | 178 | 178 | ||
735 | 179 | func (s Settings) Get(k string) (interface{}, bool) { | 179 | func (s Settings) Get(k string) (interface{}, bool) { |
736 | 180 | v, f := s[k] | 180 | v, f := s[k] |
737 | @@ -189,8 +189,8 @@ | |||
738 | 189 | delete(s, k) | 189 | delete(s, k) |
739 | 190 | } | 190 | } |
740 | 191 | 191 | ||
743 | 192 | func (s Settings) Map() params.Settings { | 192 | func (s Settings) Map() params.RelationSettings { |
744 | 193 | r := params.Settings{} | 193 | r := params.RelationSettings{} |
745 | 194 | for k, v := range s { | 194 | for k, v := range s { |
746 | 195 | r[k] = v | 195 | r[k] = v |
747 | 196 | } | 196 | } |
Reviewers: mp+187824_ code.launchpad. net,
Message:
Please take a look.
Description:
apiuniter: Fix lp:1231457
This changes several params types, while keeping interface{ }, because charm
the field names for backward compatibility.
And changes the result of ConfigSettings() call
to return map[string]
settings are different from relation settings
(which are always strings), and coercing charm
settings to stings discards non-string config
settings, so this is fixed here.
https:/ /code.launchpad .net/~dimitern/ juju-core/ 148-apiuniter- fix-configsetti ngs/+merge/ 187824
Requires: /code.launchpad .net/~dimitern/ juju-core/ 147-apiprovisio ner-blank- env-secrets/ +merge/ 187738
https:/
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/13908044/
Affected files (+121, -111 lines): params/ internal. go provisioner/ provisioner. go uniter/ relationunit. go uniter/ relationunit_ test.go uniter/ settings. go uniter/ settings_ test.go uniter/ unit.go /provisioner/ provisioner. go /provisioner/ provisioner_ test.go /uniter/ uniter. go /uniter/ uniter_ test.go uniter/ context. go uniter/ context_ test.go uniter/ jujuc/context. go uniter/ jujuc/relation- get.go uniter/ jujuc/util_ test.go
A [revision details]
M state/api/
M state/api/
M state/api/
M state/api/
M state/api/
M state/api/
M state/api/
M state/apiserver
M state/apiserver
M state/apiserver
M state/apiserver
M worker/
M worker/
M worker/
M worker/
M worker/