Skip to content

Commit

Permalink
Merge branch 'master' into merge-master-0204
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Feb 4, 2016
2 parents 7d2e6c8 + 3828fbe commit 713e771
Show file tree
Hide file tree
Showing 215 changed files with 1,459 additions and 1,680 deletions.
58 changes: 11 additions & 47 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/juju/errors"
"github.com/juju/loggo"
Expand Down Expand Up @@ -161,7 +160,7 @@ const (
AgentServiceName = "AGENT_SERVICE_NAME"
MongoOplogSize = "MONGO_OPLOG_SIZE"
NumaCtlPreference = "NUMA_CTL_PREFERENCE"
AllowsSecureConnection = "SECURE_STATESERVER_CONNECTION"
AllowsSecureConnection = "SECURE_CONTROLLER_CONNECTION"
)

// The Config interface is the sole way that the agent gets access to the
Expand Down Expand Up @@ -214,15 +213,15 @@ type Config interface {
WriteCommands(renderer shell.Renderer) ([]string, error)

// StateServingInfo returns the details needed to run
// a state server and reports whether those details
// a controller and reports whether those details
// are available
StateServingInfo() (params.StateServingInfo, bool)

// APIInfo returns details for connecting to the API server and
// reports whether the details are available.
APIInfo() (*api.Info, bool)

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

Expand Down Expand Up @@ -292,7 +291,7 @@ type configSetterOnly interface {
Migrate(MigrateParams) error

// SetStateServingInfo sets the information needed
// to run a state server
// to run a controller
SetStateServingInfo(info params.StateServingInfo)
}

Expand Down Expand Up @@ -443,13 +442,13 @@ func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)
}

// NewStateMachineConfig returns a configuration suitable for
// a machine running the state server.
// a machine running the controller.
func NewStateMachineConfig(configParams AgentConfigParams, serverInfo params.StateServingInfo) (ConfigSetterWriter, error) {
if serverInfo.Cert == "" {
return nil, errors.Trace(requiredError("state server cert"))
return nil, errors.Trace(requiredError("controller cert"))
}
if serverInfo.PrivateKey == "" {
return nil, errors.Trace(requiredError("state server key"))
return nil, errors.Trace(requiredError("controller key"))
}
if serverInfo.CAPrivateKey == "" {
return nil, errors.Trace(requiredError("ca cert key"))
Expand Down Expand Up @@ -500,47 +499,12 @@ func ReadConfig(configFilePath string) (ConfigSetterWriter, error) {
if err != nil {
return nil, fmt.Errorf("cannot read agent config %q: %v", configFilePath, err)
}

// Try to read the legacy format file.
dir := filepath.Dir(configFilePath)
legacyFormatPath := filepath.Join(dir, legacyFormatFilename)
formatBytes, err := ioutil.ReadFile(legacyFormatPath)
if err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("cannot read format file: %v", err)
}
formatData := string(formatBytes)
if err == nil {
// It exists, so unmarshal with a legacy formatter.
// Drop the format prefix to leave the version only.
if !strings.HasPrefix(formatData, legacyFormatPrefix) {
return nil, fmt.Errorf("malformed agent config format %q", formatData)
}
format, err = getFormatter(strings.TrimPrefix(formatData, legacyFormatPrefix))
if err != nil {
return nil, err
}
config, err = format.unmarshal(configData)
} else {
// Does not exist, just parse the data.
format, config, err = parseConfigData(configData)
}
format, config, err = parseConfigData(configData)
if err != nil {
return nil, err
}
logger.Debugf("read agent config, format %q", format.version())
config.configFilePath = configFilePath
if format != currentFormat {
// Migrate from a legacy format to the new one.
err := config.Write()
if err != nil {
return nil, fmt.Errorf("cannot migrate %s agent config to %s: %v", format.version(), currentFormat.version(), err)
}
logger.Debugf("migrated agent config from %s to %s", format.version(), currentFormat.version())
err = os.Remove(legacyFormatPath)
if err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("cannot remove legacy format file %q: %v", legacyFormatPath, err)
}
}
return config, nil
}

Expand Down Expand Up @@ -720,7 +684,7 @@ func (c *configInternal) check() error {
return errors.Trace(requiredError("state or API addresses"))
}
if c.stateDetails != nil {
if err := checkAddrs(c.stateDetails.addresses, "state server address"); err != nil {
if err := checkAddrs(c.stateDetails.addresses, "controller address"); err != nil {
return err
}
}
Expand Down Expand Up @@ -775,9 +739,9 @@ func (c *configInternal) APIInfo() (*api.Info, bool) {
if c.apiDetails == nil || c.apiDetails.addresses == nil {
return nil, false
}
servingInfo, isStateServer := c.StateServingInfo()
servingInfo, isController := c.StateServingInfo()
addrs := c.apiDetails.addresses
if isStateServer {
if isController {
port := servingInfo.APIPort
localAPIAddr := net.JoinHostPort("localhost", strconv.Itoa(port))
if c.preferIPv6 {
Expand Down
10 changes: 5 additions & 5 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var agentConfigTests = []struct {
Model: testing.ModelTag,
StateAddresses: []string{"localhost:8080", "bad-address"},
},
checkErr: `invalid state server address "bad-address"`,
checkErr: `invalid controller address "bad-address"`,
}, {
about: "invalid api address",
params: agent.AgentConfigParams{
Expand Down Expand Up @@ -445,14 +445,14 @@ func (*suite) TestNewStateMachineConfig(c *gc.C) {
inspectConfig func(*gc.C, agent.Config)
}
var tests = []testStruct{{
about: "missing state server cert",
checkErr: "state server cert not found in configuration",
about: "missing controller cert",
checkErr: "controller cert not found in configuration",
}, {
about: "missing state server key",
about: "missing controller key",
servingInfo: params.StateServingInfo{
Cert: "server cert",
},
checkErr: "state server key not found in configuration",
checkErr: "controller key not found in configuration",
}, {
about: "missing ca cert key",
servingInfo: params.StateServingInfo{
Expand Down
8 changes: 4 additions & 4 deletions agent/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

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

Expand Down Expand Up @@ -54,14 +54,14 @@ type BootstrapMachineConfig struct {
const BootstrapMachineId = "0"

// 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
// configuration. It uses that information to create the controller, dial the
// controller, and initialize it. It also generates a new password for the
// bootstrap machine and calls Write to save the the configuration.
//
// The envCfg values will be stored in the state's ModelConfig; the
// machineCfg values will be used to configure the bootstrap Machine,
// and its constraints will be also be used for the model-level
// constraints. The connection to the state server will respect the
// constraints. The connection to the controller will respect the
// given timeout parameter.
//
// InitializeState returns the newly initialized state and bootstrap
Expand Down
144 changes: 0 additions & 144 deletions agent/format-1.16.go

This file was deleted.

Loading

0 comments on commit 713e771

Please sign in to comment.