Merge lp:~axwalk/juju-core/1.16 into lp:juju-core/1.16

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 1963
Proposed branch: lp:~axwalk/juju-core/1.16
Merge into: lp:juju-core/1.16
Diff against target: 231 lines (+67/-24)
3 files modified
cmd/juju/bootstrap_test.go (+48/-16)
cmd/juju/cmd_test.go (+15/-5)
environs/sync/sync.go (+4/-3)
To merge this branch: bzr merge lp:~axwalk/juju-core/1.16
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+190085@code.launchpad.net

Commit message

Fix upload-tools for released versions; fix tests

(Cherry picked from juju-core to juju-core/1.16)

There was an issue with sync.Upload/SyncTools for
release versions. Upload sets Dev to true in SyncContext,
and calls SyncTools. SyncTools then sets Dev to false
because MinorVersion==-1. This caused SyncTools to fail,
since uploaded tools are *always* dev (version.Build++).

Also, several bootstrap and upgrade-juju tests have been
fixed for running in release versions (tested with
version.version=="1.16.0").

Finally, some test cleanup (don't connect commands
to stdio in tests):
- Added nullContext helper
- Make runCommand panic if ctx is nil
- Replace runCommand(nil...) with runCommand(nullContext()...)

Fixes #1237123

https://codereview.appspot.com/14579044/

Description of the change

Fix upload-tools for released versions; fix tests

(Cherry picked from juju-core to juju-core/1.16)

There was an issue with sync.Upload/SyncTools for
release versions. Upload sets Dev to true in SyncContext,
and calls SyncTools. SyncTools then sets Dev to false
because MinorVersion==-1. This caused SyncTools to fail,
since uploaded tools are *always* dev (version.Build++).

Also, several bootstrap and upgrade-juju tests have been
fixed for running in release versions (tested with
version.version=="1.16.0").

Finally, some test cleanup (don't connect commands
to stdio in tests):
- Added nullContext helper
- Make runCommand panic if ctx is nil
- Replace runCommand(nil...) with runCommand(nullContext()...)

Fixes #1237123

https://codereview.appspot.com/14579044/

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

Reviewers: mp+190085_code.launchpad.net,

Message:
Please take a look.

Description:
Fix upload-tools for released versions; fix tests

(Cherry picked from juju-core to juju-core/1.16)

There was an issue with sync.Upload/SyncTools for
release versions. Upload sets Dev to true in SyncContext,
and calls SyncTools. SyncTools then sets Dev to false
because MinorVersion==-1. This caused SyncTools to fail,
since uploaded tools are *always* dev (version.Build++).

Also, several bootstrap and upgrade-juju tests have been
fixed for running in release versions (tested with
version.version=="1.16.0").

Finally, some test cleanup (don't connect commands
to stdio in tests):
- Added nullContext helper
- Make runCommand panic if ctx is nil
- Replace runCommand(nil...) with runCommand(nullContext()...)

Fixes #1237123

https://code.launchpad.net/~axwalk/juju-core/1.16/+merge/190085

(do not edit description out of merge proposal)

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

Affected files (+69, -24 lines):
   A [revision details]
   M cmd/juju/bootstrap_test.go
   M cmd/juju/cmd_test.go
   M environs/sync/sync.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20131009063247-dtp5u8dlhoevxio4
+New revision: <email address hidden>

Index: cmd/juju/bootstrap_test.go
=== modified file 'cmd/juju/bootstrap_test.go'
--- cmd/juju/bootstrap_test.go 2013-10-03 01:56:15 +0000
+++ cmd/juju/bootstrap_test.go 2013-10-09 10:33:58 +0000
@@ -65,12 +65,30 @@
   args []string
   expectedAllowRetry []bool
   err string
