Skip to content

Commit

Permalink
Replace EnvironTag with ModelTag and related search/replace changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Jan 25, 2016
1 parent 4cc176c commit f315ea3
Show file tree
Hide file tree
Showing 293 changed files with 1,854 additions and 1,857 deletions.
37 changes: 17 additions & 20 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ const (
ProviderType = "PROVIDER_TYPE"
ContainerType = "CONTAINER_TYPE"
Namespace = "NAMESPACE"
StorageDir = "STORAGE_DIR"
StorageAddr = "STORAGE_ADDR"
AgentServiceName = "AGENT_SERVICE_NAME"
MongoOplogSize = "MONGO_OPLOG_SIZE"
NumaCtlPreference = "NUMA_CTL_PREFERENCE"
Expand Down Expand Up @@ -244,9 +242,8 @@ type Config interface {
// available) when connecting to the state or API server.
PreferIPv6() bool

// Environment returns the tag for the environment that the agent belongs
// to.
Environment() names.EnvironTag
// Model returns the tag for the model that the agent belongs to.
Model() names.ModelTag

// MetricsSpoolDir returns the spool directory where workloads store
// collected metrics.
Expand Down Expand Up @@ -330,7 +327,7 @@ type MigrateParams struct {
Jobs []multiwatcher.MachineJob
DeleteValues []string
Values map[string]string
Environment names.EnvironTag
Environment names.ModelTag
}

// Ensure that the configInternal struct implements the Config interface.
Expand All @@ -355,7 +352,7 @@ type configInternal struct {
paths Paths
tag names.Tag
nonce string
environment names.EnvironTag
model names.ModelTag
jobs []multiwatcher.MachineJob
upgradedToVersion version.Number
caCert string
Expand All @@ -374,7 +371,7 @@ type AgentConfigParams struct {
Tag names.Tag
Password string
Nonce string
Environment names.EnvironTag
Model names.ModelTag
StateAddresses []string
APIAddresses []string
CACert string
Expand Down Expand Up @@ -403,9 +400,9 @@ func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)
if configParams.Password == "" {
return nil, errors.Trace(requiredError("password"))
}
if uuid := configParams.Environment.Id(); uuid == "" {
if uuid := configParams.Model.Id(); uuid == "" {
return nil, errors.Trace(requiredError("model"))
} else if !names.IsValidEnvironment(uuid) {
} else if !names.IsValidModel(uuid) {
return nil, errors.Errorf("%q is not a valid model uuid", uuid)
}
if len(configParams.CACert) == 0 {
Expand All @@ -419,7 +416,7 @@ func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)
upgradedToVersion: configParams.UpgradedToVersion,
tag: configParams.Tag,
nonce: configParams.Nonce,
environment: configParams.Environment,
model: configParams.Model,
caCert: configParams.CACert,
oldPassword: configParams.Password,
values: configParams.Values,
Expand Down Expand Up @@ -578,7 +575,7 @@ func (config *configInternal) Migrate(newParams MigrateParams) error {
config.values[key] = value
}
if newParams.Environment.Id() != "" {
config.environment = newParams.Environment
config.model = newParams.Environment
}
if err := config.check(); err != nil {
return fmt.Errorf("migrated agent config is invalid: %v", err)
Expand Down Expand Up @@ -710,8 +707,8 @@ func (c *configInternal) Tag() names.Tag {
return c.tag
}

func (c *configInternal) Environment() names.EnvironTag {
return c.environment
func (c *configInternal) Model() names.ModelTag {
return c.model
}

func (c *configInternal) Dir() string {
Expand Down Expand Up @@ -798,12 +795,12 @@ func (c *configInternal) APIInfo() (*api.Info, bool) {
}
}
return &api.Info{
Addrs: addrs,
Password: c.apiDetails.password,
CACert: c.caCert,
Tag: c.tag,
Nonce: c.nonce,
EnvironTag: c.environment,
Addrs: addrs,
Password: c.apiDetails.password,
CACert: c.caCert,
Tag: c.tag,
Nonce: c.nonce,
ModelTag: c.model,
}, true
}

Expand Down
46 changes: 23 additions & 23 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var agentConfigTests = []struct {
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current,
Password: "sekrit",
Environment: names.NewEnvironTag("uuid"),
Model: names.NewModelTag("uuid"),
},
checkErr: `"uuid" is not a valid model uuid`,
}, {
Expand All @@ -84,7 +84,7 @@ var agentConfigTests = []struct {
Tag: names.NewMachineTag("1"),
UpgradedToVersion: version.Current,
Password: "sekrit",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
},
checkErr: "CA certificate not found in configuration",
}, {
Expand All @@ -95,7 +95,7 @@ var agentConfigTests = []struct {
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
},
checkErr: "state or API addresses not found in configuration",
}, {
Expand All @@ -106,7 +106,7 @@ var agentConfigTests = []struct {
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:8080", "bad-address"},
},
checkErr: `invalid state server address "bad-address"`,
Expand All @@ -118,7 +118,7 @@ var agentConfigTests = []struct {
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
APIAddresses: []string{"localhost:8080", "bad-address"},
},
checkErr: `invalid API server address "bad-address"`,
Expand All @@ -130,7 +130,7 @@ var agentConfigTests = []struct {
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
},
}, {
Expand All @@ -141,7 +141,7 @@ var agentConfigTests = []struct {
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
APIAddresses: []string{"localhost:1234"},
},
}, {
Expand All @@ -152,7 +152,7 @@ var agentConfigTests = []struct {
UpgradedToVersion: version.Current,
Password: "sekrit",
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
},
Expand All @@ -164,7 +164,7 @@ var agentConfigTests = []struct {
Password: "sekrit",
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Expand All @@ -177,7 +177,7 @@ var agentConfigTests = []struct {
Password: "sekrit",
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Expand All @@ -193,7 +193,7 @@ var agentConfigTests = []struct {
Password: "sekrit",
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Expand All @@ -212,7 +212,7 @@ var agentConfigTests = []struct {
Password: "sekrit",
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Expand All @@ -236,7 +236,7 @@ var agentConfigTests = []struct {
Tag: names.NewUnitTag("ubuntu/1"),
Password: "sekrit",
UpgradedToVersion: version.Current,
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Expand All @@ -252,7 +252,7 @@ var agentConfigTests = []struct {
Password: "sekrit",
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Expand All @@ -269,7 +269,7 @@ var agentConfigTests = []struct {
Password: "sekrit",
UpgradedToVersion: version.Current,
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Expand Down Expand Up @@ -309,7 +309,7 @@ func (*suite) TestMigrate(c *gc.C) {
multiwatcher.JobHostUnits,
},
CACert: "ca cert",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:4321"},
Values: map[string]string{
Expand Down Expand Up @@ -512,7 +512,7 @@ var attributeParams = agent.AgentConfigParams{
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
}

func (*suite) TestAttributes(c *gc.C) {
Expand Down Expand Up @@ -674,12 +674,12 @@ func (*suite) TestSetPassword(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

expectAPIInfo := &api.Info{
Addrs: attrParams.APIAddresses,
CACert: attrParams.CACert,
Tag: attrParams.Tag,
Password: "",
Nonce: attrParams.Nonce,
EnvironTag: attrParams.Environment,
Addrs: attrParams.APIAddresses,
CACert: attrParams.CACert,
Tag: attrParams.Tag,
Password: "",
Nonce: attrParams.Nonce,
ModelTag: attrParams.Model,
}
apiInfo, ok := conf.APIInfo()
c.Assert(ok, jc.IsTrue)
Expand Down
18 changes: 9 additions & 9 deletions agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ LXC_BRIDGE="ignored"`[1:])
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: pwHash,
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
}
servingInfo := params.StateServingInfo{
Cert: testing.ServerCert,
Expand Down Expand Up @@ -153,15 +153,15 @@ LXC_BRIDGE="ignored"`[1:])
c.Assert(err, jc.ErrorIsNil)

// Check that the environment has been set up.
env, err := st.Environment()
env, err := st.Model()
c.Assert(err, jc.ErrorIsNil)
uuid, ok := envCfg.UUID()
c.Assert(ok, jc.IsTrue)
c.Assert(env.UUID(), gc.Equals, uuid)

// Check that initial admin user has been set up correctly.
envTag := env.Tag().(names.EnvironTag)
s.assertCanLogInAsAdmin(c, envTag, pwHash)
modelTag := env.Tag().(names.ModelTag)
s.assertCanLogInAsAdmin(c, modelTag, pwHash)
user, err := st.User(env.Owner())
c.Assert(err, jc.ErrorIsNil)
c.Assert(user.PasswordValid(testing.DefaultMongoPassword), jc.IsTrue)
Expand Down Expand Up @@ -219,7 +219,7 @@ LXC_BRIDGE="ignored"`[1:])
c.Assert(agent.Password(newCfg), gc.Not(gc.Equals), testing.DefaultMongoPassword)
info, ok := cfg.MongoInfo()
c.Assert(ok, jc.IsTrue)
st1, err := state.Open(newCfg.Environment(), info, mongo.DefaultDialOpts(), environs.NewStatePolicy())
st1, err := state.Open(newCfg.Model(), info, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, jc.ErrorIsNil)
defer st1.Close()
}
Expand All @@ -232,7 +232,7 @@ func (s *bootstrapSuite) TestInitializeStateWithStateServingInfoNotAvailable(c *
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: "fake",
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
}
cfg, err := agent.NewAgentConfig(configParams)
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -257,7 +257,7 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
StateAddresses: []string{s.mgoInst.Addr()},
CACert: testing.CACert,
Password: pwHash,
Environment: testing.EnvironmentTag,
Model: testing.ModelTag,
}
cfg, err := agent.NewAgentConfig(configParams)
c.Assert(err, jc.ErrorIsNil)
Expand Down Expand Up @@ -326,7 +326,7 @@ func (s *bootstrapSuite) TestMachineJobFromParams(c *gc.C) {
}
}

func (s *bootstrapSuite) assertCanLogInAsAdmin(c *gc.C, environTag names.EnvironTag, password string) {
func (s *bootstrapSuite) assertCanLogInAsAdmin(c *gc.C, modelTag names.ModelTag, password string) {
info := &mongo.MongoInfo{
Info: mongo.Info{
Addrs: []string{s.mgoInst.Addr()},
Expand All @@ -335,7 +335,7 @@ func (s *bootstrapSuite) assertCanLogInAsAdmin(c *gc.C, environTag names.Environ
Tag: nil, // admin user
Password: password,
}
st, err := state.Open(environTag, info, mongo.DefaultDialOpts(), environs.NewStatePolicy())
st, err := state.Open(modelTag, info, mongo.DefaultDialOpts(), environs.NewStatePolicy())
c.Assert(err, jc.ErrorIsNil)
defer st.Close()
_, err = st.Machine("0")
Expand Down
Loading

0 comments on commit f315ea3

Please sign in to comment.