Merge lp:~axwalk/juju-core/lp1314430-bootstrap-machine-addresses-1.18 into lp:juju-core/1.18

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 2281
Proposed branch: lp:~axwalk/juju-core/lp1314430-bootstrap-machine-addresses-1.18
Merge into: lp:juju-core/1.18
Diff against target: 262 lines (+97/-17)
4 files modified
agent/bootstrap.go (+4/-0)
agent/bootstrap_test.go (+3/-0)
cmd/jujud/bootstrap.go (+17/-0)
cmd/jujud/bootstrap_test.go (+73/-17)
To merge this branch: bzr merge lp:~axwalk/juju-core/lp1314430-bootstrap-machine-addresses-1.18
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+217815@code.launchpad.net

Commit message

Set machine addresses during bootstrap

Fixes lp:1314430

https://codereview.appspot.com/99950043/

Description of the change

Set machine addresses during bootstrap

Fixes lp:1314430

https://codereview.appspot.com/99950043/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :

Reviewers: mp+217815_code.launchpad.net,

Message:
Please take a look.

Description:
Set machine addresses during bootstrap

Fixes lp:1314430

https://code.launchpad.net/~axwalk/juju-core/lp1314430-bootstrap-machine-addresses-1.18/+merge/217815

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/99950043/

Affected files (+99, -17 lines):
   A [revision details]
   M agent/bootstrap.go
   M agent/bootstrap_test.go
   M cmd/jujud/bootstrap.go
   M cmd/jujud/bootstrap_test.go

Revision history for this message
Martin Packman (gz) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'agent/bootstrap.go'
--- agent/bootstrap.go 2014-03-05 16:30:01 +0000
+++ agent/bootstrap.go 2014-04-30 19:29:23 +0000
@@ -35,6 +35,9 @@
35// BootstrapMachineConfig holds configuration information35// BootstrapMachineConfig holds configuration information
36// to attach to the bootstrap machine.36// to attach to the bootstrap machine.
37type BootstrapMachineConfig struct {37type BootstrapMachineConfig struct {
38 // Addresses holds the bootstrap machine's addresses.
39 Addresses []instance.Address
40
38 // Constraints holds the bootstrap machine's constraints.41 // Constraints holds the bootstrap machine's constraints.
39 // This value is also used for the environment-level constraints.42 // This value is also used for the environment-level constraints.
40 Constraints constraints.Value43 Constraints constraints.Value
@@ -132,6 +135,7 @@
132 jobs[i] = machineJob135 jobs[i] = machineJob
133 }136 }
134 m, err := st.AddOneMachine(state.MachineTemplate{137 m, err := st.AddOneMachine(state.MachineTemplate{
138 Addresses: cfg.Addresses,
135 Series: version.Current.Series,139 Series: version.Current.Series,
136 Nonce: state.BootstrapNonce,140 Nonce: state.BootstrapNonce,
137 Constraints: cfg.Constraints,141 Constraints: cfg.Constraints,
138142
=== modified file 'agent/bootstrap_test.go'
--- agent/bootstrap_test.go 2014-03-13 07:54:56 +0000
+++ agent/bootstrap_test.go 2014-04-30 19:29:23 +0000
@@ -63,6 +63,7 @@
63 expectConstraints := constraints.MustParse("mem=1024M")63 expectConstraints := constraints.MustParse("mem=1024M")
64 expectHW := instance.MustParseHardware("mem=2048M")64 expectHW := instance.MustParseHardware("mem=2048M")
65 mcfg := agent.BootstrapMachineConfig{65 mcfg := agent.BootstrapMachineConfig{
66 Addresses: instance.NewAddresses([]string{"testing.invalid", "0.1.2.3"}),
66 Constraints: expectConstraints,67 Constraints: expectConstraints,
67 Jobs: []params.MachineJob{params.JobHostUnits},68 Jobs: []params.MachineJob{params.JobHostUnits},
68 InstanceId: "i-bootstrap",69 InstanceId: "i-bootstrap",
@@ -101,6 +102,8 @@
101 gotHW, err := m.HardwareCharacteristics()102 gotHW, err := m.HardwareCharacteristics()
102 c.Assert(err, gc.IsNil)103 c.Assert(err, gc.IsNil)
103 c.Assert(*gotHW, gc.DeepEquals, expectHW)104 c.Assert(*gotHW, gc.DeepEquals, expectHW)
105 gotAddrs := m.Addresses()
106 c.Assert(gotAddrs, gc.DeepEquals, mcfg.Addresses)
104107
105 // Check that the machine agent's config has been written108 // Check that the machine agent's config has been written
106 // and that we can use it to connect to the state.109 // and that we can use it to connect to the state.
107110
=== modified file 'cmd/jujud/bootstrap.go'
--- cmd/jujud/bootstrap.go 2014-03-24 03:15:34 +0000
+++ cmd/jujud/bootstrap.go 2014-04-30 19:29:23 +0000
@@ -65,6 +65,22 @@
65 if err := c.Conf.read("machine-0"); err != nil {65 if err := c.Conf.read("machine-0"); err != nil {
66 return err66 return err
67 }67 }
68
69 // Get the bootstrap machine's addresses from the provider.
70 env, err := environs.New(envCfg)
71 if err != nil {
72 return err
73 }
74 instanceId := instance.Id(c.InstanceId)
75 instances, err := env.Instances([]instance.Id{instanceId})
76 if err != nil {
77 return err
78 }
79 addrs, err := instances[0].Addresses()
80 if err != nil {
81 return err
82 }
83
68 // agent.Jobs is an optional field in the agent config, and was84 // agent.Jobs is an optional field in the agent config, and was
69 // introduced after 1.17.2. We default to allowing units on85 // introduced after 1.17.2. We default to allowing units on
70 // machine-0 if missing.86 // machine-0 if missing.
@@ -76,6 +92,7 @@
76 }92 }
77 }93 }
78 st, _, err := c.Conf.config.InitializeState(envCfg, agent.BootstrapMachineConfig{94 st, _, err := c.Conf.config.InitializeState(envCfg, agent.BootstrapMachineConfig{
95 Addresses: addrs,
79 Constraints: c.Constraints,96 Constraints: c.Constraints,
80 Jobs: jobs,97 Jobs: jobs,
81 InstanceId: instance.Id(c.InstanceId),98 InstanceId: instance.Id(c.InstanceId),
8299
=== modified file 'cmd/jujud/bootstrap_test.go'
--- cmd/jujud/bootstrap_test.go 2014-03-21 14:39:23 +0000
+++ cmd/jujud/bootstrap_test.go 2014-04-30 19:29:23 +0000
@@ -5,16 +5,22 @@
55
6import (6import (
7 "encoding/base64"7 "encoding/base64"
8 "io"
9 "io/ioutil"
810
9 jc "github.com/juju/testing/checkers"11 jc "github.com/juju/testing/checkers"
10 gc "launchpad.net/gocheck"12 gc "launchpad.net/gocheck"
11 "launchpad.net/goyaml"13 "launchpad.net/goyaml"
1214
13 "launchpad.net/juju-core/agent"15 "launchpad.net/juju-core/agent"
16 "launchpad.net/juju-core/cmd"
14 "launchpad.net/juju-core/constraints"17 "launchpad.net/juju-core/constraints"
15 "launchpad.net/juju-core/environs"18 "launchpad.net/juju-core/environs"
19 "launchpad.net/juju-core/environs/config"
20 envtesting "launchpad.net/juju-core/environs/testing"
16 "launchpad.net/juju-core/errors"21 "launchpad.net/juju-core/errors"
17 "launchpad.net/juju-core/instance"22 "launchpad.net/juju-core/instance"
23 jujutesting "launchpad.net/juju-core/juju/testing"
18 "launchpad.net/juju-core/provider/dummy"24 "launchpad.net/juju-core/provider/dummy"
19 "launchpad.net/juju-core/state"25 "launchpad.net/juju-core/state"
20 "launchpad.net/juju-core/state/api/params"26 "launchpad.net/juju-core/state/api/params"
@@ -29,8 +35,11 @@
29type BootstrapSuite struct {35type BootstrapSuite struct {
30 testbase.LoggingSuite36 testbase.LoggingSuite
31 testing.MgoSuite37 testing.MgoSuite
32 dataDir string38 envcfg string
33 logDir string39 instance instance.Instance
40 dataDir string
41 logDir string
42 bootstrapName string
34}43}
3544
36var _ = gc.Suite(&BootstrapSuite{})45var _ = gc.Suite(&BootstrapSuite{})
@@ -38,11 +47,13 @@
38func (s *BootstrapSuite) SetUpSuite(c *gc.C) {47func (s *BootstrapSuite) SetUpSuite(c *gc.C) {
39 s.LoggingSuite.SetUpSuite(c)48 s.LoggingSuite.SetUpSuite(c)
40 s.MgoSuite.SetUpSuite(c)49 s.MgoSuite.SetUpSuite(c)
50 s.makeTestEnv(c)
41}51}
4252
43func (s *BootstrapSuite) TearDownSuite(c *gc.C) {53func (s *BootstrapSuite) TearDownSuite(c *gc.C) {
44 s.MgoSuite.TearDownSuite(c)54 s.MgoSuite.TearDownSuite(c)
45 s.LoggingSuite.TearDownSuite(c)55 s.LoggingSuite.TearDownSuite(c)
56 dummy.Reset()
46}57}
4758
48func (s *BootstrapSuite) SetUpTest(c *gc.C) {59func (s *BootstrapSuite) SetUpTest(c *gc.C) {
@@ -102,7 +113,7 @@
102113
103func (s *BootstrapSuite) TestInitializeEnvironment(c *gc.C) {114func (s *BootstrapSuite) TestInitializeEnvironment(c *gc.C) {
104 hw := instance.MustParseHardware("arch=amd64 mem=8G")115 hw := instance.MustParseHardware("arch=amd64 mem=8G")
105 _, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", testConfig, "--instance-id", "anything", "--hardware", hw.String())116 _, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instance.Id()), "--hardware", hw.String())
106 c.Assert(err, gc.IsNil)117 c.Assert(err, gc.IsNil)
107 err = cmd.Run(nil)118 err = cmd.Run(nil)
108 c.Assert(err, gc.IsNil)119 c.Assert(err, gc.IsNil)
@@ -120,7 +131,7 @@
120131
121 instid, err := machines[0].InstanceId()132 instid, err := machines[0].InstanceId()
122 c.Assert(err, gc.IsNil)133 c.Assert(err, gc.IsNil)
123 c.Assert(instid, gc.Equals, instance.Id("anything"))134 c.Assert(instid, gc.Equals, s.instance.Id())
124135
125 stateHw, err := machines[0].HardwareCharacteristics()136 stateHw, err := machines[0].HardwareCharacteristics()
126 c.Assert(err, gc.IsNil)137 c.Assert(err, gc.IsNil)
@@ -135,8 +146,8 @@
135func (s *BootstrapSuite) TestSetConstraints(c *gc.C) {146func (s *BootstrapSuite) TestSetConstraints(c *gc.C) {
136 tcons := constraints.Value{Mem: uint64p(2048), CpuCores: uint64p(2)}147 tcons := constraints.Value{Mem: uint64p(2048), CpuCores: uint64p(2)}
137 _, cmd, err := s.initBootstrapCommand(c, nil,148 _, cmd, err := s.initBootstrapCommand(c, nil,
138 "--env-config", testConfig,149 "--env-config", s.envcfg,
139 "--instance-id", "anything",150 "--instance-id", string(s.instance.Id()),
140 "--constraints", tcons.String(),151 "--constraints", tcons.String(),
141 )152 )
142 c.Assert(err, gc.IsNil)153 c.Assert(err, gc.IsNil)
@@ -170,7 +181,7 @@
170 expectedJobs := []state.MachineJob{181 expectedJobs := []state.MachineJob{
171 state.JobManageEnviron, state.JobHostUnits,182 state.JobManageEnviron, state.JobHostUnits,
172 }183 }
173 _, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", testConfig, "--instance-id", "anything")184 _, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instance.Id()))
174 c.Assert(err, gc.IsNil)185 c.Assert(err, gc.IsNil)
175 err = cmd.Run(nil)186 err = cmd.Run(nil)
176 c.Assert(err, gc.IsNil)187 c.Assert(err, gc.IsNil)
@@ -187,9 +198,31 @@
187 c.Assert(m.Jobs(), gc.DeepEquals, expectedJobs)198 c.Assert(m.Jobs(), gc.DeepEquals, expectedJobs)
188}199}
189200
201func (s *BootstrapSuite) TestMachineAddresses(c *gc.C) {
202 addrs := instance.NewAddresses([]string{"testing.invalid", "0.1.2.3"})
203 dummy.SetInstanceAddresses(s.instance, addrs)
204
205 _, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instance.Id()))
206 c.Assert(err, gc.IsNil)
207 err = cmd.Run(nil)
208 c.Assert(err, gc.IsNil)
209
210 st, err := state.Open(&state.Info{
211 Addrs: []string{testing.MgoServer.Addr()},
212 CACert: []byte(testing.CACert),
213 Password: testPasswordHash(),
214 }, state.DefaultDialOpts(), environs.NewStatePolicy())
215 c.Assert(err, gc.IsNil)
216 defer st.Close()
217
218 m, err := st.Machine("0")
219 c.Assert(err, gc.IsNil)
220 c.Assert(m.Addresses(), gc.DeepEquals, addrs)
221}
222
190func (s *BootstrapSuite) TestConfiguredMachineJobs(c *gc.C) {223func (s *BootstrapSuite) TestConfiguredMachineJobs(c *gc.C) {
191 jobs := []params.MachineJob{params.JobManageEnviron}224 jobs := []params.MachineJob{params.JobManageEnviron}
192 _, cmd, err := s.initBootstrapCommand(c, jobs, "--env-config", testConfig, "--instance-id", "anything")225 _, cmd, err := s.initBootstrapCommand(c, jobs, "--env-config", s.envcfg, "--instance-id", string(s.instance.Id()))
193 c.Assert(err, gc.IsNil)226 c.Assert(err, gc.IsNil)
194 err = cmd.Run(nil)227 err = cmd.Run(nil)
195 c.Assert(err, gc.IsNil)228 c.Assert(err, gc.IsNil)
@@ -219,7 +252,7 @@
219}252}
220253
221func (s *BootstrapSuite) TestInitialPassword(c *gc.C) {254func (s *BootstrapSuite) TestInitialPassword(c *gc.C) {
222 machineConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", testConfig, "--instance-id", "anything")255 machineConf, cmd, err := s.initBootstrapCommand(c, nil, "--env-config", s.envcfg, "--instance-id", string(s.instance.Id()))
223 c.Assert(err, gc.IsNil)256 c.Assert(err, gc.IsNil)
224257
225 err = cmd.Run(nil)258 err = cmd.Run(nil)
@@ -333,6 +366,37 @@
333 }366 }
334}367}
335368
369func (s *BootstrapSuite) makeTestEnv(c *gc.C) {
370 attrs := dummy.SampleConfig().Merge(
371 testing.Attrs{
372 "agent-version": version.Current.Number.String(),
373 },
374 ).Delete("admin-secret", "ca-private-key")
375
376 cfg, err := config.New(config.NoDefaults, attrs)
377 c.Assert(err, gc.IsNil)
378 provider, err := environs.Provider(cfg.Type())
379 c.Assert(err, gc.IsNil)
380 env, err := provider.Prepare(nullContext(), cfg)
381 c.Assert(err, gc.IsNil)
382
383 envtesting.MustUploadFakeTools(env.Storage())
384 inst, _, err := jujutesting.StartInstance(env, "0")
385 c.Assert(err, gc.IsNil)
386 s.instance = inst
387 s.bootstrapName, err = inst.DNSName()
388 c.Assert(err, gc.IsNil)
389 s.envcfg = b64yaml(env.Config().AllAttrs()).encode()
390}
391
392func nullContext() *cmd.Context {
393 ctx, _ := cmd.DefaultContext()
394 ctx.Stdin = io.LimitReader(nil, 0)
395 ctx.Stdout = ioutil.Discard
396 ctx.Stderr = ioutil.Discard
397 return ctx
398}
399
336type b64yaml map[string]interface{}400type b64yaml map[string]interface{}
337401
338func (m b64yaml) encode() string {402func (m b64yaml) encode() string {
@@ -342,11 +406,3 @@
342 }406 }
343 return base64.StdEncoding.EncodeToString(data)407 return base64.StdEncoding.EncodeToString(data)
344}408}
345
346var testConfig = b64yaml(
347 dummy.SampleConfig().Merge(
348 testing.Attrs{
349 "state-server": false,
350 "agent-version": "3.4.5",
351 },
352 ).Delete("admin-secret", "ca-private-key")).encode()

Subscribers

People subscribed via source and target branches

to all changes: