Merge lp:~thumper/juju-core/provisioner-auth-provider 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: 1331
Proposed branch: lp:~thumper/juju-core/provisioner-auth-provider
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~thumper/juju-core/lxc-broker
Diff against target: 191 lines (+65/-35)
3 files modified
worker/provisioner/authentication.go (+50/-0)
worker/provisioner/provisioner.go (+3/-6)
worker/provisioner/provisioner_task.go (+12/-29)
To merge this branch: bzr merge lp:~thumper/juju-core/provisioner-auth-provider
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+171006@code.launchpad.net

Commit message

Add an AuthenticationProvider interface.

To be used by the provisioner. Very simple implementation now to mirror what
is currently happening. We can add caching and re-getting the information as
we desire.

https://codereview.appspot.com/10478043/

Description of the change

Add an AuthenticationProvider interface.

To be used by the provisioner. Very simple implementation now to mirror what
is currently happening. We can add caching and re-getting the information as
we desire.

https://codereview.appspot.com/10478043/

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

Reviewers: mp+171006_code.launchpad.net,

Message:
Please take a look.

Description:
Add an AuthenticationProvider interface.

To be used by the provisioner. Very simple implementation now to mirror
what
is currently happening. We can add caching and re-getting the
information as
we desire.

https://code.launchpad.net/~thumper/juju-core/provisioner-auth-provider/+merge/171006

Requires:
https://code.launchpad.net/~thumper/juju-core/lxc-broker/+merge/170713

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   A worker/provisioner/authentication.go
   M worker/provisioner/provisioner.go
   M worker/provisioner/provisioner_task.go

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

https://codereview.appspot.com/10478043/diff/1/worker/provisioner/authentication.go
File worker/provisioner/authentication.go (right):

https://codereview.appspot.com/10478043/diff/1/worker/provisioner/authentication.go#newcode15
worker/provisioner/authentication.go:15: // AuthenticationProvider
defines the single function that the provisioner
On 2013/06/24 06:30:32, dfc wrote:
> /s/function/method, only types with receivers can fulfil interfaces

Done.

https://codereview.appspot.com/10478043/diff/1/worker/provisioner/authentication.go#newcode27
worker/provisioner/authentication.go:27: return &simpleAuth{stateInfo,
apiInfo}, nil
On 2013/06/24 06:30:32, dfc wrote:
> return &simpleAuth{stateInfo, apiInfo}, err

> In the unlikely case of an error, the heap allocation of the
simpleAuth won't be
> noticable.

I thought it was idiomatic go to make sure that if you have an error,
the other return params are nil or zero initialized.

https://codereview.appspot.com/10478043/diff/1/worker/provisioner/authentication.go#newcode41
worker/provisioner/authentication.go:41: return nil, nil,
fmt.Errorf("cannot set password for machine %v: %v", machine, err)
On 2013/06/24 06:30:32, dfc wrote:
> cannot set mongo password ? there must be a million different
username/password
> combinations, I don't think it hurts to give a hint which is wrong.

Done.

https://codereview.appspot.com/10478043/diff/1/worker/provisioner/authentication.go#newcode43
worker/provisioner/authentication.go:43: stateInfo := *auth.stateInfo
On 2013/06/24 06:30:32, dfc wrote:
> stateInfo := &auth.StateInfo {
> Tag: machine.Tag(),
> Password: password,
> }

> etc

However we are copying some of the fields from stateInfo. This is the
same code that was elsewhere, just moved here.

https://codereview.appspot.com/10478043/

Revision history for this message
Ian Booth (wallyworld) wrote :

LGTM. If Dave is happy, I'm happy