+ // If version != "", version.Current will be
+ // set to it for the duration of the test.
+ version string
+ // If addVersionToSource is true, then "version"
+ // above will be populated in the tools source.
+ addVersionToSource bool
  }

  var bootstrapRetryTests = []bootstrapRetryTest{{
- info: "no tools uploaded, first check has no retries; check
after upload has retries",
- expectedAllowRetry: []bool{false, true},
- err: "tools not found",
+ info: "no tools uploaded, first check has no retries; no
matching binary in source; sync fails with no second attempt",
+ expectedAllowRetry: []bool{false},
+ err: "no matching tools available",
+ version: "1.16.0-precise-amd64",
+}, {
+ info: "no tools uploaded, first check has no retries;
matching binary in source; check after sync has retries",
+ expectedAllowRetry: []bool{false, true},
+ err: "tools not found",
+ version: "1.16.0-precise-amd64",
+ addVersionToSource: true,
+}, {
+ info: "no tools uploaded, first check has no retries; no
matching binary in source; check after upload has retries",
+ expectedAllowRetry: []bool{false, true},
+ err: "tools not found",
+ version: "1.15.1-precise-amd64", // dev version to force upload
  }, {
   info: "new tools uploaded, so we want to allow retries to
give them a cha...

Read more...

Revision history for this message
William Reade (fwereade) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/juju/bootstrap_test.go'
2--- cmd/juju/bootstrap_test.go 2013-10-03 01:56:15 +0000
3+++ cmd/juju/bootstrap_test.go 2013-10-09 10:37:06 +0000
4@@ -65,12 +65,30 @@
5 args []string
6 expectedAllowRetry []bool
7 err string
8+ // If version != "", version.Current will be
9+ // set to it for the duration of the test.
10+ version string
11+ // If addVersionToSource is true, then "version"
12+ // above will be populated in the tools source.
13+ addVersionToSource bool
14 }
15
16 var bootstrapRetryTests = []bootstrapRetryTest{{
17- info: "no tools uploaded, first check has no retries; check after upload has retries",
18- expectedAllowRetry: []bool{false, true},
19- err: "tools not found",
20+ info: "no tools uploaded, first check has no retries; no matching binary in source; sync fails with no second attempt",
21+ expectedAllowRetry: []bool{false},
22+ err: "no matching tools available",
23+ version: "1.16.0-precise-amd64",
24+}, {
25+ info: "no tools uploaded, first check has no retries; matching binary in source; check after sync has retries",
26+ expectedAllowRetry: []bool{false, true},
27+ err: "tools not found",
28+ version: "1.16.0-precise-amd64",
29+ addVersionToSource: true,
30+}, {
31+ info: "no tools uploaded, first check has no retries; no matching binary in source; check after upload has retries",
32+ expectedAllowRetry: []bool{false, true},
33+ err: "tools not found",
34+ version: "1.15.1-precise-amd64", // dev version to force upload
35 }, {
36 info: "new tools uploaded, so we want to allow retries to give them a chance at showing up",
37 args: []string{"--upload-tools"},
38@@ -87,12 +105,20 @@
39 }
40
41 func (s *BootstrapSuite) runAllowRetriesTest(c *gc.C, test bootstrapRetryTest) {
42+ var extraVersions []version.Binary
43+ if test.version != "" {
44+ testVersion := version.MustParseBinary(test.version)
45+ restore := testbase.PatchValue(&version.Current, testVersion)
46+ defer restore()
47+ if test.addVersionToSource {
48+ extraVersions = append(extraVersions, testVersion)
49+ }
50+ }
51 _, fake := makeEmptyFakeHome(c)
52 defer fake.Restore()
53- defer createToolsStore(c)()
54+ defer createToolsStore(c, extraVersions...)()
55
56 var findToolsRetryValues []bool
57-
58 mockFindTools := func(cloudInst environs.ConfigGetter, majorVersion, minorVersion int,
59 filter coretools.Filter, allowRetry bool) (list coretools.List, err error) {
60 findToolsRetryValues = append(findToolsRetryValues, allowRetry)
61@@ -102,7 +128,7 @@
62 restore := envtools.TestingPatchBootstrapFindTools(mockFindTools)
63 defer restore()
64
65- _, errc := runCommand(nil, new(BootstrapCommand), test.args...)
66+ _, errc := runCommand(nullContext(), new(BootstrapCommand), test.args...)
67 err := <-errc
68 c.Check(findToolsRetryValues, gc.DeepEquals, test.expectedAllowRetry)
69 c.Assert(err, gc.ErrorMatches, test.err)
70@@ -155,7 +181,7 @@
71 }
72
73 // Run command and check for uploads.
74- opc, errc := runCommand(nil, new(BootstrapCommand), test.args...)
75+ opc, errc := runCommand(nullContext(), new(BootstrapCommand), test.args...)
76 if uploadCount > 0 {
77 for i := 0; i < uploadCount; i++ {
78 c.Check((<-opc).(dummy.OpPutFile).Env, gc.Equals, "peckham")
79@@ -230,9 +256,10 @@
80 args: []string{"--series", "fine"},
81 err: `--series requires --upload-tools`,
82 }, {
83- info: "bad environment",
84- args: []string{"-e", "brokenenv"},
85- err: `dummy.Bootstrap is broken`,
86+ info: "bad environment",
87+ version: "1.2.3-precise-amd64",
88+ args: []string{"-e", "brokenenv"},
89+ err: `dummy.Bootstrap is broken`,
90 }, {
91 info: "constraints",
92 args: []string{"--constraints", "mem=4G cpu-cores=4"},
93@@ -270,10 +297,12 @@
94 }}
95
96 func (s *BootstrapSuite) TestBootstrapTwice(c *gc.C) {
97- restore := createToolsStore(c)
98+ env, fake := makeEmptyFakeHome(c)
99+ defer fake.Restore()
100+ defaultSeriesVersion := version.Current
101+ defaultSeriesVersion.Series = env.Config().DefaultSeries()
102+ restore := createToolsStore(c, defaultSeriesVersion)
103 defer restore()
104- _, fake := makeEmptyFakeHome(c)
105- defer fake.Restore()
106
107 ctx := coretesting.Context(c)
108 code := cmd.Main(&BootstrapCommand{}, ctx, nil)
109@@ -385,7 +414,7 @@
110 }
111 env := s.setupAutoUploadTest(c, "1.7.3", otherSeries)
112 // Run command and check for that upload has been run for tools matching the current juju version.
113- opc, errc := runCommand(nil, new(BootstrapCommand))
114+ opc, errc := runCommand(nullContext(), new(BootstrapCommand))
115 c.Assert(<-errc, gc.IsNil)
116 c.Assert((<-opc).(dummy.OpPutFile).Env, gc.Equals, "peckham")
117 list, err := envtools.FindTools(env, version.Current.Major, version.Current.Minor, coretools.Filter{}, false)
118@@ -406,7 +435,7 @@
119
120 func (s *BootstrapSuite) TestAutoUploadOnlyForDev(c *gc.C) {
121 s.setupAutoUploadTest(c, "1.8.3", "precise")
122- _, errc := runCommand(nil, new(BootstrapCommand))
123+ _, errc := runCommand(nullContext(), new(BootstrapCommand))
124 err := <-errc
125 c.Assert(err, gc.ErrorMatches, "no matching tools available")
126 }
127@@ -439,7 +468,7 @@
128 }
129
130 // createToolsStore creates the fake tools store.
131-func createToolsStore(c *gc.C) func() {
132+func createToolsStore(c *gc.C, additionalBinaries ...version.Binary) func() {
133 stor, err := envtesting.NewEC2HTTPTestStorage("127.0.0.1")
134 c.Assert(err, gc.IsNil)
135 origLocation := sync.DefaultToolsLocation
136@@ -447,6 +476,9 @@
137 for _, vers := range vAll {
138 stor.PutBinary(vers)
139 }
140+ for _, vers := range additionalBinaries {
141+ stor.PutBinary(vers)
142+ }
143 restore := func() {
144 sync.DefaultToolsLocation = origLocation
145 }
146
147=== modified file 'cmd/juju/cmd_test.go'
148--- cmd/juju/cmd_test.go 2013-09-30 20:01:49 +0000
149+++ cmd/juju/cmd_test.go 2013-10-09 10:37:06 +0000
150@@ -5,6 +5,8 @@
151
152 import (
153 "bytes"
154+ "io"
155+ "io/ioutil"
156 "os"
157 "reflect"
158
159@@ -126,7 +128,18 @@
160 }
161 }
162
163+func nullContext() *cmd.Context {
164+ ctx := cmd.DefaultContext()
165+ ctx.Stdin = io.LimitReader(nil, 0)
166+ ctx.Stdout = ioutil.Discard
167+ ctx.Stderr = ioutil.Discard
168+ return ctx
169+}
170+
171 func runCommand(ctx *cmd.Context, com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) {
172+ if ctx == nil {
173+ panic("ctx == nil")
174+ }
175 errc = make(chan error, 1)
176 opc = make(chan dummy.Operation, 200)
177 dummy.Listen(opc)
178@@ -140,9 +153,6 @@
179 return
180 }
181
182- if ctx == nil {
183- ctx = cmd.DefaultContext()
184- }
185 err = com.Run(ctx)
186 errc <- err
187 }()
188@@ -161,7 +171,7 @@
189 c.Assert(err, gc.IsNil)
190
191 // normal destroy
192- opc, errc := runCommand(nil, new(DestroyEnvironmentCommand), "--yes")
193+ opc, errc := runCommand(nullContext(), new(DestroyEnvironmentCommand), "--yes")
194 c.Check(<-errc, gc.IsNil)
195 c.Check((<-opc).(dummy.OpDestroy).Env, gc.Equals, "peckham")
196
197@@ -173,7 +183,7 @@
198 c.Assert(err, gc.IsNil)
199
200 // destroy with broken environment
201- opc, errc = runCommand(nil, new(DestroyEnvironmentCommand), "--yes", "-e", "brokenenv")
202+ opc, errc = runCommand(nullContext(), new(DestroyEnvironmentCommand), "--yes", "-e", "brokenenv")
203 c.Check(<-opc, gc.IsNil)
204 c.Check(<-errc, gc.ErrorMatches, "dummy.Destroy is broken")
205 c.Check(<-opc, gc.IsNil)
206
207=== modified file 'environs/sync/sync.go'
208--- environs/sync/sync.go 2013-09-27 02:31:45 +0000
209+++ environs/sync/sync.go 2013-10-09 10:37:06 +0000
210@@ -70,9 +70,10 @@
211 if !syncContext.AllVersions {
212 syncContext.MinorVersion = version.Current.Minor
213 }
214- } else {
215+ } else if !syncContext.Dev && syncContext.MinorVersion != -1 {
216 // If a major.minor version is specified, we allow dev versions.
217- syncContext.Dev = syncContext.MinorVersion != -1
218+ // If Dev is already true, leave it alone.
219+ syncContext.Dev = true
220 }
221 sourceTools, err := envtools.ReadList(sourceStorage, syncContext.MajorVersion, syncContext.MinorVersion)
222 if err != nil {
223@@ -261,7 +262,7 @@
224 Source: baseToolsDir,
225 Target: stor,
226 AllVersions: true,
227- Dev: true,
228+ Dev: toolsVersion.IsDev(),
229 MajorVersion: toolsVersion.Major,
230 MinorVersion: -1,
231 }

Subscribers

People subscribed via source and target branches

to all changes: