Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/juju/juju into 132-names-…
Browse files Browse the repository at this point in the history
…refactor-part-v

Conflicts:
	agent/agent_test.go
	environs/cloudinit/cloudinit_test.go
	environs/cloudinit_test.go
	state/open.go
  • Loading branch information
davecheney committed Jul 9, 2014
2 parents 8404bcf + 16af08d commit 61c9e8a
Show file tree
Hide file tree
Showing 66 changed files with 495 additions and 285 deletions.
9 changes: 5 additions & 4 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"github.com/juju/names"
"github.com/juju/utils"

"github.com/juju/juju/environmentserver/authentication"
"github.com/juju/juju/juju/paths"
"github.com/juju/juju/mongo"
"github.com/juju/juju/network"
"github.com/juju/juju/state"
"github.com/juju/juju/state/api"
"github.com/juju/juju/state/api/params"
"github.com/juju/juju/version"
Expand Down Expand Up @@ -57,6 +57,7 @@ const (
StorageDir = "STORAGE_DIR"
StorageAddr = "STORAGE_ADDR"
AgentServiceName = "AGENT_SERVICE_NAME"
MongoOplogSize = "MONGO_OPLOG_SIZE"
)

// The Config interface is the sole way that the agent gets access to the
Expand Down Expand Up @@ -118,7 +119,7 @@ type Config interface {

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

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

func (c *configInternal) StateInfo() (info *state.Info, ok bool) {
func (c *configInternal) StateInfo() (info *authentication.ConnectionInfo, ok bool) {
ssi, ok := c.StateServingInfo()
if !ok {
return nil, false
}
addr := net.JoinHostPort("127.0.0.1", strconv.Itoa(ssi.StatePort))
return &state.Info{
return &authentication.ConnectionInfo{
Info: mongo.Info{
Addrs: []string{addr},
CACert: c.caCert,
Expand Down
4 changes: 2 additions & 2 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
gc "launchpad.net/gocheck"

"github.com/juju/juju/agent"
"github.com/juju/juju/environmentserver/authentication"
"github.com/juju/juju/mongo"
"github.com/juju/juju/network"
"github.com/juju/juju/state"
"github.com/juju/juju/state/api"
"github.com/juju/juju/state/api/params"
"github.com/juju/juju/testing"
Expand Down Expand Up @@ -499,7 +499,7 @@ func (*suite) TestSetPassword(c *gc.C) {
addr := fmt.Sprintf("127.0.0.1:%d", servingInfo.StatePort)
userTag, err := names.ParseTag(attrParams.Tag)
c.Assert(err, gc.IsNil)
expectStateInfo := &state.Info{
expectStateInfo := &authentication.ConnectionInfo{
Info: mongo.Info{
Addrs: []string{addr},
CACert: attrParams.CACert,
Expand Down
7 changes: 6 additions & 1 deletion agent/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import (
"github.com/juju/juju/version"
)

const (
// BootstrapNonce is used as a nonce for the state server machine.
BootstrapNonce = "user-admin:bootstrap"
)

// InitializeState should be called on the bootstrap machine's agent
// configuration. It uses that information to create the state server, dial the
// state server, and initialize it. It also generates a new password for the
Expand Down Expand Up @@ -164,7 +169,7 @@ func initBootstrapMachine(c ConfigSetter, st *state.State, cfg BootstrapMachineC
m, err := st.AddOneMachine(state.MachineTemplate{
Addresses: cfg.Addresses,
Series: version.Current.Series,
Nonce: state.BootstrapNonce,
Nonce: BootstrapNonce,
Constraints: cfg.Constraints,
InstanceId: cfg.InstanceId,
HardwareCharacteristics: cfg.Characteristics,
Expand Down
5 changes: 3 additions & 2 deletions agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/juju/juju/agent"
"github.com/juju/juju/constraints"
"github.com/juju/juju/environmentserver/authentication"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/instance"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (s *bootstrapSuite) TestInitializeState(c *gc.C) {
c.Assert(m.Id(), gc.Equals, "0")
c.Assert(m.Jobs(), gc.DeepEquals, []state.MachineJob{state.JobHostUnits})
c.Assert(m.Series(), gc.Equals, version.Current.Series)
c.Assert(m.CheckProvisioned(state.BootstrapNonce), jc.IsTrue)
c.Assert(m.CheckProvisioned(agent.BootstrapNonce), jc.IsTrue)
c.Assert(m.Addresses(), gc.DeepEquals, mcfg.Addresses)
gotConstraints, err := m.Constraints()
c.Assert(err, gc.IsNil)
Expand Down Expand Up @@ -231,7 +232,7 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
}

func (*bootstrapSuite) assertCanLogInAsAdmin(c *gc.C, password string) {
info := &state.Info{
info := &authentication.ConnectionInfo{
Info: mongo.Info{
Addrs: []string{gitjujutesting.MgoServer.Addr()},
CACert: testing.CACert,
Expand Down
22 changes: 0 additions & 22 deletions cmd/juju/debuglog.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"

"github.com/juju/cmd"
"github.com/juju/errors"
"github.com/juju/loggo"
"launchpad.net/gnuflag"

Expand Down Expand Up @@ -89,9 +88,6 @@ func (c *DebugLogCommand) Run(ctx *cmd.Context) (err error) {
defer client.Close()
debugLog, err := client.WatchDebugLog(c.params)
if err != nil {
if errors.IsNotSupported(err) {
return c.watchDebugLog1dot18(ctx)
}
return err
}
defer debugLog.Close()
Expand All @@ -102,21 +98,3 @@ func (c *DebugLogCommand) Run(ctx *cmd.Context) (err error) {
var runSSHCommand = func(sshCmd *SSHCommand, ctx *cmd.Context) error {
return sshCmd.Run(ctx)
}

// watchDebugLog1dot18 runs in case of an older API server and uses ssh
// but with server-side grep.
func (c *DebugLogCommand) watchDebugLog1dot18(ctx *cmd.Context) error {
ctx.Infof("Server does not support new stream log, falling back to tail")
ctx.Verbosef("filters are not supported with tail")
sshCmd := &SSHCommand{}
tailCmd := fmt.Sprintf("tail -n -%d -f %s", c.params.Backlog, DefaultLogLocation)
// If the api doesn't support WatchDebugLog, then it won't be running in
// HA either, so machine 0 is where it is all at.
args := []string{"0", tailCmd}
err := sshCmd.Init(args)
if err != nil {
return err
}
sshCmd.EnvName = c.EnvName
return runSSHCommand(sshCmd, ctx)
}
17 changes: 0 additions & 17 deletions cmd/juju/debuglog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
package main

import (
"fmt"
"io"
"io/ioutil"
"strings"

"github.com/juju/cmd"
"github.com/juju/errors"
"github.com/juju/loggo"
jc "github.com/juju/testing/checkers"
gc "launchpad.net/gocheck"
Expand Down Expand Up @@ -132,20 +129,6 @@ func (s *DebugLogSuite) TestLogOutput(c *gc.C) {
c.Assert(testing.Stdout(ctx), gc.Equals, "this is the log output")
}

func (s *DebugLogSuite) TestTailFallback(c *gc.C) {
s.PatchValue(&runSSHCommand, func(sshCmd *SSHCommand, ctx *cmd.Context) error {
fmt.Fprintf(ctx.Stdout, "%s", sshCmd.Args)
return nil
})
s.PatchValue(&getDebugLogAPI, func(_ *DebugLogCommand) (DebugLogAPI, error) {
return &fakeDebugLogAPI{err: errors.NotSupportedf("testing")}, nil
})
ctx, err := testing.RunCommand(c, envcmd.Wrap(&DebugLogCommand{}), "-n", "100")
c.Assert(err, gc.IsNil)
c.Check(testing.Stderr(ctx), gc.Equals, "Server does not support new stream log, falling back to tail\n")
c.Check(testing.Stdout(ctx), gc.Equals, "[tail -n -100 -f /var/log/juju/all-machines.log]")
}

func newFakeDebugLogAPI(log string) DebugLogAPI {
return &fakeDebugLogAPI{log: log}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/juju/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ func (s *DeploySuite) TestForceMachineNewContainer(c *gc.C) {
func (s *DeploySuite) TestForceMachineNotFound(c *gc.C) {
charmtesting.Charms.BundlePath(s.SeriesPath, "dummy")
err := runDeploy(c, "--to", "42", "local:dummy", "portlandia")
c.Assert(err, gc.ErrorMatches, `cannot assign unit "portlandia/0" to machine: machine 42 not found`)
_, err = s.State.Service("dummy")
c.Assert(err, gc.ErrorMatches, `service "dummy" not found`)
c.Assert(err, gc.ErrorMatches, `cannot deploy "portlandia" to machine 42: machine 42 not found`)
_, err = s.State.Service("portlandia")
c.Assert(err, gc.ErrorMatches, `service "portlandia" not found`)
}

func (s *DeploySuite) TestForceMachineSubordinate(c *gc.C) {
Expand Down
1 change: 1 addition & 0 deletions cmd/juju/user_change_password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"errors"
"fmt"

gc "launchpad.net/gocheck"

"github.com/juju/cmd"
Expand Down
9 changes: 5 additions & 4 deletions cmd/jujud/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/juju/juju/agent"
agenttools "github.com/juju/juju/agent/tools"
"github.com/juju/juju/environmentserver/authentication"
"github.com/juju/juju/environs"
envtesting "github.com/juju/juju/environs/testing"
envtools "github.com/juju/juju/environs/tools"
Expand Down Expand Up @@ -242,7 +243,7 @@ func (s *agentSuite) SetUpSuite(c *gc.C) {
// a bit when some tests are restarting every 50ms for 10 seconds,
// so use a slightly more friendly delay.
worker.RestartDelay = 250 * time.Millisecond
s.PatchValue(&ensureMongoServer, func(string, string, params.StateServingInfo) error {
s.PatchValue(&ensureMongoServer, func(mongo.EnsureServerParams) error {
return nil
})
}
Expand Down Expand Up @@ -272,7 +273,7 @@ func (s *agentSuite) primeAgent(c *gc.C, tag, password string, vers version.Bina
Tag: tag,
UpgradedToVersion: vers.Number,
Password: password,
Nonce: state.BootstrapNonce,
Nonce: agent.BootstrapNonce,
StateAddresses: stateInfo.Addrs,
APIAddresses: apiInfo.Addrs,
CACert: stateInfo.CACert,
Expand Down Expand Up @@ -309,7 +310,7 @@ func parseHostPort(s string) (network.HostPort, error) {
}

// writeStateAgentConfig creates and writes a state agent config.
func writeStateAgentConfig(c *gc.C, stateInfo *state.Info, dataDir, tag, password string, vers version.Binary) agent.ConfigSetterWriter {
func writeStateAgentConfig(c *gc.C, stateInfo *authentication.ConnectionInfo, dataDir, tag, password string, vers version.Binary) agent.ConfigSetterWriter {
port := gitjujutesting.FindTCPPort()
apiAddr := []string{fmt.Sprintf("localhost:%d", port)}
conf, err := agent.NewStateMachineConfig(
Expand All @@ -318,7 +319,7 @@ func writeStateAgentConfig(c *gc.C, stateInfo *state.Info, dataDir, tag, passwor
Tag: tag,
UpgradedToVersion: vers.Number,
Password: password,
Nonce: state.BootstrapNonce,
Nonce: agent.BootstrapNonce,
StateAddresses: stateInfo.Addrs,
APIAddresses: apiAddr,
CACert: stateInfo.CACert,
Expand Down
38 changes: 33 additions & 5 deletions cmd/jujud/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/base64"
"fmt"
"net"
"strconv"
"time"

"github.com/juju/cmd"
Expand Down Expand Up @@ -159,6 +160,33 @@ func (c *BootstrapCommand) Run(_ *cmd.Context) error {
return m.SetHasVote(true)
}

// newEnsureServerParams creates an EnsureServerParams from an agent configuration.
func newEnsureServerParams(agentConfig agent.Config) (mongo.EnsureServerParams, error) {
// If oplog size is specified in the agent configuration, use that.
// Otherwise leave the default zero value to indicate to EnsureServer
// that it should calculate the size.
var oplogSize int
if oplogSizeString := agentConfig.Value(agent.MongoOplogSize); oplogSizeString != "" {
var err error
if oplogSize, err = strconv.Atoi(oplogSizeString); err != nil {
return mongo.EnsureServerParams{}, fmt.Errorf("invalid oplog size: %q", oplogSizeString)
}
}

servingInfo, ok := agentConfig.StateServingInfo()
if !ok {
return mongo.EnsureServerParams{}, fmt.Errorf("agent config has no state serving info")
}

params := mongo.EnsureServerParams{
StateServingInfo: servingInfo,
DataDir: agentConfig.DataDir(),
Namespace: agentConfig.Value(agent.Namespace),
OplogSize: oplogSize,
}
return params, nil
}

func (c *BootstrapCommand) startMongo(addrs []network.Address, agentConfig agent.Config) error {
logger.Debugf("starting mongo")

Expand Down Expand Up @@ -186,11 +214,11 @@ func (c *BootstrapCommand) startMongo(addrs []network.Address, agentConfig agent
}

logger.Debugf("calling ensureMongoServer")
err = ensureMongoServer(
agentConfig.DataDir(),
agentConfig.Value(agent.Namespace),
servingInfo,
)
ensureServerParams, err := newEnsureServerParams(agentConfig)
if err != nil {
return err
}
err = ensureMongoServer(ensureServerParams)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 61c9e8a

Please sign in to comment.