https://codereview.appspot.com/10478043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'worker/provisioner/authentication.go'
2--- worker/provisioner/authentication.go 1970-01-01 00:00:00 +0000
3+++ worker/provisioner/authentication.go 2013-06-25 22:13:27 +0000
4@@ -0,0 +1,50 @@
5+// Copyright 2012, 2013 Canonical Ltd.
6+// Licensed under the AGPLv3, see LICENCE file for details.
7+
8+package provisioner
9+
10+import (
11+ "fmt"
12+
13+ "launchpad.net/juju-core/environs"
14+ "launchpad.net/juju-core/state"
15+ "launchpad.net/juju-core/state/api"
16+ "launchpad.net/juju-core/utils"
17+)
18+
19+// AuthenticationProvider defines the single method that the provisioner
20+// task needs to set up authentication for a machine.
21+type AuthenticationProvider interface {
22+ SetupAuthentication(*state.Machine) (*state.Info, *api.Info, error)
23+}
24+
25+// NewSimpleAuthenticator gets the state and api info once from the environ.
26+func NewSimpleAuthenticator(environ environs.Environ) (AuthenticationProvider, error) {
27+ stateInfo, apiInfo, err := environ.StateInfo()
28+ if err != nil {
29+ return nil, err
30+ }
31+ return &simpleAuth{stateInfo, apiInfo}, nil
32+}
33+
34+type simpleAuth struct {
35+ stateInfo *state.Info
36+ apiInfo *api.Info
37+}
38+
39+func (auth *simpleAuth) SetupAuthentication(machine *state.Machine) (*state.Info, *api.Info, error) {
40+ password, err := utils.RandomPassword()
41+ if err != nil {
42+ return nil, nil, fmt.Errorf("cannot make password for machine %v: %v", machine, err)
43+ }
44+ if err := machine.SetMongoPassword(password); err != nil {
45+ return nil, nil, fmt.Errorf("cannot set mongo password for machine %v: %v", machine, err)
46+ }
47+ stateInfo := *auth.stateInfo
48+ stateInfo.Tag = machine.Tag()
49+ stateInfo.Password = password
50+ apiInfo := *auth.apiInfo
51+ apiInfo.Tag = machine.Tag()
52+ apiInfo.Password = password
53+ return &stateInfo, &apiInfo, nil
54+}
55
56=== modified file 'worker/provisioner/provisioner.go'
57--- worker/provisioner/provisioner.go 2013-06-25 22:13:27 +0000
58+++ worker/provisioner/provisioner.go 2013-06-25 22:13:27 +0000
59@@ -66,10 +66,7 @@
60 return err
61 }
62
63- // Get a new StateInfo from the environment: the one used to
64- // launch the agent may refer to localhost, which will be
65- // unhelpful when attempting to run an agent on a new machine.
66- stateInfo, apiInfo, err := p.environ.StateInfo()
67+ auth, err := NewSimpleAuthenticator(p.environ)
68 if err != nil {
69 return err
70 }
71@@ -81,12 +78,12 @@
72 machinesWatcher := p.st.WatchEnvironMachines()
73 environmentBroker := newEnvironBroker(p.environ)
74 environmentProvisioner := NewProvisionerTask(
75+ "environ provisioner for machine "+p.machineId,
76 p.machineId,
77 p.st,
78 machinesWatcher,
79 environmentBroker,
80- stateInfo,
81- apiInfo)
82+ auth)
83 defer watcher.Stop(environmentProvisioner, &p.tomb)
84
85 for {
86
87=== modified file 'worker/provisioner/provisioner_task.go'
88--- worker/provisioner/provisioner_task.go 2013-06-25 22:13:27 +0000
89+++ worker/provisioner/provisioner_task.go 2013-06-25 22:13:27 +0000
90@@ -9,7 +9,6 @@
91 "launchpad.net/juju-core/errors"
92 "launchpad.net/juju-core/instance"
93 "launchpad.net/juju-core/state"
94- "launchpad.net/juju-core/state/api"
95 "launchpad.net/juju-core/state/api/params"
96 "launchpad.net/juju-core/state/watcher"
97 "launchpad.net/juju-core/utils"
98@@ -22,6 +21,7 @@
99 Stop() error
100 Dying() <-chan struct{}
101 Err() error
102+ String() string
103 }
104
105 type Watcher interface {
106@@ -35,20 +35,20 @@
107 }
108
109 func NewProvisionerTask(
110+ name string,
111 machineId string,
112 machineGetter MachineGetter,
113 watcher Watcher,
114 broker Broker,
115- stateInfo *state.Info,
116- apiInfo *api.Info,
117+ auth AuthenticationProvider,
118 ) ProvisionerTask {
119 task := &provisionerTask{
120+ name: name,
121 machineId: machineId,
122 machineGetter: machineGetter,
123 machineWatcher: watcher,
124 broker: broker,
125- stateInfo: stateInfo,
126- apiInfo: apiInfo,
127+ auth: auth,
128 machines: make(map[string]*state.Machine),
129 }
130 go func() {
131@@ -59,13 +59,13 @@
132 }
133
134 type provisionerTask struct {
135+ name string
136 machineId string
137 machineGetter MachineGetter
138 machineWatcher Watcher
139 broker Broker
140 tomb tomb.Tomb
141- stateInfo *state.Info
142- apiInfo *api.Info
143+ auth AuthenticationProvider
144
145 // instance id -> instance
146 instances map[instance.Id]instance.Instance
147@@ -96,6 +96,10 @@
148 return task.tomb.Err()
149 }
150
151+func (task *provisionerTask) String() string {
152+ return task.name
153+}
154+
155 func (task *provisionerTask) loop() error {
156 logger.Infof("Starting up provisioner task %s", task.machineId)
157 defer watcher.Stop(task.machineWatcher, &task.tomb)
158@@ -300,11 +304,7 @@
159 }
160
161 func (task *provisionerTask) startMachine(machine *state.Machine) error {
162- // TODO(dfc) the state.Info passed to environ.StartInstance remains contentious
163- // however as the PA only knows one state.Info, and that info is used by MAs and
164- // UAs to locate the state for this environment, it is logical to use the same
165- // state.Info as the PA.
166- stateInfo, apiInfo, err := task.setupAuthentication(machine)
167+ stateInfo, apiInfo, err := task.auth.SetupAuthentication(machine)
168 if err != nil {
169 logger.Errorf("failed to setup authentication: %v", err)
170 return err
171@@ -353,20 +353,3 @@
172 logger.Infof("started machine %s as instance %s", machine, inst.Id())
173 return nil
174 }
175-
176-func (task *provisionerTask) setupAuthentication(machine *state.Machine) (*state.Info, *api.Info, error) {
177- password, err := utils.RandomPassword()
178- if err != nil {
179- return nil, nil, fmt.Errorf("cannot make password for machine %v: %v", machine, err)
180- }
181- if err := machine.SetMongoPassword(password); err != nil {
182- return nil, nil, fmt.Errorf("cannot set password for machine %v: %v", machine, err)
183- }
184- stateInfo := *task.stateInfo
185- stateInfo.Tag = machine.Tag()
186- stateInfo.Password = password
187- apiInfo := *task.apiInfo
188- apiInfo.Tag = machine.Tag()
189- apiInfo.Password = password
190- return &stateInfo, &apiInfo, nil
191-}

Subscribers

People subscribed via source and target branches

to status/vote changes: