Merge lp:~wallyworld/juju-core/fix-tools-tests-1.18 into lp:juju-core/1.18

Proposed by Ian Booth
Status: Merged
Approved by: William Reade
Approved revision: no longer in the source branch.
Merged at revision: 2261
Proposed branch: lp:~wallyworld/juju-core/fix-tools-tests-1.18
Merge into: lp:juju-core/1.18
Diff against target: 220 lines (+59/-22)
3 files modified
cmd/juju/bootstrap_test.go (+26/-3)
environs/bootstrap/bootstrap_test.go (+25/-14)
environs/bootstrap/synctools.go (+8/-5)
To merge this branch: bzr merge lp:~wallyworld/juju-core/fix-tools-tests-1.18
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+214159@code.launchpad.net

Commit message

A handful of unit tests which call bootstrap or functions which upload tools failed if the Juju version is a release number eg 1.18. This is because those tests did not first explicitly upload tools and auto upload for release tools is not allowed.

The affected tests patch the version.Current variable to change the version to a dev release.

Also, changes were made to allow release tools be uploaded (a version.Dev() check is removed). Tested live with EC2.

Description of the change

A handful of unit tests which call bootstrap or functions which upload tools failed if the Juju version is a release number eg 1.18. This is because those tests did not first explicitly upload tools and auto upload for release tools is not allowed.

The affected tests patch the version.Current variable to change the version to a dev release.

Also, changes were made to allow release tools be uploaded (a version.Dev() check is removed). Tested live with EC2.

To post a comment you must log in.
Revision history for this message
William Reade (fwereade) wrote :

