Merge lp:~thumper/juju-core/environ-bootstrap into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1408
Proposed branch: lp:~thumper/juju-core/environ-bootstrap
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~thumper/juju-core/local-provider-storage
Diff against target: 202 lines (+92/-66)
2 files modified
cmd/jujud/bootstrap.go (+5/-66)
environs/bootstrap.go (+87/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/environ-bootstrap
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+173390@code.launchpad.net

Commit message

Move state initialization out of jujud bootstrap

Methods to configure the initial state connection and dealing
with passwords were inside the jujud bootstrap command, which
isn't going to be used by the local provider, so the functions
need to be extracted.

https://codereview.appspot.com/10990043/

Description of the change

Move state initialization out of jujud bootstrap

Methods to configure the initial state connection and dealing
with passwords were inside the jujud bootstrap command, which
isn't going to be used by the local provider, so the functions
need to be extracted.

https://codereview.appspot.com/10990043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+173390_code.launchpad.net,

Message:
Please take a look.

Description:
Move state initialization out of jujud bootstrap

Methods to configure the initial state connection and dealing
with passwords were inside the jujud bootstrap command, which
isn't going to be used by the local provider, so the functions
need to be extracted.

https://code.launchpad.net/~thumper/juju-core/environ-bootstrap/+merge/173390

Requires:
https://code.launchpad.net/~thumper/juju-core/local-provider-storage/+merge/173386

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M cmd/jujud/bootstrap.go
   M environs/bootstrap.go

Revision history for this message
Frank Mueller (themue) wrote :

LGTM, only one wish for a name change.

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go
File environs/bootstrap.go (right):

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go#newcode66
environs/bootstrap.go:66:
On 2013/07/08 01:55:38, dfc wrote:
> comment please

+1

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go#newcode67
environs/bootstrap.go:67: func BootstrapMongoUsers(st *state.State, cfg
*config.Config, passwordHash string) error {
Would prefer a technology independent name here:

- BootstrapUsers()
- BootstrapDatabaseUsers()
- BootstrapstateUsers()
- ...

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go#newcode89
environs/bootstrap.go:89:
On 2013/07/08 01:55:38, dfc wrote:
> comment please

+1

https://codereview.appspot.com/10990043/

Revision history for this message
Tim Penhey (thumper) wrote :

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go
File environs/bootstrap.go (right):

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go#newcode66
environs/bootstrap.go:66:
On 2013/07/08 08:44:14, mue wrote:
> On 2013/07/08 01:55:38, dfc wrote:
> > comment please

> +1

Done.

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go#newcode67
environs/bootstrap.go:67: func BootstrapMongoUsers(st *state.State, cfg
*config.Config, passwordHash string) error {
On 2013/07/08 08:44:14, mue wrote:
> Would prefer a technology independent name here:

> - BootstrapUsers()
> - BootstrapDatabaseUsers()
> - BootstrapstateUsers()
> - ...

BootstrapUsers it is.

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go#newcode68
environs/bootstrap.go:68: logger.Debugf("add admin user")
On 2013/07/08 01:55:38, dfc wrote:
> adding admin user

Done.

https://codereview.appspot.com/10990043/diff/1/environs/bootstrap.go#newcode89
environs/bootstrap.go:89:
On 2013/07/08 08:44:14, mue wrote:
> On 2013/07/08 01:55:38, dfc wrote:
> > comment please

> +1

Done.

https://codereview.appspot.com/10990043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/jujud/bootstrap.go'
2--- cmd/jujud/bootstrap.go 2013-06-21 15:35:28 +0000
3+++ cmd/jujud/bootstrap.go 2013-07-08 22:52:25 +0000
4@@ -11,11 +11,8 @@
5 "launchpad.net/juju-core/cmd"
6 "launchpad.net/juju-core/constraints"
7 "launchpad.net/juju-core/environs"
8- "launchpad.net/juju-core/environs/agent"
9 "launchpad.net/juju-core/environs/config"
10 "launchpad.net/juju-core/state"
11- "launchpad.net/juju-core/utils"
12- "launchpad.net/juju-core/version"
13 )
14
15 type BootstrapCommand struct {
16@@ -65,41 +62,10 @@
17 }
18 defer st.Close()
19
20- if err := st.SetEnvironConstraints(c.Constraints); err != nil {
21- return err
22- }
23- if err := c.configureBootstrapMachine(st, cfg); err != nil {
24- return err
25- }
26-
27- // Set up initial authentication.
28- u, err := st.AddUser("admin", "")
29- if err != nil {
30- return err
31- }
32-
33- // Note that at bootstrap time, the password is set to
34- // the hash of its actual value. The first time a client
35- // connects to mongo, it changes the mongo password
36- // to the original password.
37- if err := u.SetPasswordHash(c.Conf.OldPassword); err != nil {
38- return err
39- }
40- if err := st.SetAdminMongoPassword(c.Conf.OldPassword); err != nil {
41- return err
42- }
43- return nil
44-}
45-
46-func (c *BootstrapCommand) configureBootstrapMachine(st *state.State, cfg *config.Config) error {
47- provider, err := environs.Provider(cfg.Type())
48- if err != nil {
49- return err
50- }
51- instanceId, err := provider.InstanceId()
52- if err != nil {
53- return err
54- }
55+ if err := environs.BootstrapUsers(st, cfg, c.Conf.OldPassword); err != nil {
56+ return err
57+ }
58+
59 // TODO(fwereade): we need to be able to customize machine jobs,
60 // not just hardcode these values; in particular, JobHostUnits
61 // on a machine, like this one, that is running JobManageEnviron
62@@ -116,35 +82,8 @@
63 jobs := []state.MachineJob{
64 state.JobManageEnviron, state.JobManageState, state.JobHostUnits,
65 }
66- m, err := st.InjectMachine(version.Current.Series, c.Constraints, instanceId, jobs...)
67- if err != nil {
68- return err
69- }
70- // Read the machine agent's password and change it to
71- // a new password (other agents will change their password
72- // via the API connection).
73- mconf, err := agent.ReadConf(c.Conf.DataDir, m.Tag())
74- if err != nil {
75- return err
76- }
77- newPassword, err := utils.RandomPassword()
78- if err != nil {
79- return err
80- }
81- mconf.StateInfo.Password = newPassword
82- mconf.APIInfo.Password = newPassword
83- mconf.OldPassword = ""
84
85- if err := mconf.Write(); err != nil {
86- return err
87- }
88- if err := m.SetMongoPassword(newPassword); err != nil {
89- return err
90- }
91- if err := m.SetPassword(newPassword); err != nil {
92- return err
93- }
94- return nil
95+ return environs.ConfigureBootstrapMachine(st, cfg, c.Constraints, c.Conf.DataDir, jobs)
96 }
97
98 // yamlBase64Value implements gnuflag.Value on a map[string]interface{}.
99
100=== modified file 'environs/bootstrap.go'
101--- environs/bootstrap.go 2013-07-04 23:05:57 +0000
102+++ environs/bootstrap.go 2013-07-08 22:52:25 +0000
103@@ -7,8 +7,12 @@
104 "fmt"
105
106 "launchpad.net/juju-core/constraints"
107+ "launchpad.net/juju-core/environs/agent"
108+ "launchpad.net/juju-core/environs/config"
109 "launchpad.net/juju-core/errors"
110+ "launchpad.net/juju-core/state"
111 "launchpad.net/juju-core/utils"
112+ "launchpad.net/juju-core/version"
113 )
114
115 // Bootstrap bootstraps the given environment. The supplied constraints are
116@@ -59,3 +63,86 @@
117
118 return VerifyStorage(env.Storage())
119 }
120+
121+// BootstrapUsers creates the initial admin user for the database, and sets
122+// the initial password.
123+func BootstrapUsers(st *state.State, cfg *config.Config, passwordHash string) error {
124+ logger.Debugf("adding admin user")
125+ // Set up initial authentication.
126+ u, err := st.AddUser("admin", "")
127+ if err != nil {
128+ return err
129+ }
130+
131+ // Note that at bootstrap time, the password is set to
132+ // the hash of its actual value. The first time a client
133+ // connects to mongo, it changes the mongo password
134+ // to the original password.
135+ logger.Debugf("setting password hash for admin user")
136+ if err := u.SetPasswordHash(passwordHash); err != nil {
137+ return err
138+ }
139+ if err := st.SetAdminMongoPassword(passwordHash); err != nil {
140+ return err
141+ }
142+ return nil
143+
144+}
145+
146+// ConfigureBootstrapMachine adds the initial machine into state. As a part
147+// of this process the environmental constraints are saved as constraints used
148+// when bootstrapping are considered constraints for the entire environment.
149+func ConfigureBootstrapMachine(
150+ st *state.State,
151+ cfg *config.Config,
152+ cons constraints.Value,
153+ datadir string,
154+ jobs []state.MachineJob,
155+) error {
156+ logger.Debugf("setting environment constraints")
157+ if err := st.SetEnvironConstraints(cons); err != nil {
158+ return err
159+ }
160+
161+ logger.Debugf("configure bootstrap machine")
162+ provider, err := Provider(cfg.Type())
163+ if err != nil {
164+ return err
165+ }
166+ instanceId, err := provider.InstanceId()
167+ if err != nil {
168+ return err
169+ }
170+
171+ logger.Debugf("create bootstrap machine in state")
172+ m, err := st.InjectMachine(version.Current.Series, cons, instanceId, jobs...)
173+ if err != nil {
174+ return err
175+ }
176+ // Read the machine agent's password and change it to
177+ // a new password (other agents will change their password
178+ // via the API connection).
179+ logger.Debugf("create new random password for machine %v", m.Id())
180+ mconf, err := agent.ReadConf(datadir, m.Tag())
181+ if err != nil {
182+ return err
183+ }
184+ newPassword, err := utils.RandomPassword()
185+ if err != nil {
186+ return err
187+ }
188+ mconf.StateInfo.Password = newPassword
189+ mconf.APIInfo.Password = newPassword
190+ mconf.OldPassword = ""
191+
192+ if err := mconf.Write(); err != nil {
193+ return err
194+ }
195+ if err := m.SetMongoPassword(newPassword); err != nil {
196+ return err
197+ }
198+ if err := m.SetPassword(newPassword); err != nil {
199+ return err
200+ }
201+ return nil
202+}

Subscribers

People subscribed via source and target branches

to status/vote changes: