Affected files:
A [revision details]
M state/unit.go
M state/unit_test.go
M worker/uniter/context.go
M worker/uniter/context_test.go
M worker/uniter/jujuc/config-get.go
M worker/uniter/jujuc/context.go
M worker/uniter/jujuc/util_test.go
-// ServiceConfig returns the contents of this unit's service configuration.
-func (u *Unit) ServiceConfig() (map[string]interface{}, error) {
+// ConfigSettings returns the complete set of service charm config settings
+// available to the unit. Unset values will be replaced with the default
+// value for the associated option, and may thus be nil when no default is
+// specified.
+func (u *Unit) ConfigSettings() (charm.Settings, error) {
if u.doc.CharmURL == nil {
return nil, fmt.Errorf("unit charm not set")
}
// Settings still reflect charm set on unit.
- settings, err := s.unit.ServiceConfig()
+ settings, err := s.unit.ConfigSettings()
c.Assert(err, IsNil)
- c.Assert(settings, DeepEquals, map[string]interface{}{"blog-title": "My
Title"})
+ c.Assert(settings, DeepEquals, charm.Settings{"blog-title": "My Title"})
// When the unit has the new charm set, it'll see the new config.
err = s.unit.SetCharmURL(newCharm.URL())
c.Assert(err, IsNil)
- settings, err = s.unit.ServiceConfig()
+ settings, err = s.unit.ConfigSettings()
c.Assert(err, IsNil)
- c.Assert(settings, DeepEquals, map[string]interface{}{})
+ c.Assert(settings, DeepEquals, charm.Settings{})
}
func (s *UnitSuite) TestGetSetPublicAddress(c *C) {
- // config holds the service configuration.
- config map[string]interface{}
+ // configSettings holds the service configuration.
+ configSettings charm.Settings
// id identifies the context.
id string
@@ -84,15 +85,19 @@
return ctx.unit.ClosePort(protocol, port)
}
-func (ctx *HookContext) Config() (map[string]interface{}, error) {
- if ctx.config == nil {
+func (ctx *HookContext) ConfigSettings() (charm.Settings, error) {
+ if ctx.configSettings == nil {
var err error
- ctx.config, err = ctx.unit.ServiceConfig()
+ ctx.configSettings, err = ctx.unit.ConfigSettings()
if err != nil {
return nil, err
}
}
- return ctx.config, nil
+ result := charm.Settings{}
+ for name, value := range ctx.configSettings {
+ result[name] = value
+ }
+ return result, nil
}
// Config returns the current service configuration of the executing unit.
- Config() (map[string]interface{}, error)
+ ConfigSettings() (charm.Settings, error)
// HookRelation returns the ContextRelation associated with the executing
// hook if it was found, and whether it was found.
Reviewers: mp+168577_ code.launchpad. net,
Message:
Please take a look.
Description:
state: Unit.ConfigSettings
Better name, better type; suitable changes propagated amongst clients.
https:/ /code.launchpad .net/~fwereade/ juju-core/ config- 3-state- unit-settings- rename/ +merge/ 168577
Requires: /code.launchpad .net/~fwereade/ juju-core/ config- 2-trivial- error-message- change/ +merge/ 168576
https:/
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/10169044/
Affected files: uniter/ context. go uniter/ context_ test.go uniter/ jujuc/config- get.go uniter/ jujuc/context. go uniter/ jujuc/util_ test.go
A [revision details]
M state/unit.go
M state/unit_test.go
M worker/
M worker/
M worker/
M worker/
M worker/
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: state/unit.go u.doc.Service)
=== modified file 'state/unit.go'
--- state/unit.go 2013-06-10 20:37:49 +0000
+++ state/unit.go 2013-06-10 21:04:37 +0000
@@ -98,8 +98,11 @@
return u.st.Service(
}
-// ServiceConfig returns the contents of this unit's service configuration. interface{ }, error) {
-func (u *Unit) ServiceConfig() (map[string]
+// ConfigSettings returns the complete set of service charm config settings
+// available to the unit. Unset values will be replaced with the default
+// value for the associated option, and may thus be nil when no default is
+// specified.
+func (u *Unit) ConfigSettings() (charm.Settings, error) {
if u.doc.CharmURL == nil {
return nil, fmt.Errorf("unit charm not set")
}
Index: state/unit_test.go unit_test. go' svc.Name( ), Equals, s.unit. ServiceName( ))
=== modified file 'state/
--- state/unit_test.go 2013-06-10 20:37:49 +0000
+++ state/unit_test.go 2013-06-10 21:04:37 +0000
@@ -45,30 +45,30 @@
c.Assert(
}
-func (s *UnitSuite) TestServiceConf igNeedsCharmURL Set(c *C) { ServiceConfig( ) ngsNeedCharmURL Set(c *C) { ConfigSettings( )
- _, err := s.unit.
+func (s *UnitSuite) TestConfigSetti
+ _, err := s.unit.
c.Assert(err, ErrorMatches, "unit charm not set")
}
-func (s *UnitSuite) TestServiceConf igIncludesDefau lts(c *C) { ngsIncludeDefau lts(c *C) { SetCharmURL( s.charm. URL()) ServiceConfig( ) ConfigSettings( ) interface{ }{"blog- title": "My "blog-title" : "My Title"})
+func (s *UnitSuite) TestConfigSetti
err := s.unit.
c.Assert(err, IsNil)
- settings, err := s.unit.
+ settings, err := s.unit.
c.Assert(err, IsNil)
- c.Assert(settings, DeepEquals, map[string]
Title"})
+ c.Assert(settings, DeepEquals, charm.Settings{
}
-func (s *UnitSuite) TestServiceConf igReflectsServi ce(c *C) { ngsReflectServi ce(c *C) { SetConfig( map[string] string{ "blog-title" : "no title"}) SetCharmURL( s.charm. URL()) ServiceConfig( ) ConfigSettings( ) interface{ }{"blog- title": "no "blog-title" : "no title"})
+func (s *UnitSuite) TestConfigSetti
err := s.service.
c.Assert(err, IsNil)
err = s.unit.
c.Assert(err, IsNil)
- settings, err := s.unit.
+ settings, err := s.unit.
c.Assert(err, IsNil)
- c.Assert(settings, DeepEquals, map[string]
title"})
+ c.Assert(settings, DeepEquals, charm.Settings{
}
-func (s *UnitSuite) TestServiceConf igReflectsCharm (c *C) { ngsReflectCharm (c *C) { SetCharmURL( s.charm. URL())
+func (s *UnitSuite) TestConfigSetti
err := s.unit.
c.Assert(err, IsNil)
newCharm := s.AddConfigCharm(c, "wordpress", "options: {}", 123)
@@ -76,16 +76,16 @@
c.Assert(err, IsNil)
// Settings still reflect charm set on unit. ServiceConfig( ) ConfigSettings( ) interface{ }{"blog- title": "My "blog-title" : "My Title"})
- settings, err := s.unit.
+ settings, err := s.unit.
c.Assert(err, IsNil)
- c.Assert(settings, DeepEquals, map[string]
Title"})
+ c.Assert(settings, DeepEquals, charm.Settings{
// When the unit has the new charm set, it'll see the new config. SetCharmURL( newCharm. URL()) ServiceConfig( ) ConfigSettings( ) interface{ }{})
err = s.unit.
c.Assert(err, IsNil)
- settings, err = s.unit.
+ settings, err = s.unit.
c.Assert(err, IsNil)
- c.Assert(settings, DeepEquals, map[string]
+ c.Assert(settings, DeepEquals, charm.Settings{})
}
func (s *UnitSuite) TestGetSetPubli cAddress( c *C) {
Index: worker/ uniter/ context. go uniter/ context. go' uniter/ context. go 2013-05-27 07:53:44 +0000 uniter/ context. go 2013-06-10 21:04:37 +0000 net/juju- core/charm" net/juju- core/log" net/juju- core/state" net/juju- core/worker/ uniter/ jujuc"
=== modified file 'worker/
--- worker/
+++ worker/
@@ -7,6 +7,7 @@
"bufio"
"fmt"
"io"
+ "launchpad.
"launchpad.
"launchpad.
"launchpad.
@@ -23,8 +24,8 @@
type HookContext struct {
unit *state.Unit
- // config holds the service configuration. interface{ }
- config map[string]
+ // configSettings holds the service configuration.
+ configSettings charm.Settings
// id identifies the context. ClosePort( protocol, port)
id string
@@ -84,15 +85,19 @@
return ctx.unit.
}
-func (ctx *HookContext) Config() (map[string] interface{ }, error) { ServiceConfig( ) ConfigSettings( )
- if ctx.config == nil {
+func (ctx *HookContext) ConfigSettings() (charm.Settings, error) {
+ if ctx.configSettings == nil {
var err error
- ctx.config, err = ctx.unit.
+ ctx.configSettings, err = ctx.unit.
if err != nil {
return nil, err
}
}
- return ctx.config, nil
+ result := charm.Settings{}
+ for name, value := range ctx.configSettings {
+ result[name] = value
+ }
+ return result, nil
}
func (ctx *HookContext) HookRelation() (jujuc. ContextRelation , bool) {
Index: worker/ uniter/ context_ test.go uniter/ context_ test.go' uniter/ context_ test.go 2013-06-04 21:43:25 +0000 uniter/ context_ test.go 2013-06-10 21:04:37 +0000 net/gocheck" net/juju- core/charm" net/juju- core/juju/ testing" net/juju- core/state" net/juju- core/utils"
=== modified file 'worker/
--- worker/
+++ worker/
@@ -7,6 +7,7 @@
"fmt"
"io/ioutil"
. "launchpad.
+ "launchpad.
"launchpad.
"launchpad.
"launchpad.
@@ -571,9 +572,9 @@
func (s *InterfaceSuite) TestConfigCaching(c *C) { ngs() interface{ }{"blog- title": "My "blog-title" : "My Title"})
ctx := s.GetContext(c, -1, "")
- cfg, err := ctx.Config()
+ settings, err := ctx.ConfigSetti
c.Assert(err, IsNil)
- c.Assert(cfg, DeepEquals, map[string]
Title"})
+ c.Assert(settings, DeepEquals, charm.Settings{
// Change remote config.
node, err := s.service.Config()
@@ -583,9 +584,9 @@
c.Assert(err, IsNil)
// Local view is not changed. ngs() interface{ }{"blog- title": "My "blog-title" : "My Title"})
- cfg, err = ctx.Config()
+ settings, err = ctx.ConfigSetti
c.Assert(err, IsNil)
- c.Assert(cfg, DeepEquals, map[string]
Title"})
+ c.Assert(settings, DeepEquals, charm.Settings{
}
type HookContextSuite struct {
Index: worker/ uniter/ jujuc/config- get.go uniter/ jujuc/config- get.go' uniter/ jujuc/config- get.go 2013-05-02 15:55:42 +0000 uniter/ jujuc/config- get.go 2013-06-10 21:04:37 +0000
=== modified file 'worker/
--- worker/
+++ worker/
@@ -42,15 +42,15 @@
}
func (c *ConfigGetCommand) Run(ctx *cmd.Context) error { tings()
- cfg, err := c.ctx.Config()
+ settings, err := c.ctx.ConfigSet
if err != nil {
return err
}
var value interface{}
if c.Key == "" {
- value = cfg
+ value = settings
} else {
- value, _ = cfg[c.Key]
+ value, _ = settings[c.Key]
}
return c.out.Write(ctx, value)
}
Index: worker/ uniter/ jujuc/context. go uniter/ jujuc/context. go' uniter/ jujuc/context. go 2013-05-02 15:55:42 +0000 uniter/ jujuc/context. go 2013-06-10 21:04:37 +0000
=== modified file 'worker/
--- worker/
+++ worker/
@@ -5,6 +5,7 @@
import ( net/juju- core/charm" protocol string, port int) error
"fmt"
+ "launchpad.
"strconv"
"strings"
)
@@ -32,7 +33,7 @@
ClosePort(
// Config returns the current service configuration of the executing unit. interface{ }, error)
- Config() (map[string]
+ ConfigSettings() (charm.Settings, error)
// HookRelation returns the ContextRelation associated with the executing
// hook if it was found, and whether it was found.
Index: worker/ uniter/ jujuc/util_ test.go uniter/ jujuc/util_ test.go' uniter/ jujuc/util_ test.go 2013-05-23 03:31:31 +0000 uniter/ jujuc/util_ test.go 2013-06-10 21:04:37 +0000 net/gocheck" net/juju- core/charm" net/juju- core/state" net/juju- core/utils/ set" net/juju- core/worker/ uniter/ jujuc"
=== modified file 'worker/
--- worker/
+++ worker/
@@ -8,6 +8,7 @@
"fmt"
"io"
. "launchpad.
+ "launchpad.
"launchpad.
"launchpad.
"launchpad.
@@ -96,8 +97,8 @@
return nil
}
-func (c *Context) Config() (map[string] interface{ }, error) { interface{ }{ reticulation" : 45.0,
- return map[string]
+func (c *Context) ConfigSettings() (charm.Settings, error) {
+ return charm.Settings{
"monsters": false,
"spline-
"title": "My Title",