Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(46)

Delta Between Two Patch Sets: cmd/jujud/upgrade_test.go

Issue 6501106: environs: remove VarDir global
Left Patch Set: environs: remove VarDir global Created 11 years, 6 months ago
Right Patch Set: environs: remove VarDir global Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/jujud/upgrade.go ('k') | cmd/jujud/util_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package main 1 package main
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "io/ioutil" 5 "io/ioutil"
6 . "launchpad.net/gocheck" 6 . "launchpad.net/gocheck"
7 "launchpad.net/juju-core/environs" 7 "launchpad.net/juju-core/environs"
8 "launchpad.net/juju-core/environs/config" 8 "launchpad.net/juju-core/environs/config"
9 "launchpad.net/juju-core/juju/testing" 9 "launchpad.net/juju-core/juju/testing"
10 "launchpad.net/juju-core/state" 10 "launchpad.net/juju-core/state"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 propose: "2.0.5", 112 propose: "2.0.5",
113 upgradeTo: "2.0.5", 113 upgradeTo: "2.0.5",
114 }, 114 },
115 } 115 }
116 116
117 func (s *upgraderSuite) TestUpgrader(c *C) { 117 func (s *upgraderSuite) TestUpgrader(c *C) {
118 // Set up the current version and tools. 118 // Set up the current version and tools.
119 version.Current = version.MustParseBinary("2.0.0-foo-bar") 119 version.Current = version.MustParseBinary("2.0.0-foo-bar")
120 v0path, v0tools := s.uploadTools(c, version.Current) 120 v0path, v0tools := s.uploadTools(c, version.Current)
121 121
122 » varDir := c.MkDir() 122 » dataDir := c.MkDir()
123 // Unpack the "current" version of the tools, and delete them from 123 // Unpack the "current" version of the tools, and delete them from
124 // the storage so that we're sure that the uploader isn't trying 124 // the storage so that we're sure that the uploader isn't trying
125 // to fetch them. 125 // to fetch them.
126 resp, err := http.Get(v0tools.URL) 126 resp, err := http.Get(v0tools.URL)
127 c.Assert(err, IsNil) 127 c.Assert(err, IsNil)
128 » err = environs.UnpackTools(varDir, v0tools, resp.Body) 128 » err = environs.UnpackTools(dataDir, v0tools, resp.Body)
129 c.Assert(err, IsNil) 129 c.Assert(err, IsNil)
130 err = s.Conn.Environ.Storage().Remove(v0path) 130 err = s.Conn.Environ.Storage().Remove(v0path)
131 c.Assert(err, IsNil) 131 c.Assert(err, IsNil)
132 132
133 var ( 133 var (
134 u *Upgrader 134 u *Upgrader
135 upgraderDone <-chan error 135 upgraderDone <-chan error
136 currentTools = v0tools 136 currentTools = v0tools
137 ) 137 )
138 138
139 defer func() { 139 defer func() {
140 if u != nil { 140 if u != nil {
141 c.Assert(u.Stop(), IsNil) 141 c.Assert(u.Stop(), IsNil)
142 } 142 }
143 }() 143 }()
144 144
145 uploaded := make(map[version.Number]*state.Tools) 145 uploaded := make(map[version.Number]*state.Tools)
146 for i, test := range upgraderTests { 146 for i, test := range upgraderTests {
147 c.Logf("%d. %s; current version: %v", i, test.about, version.Cur rent) 147 c.Logf("%d. %s; current version: %v", i, test.about, version.Cur rent)
148 for _, v := range test.upload { 148 for _, v := range test.upload {
149 vers := version.Current 149 vers := version.Current
150 vers.Number = version.MustParse(v) 150 vers.Number = version.MustParse(v)
151 _, tools := s.uploadTools(c, vers) 151 _, tools := s.uploadTools(c, vers)
152 uploaded[vers.Number] = tools 152 uploaded[vers.Number] = tools
153 } 153 }
154 if u == nil { 154 if u == nil {
155 » » » u = startUpgrader(c, s.State, varDir, currentTools) 155 » » » u = startUpgrader(c, s.State, dataDir, currentTools)
156 } 156 }
157 s.proposeVersion(c, version.MustParse(test.propose), test.devVer sion) 157 s.proposeVersion(c, version.MustParse(test.propose), test.devVer sion)
158 if test.upgradeTo == "" { 158 if test.upgradeTo == "" {
159 assertNothingHappens(c, upgraderDone) 159 assertNothingHappens(c, upgraderDone)
160 } else { 160 } else {
161 tools := uploaded[version.MustParse(test.upgradeTo)] 161 tools := uploaded[version.MustParse(test.upgradeTo)]
162 waitDeath(c, u, tools, "") 162 waitDeath(c, u, tools, "")
163 // Check that the upgraded version was really downloaded . 163 // Check that the upgraded version was really downloaded .
164 » » » data, err := ioutil.ReadFile(filepath.Join(environs.Tool sDir(varDir, tools.Binary), "jujud")) 164 » » » data, err := ioutil.ReadFile(filepath.Join(environs.Tool sDir(dataDir, tools.Binary), "jujud"))
165 c.Assert(err, IsNil) 165 c.Assert(err, IsNil)
166 c.Assert(string(data), Equals, "jujud contents "+tools.B inary.String()) 166 c.Assert(string(data), Equals, "jujud contents "+tools.B inary.String())
167 167
168 u, upgraderDone = nil, nil 168 u, upgraderDone = nil, nil
169 currentTools = tools 169 currentTools = tools
170 version.Current = tools.Binary 170 version.Current = tools.Binary
171 } 171 }
172 } 172 }
173 } 173 }
174 174
175 func assertNothingHappens(c *C, upgraderDone <-chan error) { 175 func assertNothingHappens(c *C, upgraderDone <-chan error) {
176 select { 176 select {
177 case got := <-upgraderDone: 177 case got := <-upgraderDone:
178 c.Fatalf("expected nothing to happen, got %v", got) 178 c.Fatalf("expected nothing to happen, got %v", got)
179 case <-time.After(100 * time.Millisecond): 179 case <-time.After(100 * time.Millisecond):
180 } 180 }
181 } 181 }
182 182
183 func assertEvent(c *C, event <-chan string, want string) { 183 func assertEvent(c *C, event <-chan string, want string) {
184 select { 184 select {
185 case got := <-event: 185 case got := <-event:
186 c.Assert(got, Equals, want) 186 c.Assert(got, Equals, want)
187 case <-time.After(500 * time.Millisecond): 187 case <-time.After(500 * time.Millisecond):
188 c.Fatalf("no event received; expected %q", want) 188 c.Fatalf("no event received; expected %q", want)
189 } 189 }
190 } 190 }
191 191
192 // startUpgrader starts the upgrader using the given machine, 192 // startUpgrader starts the upgrader using the given machine,
193 // expecting to see it set the given agent tools. 193 // expecting to see it set the given agent tools.
194 func startUpgrader(c *C, st *state.State, varDir string, expectTools *state.Tool s) *Upgrader { 194 func startUpgrader(c *C, st *state.State, dataDir string, expectTools *state.Too ls) *Upgrader {
195 as := testAgentState(make(chan *state.Tools)) 195 as := testAgentState(make(chan *state.Tools))
196 » u := NewUpgrader(st, as, varDir) 196 » u := NewUpgrader(st, as, dataDir)
197 select { 197 select {
198 case tools := <-as: 198 case tools := <-as:
199 c.Assert(tools, DeepEquals, expectTools) 199 c.Assert(tools, DeepEquals, expectTools)
200 case <-time.After(500 * time.Millisecond): 200 case <-time.After(500 * time.Millisecond):
201 c.Fatalf("upgrader did not set agent tools") 201 c.Fatalf("upgrader did not set agent tools")
202 } 202 }
203 return u 203 return u
204 } 204 }
205 205
206 func waitDeath(c *C, u *Upgrader, upgradeTo *state.Tools, errPat string) { 206 func waitDeath(c *C, u *Upgrader, upgradeTo *state.Tools, errPat string) {
(...skipping 16 matching lines...) Expand all
223 } 223 }
224 } 224 }
225 225
226 type testAgentState chan *state.Tools 226 type testAgentState chan *state.Tools
227 227
228 func (as testAgentState) SetAgentTools(tools *state.Tools) error { 228 func (as testAgentState) SetAgentTools(tools *state.Tools) error {
229 t := *tools 229 t := *tools
230 as <- &t 230 as <- &t
231 return nil 231 return nil
232 } 232 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b