Merge lp:~axwalk/juju-core/lp1270043-drop-machineconfig-api into lp:~go-bot/juju-core/trunk
- lp1270043-drop-machineconfig-api
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Andrew Wilkins | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 2251 | ||||
Proposed branch: | lp:~axwalk/juju-core/lp1270043-drop-machineconfig-api | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
562 lines (+157/-189) 10 files modified
cloudinit/sshinit/configure.go (+12/-4) environs/manual/provisioner.go (+32/-19) environs/manual/provisioner_test.go (+1/-4) provider/common/bootstrap.go (+4/-4) state/api/client.go (+0/-10) state/api/params/params.go (+0/-18) state/apiserver/client/client.go (+1/-11) state/apiserver/client/client_test.go (+1/-71) state/statecmd/machineconfig.go (+16/-48) state/statecmd/machineconfig_test.go (+90/-0) |
||||
To merge this branch: | bzr merge lp:~axwalk/juju-core/lp1270043-drop-machineconfig-api | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+202592@code.launchpad.net |
Commit message
Eliminate MachineConfig client API
The MachineConfig API has been superseded by
ProvisioningScript for manual provisioning.
Manual provisioning has been updated to use
ProvisioningScript, and MachineConfig removed
as it was added in the 1.17.0 release, and so
is unsupported.
Accordingly, statecmd.
combined with statecmd.
and it deals directly with the environs/config
MachineConfig struct.
Fixes #1270043
Description of the change
Eliminate MachineConfig client API
The MachineConfig API has been superseded by
ProvisioningScript for manual provisioning.
Manual provisioning has been updated to use
ProvisioningScript, and MachineConfig removed
as it was added in the 1.17.0 release, and so
is unsupported.
Accordingly, statecmd.
combined with statecmd.
and it deals directly with the environs/config
MachineConfig struct.
Fixes #1270043
Andrew Wilkins (axwalk) wrote : | # |
Martin Packman (gz) wrote : | # |
LGTM, please land for 1.17.1 release. :)
https:/
File cloudinit/
https:/
cloudinit/
over SSH,
*RunConfigureScript
https:/
cloudinit/
agent on %s", params.Host)
Why move this log line later? Having it right next to the debug one
below is just a little silly, and it seemed fine where it was (logging
even if ConfigureScript errored).
https:/
File environs/
https:/
environs/
string, mcfg *cloudinit.
Pre-exisiting nit, naming the writer 'stderr' when it can be any writer
is confusing.
https:/
File state/statecmd/
https:/
state/statecmd/
c.Assert(
These two DeepEquals Asserts could be Check instead?
Andrew Wilkins (axwalk) wrote : | # |
Please take a look.
https:/
File cloudinit/
https:/
cloudinit/
over SSH,
On 2014/01/23 13:43:37, gz wrote:
> *RunConfigureScript
Done.
https:/
cloudinit/
agent on %s", params.Host)
On 2014/01/23 13:43:37, gz wrote:
> Why move this log line later? Having it right next to the debug one
below is
> just a little silly, and it seemed fine where it was (logging even if
> ConfigureScript errored).
I moved it because not everything uses Configure, and DEBUG may not be
enabled. Manual provisioning uses ConfigureScript and RunConfigureScript
separately. It doesn't really matter; I will move the log line back.
https:/
File environs/
https:/
environs/
string, mcfg *cloudinit.
On 2014/01/23 13:43:37, gz wrote:
> Pre-exisiting nit, naming the writer 'stderr' when it can be any
writer is
> confusing.
Yeah, good call. I've renamed to progressWriter. Also renamed
sshinit.
https:/
File state/statecmd/
https:/
state/statecmd/
c.Assert(
On 2014/01/23 13:43:37, gz wrote:
> These two DeepEquals Asserts could be Check instead?
Done.
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~axwalk/juju-core/lp1270043-drop-machineconfig-api into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
-------
FAIL: machine_
[LOG] 64.43716 DEBUG juju.environs.
[LOG] 64.53346 DEBUG juju.environs.tools reading v1.* tools
[LOG] 64.53350 INFO juju environs/testing: uploading FAKE tools 1.17.1-
[LOG] 64.53443 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 64.53445 DEBUG juju.environs.tools no series specified when finding tools, looking for any
[LOG] 64.53451 DEBUG juju.environs.
[LOG] 64.53453 DEBUG juju.environs.
[LOG] 64.53457 DEBUG juju.environs.
[LOG] 64.53458 DEBUG juju.environs.
[LOG] 64.53484 INFO juju.environs.tools Writing tools/streams/
[LOG] 64.53490 INFO juju.environs.tools Writing tools/streams/
[LOG] 64.53504 INFO juju.environs.
[LOG] 64.53506 DEBUG juju.environs.
[LOG] 64.53508 INFO juju.environs.tools reading tools with major.minor version 1.17
[LOG] 64.53509 INFO juju.environs.tools filtering tools by version: 1.17.1
[LOG] 64.53510 INFO juju.environs.tools filtering tools by series: precise
[LOG] 64.53512 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 64.53516 DEBUG juju.environs.
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~axwalk/juju-core/lp1270043-drop-machineconfig-api into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad...
Preview Diff
1 | === modified file 'cloudinit/sshinit/configure.go' |
2 | --- cloudinit/sshinit/configure.go 2014-01-16 07:10:50 +0000 |
3 | +++ cloudinit/sshinit/configure.go 2014-01-23 23:05:20 +0000 |
4 | @@ -28,8 +28,9 @@ |
5 | // Config is the cloudinit config to carry out. |
6 | Config *cloudinit.Config |
7 | |
8 | - // Stderr is required to present bootstrap progress to the user. |
9 | - Stderr io.Writer |
10 | + // ProgressWriter is an io.Writer to which progress will be written, |
11 | + // for realtime feedback. |
12 | + ProgressWriter io.Writer |
13 | } |
14 | |
15 | // Configure connects to the specified host over SSH, |
16 | @@ -40,14 +41,21 @@ |
17 | if err != nil { |
18 | return err |
19 | } |
20 | - logger.Debugf("running script on %s: %s", params.Host, script) |
21 | + return RunConfigureScript(script, params) |
22 | +} |
23 | + |
24 | +// RunConfigureScript connects to the specified host over |
25 | +// SSH, and executes the provided script which is expected |
26 | +// to have been returned by ConfigureScript. |
27 | +func RunConfigureScript(script string, params ConfigureParams) error { |
28 | + logger.Debugf("Running script on %s: %s", params.Host, script) |
29 | client := params.Client |
30 | if client == nil { |
31 | client = ssh.DefaultClient |
32 | } |
33 | cmd := ssh.Command(params.Host, []string{"sudo", "/bin/bash"}, nil) |
34 | cmd.Stdin = strings.NewReader(script) |
35 | - cmd.Stderr = params.Stderr |
36 | + cmd.Stderr = params.ProgressWriter |
37 | return cmd.Run() |
38 | } |
39 | |
40 | |
41 | === modified file 'environs/manual/provisioner.go' |
42 | --- environs/manual/provisioner.go 2014-01-16 07:10:50 +0000 |
43 | +++ environs/manual/provisioner.go 2014-01-23 23:05:20 +0000 |
44 | @@ -131,23 +131,24 @@ |
45 | return "", err |
46 | } |
47 | |
48 | - var configParameters params.MachineConfig |
49 | + var provisioningScript string |
50 | if stateConn == nil { |
51 | - configParameters, err = client.MachineConfig(machineId) |
52 | + provisioningScript, err = client.ProvisioningScript(machineId, machineParams.Nonce) |
53 | + if err != nil { |
54 | + return "", err |
55 | + } |
56 | } else { |
57 | - configParameters, err = statecmd.MachineConfig(stateConn.State, machineId) |
58 | - } |
59 | - if err != nil { |
60 | - return "", err |
61 | - } |
62 | - // Gather the information needed by the machine agent to run the provisioning script. |
63 | - mcfg, err := statecmd.FinishMachineConfig(configParameters, machineId, machineParams.Nonce, args.DataDir) |
64 | - if err != nil { |
65 | - return machineId, err |
66 | + mcfg, err := statecmd.MachineConfig(stateConn.State, machineId, machineParams.Nonce, args.DataDir) |
67 | + if err == nil { |
68 | + provisioningScript, err = generateProvisioningScript(mcfg) |
69 | + } |
70 | + if err != nil { |
71 | + return "", err |
72 | + } |
73 | } |
74 | |
75 | // Finally, provision the machine agent. |
76 | - err = provisionMachineAgent(hostname, mcfg, args.Stderr) |
77 | + err = runProvisionScript(provisioningScript, hostname, args.Stderr) |
78 | if err != nil { |
79 | return machineId, err |
80 | } |
81 | @@ -289,17 +290,29 @@ |
82 | return machineParams, nil |
83 | } |
84 | |
85 | -func provisionMachineAgent(host string, mcfg *cloudinit.MachineConfig, stderr io.Writer) error { |
86 | +func provisionMachineAgent(host string, mcfg *cloudinit.MachineConfig, progressWriter io.Writer) error { |
87 | + script, err := generateProvisioningScript(mcfg) |
88 | + if err != nil { |
89 | + return err |
90 | + } |
91 | + return runProvisionScript(script, host, progressWriter) |
92 | +} |
93 | + |
94 | +func generateProvisioningScript(mcfg *cloudinit.MachineConfig) (string, error) { |
95 | cloudcfg := coreCloudinit.New() |
96 | if err := cloudinit.ConfigureJuju(mcfg, cloudcfg); err != nil { |
97 | - return err |
98 | + return "", err |
99 | } |
100 | // Explicitly disabling apt_upgrade so as not to trample |
101 | // the target machine's existing configuration. |
102 | cloudcfg.SetAptUpgrade(false) |
103 | - return sshinit.Configure(sshinit.ConfigureParams{ |
104 | - Host: "ubuntu@" + host, |
105 | - Config: cloudcfg, |
106 | - Stderr: stderr, |
107 | - }) |
108 | + return sshinit.ConfigureScript(cloudcfg) |
109 | +} |
110 | + |
111 | +func runProvisionScript(script, host string, progressWriter io.Writer) error { |
112 | + params := sshinit.ConfigureParams{ |
113 | + Host: "ubuntu@" + host, |
114 | + ProgressWriter: progressWriter, |
115 | + } |
116 | + return sshinit.RunConfigureScript(script, params) |
117 | } |
118 | |
119 | === modified file 'environs/manual/provisioner_test.go' |
120 | --- environs/manual/provisioner_test.go 2014-01-16 07:10:50 +0000 |
121 | +++ environs/manual/provisioner_test.go 2014-01-23 23:05:20 +0000 |
122 | @@ -119,10 +119,7 @@ |
123 | c.Assert(err, gc.IsNil) |
124 | |
125 | // Now check what we would've configured it with. |
126 | - client := s.APIConn.State.Client() |
127 | - configParams, err := client.MachineConfig(machineId) |
128 | - c.Assert(err, gc.IsNil) |
129 | - mcfg, err := statecmd.FinishMachineConfig(configParams, machineId, state.BootstrapNonce, "/var/lib/juju") |
130 | + mcfg, err := statecmd.MachineConfig(s.State, machineId, state.BootstrapNonce, "/var/lib/juju") |
131 | c.Assert(err, gc.IsNil) |
132 | c.Check(mcfg, gc.NotNil) |
133 | c.Check(mcfg.APIInfo, gc.NotNil) |
134 | |
135 | === modified file 'provider/common/bootstrap.go' |
136 | --- provider/common/bootstrap.go 2014-01-14 09:56:52 +0000 |
137 | +++ provider/common/bootstrap.go 2014-01-23 23:05:20 +0000 |
138 | @@ -192,10 +192,10 @@ |
139 | return err |
140 | } |
141 | return sshinit.Configure(sshinit.ConfigureParams{ |
142 | - Host: "ubuntu@" + addr, |
143 | - Client: client, |
144 | - Config: cloudcfg, |
145 | - Stderr: ctx.Stderr(), |
146 | + Host: "ubuntu@" + addr, |
147 | + Client: client, |
148 | + Config: cloudcfg, |
149 | + ProgressWriter: ctx.Stderr(), |
150 | }) |
151 | } |
152 | |
153 | |
154 | === modified file 'state/api/client.go' |
155 | --- state/api/client.go 2014-01-18 01:01:42 +0000 |
156 | +++ state/api/client.go 2014-01-23 23:05:20 +0000 |
157 | @@ -171,16 +171,6 @@ |
158 | return results.Machines, err |
159 | } |
160 | |
161 | -// MachineConfig returns information from the environment config that are |
162 | -// needed for machine cloud-init. |
163 | -func (c *Client) MachineConfig(machineId string) (result params.MachineConfig, err error) { |
164 | - args := params.MachineConfigParams{ |
165 | - MachineId: machineId, |
166 | - } |
167 | - err = c.st.Call("Client", "", "MachineConfig", args, &result) |
168 | - return result, err |
169 | -} |
170 | - |
171 | // ProvisioningScript returns a shell script that, when run, |
172 | // provisions a machine agent on the machine executing the script. |
173 | func (c *Client) ProvisioningScript(machineId, nonce string) (script string, err error) { |
174 | |
175 | === modified file 'state/api/params/params.go' |
176 | --- state/api/params/params.go 2014-01-17 03:09:38 +0000 |
177 | +++ state/api/params/params.go 2014-01-23 23:05:20 +0000 |
178 | @@ -11,7 +11,6 @@ |
179 | "launchpad.net/juju-core/charm" |
180 | "launchpad.net/juju-core/constraints" |
181 | "launchpad.net/juju-core/instance" |
182 | - "launchpad.net/juju-core/tools" |
183 | "launchpad.net/juju-core/utils/ssh" |
184 | "launchpad.net/juju-core/version" |
185 | ) |
186 | @@ -516,23 +515,6 @@ |
187 | SyslogPort int |
188 | } |
189 | |
190 | -type MachineConfigParams struct { |
191 | - MachineId string |
192 | -} |
193 | - |
194 | -// MachineConfig contains information from the environment config that is |
195 | -// needed for a machine cloud-init. |
196 | -type MachineConfig struct { |
197 | - EnvironAttrs map[string]interface{} |
198 | - Tools *tools.Tools |
199 | - // state.Info and api.Info attributes (cannot use state.Info, api.Info directly due to import loops) |
200 | - StateAddrs []string |
201 | - APIAddrs []string |
202 | - CACert []byte |
203 | - Tag string |
204 | - Password string |
205 | -} |
206 | - |
207 | // ProvisioningScriptParams contains the parameters for the |
208 | // ProvisioningScript client API call. |
209 | type ProvisioningScriptParams struct { |
210 | |
211 | === modified file 'state/apiserver/client/client.go' |
212 | --- state/apiserver/client/client.go 2014-01-16 07:10:50 +0000 |
213 | +++ state/apiserver/client/client.go 2014-01-23 23:05:20 +0000 |
214 | @@ -601,21 +601,11 @@ |
215 | return newJobs, nil |
216 | } |
217 | |
218 | -// MachineConfig returns information from the environment config that is |
219 | -// needed for machine cloud-init (both state servers and host nodes). |
220 | -func (c *Client) MachineConfig(args params.MachineConfigParams) (params.MachineConfig, error) { |
221 | - return statecmd.MachineConfig(c.api.state, args.MachineId) |
222 | -} |
223 | - |
224 | // ProvisioningScript returns a shell script that, when run, |
225 | // provisions a machine agent on the machine executing the script. |
226 | func (c *Client) ProvisioningScript(args params.ProvisioningScriptParams) (params.ProvisioningScriptResult, error) { |
227 | var result params.ProvisioningScriptResult |
228 | - mcfgParams, err := statecmd.MachineConfig(c.api.state, args.MachineId) |
229 | - if err != nil { |
230 | - return result, err |
231 | - } |
232 | - mcfg, err := statecmd.FinishMachineConfig(mcfgParams, args.MachineId, args.Nonce, args.DataDir) |
233 | + mcfg, err := statecmd.MachineConfig(c.api.state, args.MachineId, args.Nonce, args.DataDir) |
234 | if err != nil { |
235 | return result, err |
236 | } |
237 | |
238 | === modified file 'state/apiserver/client/client_test.go' |
239 | --- state/apiserver/client/client_test.go 2014-01-20 23:32:00 +0000 |
240 | +++ state/apiserver/client/client_test.go 2014-01-23 23:05:20 +0000 |
241 | @@ -15,10 +15,8 @@ |
242 | coreCloudinit "launchpad.net/juju-core/cloudinit" |
243 | "launchpad.net/juju-core/cloudinit/sshinit" |
244 | "launchpad.net/juju-core/constraints" |
245 | - "launchpad.net/juju-core/environs" |
246 | "launchpad.net/juju-core/environs/cloudinit" |
247 | "launchpad.net/juju-core/environs/config" |
248 | - envtools "launchpad.net/juju-core/environs/tools" |
249 | "launchpad.net/juju-core/errors" |
250 | "launchpad.net/juju-core/instance" |
251 | "launchpad.net/juju-core/state" |
252 | @@ -28,7 +26,6 @@ |
253 | "launchpad.net/juju-core/state/statecmd" |
254 | coretesting "launchpad.net/juju-core/testing" |
255 | jc "launchpad.net/juju-core/testing/checkers" |
256 | - coretools "launchpad.net/juju-core/tools" |
257 | "launchpad.net/juju-core/version" |
258 | ) |
259 | |
260 | @@ -1654,71 +1651,6 @@ |
261 | c.Assert(results.Machines, gc.HasLen, 1) |
262 | } |
263 | |
264 | -func (s *clientSuite) TestMachineConfig(c *gc.C) { |
265 | - addrs := []instance.Address{instance.NewAddress("1.2.3.4")} |
266 | - hc := instance.MustParseHardware("mem=4G arch=amd64") |
267 | - apiParams := params.AddMachineParams{ |
268 | - Jobs: []params.MachineJob{params.JobHostUnits}, |
269 | - InstanceId: instance.Id("1234"), |
270 | - Nonce: "foo", |
271 | - HardwareCharacteristics: hc, |
272 | - Addrs: addrs, |
273 | - } |
274 | - machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) |
275 | - c.Assert(err, gc.IsNil) |
276 | - c.Assert(len(machines), gc.Equals, 1) |
277 | - |
278 | - machineId := machines[0].Machine |
279 | - machineConfig, err := s.APIState.Client().MachineConfig(machineId) |
280 | - c.Assert(err, gc.IsNil) |
281 | - |
282 | - envConfig, err := s.State.EnvironConfig() |
283 | - c.Assert(err, gc.IsNil) |
284 | - env, err := environs.New(envConfig) |
285 | - c.Assert(err, gc.IsNil) |
286 | - stateInfo, apiInfo, err := env.StateInfo() |
287 | - c.Assert(err, gc.IsNil) |
288 | - c.Assert(machineConfig.StateAddrs, gc.DeepEquals, stateInfo.Addrs) |
289 | - c.Assert(machineConfig.APIAddrs, gc.DeepEquals, apiInfo.Addrs) |
290 | - c.Assert(machineConfig.Tag, gc.Equals, "machine-0") |
291 | - caCert, _ := envConfig.CACert() |
292 | - c.Assert(machineConfig.CACert, gc.DeepEquals, caCert) |
293 | - c.Assert(machineConfig.Password, gc.Not(gc.Equals), "") |
294 | - c.Assert(machineConfig.Tools.URL, gc.Not(gc.Equals), "") |
295 | - c.Assert(machineConfig.EnvironAttrs["name"], gc.Equals, "dummyenv") |
296 | -} |
297 | - |
298 | -func (s *clientSuite) TestMachineConfigNoArch(c *gc.C) { |
299 | - apiParams := params.AddMachineParams{ |
300 | - Jobs: []params.MachineJob{params.JobHostUnits}, |
301 | - InstanceId: instance.Id("1234"), |
302 | - Nonce: "foo", |
303 | - } |
304 | - machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) |
305 | - c.Assert(err, gc.IsNil) |
306 | - c.Assert(len(machines), gc.Equals, 1) |
307 | - _, err = s.APIState.Client().MachineConfig(machines[0].Machine) |
308 | - c.Assert(err, gc.ErrorMatches, fmt.Sprintf("arch is not set for %q", "machine-"+machines[0].Machine)) |
309 | -} |
310 | - |
311 | -func (s *clientSuite) TestMachineConfigNoTools(c *gc.C) { |
312 | - s.PatchValue(&envtools.DefaultBaseURL, "") |
313 | - addrs := []instance.Address{instance.NewAddress("1.2.3.4")} |
314 | - hc := instance.MustParseHardware("mem=4G arch=amd64") |
315 | - apiParams := params.AddMachineParams{ |
316 | - Series: "quantal", |
317 | - Jobs: []params.MachineJob{params.JobHostUnits}, |
318 | - InstanceId: instance.Id("1234"), |
319 | - Nonce: "foo", |
320 | - HardwareCharacteristics: hc, |
321 | - Addrs: addrs, |
322 | - } |
323 | - machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) |
324 | - c.Assert(err, gc.IsNil) |
325 | - _, err = s.APIState.Client().MachineConfig(machines[0].Machine) |
326 | - c.Assert(err, gc.ErrorMatches, coretools.ErrNoMatches.Error()) |
327 | -} |
328 | - |
329 | func (s *clientSuite) TestProvisioningScript(c *gc.C) { |
330 | // Inject a machine and then call the ProvisioningScript API. |
331 | // The result should be the same as when calling MachineConfig, |
332 | @@ -1734,14 +1666,12 @@ |
333 | c.Assert(err, gc.IsNil) |
334 | c.Assert(len(machines), gc.Equals, 1) |
335 | machineId := machines[0].Machine |
336 | - machineConfig, err := s.APIState.Client().MachineConfig(machineId) |
337 | - c.Assert(err, gc.IsNil) |
338 | // Call ProvisioningScript. Normally ProvisioningScript and |
339 | // MachineConfig are mutually exclusive; both of them will |
340 | // allocate a state/api password for the machine agent. |
341 | script, err := s.APIState.Client().ProvisioningScript(machineId, apiParams.Nonce) |
342 | c.Assert(err, gc.IsNil) |
343 | - mcfg, err := statecmd.FinishMachineConfig(machineConfig, machineId, apiParams.Nonce, "") |
344 | + mcfg, err := statecmd.MachineConfig(s.State, machineId, apiParams.Nonce, "") |
345 | c.Assert(err, gc.IsNil) |
346 | cloudcfg := coreCloudinit.New() |
347 | err = cloudinit.ConfigureJuju(mcfg, cloudcfg) |
348 | |
349 | === modified file 'state/statecmd/machineconfig.go' |
350 | --- state/statecmd/machineconfig.go 2014-01-17 03:09:38 +0000 |
351 | +++ state/statecmd/machineconfig.go 2014-01-23 23:05:20 +0000 |
352 | @@ -9,11 +9,8 @@ |
353 | "launchpad.net/juju-core/constraints" |
354 | "launchpad.net/juju-core/environs" |
355 | "launchpad.net/juju-core/environs/cloudinit" |
356 | - "launchpad.net/juju-core/environs/config" |
357 | envtools "launchpad.net/juju-core/environs/tools" |
358 | "launchpad.net/juju-core/state" |
359 | - "launchpad.net/juju-core/state/api" |
360 | - "launchpad.net/juju-core/state/api/params" |
361 | "launchpad.net/juju-core/tools" |
362 | ) |
363 | |
364 | @@ -30,87 +27,58 @@ |
365 | } |
366 | |
367 | // MachineConfig returns information from the environment config that is |
368 | -// needed for machine cloud-init (both state servers and host nodes). |
369 | -// The code is here so that it can be shared between the API server and the CLI |
370 | -// for maintaining compatibiility with juju-1.16 (where the API MachineConfig |
371 | -// did not exist). When we drop 1.16 compatibility, this code should be moved |
372 | -// back into api.Client |
373 | -func MachineConfig(st *state.State, machineId string) (params.MachineConfig, error) { |
374 | - result := params.MachineConfig{} |
375 | +// needed for machine cloud-init (for non-state servers only). |
376 | +// |
377 | +// The code is here so that it can be shared between the API server |
378 | +// (for ProvisioningScript) and the CLI (for manual provisioning) for maintaining |
379 | +// compatibiility with juju-1.16 (where the API MachineConfig did not exist). |
380 | +// When we drop 1.16 compatibility, this code should be moved into apiserver. |
381 | +func MachineConfig(st *state.State, machineId, nonce, dataDir string) (*cloudinit.MachineConfig, error) { |
382 | environConfig, err := st.EnvironConfig() |
383 | if err != nil { |
384 | - return result, err |
385 | + return nil, err |
386 | } |
387 | - // The basic information. |
388 | - result.EnvironAttrs = environConfig.AllAttrs() |
389 | |
390 | // Get the machine so we can get its series and arch. |
391 | // If the Arch is not set in hardware-characteristics, |
392 | // an error is returned. |
393 | machine, err := st.Machine(machineId) |
394 | if err != nil { |
395 | - return result, err |
396 | + return nil, err |
397 | } |
398 | hc, err := machine.HardwareCharacteristics() |
399 | if err != nil { |
400 | - return result, err |
401 | + return nil, err |
402 | } |
403 | if hc.Arch == nil { |
404 | - return result, fmt.Errorf("arch is not set for %q", machine.Tag()) |
405 | + return nil, fmt.Errorf("arch is not set for %q", machine.Tag()) |
406 | } |
407 | |
408 | // Find the appropriate tools information. |
409 | env, err := environs.New(environConfig) |
410 | if err != nil { |
411 | - return result, err |
412 | + return nil, err |
413 | } |
414 | tools, err := findInstanceTools(env, machine.Series(), *hc.Arch) |
415 | if err != nil { |
416 | - return result, err |
417 | + return nil, err |
418 | } |
419 | - result.Tools = tools |
420 | |
421 | // Find the secrets and API endpoints. |
422 | auth, err := environs.NewEnvironAuthenticator(env) |
423 | if err != nil { |
424 | - return result, err |
425 | + return nil, err |
426 | } |
427 | stateInfo, apiInfo, err := auth.SetupAuthentication(machine) |
428 | if err != nil { |
429 | - return result, err |
430 | + return nil, err |
431 | } |
432 | - result.APIAddrs = apiInfo.Addrs |
433 | - result.StateAddrs = stateInfo.Addrs |
434 | - result.CACert = stateInfo.CACert |
435 | - result.Password = stateInfo.Password |
436 | - result.Tag = stateInfo.Tag |
437 | - return result, nil |
438 | -} |
439 | |
440 | -// FinishMachineConfig is shared by environs/manual and state/apiserver/client |
441 | -// to create a complete cloudinit.MachineConfig from a params.MachineConfig. |
442 | -func FinishMachineConfig(configParameters params.MachineConfig, machineId, nonce, dataDir string) (*cloudinit.MachineConfig, error) { |
443 | - stateInfo := &state.Info{ |
444 | - Addrs: configParameters.StateAddrs, |
445 | - Password: configParameters.Password, |
446 | - Tag: configParameters.Tag, |
447 | - CACert: configParameters.CACert, |
448 | - } |
449 | - apiInfo := &api.Info{ |
450 | - Addrs: configParameters.APIAddrs, |
451 | - Password: configParameters.Password, |
452 | - Tag: configParameters.Tag, |
453 | - CACert: configParameters.CACert, |
454 | - } |
455 | - environConfig, err := config.New(config.NoDefaults, configParameters.EnvironAttrs) |
456 | - if err != nil { |
457 | - return nil, err |
458 | - } |
459 | mcfg := environs.NewMachineConfig(machineId, nonce, stateInfo, apiInfo) |
460 | if dataDir != "" { |
461 | mcfg.DataDir = dataDir |
462 | } |
463 | - mcfg.Tools = configParameters.Tools |
464 | + mcfg.Tools = tools |
465 | err = environs.FinishMachineConfig(mcfg, environConfig, constraints.Value{}) |
466 | if err != nil { |
467 | return nil, err |
468 | |
469 | === added file 'state/statecmd/machineconfig_test.go' |
470 | --- state/statecmd/machineconfig_test.go 1970-01-01 00:00:00 +0000 |
471 | +++ state/statecmd/machineconfig_test.go 2014-01-23 23:05:20 +0000 |
472 | @@ -0,0 +1,90 @@ |
473 | +// Copyright 2012, 2013 Canonical Ltd. |
474 | +// Licensed under the AGPLv3, see LICENCE file for details. |
475 | + |
476 | +package statecmd_test |
477 | + |
478 | +import ( |
479 | + "fmt" |
480 | + stdtesting "testing" |
481 | + |
482 | + gc "launchpad.net/gocheck" |
483 | + |
484 | + "launchpad.net/juju-core/environs" |
485 | + envtools "launchpad.net/juju-core/environs/tools" |
486 | + "launchpad.net/juju-core/instance" |
487 | + "launchpad.net/juju-core/juju/testing" |
488 | + "launchpad.net/juju-core/state/api/params" |
489 | + "launchpad.net/juju-core/state/statecmd" |
490 | + coretesting "launchpad.net/juju-core/testing" |
491 | + coretools "launchpad.net/juju-core/tools" |
492 | +) |
493 | + |
494 | +func TestPackage(t *stdtesting.T) { |
495 | + coretesting.MgoTestPackage(t) |
496 | +} |
497 | + |
498 | +type machineConfigSuite struct { |
499 | + testing.JujuConnSuite |
500 | +} |
501 | + |
502 | +var _ = gc.Suite(&machineConfigSuite{}) |
503 | + |
504 | +func (s *machineConfigSuite) TestMachineConfig(c *gc.C) { |
505 | + addrs := []instance.Address{instance.NewAddress("1.2.3.4")} |
506 | + hc := instance.MustParseHardware("mem=4G arch=amd64") |
507 | + apiParams := params.AddMachineParams{ |
508 | + Jobs: []params.MachineJob{params.JobHostUnits}, |
509 | + InstanceId: instance.Id("1234"), |
510 | + Nonce: "foo", |
511 | + HardwareCharacteristics: hc, |
512 | + Addrs: addrs, |
513 | + } |
514 | + machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) |
515 | + c.Assert(err, gc.IsNil) |
516 | + c.Assert(len(machines), gc.Equals, 1) |
517 | + |
518 | + machineId := machines[0].Machine |
519 | + machineConfig, err := statecmd.MachineConfig(s.State, machineId, apiParams.Nonce, "") |
520 | + c.Assert(err, gc.IsNil) |
521 | + |
522 | + envConfig, err := s.State.EnvironConfig() |
523 | + c.Assert(err, gc.IsNil) |
524 | + env, err := environs.New(envConfig) |
525 | + c.Assert(err, gc.IsNil) |
526 | + stateInfo, apiInfo, err := env.StateInfo() |
527 | + c.Assert(err, gc.IsNil) |
528 | + c.Check(machineConfig.StateInfo.Addrs, gc.DeepEquals, stateInfo.Addrs) |
529 | + c.Check(machineConfig.APIInfo.Addrs, gc.DeepEquals, apiInfo.Addrs) |
530 | + c.Assert(machineConfig.Tools.URL, gc.Not(gc.Equals), "") |
531 | +} |
532 | + |
533 | +func (s *machineConfigSuite) TestMachineConfigNoArch(c *gc.C) { |
534 | + apiParams := params.AddMachineParams{ |
535 | + Jobs: []params.MachineJob{params.JobHostUnits}, |
536 | + InstanceId: instance.Id("1234"), |
537 | + Nonce: "foo", |
538 | + } |
539 | + machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) |
540 | + c.Assert(err, gc.IsNil) |
541 | + c.Assert(len(machines), gc.Equals, 1) |
542 | + _, err = statecmd.MachineConfig(s.State, machines[0].Machine, apiParams.Nonce, "") |
543 | + c.Assert(err, gc.ErrorMatches, fmt.Sprintf("arch is not set for %q", "machine-"+machines[0].Machine)) |
544 | +} |
545 | + |
546 | +func (s *machineConfigSuite) TestMachineConfigNoTools(c *gc.C) { |
547 | + s.PatchValue(&envtools.DefaultBaseURL, "") |
548 | + addrs := []instance.Address{instance.NewAddress("1.2.3.4")} |
549 | + hc := instance.MustParseHardware("mem=4G arch=amd64") |
550 | + apiParams := params.AddMachineParams{ |
551 | + Series: "quantal", |
552 | + Jobs: []params.MachineJob{params.JobHostUnits}, |
553 | + InstanceId: instance.Id("1234"), |
554 | + Nonce: "foo", |
555 | + HardwareCharacteristics: hc, |
556 | + Addrs: addrs, |
557 | + } |
558 | + machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{apiParams}) |
559 | + c.Assert(err, gc.IsNil) |
560 | + _, err = statecmd.MachineConfig(s.State, machines[0].Machine, apiParams.Nonce, "") |
561 | + c.Assert(err, gc.ErrorMatches, coretools.ErrNoMatches.Error()) |
562 | +} |
Reviewers: mp+202592_ code.launchpad. net,
Message:
Please take a look.
Description:
Eliminate MachineConfig client API
The MachineConfig API has been superseded by
ProvisioningScript for manual provisioning.
Manual provisioning has been updated to use
ProvisioningScript, and MachineConfig removed
as it was added in the 1.17.0 release, and so
is unsupported.
Accordingly, statecmd. MachineConfig has been FinishMachineCo nfig,
combined with statecmd.
and it deals directly with the environs/config
MachineConfig struct.
Fixes #1270043
https:/ /code.launchpad .net/~axwalk/ juju-core/ lp1270043- drop-machinecon fig-api/ +merge/ 202592
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/52900045/
Affected files (+149, -180 lines): sshinit/ configure. go manual/ provisioner. go manual/ provisioner_ test.go params/ params. go /client/ client. go /client/ client_ test.go machineconfig. go machineconfig_ test.go
A [revision details]
M cloudinit/
M environs/
M environs/
M state/api/client.go
M state/api/
M state/apiserver
M state/apiserver
M state/statecmd/
A state/statecmd/