Skip to content

Commit

Permalink
AgentConfigParams.Tag is now a names.Tag
Browse files Browse the repository at this point in the history
  • Loading branch information
davecheney committed Jul 14, 2014
1 parent 4ee1e0b commit 7ecb35a
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 52 deletions.
10 changes: 3 additions & 7 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ type AgentConfigParams struct {
LogDir string
Jobs []params.MachineJob
UpgradedToVersion version.Number
Tag string
Tag names.Tag
Password string
Nonce string
StateAddresses []string
Expand All @@ -264,7 +264,7 @@ func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)
if configParams.LogDir != "" {
logDir = configParams.LogDir
}
if configParams.Tag == "" {
if configParams.Tag == nil {
return nil, errors.Trace(requiredError("entity tag"))
}
if configParams.UpgradedToVersion == version.Zero {
Expand All @@ -276,18 +276,14 @@ func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)
if len(configParams.CACert) == 0 {
return nil, errors.Trace(requiredError("CA certificate"))
}
tag, err := names.ParseTag(configParams.Tag)
if err != nil {
return nil, err
}
// Note that the password parts of the state and api information are
// blank. This is by design.
config := &configInternal{
logDir: logDir,
dataDir: configParams.DataDir,
jobs: configParams.Jobs,
upgradedToVersion: configParams.UpgradedToVersion,
tag: tag,
tag: configParams.Tag,
nonce: configParams.Nonce,
caCert: configParams.CACert,
oldPassword: configParams.Password,
Expand Down
35 changes: 15 additions & 20 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ var agentConfigTests = []struct {
about: "missing upgraded to version",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg", // a user calle omg
Tag: names.NewUserTag("omg"), // a user called omg
},
checkErr: "upgradedToVersion not found in configuration",
}, {
about: "missing password",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
},
checkErr: "password not found in configuration",
}, {
about: "missing CA cert",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
},
Expand All @@ -69,7 +69,7 @@ var agentConfigTests = []struct {
about: "need either state or api addresses",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand All @@ -79,7 +79,7 @@ var agentConfigTests = []struct {
about: "invalid state address",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand All @@ -90,7 +90,7 @@ var agentConfigTests = []struct {
about: "invalid api address",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand All @@ -101,7 +101,7 @@ var agentConfigTests = []struct {
about: "good state addresses",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand All @@ -111,7 +111,7 @@ var agentConfigTests = []struct {
about: "good api addresses",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand All @@ -121,7 +121,7 @@ var agentConfigTests = []struct {
about: "both state and api addresses",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand All @@ -132,7 +132,7 @@ var agentConfigTests = []struct {
about: "everything...",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
CACert: "ca cert",
Expand All @@ -144,7 +144,7 @@ var agentConfigTests = []struct {
about: "missing logDir sets default",
params: agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
Password: "sekrit",
UpgradedToVersion: version.Current.Number,
CACert: "ca cert",
Expand Down Expand Up @@ -174,7 +174,7 @@ func (*suite) TestMigrate(c *gc.C) {
initialParams := agent.AgentConfigParams{
DataDir: c.MkDir(),
LogDir: c.MkDir(),
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
Nonce: "nonce",
Password: "secret",
UpgradedToVersion: version.MustParse("1.16.5"),
Expand Down Expand Up @@ -359,7 +359,7 @@ func (*suite) TestNewStateMachineConfig(c *gc.C) {

var attributeParams = agent.AgentConfigParams{
DataDir: "/data/dir",
Tag: "user-omg", // the omg user
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand Down Expand Up @@ -488,26 +488,21 @@ func (*suite) TestSetPassword(c *gc.C) {
conf, err := agent.NewStateMachineConfig(attrParams, servingInfo)
c.Assert(err, gc.IsNil)

tag, err := names.ParseTag(attrParams.Tag)
c.Assert(err, gc.IsNil)

expectAPIInfo := &api.Info{
Addrs: attrParams.APIAddresses,
CACert: attrParams.CACert,
Tag: tag,
Tag: attrParams.Tag,
Password: "",
Nonce: attrParams.Nonce,
}
c.Assert(conf.APIInfo(), jc.DeepEquals, expectAPIInfo)
addr := fmt.Sprintf("127.0.0.1:%d", servingInfo.StatePort)
userTag, err := names.ParseTag(attrParams.Tag)
c.Assert(err, gc.IsNil)
expectStateInfo := &authentication.MongoInfo{
Info: mongo.Info{
Addrs: []string{addr},
CACert: attrParams.CACert,
},
Tag: userTag,
Tag: attrParams.Tag,
Password: "",
}
info, ok := conf.MongoInfo()
Expand Down
6 changes: 3 additions & 3 deletions agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *bootstrapSuite) TestInitializeState(c *gc.C) {
pwHash := utils.UserPasswordHash(testing.DefaultMongoPassword, utils.CompatSalt)
configParams := agent.AgentConfigParams{
DataDir: dataDir,
Tag: "machine-0",
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
StateAddresses: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
Expand Down Expand Up @@ -164,7 +164,7 @@ func (s *bootstrapSuite) TestInitializeState(c *gc.C) {
func (s *bootstrapSuite) TestInitializeStateWithStateServingInfoNotAvailable(c *gc.C) {
configParams := agent.AgentConfigParams{
DataDir: c.MkDir(),
Tag: "machine-0",
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
StateAddresses: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
Expand All @@ -187,7 +187,7 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
pwHash := utils.UserPasswordHash(testing.DefaultMongoPassword, utils.CompatSalt)
configParams := agent.AgentConfigParams{
DataDir: dataDir,
Tag: "machine-0",
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
StateAddresses: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
Expand Down
2 changes: 1 addition & 1 deletion agent/format_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = gc.Suite(&formatSuite{})
// The agentParams are used by the specific formatter whitebox tests, and is
// located here for easy reuse.
var agentParams = AgentConfigParams{
Tag: "user-omg",
Tag: names.NewUserTag("omg"),
UpgradedToVersion: version.Current.Number,
Jobs: []params.MachineJob{params.JobHostUnits},
Password: "sekrit",
Expand Down
3 changes: 2 additions & 1 deletion agent/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"

"github.com/juju/names"
gc "launchpad.net/gocheck"

"github.com/juju/juju/state/api/params"
Expand All @@ -23,7 +24,7 @@ type identitySuite struct {
var _ = gc.Suite(&identitySuite{})

var attributeParams = AgentConfigParams{
Tag: "user-omg", // the omg user
Tag: names.NewUserTag("omg"), // the omg user
UpgradedToVersion: version.Current.Number,
Password: "sekrit",
CACert: "ca cert",
Expand Down
12 changes: 7 additions & 5 deletions cmd/jujud/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,13 @@ func (s *agentSuite) TearDownSuite(c *gc.C) {
// primeAgent writes the configuration file and tools with version vers
// for an agent with the given entity name. It returns the agent's
// configuration and the current tools.
func (s *agentSuite) primeAgent(c *gc.C, tag, password string, vers version.Binary) (agent.ConfigSetterWriter, *coretools.Tools) {
func (s *agentSuite) primeAgent(c *gc.C, tag names.Tag, password string, vers version.Binary) (agent.ConfigSetterWriter, *coretools.Tools) {
stor := s.Environ.Storage()
agentTools := envtesting.PrimeTools(c, stor, s.DataDir(), vers)
err := envtools.MergeAndWriteMetadata(stor, coretools.List{agentTools}, envtools.DoNotWriteMirrors)
c.Assert(err, gc.IsNil)
tools1, err := agenttools.ChangeAgentTools(s.DataDir(), tag, vers)
// TODO(dfc)
tools1, err := agenttools.ChangeAgentTools(s.DataDir(), tag.String(), vers)
c.Assert(err, gc.IsNil)
c.Assert(tools1, gc.DeepEquals, agentTools)

Expand Down Expand Up @@ -310,7 +311,7 @@ func parseHostPort(s string) (network.HostPort, error) {
}

// writeStateAgentConfig creates and writes a state agent config.
func writeStateAgentConfig(c *gc.C, stateInfo *authentication.MongoInfo, dataDir, tag, password string, vers version.Binary) agent.ConfigSetterWriter {
func writeStateAgentConfig(c *gc.C, stateInfo *authentication.MongoInfo, dataDir string, tag names.Tag, password string, vers version.Binary) agent.ConfigSetterWriter {
port := gitjujutesting.FindTCPPort()
apiAddr := []string{fmt.Sprintf("localhost:%d", port)}
conf, err := agent.NewStateMachineConfig(
Expand Down Expand Up @@ -340,10 +341,11 @@ func writeStateAgentConfig(c *gc.C, stateInfo *authentication.MongoInfo, dataDir
// for an agent with the given entity name. It returns the agent's configuration
// and the current tools.
func (s *agentSuite) primeStateAgent(
c *gc.C, tag, password string, vers version.Binary) (agent.ConfigSetterWriter, *coretools.Tools) {
c *gc.C, tag names.Tag, password string, vers version.Binary) (agent.ConfigSetterWriter, *coretools.Tools) {

agentTools := envtesting.PrimeTools(c, s.Environ.Storage(), s.DataDir(), vers)
tools1, err := agenttools.ChangeAgentTools(s.DataDir(), tag, vers)
// TODO(dfc)
tools1, err := agenttools.ChangeAgentTools(s.DataDir(), tag.String(), vers)
c.Assert(err, gc.IsNil)
c.Assert(tools1, gc.DeepEquals, agentTools)

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 @@ -126,7 +126,7 @@ func (s *BootstrapSuite) initBootstrapCommand(c *gc.C, jobs []params.MachineJob,
LogDir: s.logDir,
DataDir: s.dataDir,
Jobs: jobs,
Tag: "machine-0",
Tag: names.NewMachineTag("0"),
UpgradedToVersion: version.Current.Number,
Password: testPasswordHash(),
Nonce: agent.BootstrapNonce,
Expand Down
3 changes: 2 additions & 1 deletion cmd/jujud/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ func (s *commonMachineSuite) primeAgent(
c.Assert(err, gc.IsNil)
err = m.SetPassword(initialMachinePassword)
c.Assert(err, gc.IsNil)
tag := names.NewMachineTag(m.Id()).String()
// TODO(dfc)
tag := names.NewMachineTag(m.Id())
if m.IsManager() {
err = m.SetMongoPassword(initialMachinePassword)
c.Assert(err, gc.IsNil)
Expand Down
4 changes: 2 additions & 2 deletions cmd/jujud/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *UnitSuite) primeAgent(c *gc.C) (*state.Machine, *state.Unit, agent.Conf
c.Assert(err, gc.IsNil)
machine, err := s.State.Machine(id)
c.Assert(err, gc.IsNil)
conf, tools := s.agentSuite.primeAgent(c, unit.Tag().String(), initialUnitPassword, version.Current)
conf, tools := s.agentSuite.primeAgent(c, unit.Tag(), initialUnitPassword, version.Current)
return machine, unit, conf, tools
}

Expand Down Expand Up @@ -206,7 +206,7 @@ func (s *UnitSuite) TestOpenAPIState(c *gc.C) {
}

func (s *UnitSuite) TestOpenAPIStateWithBadCredsTerminates(c *gc.C) {
conf, _ := s.agentSuite.primeAgent(c, "unit-missing-0", "no-password", version.Current)
conf, _ := s.agentSuite.primeAgent(c, names.NewUnitTag("missing/0"), "no-password", version.Current)
_, _, err := openAPIState(conf, nil)
c.Assert(err, gc.Equals, worker.ErrTerminateAgent)
}
Expand Down
8 changes: 4 additions & 4 deletions environs/cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func ConfigureJuju(cfg *MachineConfig, c *cloudinit.Config) error {
// It would be cleaner to change bootstrap-state to
// be responsible for starting the machine agent itself,
// but this would not be backwardly compatible.
machineTag := names.NewMachineTag(cfg.MachineId).String()
machineTag := names.NewMachineTag(cfg.MachineId)
_, err = cfg.addAgentInfo(c, machineTag)
if err != nil {
return err
Expand Down Expand Up @@ -358,14 +358,14 @@ func ConfigureJuju(cfg *MachineConfig, c *cloudinit.Config) error {
)
}

return cfg.addMachineAgentToBoot(c, machineTag, cfg.MachineId)
return cfg.addMachineAgentToBoot(c, machineTag.String(), cfg.MachineId)
}

func (cfg *MachineConfig) dataFile(name string) string {
return path.Join(cfg.DataDir, name)
}

func (cfg *MachineConfig) agentConfig(tag string) (agent.ConfigSetter, error) {
func (cfg *MachineConfig) agentConfig(tag names.Tag) (agent.ConfigSetter, error) {
// TODO for HAState: the stateHostAddrs and apiHostAddrs here assume that
// if the machine is a stateServer then to use localhost. This may be
// sufficient, but needs thought in the new world order.
Expand Down Expand Up @@ -396,7 +396,7 @@ func (cfg *MachineConfig) agentConfig(tag string) (agent.ConfigSetter, error) {

// addAgentInfo adds agent-required information to the agent's directory
// and returns the agent directory name.
func (cfg *MachineConfig) addAgentInfo(c *cloudinit.Config, tag string) (agent.Config, error) {
func (cfg *MachineConfig) addAgentInfo(c *cloudinit.Config, tag names.Tag) (agent.Config, error) {
acfg, err := cfg.agentConfig(tag)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion juju/testing/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (s *JujuConnSuite) AgentConfigForTag(c *gc.C, tag names.Tag) agent.ConfigSe
config, err := agent.NewAgentConfig(
agent.AgentConfigParams{
DataDir: s.DataDir(),
Tag: tag.String(),
Tag: tag,
UpgradedToVersion: version.Current.Number,
Password: password,
Nonce: "nonce",
Expand Down
10 changes: 6 additions & 4 deletions worker/deployer/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ func (ctx *SimpleContext) DeployUnit(unitName, initialPassword string) (err erro
}

// Link the current tools for use by the new agent.
tag := names.NewUnitTag(unitName).String()
tag := names.NewUnitTag(unitName)
dataDir := ctx.agentConfig.DataDir()
logDir := ctx.agentConfig.LogDir()
_, err = tools.ChangeAgentTools(dataDir, tag, version.Current)
toolsDir := tools.ToolsDir(dataDir, tag)
// TODO(dfc)
_, err = tools.ChangeAgentTools(dataDir, tag.String(), version.Current)
// TODO(dfc)
toolsDir := tools.ToolsDir(dataDir, tag.String())
defer removeOnErr(&err, toolsDir)

result, err := ctx.api.ConnectionInfo()
Expand Down Expand Up @@ -114,7 +116,7 @@ func (ctx *SimpleContext) DeployUnit(unitName, initialPassword string) (err erro
defer removeOnErr(&err, conf.Dir())

// Install an upstart job that runs the unit agent.
logPath := path.Join(logDir, tag+".log")
logPath := path.Join(logDir, tag.String()+".log")
cmd := strings.Join([]string{
path.Join(toolsDir, "jujud"), "unit",
"--data-dir", dataDir,
Expand Down
2 changes: 1 addition & 1 deletion worker/provisioner/kvm-broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *kvmBrokerSuite) SetUpTest(c *gc.C) {
s.agentConfig, err = agent.NewAgentConfig(
agent.AgentConfigParams{
DataDir: "/not/used/here",
Tag: "user-tag", // a user called tag
Tag: names.NewUserTag("tag"), // a user called tag
UpgradedToVersion: version.Current.Number,
Password: "dummy-secret",
Nonce: "nonce",
Expand Down
2 changes: 1 addition & 1 deletion worker/provisioner/lxc-broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *lxcBrokerSuite) SetUpTest(c *gc.C) {
s.agentConfig, err = agent.NewAgentConfig(
agent.AgentConfigParams{
DataDir: "/not/used/here",
Tag: "user-tag",
Tag: names.NewUserTag("tag"),
UpgradedToVersion: version.Current.Number,
Password: "dummy-secret",
Nonce: "nonce",
Expand Down

0 comments on commit 7ecb35a

Please sign in to comment.