Skip to content

Commit

Permalink
Rename config StateInfo() to MongoInfo() to better reflect the purpos…
Browse files Browse the repository at this point in the history
…e of the method
  • Loading branch information
wallyworld committed Jul 10, 2014
1 parent 8ca2f8f commit 5ca6f80
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 57 deletions.
8 changes: 4 additions & 4 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ type Config interface {
// APIInfo returns details for connecting to the API server.
APIInfo() *api.Info

// StateInfo returns details for connecting to the state server and reports
// whether those details are available
StateInfo() (*authentication.ConnectionInfo, bool)
// MongoInfo returns details for connecting to the state server's mongo
// database and reports whether those details are available
MongoInfo() (*authentication.ConnectionInfo, bool)

// OldPassword returns the fallback password when connecting to the
// API server.
Expand Down Expand Up @@ -645,7 +645,7 @@ func (c *configInternal) APIInfo() *api.Info {
}
}

func (c *configInternal) StateInfo() (info *authentication.ConnectionInfo, ok bool) {
func (c *configInternal) MongoInfo() (info *authentication.ConnectionInfo, ok bool) {
ssi, ok := c.StateServingInfo()
if !ok {
return nil, false
Expand Down
4 changes: 2 additions & 2 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func (*suite) TestSetPassword(c *gc.C) {
Tag: userTag,
Password: "",
}
info, ok := conf.StateInfo()
info, ok := conf.MongoInfo()
c.Assert(ok, jc.IsTrue)
c.Assert(info, jc.DeepEquals, expectStateInfo)

Expand All @@ -517,7 +517,7 @@ func (*suite) TestSetPassword(c *gc.C) {
expectStateInfo.Password = "newpassword"

c.Assert(conf.APIInfo(), jc.DeepEquals, expectAPIInfo)
info, ok = conf.StateInfo()
info, ok = conf.MongoInfo()
c.Assert(ok, jc.IsTrue)
c.Assert(info, jc.DeepEquals, expectStateInfo)
}
Expand Down
2 changes: 1 addition & 1 deletion agent/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func InitializeState(c ConfigSetter, envCfg *config.Config, machineCfg Bootstrap
}
// N.B. no users are set up when we're initializing the state,
// so don't use any tag or password when opening it.
info, ok := c.StateInfo()
info, ok := c.MongoInfo()
if !ok {
return nil, nil, fmt.Errorf("stateinfo not available")
}
Expand Down
2 changes: 1 addition & 1 deletion agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *bootstrapSuite) TestInitializeState(c *gc.C) {
c.Assert(newCfg.Tag(), gc.Equals, "machine-0")
c.Assert(agent.Password(newCfg), gc.Not(gc.Equals), pwHash)
c.Assert(agent.Password(newCfg), gc.Not(gc.Equals), testing.DefaultMongoPassword)
info, ok := cfg.StateInfo()
info, ok := cfg.MongoInfo()
c.Assert(ok, jc.IsTrue)
st1, err := state.Open(info, mongo.DialOpts{}, environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
Expand Down
8 changes: 4 additions & 4 deletions cmd/jujud/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (s *agentSuite) primeAgent(c *gc.C, tag, password string, vers version.Bina
c.Assert(err, gc.IsNil)
c.Assert(tools1, gc.DeepEquals, agentTools)

stateInfo := s.StateInfo(c)
stateInfo := s.MongoInfo(c)
apiInfo := s.APIInfo(c)
conf, err := agent.NewAgentConfig(
agent.AgentConfigParams{
Expand Down Expand Up @@ -347,7 +347,7 @@ func (s *agentSuite) primeStateAgent(
c.Assert(err, gc.IsNil)
c.Assert(tools1, gc.DeepEquals, agentTools)

stateInfo := s.StateInfo(c)
stateInfo := s.MongoInfo(c)
conf := writeStateAgentConfig(c, stateInfo, s.DataDir(), tag, password, vers)
s.primeAPIHostPorts(c)
return conf, agentTools
Expand Down Expand Up @@ -404,7 +404,7 @@ func (s *agentSuite) assertCanOpenState(c *gc.C, tag, dataDir string) {
c.Assert(err, gc.IsNil)
config, err := agent.ReadConfig(agent.ConfigPath(dataDir, t))
c.Assert(err, gc.IsNil)
info, ok := config.StateInfo()
info, ok := config.MongoInfo()
c.Assert(ok, jc.IsTrue)
st, err := state.Open(info, mongo.DialOpts{}, environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
Expand All @@ -417,7 +417,7 @@ func (s *agentSuite) assertCannotOpenState(c *gc.C, tag, dataDir string) {
c.Assert(err, gc.IsNil)
config, err := agent.ReadConfig(agent.ConfigPath(dataDir, t))
c.Assert(err, gc.IsNil)
_, ok := config.StateInfo()
_, ok := config.MongoInfo()
c.Assert(ok, jc.IsFalse)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/jujud/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func newEnsureServerParams(agentConfig agent.Config) (mongo.EnsureServerParams,
func (c *BootstrapCommand) startMongo(addrs []network.Address, agentConfig agent.Config) error {
logger.Debugf("starting mongo")

info, ok := agentConfig.StateInfo()
info, ok := agentConfig.MongoInfo()
if !ok {
return fmt.Errorf("no state info available")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/jujud/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (s *BootstrapSuite) TestInitialPassword(c *gc.C) {
machineConf1, err := agent.ReadConfig(agent.ConfigPath(machineConf.DataDir(), names.NewMachineTag("0")))
c.Assert(err, gc.IsNil)

stateinfo, ok := machineConf1.StateInfo()
stateinfo, ok := machineConf1.MongoInfo()
c.Assert(ok, jc.IsTrue)
st, err = state.Open(stateinfo, mongo.DialOpts{}, environs.NewStatePolicy())
c.Assert(err, gc.IsNil)
Expand Down
8 changes: 4 additions & 4 deletions cmd/jujud/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func (a *MachineAgent) ensureMongoServer(agentConfig agent.Config) (err error) {
//
// TODO(axw) remove this when we no longer need
// to upgrade from pre-HA-capable environments.
stateInfo, ok := agentConfig.StateInfo()
stateInfo, ok := agentConfig.MongoInfo()
if !ok {
return fmt.Errorf("state worker was started with no state serving info")
}
Expand All @@ -642,7 +642,7 @@ func (a *MachineAgent) ensureMongoServer(agentConfig agent.Config) (err error) {
}

func (a *MachineAgent) ensureMongoAdminUser(agentConfig agent.Config) (added bool, err error) {
stateInfo, ok1 := agentConfig.StateInfo()
stateInfo, ok1 := agentConfig.MongoInfo()
servingInfo, ok2 := agentConfig.StateServingInfo()
if !ok1 || !ok2 {
return false, fmt.Errorf("no state serving info configuration")
Expand Down Expand Up @@ -670,7 +670,7 @@ func isPreHAVersion(v version.Number) bool {
}

func openState(agentConfig agent.Config, dialOpts mongo.DialOpts) (_ *state.State, _ *state.Machine, err error) {
info, ok := agentConfig.StateInfo()
info, ok := agentConfig.MongoInfo()
if !ok {
return nil, nil, fmt.Errorf("no state info available")
}
Expand Down Expand Up @@ -773,7 +773,7 @@ func (a *MachineAgent) upgradeWorker(
return err
}
var err error
info, ok := agentConfig.StateInfo()
info, ok := agentConfig.MongoInfo()
if !ok {
return fmt.Errorf("no state info available")
}
Expand Down
4 changes: 2 additions & 2 deletions juju/testing/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s *JujuConnSuite) Reset(c *gc.C) {
s.setUpConn(c)
}

func (s *JujuConnSuite) StateInfo(c *gc.C) *authentication.ConnectionInfo {
func (s *JujuConnSuite) MongoInfo(c *gc.C) *authentication.ConnectionInfo {
info, _, err := s.Conn.Environ.StateInfo()
c.Assert(err, gc.IsNil)
info.Password = "dummy-secret"
Expand Down Expand Up @@ -354,7 +354,7 @@ func (s *JujuConnSuite) AgentConfigForTag(c *gc.C, tag names.Tag) agent.ConfigSe
UpgradedToVersion: version.Current.Number,
Password: password,
Nonce: "nonce",
StateAddresses: s.StateInfo(c).Addrs,
StateAddresses: s.MongoInfo(c).Addrs,
APIAddresses: s.APIInfo(c).Addrs,
CACert: testing.CACert,
})
Expand Down
2 changes: 1 addition & 1 deletion state/api/agent/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (s *machineSuite) TestEntitySetPassword(c *gc.C) {
// Check that we cannot log in to mongo with the correct password.
// This is because there's no mongo password set for s.machine,
// which has JobHostUnits
info := s.StateInfo(c)
info := s.MongoInfo(c)
// TODO(dfc) this entity.Tag should return a Tag
tag, err := names.ParseTag(entity.Tag())
c.Assert(err, gc.IsNil)
Expand Down
2 changes: 1 addition & 1 deletion state/api/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ func (s *provisionerSuite) TestContainerManagerConfigKVM(c *gc.C) {

func (s *provisionerSuite) TestContainerManagerConfigLXC(c *gc.C) {
args := params.ContainerManagerConfigParams{Type: instance.LXC}
st, err := state.Open(s.StateInfo(c), mongo.DialOpts{}, state.Policy(nil))
st, err := state.Open(s.MongoInfo(c), mongo.DialOpts{}, state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()

Expand Down
2 changes: 1 addition & 1 deletion state/apiserver/client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func setDefaultStatus(c *gc.C, entity setStatuser) {
}

func (s *baseSuite) tryOpenState(c *gc.C, e apiAuthenticator, password string) error {
stateInfo := s.StateInfo(c)
stateInfo := s.MongoInfo(c)
stateInfo.Tag = e.Tag()
stateInfo.Password = password
st, err := state.Open(stateInfo, mongo.DialOpts{
Expand Down
2 changes: 1 addition & 1 deletion state/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestingInitialize(c *gc.C, cfg *config.Config, policy Policy) *State {
if cfg == nil {
cfg = testing.EnvironConfig(c)
}
st, err := Initialize(TestingStateInfo(), cfg, TestingDialOpts(), policy)
st, err := Initialize(TestingMongoInfo(), cfg, TestingDialOpts(), policy)
c.Assert(err, gc.IsNil)
return st
}
Expand Down
10 changes: 5 additions & 5 deletions state/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *InitializeSuite) SetUpTest(c *gc.C) {
}

func (s *InitializeSuite) openState(c *gc.C) {
st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
s.State = st
}
Expand All @@ -56,7 +56,7 @@ func (s *InitializeSuite) TearDownTest(c *gc.C) {
func (s *InitializeSuite) TestInitialize(c *gc.C) {
cfg := testing.EnvironConfig(c)
initial := cfg.AllAttrs()
st, err := state.Initialize(state.TestingStateInfo(), cfg, state.TestingDialOpts(), state.Policy(nil))
st, err := state.Initialize(state.TestingMongoInfo(), cfg, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
err = st.Close()
Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *InitializeSuite) TestDoubleInitializeConfig(c *gc.C) {
// for originally...
cfg, err := cfg.Apply(map[string]interface{}{"authorized-keys": "something-else"})
c.Assert(err, gc.IsNil)
st, err = state.Initialize(state.TestingStateInfo(), cfg, state.TestingDialOpts(), state.Policy(nil))
st, err = state.Initialize(state.TestingMongoInfo(), cfg, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
st.Close()
Expand All @@ -117,7 +117,7 @@ func (s *InitializeSuite) TestEnvironConfigWithAdminSecret(c *gc.C) {
badUpdateAttrs := map[string]interface{}{"admin-secret": "foo"}
bad, err := good.Apply(badUpdateAttrs)

_, err = state.Initialize(state.TestingStateInfo(), bad, state.TestingDialOpts(), state.Policy(nil))
_, err = state.Initialize(state.TestingMongoInfo(), bad, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.ErrorMatches, "admin-secret should never be written to the state")

// admin-secret blocks UpdateEnvironConfig.
Expand All @@ -142,7 +142,7 @@ func (s *InitializeSuite) TestEnvironConfigWithoutAgentVersion(c *gc.C) {
bad, err := config.New(config.NoDefaults, attrs)
c.Assert(err, gc.IsNil)

_, err = state.Initialize(state.TestingStateInfo(), bad, state.TestingDialOpts(), state.Policy(nil))
_, err = state.Initialize(state.TestingMongoInfo(), bad, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.ErrorMatches, "agent-version must always be set in state")

st := state.TestingInitialize(c, good, state.Policy(nil))
Expand Down
8 changes: 4 additions & 4 deletions state/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type SettingsSuite struct {

var _ = gc.Suite(&SettingsSuite{})

// TestingStateInfo returns information suitable for
// connecting to the testing state server.
func TestingStateInfo() *authentication.ConnectionInfo {
// TestingMongoInfo returns information suitable for
// connecting to the testing state server's mongo database.
func TestingMongoInfo() *authentication.ConnectionInfo {
return &authentication.ConnectionInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
Expand Down Expand Up @@ -57,7 +57,7 @@ func (s *SettingsSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
s.MgoSuite.SetUpTest(c)
// TODO(dfc) this logic is duplicated with the metawatcher_test.
state, err := Open(TestingStateInfo(), TestingDialOpts(), Policy(nil))
state, err := Open(TestingMongoInfo(), TestingDialOpts(), Policy(nil))
c.Assert(err, gc.IsNil)

s.state = state
Expand Down
26 changes: 13 additions & 13 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *StateSuite) SetUpTest(c *gc.C) {
func (s *StateSuite) TestDialAgain(c *gc.C) {
// Ensure idempotent operations on Dial are working fine.
for i := 0; i < 2; i++ {
st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
c.Assert(st.Close(), gc.IsNil)
}
Expand Down Expand Up @@ -2076,7 +2076,7 @@ func tryOpenState(info *authentication.ConnectionInfo) error {
}

func (s *StateSuite) TestOpenWithoutSetMongoPassword(c *gc.C) {
info := state.TestingStateInfo()
info := state.TestingMongoInfo()
info.Tag, info.Password = names.NewUserTag("arble"), "bar"
err := tryOpenState(info)
c.Assert(err, jc.Satisfies, errors.IsUnauthorized)
Expand All @@ -2091,7 +2091,7 @@ func (s *StateSuite) TestOpenWithoutSetMongoPassword(c *gc.C) {
}

func (s *StateSuite) TestOpenDoesnotSetWriteMajority(c *gc.C) {
info := state.TestingStateInfo()
info := state.TestingMongoInfo()
st, err := state.Open(info, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()
Expand Down Expand Up @@ -2130,7 +2130,7 @@ func (s *StateSuite) TestOpenSetsWriteMajority(c *gc.C) {
}

func (s *StateSuite) TestOpenBadAddress(c *gc.C) {
info := state.TestingStateInfo()
info := state.TestingMongoInfo()
info.Addrs = []string{"0.1.2.3:1234"}
st, err := state.Open(info, mongo.DialOpts{
Timeout: 1 * time.Millisecond,
Expand All @@ -2144,7 +2144,7 @@ func (s *StateSuite) TestOpenBadAddress(c *gc.C) {
func (s *StateSuite) TestOpenDelaysRetryBadAddress(c *gc.C) {
// Default mgo retry delay
retryDelay := 500 * time.Millisecond
info := state.TestingStateInfo()
info := state.TestingMongoInfo()
info.Addrs = []string{"0.1.2.3:1234"}

t0 := time.Now()
Expand Down Expand Up @@ -2245,7 +2245,7 @@ type entity interface {
}

func testSetMongoPassword(c *gc.C, getEntity func(st *state.State) (entity, error)) {
info := state.TestingStateInfo()
info := state.TestingMongoInfo()
st, err := state.Open(info, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()
Expand Down Expand Up @@ -2307,7 +2307,7 @@ func (s *StateSuite) TestSetAdminMongoPassword(c *gc.C) {
err = s.State.SetAdminMongoPassword("foo")
c.Assert(err, gc.IsNil)
defer s.State.SetAdminMongoPassword("")
info := state.TestingStateInfo()
info := state.TestingMongoInfo()
err = tryOpenState(info)
c.Assert(err, jc.Satisfies, errors.IsUnauthorized)

Expand Down Expand Up @@ -2945,7 +2945,7 @@ type waiter interface {
// interact with the closed state, causing it to return an
// unexpected error (often "Closed explictly").
func testWatcherDiesWhenStateCloses(c *gc.C, startWatcher func(c *gc.C, st *state.State) waiter) {
st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
watcher := startWatcher(c, st)
err = st.Close()
Expand Down Expand Up @@ -2987,7 +2987,7 @@ func (s *StateSuite) TestOpenCreatesStateServersDoc(c *gc.C) {
c.Assert(err, gc.NotNil)
c.Assert(info, gc.IsNil)

st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()

Expand All @@ -3013,7 +3013,7 @@ func (s *StateSuite) TestOpenCreatesAPIHostPortsDoc(c *gc.C) {
c.Assert(err, gc.NotNil)
c.Assert(addrs, gc.IsNil)

st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()

Expand All @@ -3027,7 +3027,7 @@ func (s *StateSuite) TestReopenWithNoMachines(c *gc.C) {
c.Assert(err, gc.IsNil)
c.Assert(info, jc.DeepEquals, &state.StateServerInfo{})

st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()

Expand Down Expand Up @@ -3058,7 +3058,7 @@ func (s *StateSuite) TestOpenReplacesOldStateServersDoc(c *gc.C) {
c.Assert(info.MachineIds, gc.HasLen, 0)
c.Assert(info.VotingMachineIds, gc.HasLen, 0)

st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()

Expand Down Expand Up @@ -3426,7 +3426,7 @@ func (s *StateSuite) TestOpenCreatesStateServingInfoDoc(c *gc.C) {
err := s.stateServers.DropCollection()
c.Assert(err, gc.IsNil)

st, err := state.Open(state.TestingStateInfo(), state.TestingDialOpts(), state.Policy(nil))
st, err := state.Open(state.TestingMongoInfo(), state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()

Expand Down
2 changes: 1 addition & 1 deletion state/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func (s *UnitSuite) TestSetMongoPasswordOnUnitAfterConnectingAsMachineEntity(c *
// as a side-effect of a principal entering relation scope.)
subUnit := s.addSubordinateUnit(c)

info := state.TestingStateInfo()
info := state.TestingMongoInfo()
st, err := state.Open(info, state.TestingDialOpts(), state.Policy(nil))
c.Assert(err, gc.IsNil)
defer st.Close()
Expand Down
Loading

0 comments on commit 5ca6f80

Please sign in to comment.