Skip to content

Commit

Permalink
Merge branch 'develop' into state-controller-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
axw committed Nov 16, 2017
2 parents 44d020f + 93f6f62 commit 1616de8
Show file tree
Hide file tree
Showing 88 changed files with 1,707 additions and 739 deletions.
19 changes: 19 additions & 0 deletions acceptancetests/assess_model_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def deploy_simple_server_to_new_model(
# Need to wait for the subordinate charms too.
new_model.wait_for(AllApplicationActive())
new_model.wait_for(AllApplicationWorkloads())
new_model.wait_for(AllAgentsIdle())
assert_deployed_charm_is_responding(new_model, resource_contents)

return new_model, application
Expand Down Expand Up @@ -430,6 +431,24 @@ def do_raise(self, model_name, status):
'Timed out waiting for all application workloads to be active.')


class AllAgentsIdle(BaseCondition):
"""Ensure all agents are finished doing setup work."""

def iter_blocking_state(self, status):
idles = []
for name, unit in status.iter_units():
try:
state = unit['juju-status']['current'] == 'idle'
except KeyError:
state = False
idles.append(state)
if not all(idles):
yield 'application-agents', 'not-all-idle'

def do_raise(self, model_name, status):
raise Exception("Timed out waiting for all agents to be idle.")


def deploy_dummy_source_to_new_model(client, model_name):
new_model_client = client.add_model(client.env.clone(model_name))
charm_path = local_charm_path(
Expand Down
36 changes: 13 additions & 23 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ type ConfigSetterWriter interface {
// Ensure that the configInternal struct implements the Config interface.
var _ Config = (*configInternal)(nil)

type connectionDetails struct {
type apiDetails struct {
addresses []string
password string
}

func (d *connectionDetails) clone() *connectionDetails {
func (d *apiDetails) clone() *apiDetails {
if d == nil {
return nil
}
Expand All @@ -369,8 +369,8 @@ type configInternal struct {
jobs []multiwatcher.MachineJob
upgradedToVersion version.Number
caCert string
stateDetails *connectionDetails
apiDetails *connectionDetails
apiDetails *apiDetails
statePassword string
oldPassword string
servingInfo *params.StateServingInfo
loggingConfig string
Expand All @@ -390,7 +390,6 @@ type AgentConfigParams struct {
Nonce string
Controller names.ControllerTag
Model names.ModelTag
StateAddresses []string
APIAddresses []string
CACert string
Values map[string]string
Expand Down Expand Up @@ -452,14 +451,8 @@ func NewAgentConfig(configParams AgentConfigParams) (ConfigSetterWriter, error)
mongoVersion: configParams.MongoVersion.String(),
mongoMemoryProfile: configParams.MongoMemoryProfile.String(),
}

if len(configParams.StateAddresses) > 0 {
config.stateDetails = &connectionDetails{
addresses: configParams.StateAddresses,
}
}
if len(configParams.APIAddresses) > 0 {
config.apiDetails = &connectionDetails{
config.apiDetails = &apiDetails{
addresses: configParams.APIAddresses,
}
}
Expand Down Expand Up @@ -544,7 +537,6 @@ func (c0 *configInternal) Clone() Config {
c1 := *c0
// Deep copy only fields which may be affected
// by ConfigSetter methods.
c1.stateDetails = c0.stateDetails.clone()
c1.apiDetails = c0.apiDetails.clone()
c1.jobs = append([]multiwatcher.MachineJob{}, c0.jobs...)
c1.values = make(map[string]string, len(c0.values))
Expand Down Expand Up @@ -602,8 +594,8 @@ func (c *configInternal) SetOldPassword(oldPassword string) {
}

func (c *configInternal) SetPassword(newPassword string) {
if c.stateDetails != nil {
c.stateDetails.password = newPassword
if c.servingInfo != nil {
c.statePassword = newPassword
}
if c.apiDetails != nil {
c.apiDetails.password = newPassword
Expand Down Expand Up @@ -676,6 +668,9 @@ func (c *configInternal) StateServingInfo() (params.StateServingInfo, bool) {

func (c *configInternal) SetStateServingInfo(info params.StateServingInfo) {
c.servingInfo = &info
if c.statePassword == "" && c.apiDetails != nil {
c.statePassword = c.apiDetails.password
}
}

func (c *configInternal) APIAddresses() ([]string, error) {
Expand Down Expand Up @@ -706,13 +701,8 @@ func (c *configInternal) Dir() string {
}

func (c *configInternal) check() error {
if c.stateDetails == nil && c.apiDetails == nil {
return errors.Trace(requiredError("state or API addresses"))
}
if c.stateDetails != nil {
if err := checkAddrs(c.stateDetails.addresses, "controller address"); err != nil {
return err
}
if c.apiDetails == nil {
return errors.Trace(requiredError("API addresses"))
}
if c.apiDetails != nil {
if err := checkAddrs(c.apiDetails.addresses, "API server address"); err != nil {
Expand Down Expand Up @@ -834,7 +824,7 @@ func (c *configInternal) MongoInfo() (info *mongo.MongoInfo, ok bool) {
Addrs: []string{addr},
CACert: c.caCert,
},
Password: c.stateDetails.password,
Password: c.statePassword,
Tag: c.tag,
}, true
}
68 changes: 22 additions & 46 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var agentConfigTests = []struct {
},
checkErr: "CA certificate not found in configuration",
}, {
about: "need either state or api addresses",
about: "need api addresses",
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
Expand All @@ -121,20 +121,7 @@ var agentConfigTests = []struct {
Controller: testing.ControllerTag,
Model: testing.ModelTag,
},
checkErr: "state or API addresses not found in configuration",
}, {
about: "invalid state address",
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: jujuversion.Current,
Password: "sekrit",
CACert: "ca cert",
Controller: testing.ControllerTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:8080", "bad-address"},
},
checkErr: `invalid controller address "bad-address"`,
checkErr: "API addresses not found in configuration",
}, {
about: "invalid api address",
params: agent.AgentConfigParams{
Expand All @@ -148,18 +135,6 @@ var agentConfigTests = []struct {
APIAddresses: []string{"localhost:8080", "bad-address"},
},
checkErr: `invalid API server address "bad-address"`,
}, {
about: "good state addresses",
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: jujuversion.Current,
Password: "sekrit",
CACert: "ca cert",
Controller: testing.ControllerTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
},
}, {
about: "good api addresses",
params: agent.AgentConfigParams{
Expand All @@ -172,19 +147,6 @@ var agentConfigTests = []struct {
Model: testing.ModelTag,
APIAddresses: []string{"localhost:1234"},
},
}, {
about: "both state and api addresses",
params: agent.AgentConfigParams{
Paths: agent.Paths{DataDir: "/data/dir"},
Tag: names.NewMachineTag("1"),
UpgradedToVersion: jujuversion.Current,
Password: "sekrit",
CACert: "ca cert",
Controller: testing.ControllerTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
},
}, {
about: "everything...",
params: agent.AgentConfigParams{
Expand All @@ -195,7 +157,6 @@ var agentConfigTests = []struct {
CACert: "ca cert",
Controller: testing.ControllerTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
},
Expand All @@ -209,7 +170,6 @@ var agentConfigTests = []struct {
CACert: "ca cert",
Controller: testing.ControllerTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
},
Expand All @@ -226,7 +186,6 @@ var agentConfigTests = []struct {
CACert: "ca cert",
Controller: testing.ControllerTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
},
Expand All @@ -246,7 +205,6 @@ var agentConfigTests = []struct {
CACert: "ca cert",
Controller: testing.ControllerTag,
Model: testing.ModelTag,
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
},
Expand All @@ -272,7 +230,6 @@ var agentConfigTests = []struct {
Controller: testing.ControllerTag,
Model: testing.ModelTag,
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
},
inspectConfig: func(c *gc.C, cfg agent.Config) {
Expand Down Expand Up @@ -380,7 +337,6 @@ var attributeParams = agent.AgentConfigParams{
UpgradedToVersion: jujuversion.Current,
Password: "sekrit",
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Controller: testing.ControllerTag,
Expand Down Expand Up @@ -496,6 +452,26 @@ func (*suite) TestMongoInfo(c *gc.C) {
c.Check(mongoInfo.Info.DisableTLS, jc.IsFalse)
}

func (*suite) TestPromotedMongoInfo(c *gc.C) {
attrParams := attributeParams
conf, err := agent.NewAgentConfig(attrParams)
c.Assert(err, jc.ErrorIsNil)

mongoInfo, ok := conf.MongoInfo()
c.Assert(ok, jc.IsFalse)

// Promote the agent to a controller by
// setting state serving info. As soon
// as this is done, we should be able
// to use MongoInfo.
conf.SetStateServingInfo(stateServingInfo())

mongoInfo, ok = conf.MongoInfo()
c.Assert(ok, jc.IsTrue)
c.Check(mongoInfo.Info.Addrs, jc.DeepEquals, []string{"localhost:69"})
c.Check(mongoInfo.Info.DisableTLS, jc.IsFalse)
}

func (*suite) TestAPIInfoDoesntAddLocalhostWhenNoServingInfo(c *gc.C) {
attrParams := attributeParams
conf, err := agent.NewAgentConfig(attrParams)
Expand Down
6 changes: 3 additions & 3 deletions agent/agentbootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ LXC_BRIDGE="ignored"`[1:])
Paths: agent.Paths{DataDir: dataDir},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: jujuversion.Current,
StateAddresses: []string{s.mgoInst.Addr()},
APIAddresses: []string{"localhost:17070"},
CACert: testing.CACert,
Password: testing.DefaultMongoPassword,
Controller: testing.ControllerTag,
Expand Down Expand Up @@ -345,7 +345,7 @@ func (s *bootstrapSuite) TestInitializeStateWithStateServingInfoNotAvailable(c *
Paths: agent.Paths{DataDir: c.MkDir()},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: jujuversion.Current,
StateAddresses: []string{s.mgoInst.Addr()},
APIAddresses: []string{"localhost:17070"},
CACert: testing.CACert,
Password: "fake",
Controller: testing.ControllerTag,
Expand All @@ -372,7 +372,7 @@ func (s *bootstrapSuite) TestInitializeStateFailsSecondTime(c *gc.C) {
Paths: agent.Paths{DataDir: dataDir},
Tag: names.NewMachineTag("0"),
UpgradedToVersion: jujuversion.Current,
StateAddresses: []string{s.mgoInst.Addr()},
APIAddresses: []string{"localhost:17070"},
CACert: testing.CACert,
Password: testing.DefaultMongoPassword,
Controller: testing.ControllerTag,
Expand Down
22 changes: 5 additions & 17 deletions agent/format-2.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,13 @@ func (formatter_2_0) unmarshal(data []byte) (*configInternal, error) {
controller: controllerTag,
model: modelTag,
caCert: format.CACert,
statePassword: format.StatePassword,
oldPassword: format.OldPassword,
loggingConfig: format.LoggingConfig,
values: format.Values,
}
if len(format.StateAddresses) > 0 {
config.stateDetails = &connectionDetails{
format.StateAddresses,
format.StatePassword,
}
}
if len(format.APIAddresses) > 0 {
config.apiDetails = &connectionDetails{
config.apiDetails = &apiDetails{
format.APIAddresses,
format.APIPassword,
}
Expand Down Expand Up @@ -186,18 +181,11 @@ func (formatter_2_0) marshal(config *configInternal) ([]byte, error) {
format.StatePort = config.servingInfo.StatePort
format.SharedSecret = config.servingInfo.SharedSecret
format.SystemIdentity = config.servingInfo.SystemIdentity
}
if config.stateDetails != nil {
if len(config.stateDetails.addresses) > 0 {
format.StateAddresses = config.stateDetails.addresses
format.StatePassword = config.stateDetails.password
}
format.StatePassword = config.statePassword
}
if config.apiDetails != nil {
if len(config.apiDetails.addresses) > 0 {
format.APIAddresses = config.apiDetails.addresses
format.APIPassword = config.apiDetails.password
}
format.APIAddresses = config.apiDetails.addresses
format.APIPassword = config.apiDetails.password
}
if config.mongoVersion != "" {
format.MongoVersion = string(config.mongoVersion)
Expand Down
1 change: 0 additions & 1 deletion agent/format_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var agentParams = AgentConfigParams{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
Password: "sekrit",
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Model: testing.ModelTag,
Expand Down
1 change: 0 additions & 1 deletion agent/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var attributeParams = AgentConfigParams{
UpgradedToVersion: jujuversion.Current,
Password: "sekrit",
CACert: "ca cert",
StateAddresses: []string{"localhost:1234"},
APIAddresses: []string{"localhost:1235"},
Nonce: "a nonce",
Controller: testing.ControllerTag,
Expand Down
6 changes: 1 addition & 5 deletions apiserver/common/modelmanagerinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ func (st modelManagerStateShim) GetModel(modelUUID string) (Model, func() bool,

// Model implements ModelManagerBackend.
func (st modelManagerStateShim) Model() (Model, error) {
m, err := st.State.Model()
if err != nil {
return nil, err
}
return modelShim{m}, nil
return modelShim{st.model}, nil
}

var _ Model = (*modelShim)(nil)
Expand Down
Loading

0 comments on commit 1616de8

Please sign in to comment.