LGTM. Thank you very much: you have gone further above and beyond than anyone can or should expect, please don't burn yourself out.

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 2014-04-03 19:11:11 +0000
3+++ cmd/juju/bootstrap_test.go 2014-04-04 14:36:15 +0000
4@@ -303,9 +303,10 @@
5 args: []string{"--series", "fine"},
6 err: `--series requires --upload-tools`,
7 }, {
8- info: "bad environment",
9- args: []string{"-e", "brokenenv"},
10- err: `dummy.Bootstrap is broken`,
11+ info: "bad environment",
12+ version: "1.2.3-%LTS%-amd64",
13+ args: []string{"-e", "brokenenv"},
14+ err: `dummy.Bootstrap is broken`,
15 }, {
16 info: "constraints",
17 args: []string{"--constraints", "mem=4G cpu-cores=4"},
18@@ -369,6 +370,11 @@
19 defer fake.Restore()
20 defaultSeriesVersion := version.Current
21 defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
22+ // Force a dev version by having an odd minor version number.
23+ // This is because we have not uploaded any tools and auto
24+ // upload is only enabled for dev versions.
25+ defaultSeriesVersion.Minor = 11
26+ s.PatchValue(&version.Current, defaultSeriesVersion)
27
28 ctx := coretesting.Context(c)
29 code := cmd.Main(&BootstrapCommand{}, ctx, nil)
30@@ -388,6 +394,11 @@
31 defer fake.Restore()
32 defaultSeriesVersion := version.Current
33 defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
34+ // Force a dev version by having an odd minor version number.
35+ // This is because we have not uploaded any tools and auto
36+ // upload is only enabled for dev versions.
37+ defaultSeriesVersion.Minor = 11
38+ s.PatchValue(&version.Current, defaultSeriesVersion)
39
40 store, err := configstore.Default()
41 c.Assert(err, gc.IsNil)
42@@ -458,6 +469,12 @@
43 defer fake.Restore()
44
45 // Bootstrap the environment with the valid source.
46+ // Force a dev version by having an odd minor version number.
47+ // This is because we have not uploaded any tools and auto
48+ // upload is only enabled for dev versions.
49+ devVersion := version.Current
50+ devVersion.Minor = 11
51+ s.PatchValue(&version.Current, devVersion)
52 ctx := coretesting.Context(c)
53 code := cmd.Main(&BootstrapCommand{}, ctx, []string{"--metadata-source", sourceDir})
54 c.Check(code, gc.Equals, 0)
55@@ -580,6 +597,12 @@
56 func (s *BootstrapSuite) TestBootstrapDestroy(c *gc.C) {
57 _, fake := makeEmptyFakeHome(c)
58 defer fake.Restore()
59+ devVersion := version.Current
60+ // Force a dev version by having an odd minor version number.
61+ // This is because we have not uploaded any tools and auto
62+ // upload is only enabled for dev versions.
63+ devVersion.Minor = 11
64+ s.PatchValue(&version.Current, devVersion)
65 opc, errc := runCommand(nullContext(c), new(BootstrapCommand), "-e", "brokenenv")
66 err := <-errc
67 c.Assert(err, gc.ErrorMatches, "dummy.Bootstrap is broken")
68
69=== modified file 'environs/bootstrap/bootstrap_test.go'
70--- environs/bootstrap/bootstrap_test.go 2014-04-03 19:11:11 +0000
71+++ environs/bootstrap/bootstrap_test.go 2014-04-04 14:36:15 +0000
72@@ -180,8 +180,11 @@
73 }
74 err = bootstrap.Bootstrap(coretesting.Context(c), env, cons)
75 if test.Err != "" {
76- stripped := strings.Replace(err.Error(), "\n", "", -1)
77- c.Check(stripped, gc.Matches, ".*"+stripped)
78+ c.Check(err, gc.NotNil)
79+ if err != nil {
80+ stripped := strings.Replace(err.Error(), "\n", "", -1)
81+ c.Check(stripped, gc.Matches, ".*"+stripped)
82+ }
83 continue
84 } else {
85 c.Check(err, gc.IsNil)
86@@ -213,6 +216,12 @@
87 s.PatchValue(&arch.HostArch, func() string {
88 return "amd64"
89 })
90+ // Force a dev version by having an odd minor version number.
91+ // This is because we have not uploaded any tools and auto
92+ // upload is only enabled for dev versions.
93+ devVersion := version.Current
94+ devVersion.Minor = 11
95+ s.PatchValue(&version.Current, devVersion)
96 env := newEnviron("foo", useDefaultKeys, nil)
97 s.setDummyStorage(c, env)
98 envtesting.RemoveFakeTools(c, env.Storage())
99@@ -230,6 +239,12 @@
100 s.PatchValue(&arch.HostArch, func() string {
101 return "ppc64"
102 })
103+ // Force a dev version by having an odd minor version number.
104+ // This is because we have not uploaded any tools and auto
105+ // upload is only enabled for dev versions.
106+ devVersion := version.Current
107+ devVersion.Minor = 11
108+ s.PatchValue(&version.Current, devVersion)
109 env := newEnviron("foo", useDefaultKeys, nil)
110 s.setDummyStorage(c, env)
111 envtesting.RemoveFakeTools(c, env.Storage())
112@@ -255,7 +270,7 @@
113 }
114
115 func (s *bootstrapSuite) TestEnsureToolsAvailabilityNonDevVersion(c *gc.C) {
116- // Can't upload tools for released versions.
117+ // Can't automatically upload tools for released versions.
118 s.PatchValue(&version.Current, version.MustParseBinary("1.18.0-trusty-arm64"))
119 env := newEnviron("foo", useDefaultKeys, nil)
120 s.setDummyStorage(c, env)
121@@ -339,7 +354,7 @@
122 c.Assert(bootstrap.SeriesToUpload(cfg, nil), jc.SameContents, []string{"quantal", config.LatestLtsSeries(), "lucid"})
123 }
124
125-func (s *bootstrapSuite) assertUploadTools(c *gc.C, vers version.Binary, allowRelease bool,
126+func (s *bootstrapSuite) assertUploadTools(c *gc.C, vers version.Binary, forceVersion bool,
127 extraConfig map[string]interface{}, errMessage string) {
128
129 s.PatchValue(&version.Current, vers)
130@@ -360,8 +375,9 @@
131 return "arm64"
132 })
133 arch := "arm64"
134- err := bootstrap.UploadTools(coretesting.Context(c), env, &arch, allowRelease, "precise")
135+ err := bootstrap.UploadTools(coretesting.Context(c), env, &arch, forceVersion, "precise")
136 if errMessage != "" {
137+ c.Assert(err, gc.NotNil)
138 stripped := strings.Replace(err.Error(), "\n", "", -1)
139 c.Assert(stripped, gc.Matches, errMessage)
140 return
141@@ -369,14 +385,14 @@
142 c.Assert(err, gc.IsNil)
143 params := envtools.BootstrapToolsParams{
144 Arch: &arch,
145- Series: "precise",
146+ Series: version.Current.Series,
147 }
148 agentTools, err := envtools.FindBootstrapTools(env, params)
149 c.Assert(err, gc.IsNil)
150 c.Assert(agentTools, gc.HasLen, 1)
151 expectedVers := vers
152 expectedVers.Number.Build++
153- expectedVers.Series = "precise"
154+ expectedVers.Series = version.Current.Series
155 c.Assert(agentTools[0].Version, gc.DeepEquals, expectedVers)
156 }
157
158@@ -385,10 +401,10 @@
159 s.assertUploadTools(c, vers, false, nil, "")
160 }
161
162-func (s *bootstrapSuite) TestUploadToolsForceVersionAllowsReleaseTools(c *gc.C) {
163+func (s *bootstrapSuite) TestUploadToolsReleaseToolsWithDevConfig(c *gc.C) {
164 vers := version.MustParseBinary("1.18.0-trusty-arm64")
165 extraCfg := map[string]interface{}{"development": true}
166- s.assertUploadTools(c, vers, true, extraCfg, "")
167+ s.assertUploadTools(c, vers, false, extraCfg, "")
168 }
169
170 func (s *bootstrapSuite) TestUploadToolsForceVersionAllowsAgentVersionSet(c *gc.C) {
171@@ -397,11 +413,6 @@
172 s.assertUploadTools(c, vers, true, extraCfg, "")
173 }
174
175-func (s *bootstrapSuite) TestUploadToolsReleaseVersionDisallowed(c *gc.C) {
176- vers := version.MustParseBinary("1.18.0-trusty-arm64")
177- s.assertUploadTools(c, vers, false, nil, "Juju cannot bootstrap because no tools are available for your environment.*")
178-}
179-
180 type bootstrapEnviron struct {
181 name string
182 cfg *config.Config
183
184=== modified file 'environs/bootstrap/synctools.go'
185--- environs/bootstrap/synctools.go 2014-04-03 19:11:11 +0000
186+++ environs/bootstrap/synctools.go 2014-04-04 14:36:15 +0000
187@@ -29,8 +29,7 @@
188
189 // UploadTools uploads tools for the specified series and any other relevant series to
190 // the environment storage, after which it sets the agent-version. If forceVersion is true,
191-// we allow uploading release tools versions and allow uploading even when the agent-version is
192-// already set in the environment.
193+// we allow uploading even when the agent-version is already set in the environment.
194 func UploadTools(ctx environs.BootstrapContext, env environs.Environ, toolsArch *string, forceVersion bool, bootstrapSeries ...string) error {
195 logger.Infof("checking that upload is possible")
196 // Check the series are valid.
197@@ -112,9 +111,8 @@
198 // not be allowed.
199 func validateUploadAllowed(env environs.Environ, toolsArch *string, forceVersion bool) error {
200 if !forceVersion {
201- // First, check that there isn't already an agent version specified, and that we
202- // are running a development version.
203- if _, hasAgentVersion := env.Config().AgentVersion(); hasAgentVersion || !version.Current.IsDev() {
204+ // First, check that there isn't already an agent version specified.
205+ if _, hasAgentVersion := env.Config().AgentVersion(); hasAgentVersion {
206 return fmt.Errorf(noToolsNoUploadMessage)
207 }
208 }
209@@ -174,6 +172,11 @@
210 return nil, err
211 }
212
213+ // Only automatically upload tools for dev versions.
214+ if !version.Current.IsDev() {
215+ return nil, fmt.Errorf("cannot upload bootstrap tools: %v", noToolsNoUploadMessage)
216+ }
217+
218 // No tools available so our only hope is to build locally and upload.
219 logger.Warningf("no prepackaged tools available")
220 uploadSeries := SeriesToUpload(cfg, nil)

Subscribers

People subscribed via source and target branches

to all changes: