Merge lp:~elopio/snappy/integration-fix-rollback into lp:~snappy-dev/snappy/snappy-moved-to-github
- integration-fix-rollback
- Merge into snappy-moved-to-github
Proposed by
Leo Arias
Status: | Needs review |
---|---|
Proposed branch: | lp:~elopio/snappy/integration-fix-rollback |
Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
Prerequisite: | lp:~elopio/snappy/assertion_messages |
Diff against target: |
515 lines (+160/-122) (has conflicts) 4 files modified
_integration-tests/tests/rollback_test.go (+2/-1) _integration-tests/testutils/partition/bootloader.go (+26/-4) _integration-tests/testutils/partition/bootloader_test.go (+121/-106) _integration-tests/testutils/partition/partition_test.go (+11/-11) Text conflict in _integration-tests/tests/examples_test.go Text conflict in _integration-tests/testutils/wait/wait_test.go |
To merge this branch: | bzr merge lp:~elopio/snappy/integration-fix-rollback |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Snappy Developers | Pending | ||
Review via email: mp+274651@code.launchpad.net |
Commit message
Fixed the integration fake rollback test. It was using the deprecated uboot config file.
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '_integration-tests/tests/rollback_test.go' | |||
2 | --- _integration-tests/tests/rollback_test.go 2015-10-16 00:47:50 +0000 | |||
3 | +++ _integration-tests/tests/rollback_test.go 2015-10-16 00:47:50 +0000 | |||
4 | @@ -44,7 +44,8 @@ | |||
5 | 44 | common.RemoveRebootMark(c) | 44 | common.RemoveRebootMark(c) |
6 | 45 | // Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293 | 45 | // Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293 |
7 | 46 | // TODO remove once the bug is fixed. --elopio - 2015-09-30 | 46 | // TODO remove once the bug is fixed. --elopio - 2015-09-30 |
9 | 47 | wait.ForFunction(c, "regular", partition.Mode) | 47 | err := wait.ForFunction(c, "regular", partition.Mode) |
10 | 48 | c.Assert(err, check.IsNil, check.Commentf("Failed to switch to regular mode: %s", err)) | ||
11 | 48 | currentVersion := common.GetCurrentUbuntuCoreVersion(c) | 49 | currentVersion := common.GetCurrentUbuntuCoreVersion(c) |
12 | 49 | c.Assert(currentVersion > common.GetSavedVersion(c), check.Equals, true, | 50 | c.Assert(currentVersion > common.GetSavedVersion(c), check.Equals, true, |
13 | 50 | check.Commentf("Rebooted to the wrong version: %d", currentVersion)) | 51 | check.Commentf("Rebooted to the wrong version: %d", currentVersion)) |
14 | 51 | 52 | ||
15 | === modified file '_integration-tests/testutils/partition/bootloader.go' | |||
16 | --- _integration-tests/testutils/partition/bootloader.go 2015-10-02 10:29:29 +0000 | |||
17 | +++ _integration-tests/testutils/partition/bootloader.go 2015-10-16 00:47:50 +0000 | |||
18 | @@ -25,13 +25,15 @@ | |||
19 | 25 | "os" | 25 | "os" |
20 | 26 | "path/filepath" | 26 | "path/filepath" |
21 | 27 | "strings" | 27 | "strings" |
22 | 28 | |||
23 | 29 | "github.com/mvo5/uboot-go/uenv" | ||
24 | 28 | ) | 30 | ) |
25 | 29 | 31 | ||
26 | 30 | const ( | 32 | const ( |
27 | 31 | bootBase = "/boot" | 33 | bootBase = "/boot" |
28 | 32 | ubootDir = bootBase + "/uboot" | 34 | ubootDir = bootBase + "/uboot" |
29 | 33 | grubDir = bootBase + "/grub" | 35 | grubDir = bootBase + "/grub" |
31 | 34 | ubootConfigFile = ubootDir + "/snappy-system.txt" | 36 | ubootConfigFile = ubootDir + "/uboot.env" |
32 | 35 | grubConfigFile = grubDir + "/grubenv" | 37 | grubConfigFile = grubDir + "/grubenv" |
33 | 36 | ) | 38 | ) |
34 | 37 | 39 | ||
35 | @@ -41,6 +43,8 @@ | |||
36 | 41 | // BootSystem proxies bootSystem | 43 | // BootSystem proxies bootSystem |
37 | 42 | BootSystem = bootSystem | 44 | BootSystem = bootSystem |
38 | 43 | 45 | ||
39 | 46 | confValue = getConfValue | ||
40 | 47 | |||
41 | 44 | configFiles = map[string]string{"uboot": ubootConfigFile, "grub": grubConfigFile} | 48 | configFiles = map[string]string{"uboot": ubootConfigFile, "grub": grubConfigFile} |
42 | 45 | ) | 49 | ) |
43 | 46 | 50 | ||
44 | @@ -101,14 +105,22 @@ | |||
45 | 101 | return confValue("snappy_mode") | 105 | return confValue("snappy_mode") |
46 | 102 | } | 106 | } |
47 | 103 | 107 | ||
49 | 104 | func confValue(key string) (partition string, err error) { | 108 | func getConfValue(key string) (value string, err error) { |
50 | 105 | system, err := BootSystem() | 109 | system, err := BootSystem() |
51 | 106 | if err != nil { | 110 | if err != nil { |
52 | 107 | return | 111 | return |
53 | 108 | } | 112 | } |
54 | 109 | 113 | ||
56 | 110 | bootConfigFile := configFiles[system] | 114 | if system == "grub" { |
57 | 115 | value, err = getGrubConfValue(key) | ||
58 | 116 | } else if system == "uboot" { | ||
59 | 117 | value, err = getUbootConfValue(key) | ||
60 | 118 | } | ||
61 | 119 | return | ||
62 | 120 | } | ||
63 | 111 | 121 | ||
64 | 122 | func getGrubConfValue(key string) (value string, err error) { | ||
65 | 123 | bootConfigFile := configFiles["grub"] | ||
66 | 112 | file, err := os.Open(bootConfigFile) | 124 | file, err := os.Open(bootConfigFile) |
67 | 113 | if err != nil { | 125 | if err != nil { |
68 | 114 | return | 126 | return |
69 | @@ -123,7 +135,7 @@ | |||
70 | 123 | if strings.HasPrefix(scanner.Text(), key) { | 135 | if strings.HasPrefix(scanner.Text(), key) { |
71 | 124 | fields := strings.Split(scanner.Text(), "=") | 136 | fields := strings.Split(scanner.Text(), "=") |
72 | 125 | if len(fields) > 1 { | 137 | if len(fields) > 1 { |
74 | 126 | partition = fields[1] | 138 | value = fields[1] |
75 | 127 | } | 139 | } |
76 | 128 | return | 140 | return |
77 | 129 | } | 141 | } |
78 | @@ -131,6 +143,16 @@ | |||
79 | 131 | return | 143 | return |
80 | 132 | } | 144 | } |
81 | 133 | 145 | ||
82 | 146 | func getUbootConfValue(key string) (value string, err error) { | ||
83 | 147 | bootConfigFile := configFiles["uboot"] | ||
84 | 148 | env, err := uenv.Open(bootConfigFile) | ||
85 | 149 | if err != nil { | ||
86 | 150 | return "", err | ||
87 | 151 | } | ||
88 | 152 | |||
89 | 153 | return env.Get(key), nil | ||
90 | 154 | } | ||
91 | 155 | |||
92 | 134 | // OtherPartition returns the backup partition, a or b. | 156 | // OtherPartition returns the backup partition, a or b. |
93 | 135 | func OtherPartition(current string) string { | 157 | func OtherPartition(current string) string { |
94 | 136 | if current == "a" { | 158 | if current == "a" { |
95 | 137 | 159 | ||
96 | === modified file '_integration-tests/testutils/partition/bootloader_test.go' | |||
97 | --- _integration-tests/testutils/partition/bootloader_test.go 2015-10-01 15:12:30 +0000 | |||
98 | +++ _integration-tests/testutils/partition/bootloader_test.go 2015-10-16 00:47:50 +0000 | |||
99 | @@ -23,8 +23,10 @@ | |||
100 | 23 | "fmt" | 23 | "fmt" |
101 | 24 | "io/ioutil" | 24 | "io/ioutil" |
102 | 25 | "os" | 25 | "os" |
103 | 26 | "path" | ||
104 | 26 | "testing" | 27 | "testing" |
105 | 27 | 28 | ||
106 | 29 | "github.com/mvo5/uboot-go/uenv" | ||
107 | 28 | "gopkg.in/check.v1" | 30 | "gopkg.in/check.v1" |
108 | 29 | ) | 31 | ) |
109 | 30 | 32 | ||
110 | @@ -36,25 +38,23 @@ | |||
111 | 36 | backFilepathGlob func(string) ([]string, error) | 38 | backFilepathGlob func(string) ([]string, error) |
112 | 37 | filepathGlobFail bool | 39 | filepathGlobFail bool |
113 | 38 | filepathGlobReturnValues []string | 40 | filepathGlobReturnValues []string |
114 | 41 | backConfValue func(string) (string, error) | ||
115 | 42 | fakeConf map[string]string | ||
116 | 39 | } | 43 | } |
117 | 40 | 44 | ||
118 | 41 | var _ = check.Suite(&bootloaderTestSuite{}) | 45 | var _ = check.Suite(&bootloaderTestSuite{}) |
119 | 42 | 46 | ||
120 | 43 | func createConfigFile(c *check.C, contents string) (name string) { | ||
121 | 44 | file, _ := ioutil.TempFile("", "snappy-bootloader-test") | ||
122 | 45 | err := ioutil.WriteFile(file.Name(), []byte(contents), 0644) | ||
123 | 46 | c.Assert(err, check.IsNil, check.Commentf("Error writing test bootloader file")) | ||
124 | 47 | |||
125 | 48 | return file.Name() | ||
126 | 49 | } | ||
127 | 50 | |||
128 | 51 | func (s *bootloaderTestSuite) SetUpSuite(c *check.C) { | 47 | func (s *bootloaderTestSuite) SetUpSuite(c *check.C) { |
129 | 52 | s.backFilepathGlob = filepathGlob | 48 | s.backFilepathGlob = filepathGlob |
130 | 53 | filepathGlob = s.fakeFilepathGlob | 49 | filepathGlob = s.fakeFilepathGlob |
131 | 50 | s.backConfValue = confValue | ||
132 | 51 | confValue = s.fakeConfValue | ||
133 | 52 | s.fakeConf = map[string]string{} | ||
134 | 54 | } | 53 | } |
135 | 55 | 54 | ||
136 | 56 | func (s *bootloaderTestSuite) TearDownSuite(c *check.C) { | 55 | func (s *bootloaderTestSuite) TearDownSuite(c *check.C) { |
137 | 57 | filepathGlob = s.backFilepathGlob | 56 | filepathGlob = s.backFilepathGlob |
138 | 57 | confValue = s.backConfValue | ||
139 | 58 | } | 58 | } |
140 | 59 | 59 | ||
141 | 60 | func (s *bootloaderTestSuite) SetUpTest(c *check.C) { | 60 | func (s *bootloaderTestSuite) SetUpTest(c *check.C) { |
142 | @@ -73,6 +73,10 @@ | |||
143 | 73 | return s.filepathGlobReturnValues, nil | 73 | return s.filepathGlobReturnValues, nil |
144 | 74 | } | 74 | } |
145 | 75 | 75 | ||
146 | 76 | func (s *bootloaderTestSuite) fakeConfValue(key string) (value string, err error) { | ||
147 | 77 | return s.fakeConf[key], nil | ||
148 | 78 | } | ||
149 | 79 | |||
150 | 76 | func (s *bootloaderTestSuite) TestOtherPartition(c *check.C) { | 80 | func (s *bootloaderTestSuite) TestOtherPartition(c *check.C) { |
151 | 77 | c.Assert(OtherPartition("a"), check.Equals, "b", | 81 | c.Assert(OtherPartition("a"), check.Equals, "b", |
152 | 78 | check.Commentf("Expected OtherPartition of 'a' to be 'b'")) | 82 | check.Commentf("Expected OtherPartition of 'a' to be 'b'")) |
153 | @@ -98,11 +102,11 @@ | |||
154 | 98 | func (s *bootloaderTestSuite) TestBootSystemCallsFilepathGlob(c *check.C) { | 102 | func (s *bootloaderTestSuite) TestBootSystemCallsFilepathGlob(c *check.C) { |
155 | 99 | BootSystem() | 103 | BootSystem() |
156 | 100 | 104 | ||
159 | 101 | path := bootBase + "/grub" | 105 | p := bootBase + "/grub" |
160 | 102 | calls := s.filepathGlobCalls[path] | 106 | calls := s.filepathGlobCalls[p] |
161 | 103 | 107 | ||
162 | 104 | c.Assert(calls, check.Equals, 1, | 108 | c.Assert(calls, check.Equals, 1, |
164 | 105 | check.Commentf("Expected calls to filepath.Glob with path %s to be 1, %d found", path, calls)) | 109 | check.Commentf("Expected calls to filepath.Glob with path %s to be 1, %d found", p, calls)) |
165 | 106 | } | 110 | } |
166 | 107 | 111 | ||
167 | 108 | func (s *bootloaderTestSuite) TestBootSystemForGrub(c *check.C) { | 112 | func (s *bootloaderTestSuite) TestBootSystemForGrub(c *check.C) { |
168 | @@ -126,6 +130,11 @@ | |||
169 | 126 | } | 130 | } |
170 | 127 | 131 | ||
171 | 128 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsBootSystemError(c *check.C) { | 132 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsBootSystemError(c *check.C) { |
172 | 133 | s.fakeConf = map[string]string{ | ||
173 | 134 | "snappy_mode": "try", | ||
174 | 135 | "snappy_ab": "dummy", | ||
175 | 136 | } | ||
176 | 137 | |||
177 | 129 | backBootSystem := BootSystem | 138 | backBootSystem := BootSystem |
178 | 130 | defer func() { BootSystem = backBootSystem }() | 139 | defer func() { BootSystem = backBootSystem }() |
179 | 131 | expectedErr := fmt.Errorf("Error from BootSystem!") | 140 | expectedErr := fmt.Errorf("Error from BootSystem!") |
180 | @@ -139,30 +148,8 @@ | |||
181 | 139 | check.Commentf("Expected error %v not found, %v", expectedErr, err)) | 148 | check.Commentf("Expected error %v not found, %v", expectedErr, err)) |
182 | 140 | } | 149 | } |
183 | 141 | 150 | ||
184 | 142 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsOsOpenError(c *check.C) { | ||
185 | 143 | backBootSystem := BootSystem | ||
186 | 144 | defer func() { BootSystem = backBootSystem }() | ||
187 | 145 | BootSystem = func() (system string, err error) { | ||
188 | 146 | return "not-expected-system", nil | ||
189 | 147 | } | ||
190 | 148 | |||
191 | 149 | backConfigFiles := configFiles | ||
192 | 150 | defer func() { configFiles = backConfigFiles }() | ||
193 | 151 | configFiles = map[string]string{"not-expected-system": "not-a-file"} | ||
194 | 152 | |||
195 | 153 | _, err := NextBootPartition() | ||
196 | 154 | |||
197 | 155 | c.Assert(err, check.FitsTypeOf, &os.PathError{}, | ||
198 | 156 | check.Commentf("Expected error type *os.PathError not found, %T", err)) | ||
199 | 157 | } | ||
200 | 158 | |||
201 | 159 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsEmptyIfPatternsNotFound(c *check.C) { | 151 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsEmptyIfPatternsNotFound(c *check.C) { |
208 | 160 | cfgFile := createConfigFile(c, "snappy_mode=try") | 152 | s.fakeConf = map[string]string{"snappy_mode": "try"} |
203 | 161 | defer os.Remove(cfgFile) | ||
204 | 162 | |||
205 | 163 | backConfigFiles := configFiles | ||
206 | 164 | defer func() { configFiles = backConfigFiles }() | ||
207 | 165 | configFiles = map[string]string{"test-system": cfgFile} | ||
209 | 166 | 153 | ||
210 | 167 | backBootSystem := BootSystem | 154 | backBootSystem := BootSystem |
211 | 168 | defer func() { BootSystem = backBootSystem }() | 155 | defer func() { BootSystem = backBootSystem }() |
212 | @@ -178,16 +165,10 @@ | |||
213 | 178 | } | 165 | } |
214 | 179 | 166 | ||
215 | 180 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsSamePartitionForGrub(c *check.C) { | 167 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsSamePartitionForGrub(c *check.C) { |
226 | 181 | cfgFileContents := `blabla | 168 | s.fakeConf = map[string]string{ |
227 | 182 | snappy_mode=try | 169 | "snappy_mode": "try", |
228 | 183 | snappy_ab=a | 170 | "snappy_ab": "a", |
229 | 184 | blabla` | 171 | } |
220 | 185 | cfgFile := createConfigFile(c, cfgFileContents) | ||
221 | 186 | defer os.Remove(cfgFile) | ||
222 | 187 | |||
223 | 188 | backConfigFiles := configFiles | ||
224 | 189 | defer func() { configFiles = backConfigFiles }() | ||
225 | 190 | configFiles = map[string]string{"grub": cfgFile} | ||
230 | 191 | 172 | ||
231 | 192 | backBootSystem := BootSystem | 173 | backBootSystem := BootSystem |
232 | 193 | defer func() { BootSystem = backBootSystem }() | 174 | defer func() { BootSystem = backBootSystem }() |
233 | @@ -203,16 +184,10 @@ | |||
234 | 203 | } | 184 | } |
235 | 204 | 185 | ||
236 | 205 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsOtherPartitionForUBoot(c *check.C) { | 186 | func (s *bootloaderTestSuite) TestNextBootPartitionReturnsOtherPartitionForUBoot(c *check.C) { |
247 | 206 | cfgFileContents := `blabla | 187 | s.fakeConf = map[string]string{ |
248 | 207 | snappy_mode=try | 188 | "snappy_mode": "try", |
249 | 208 | snappy_ab=a | 189 | "snappy_ab": "a", |
250 | 209 | blabla` | 190 | } |
241 | 210 | cfgFile := createConfigFile(c, cfgFileContents) | ||
242 | 211 | defer os.Remove(cfgFile) | ||
243 | 212 | |||
244 | 213 | backConfigFiles := configFiles | ||
245 | 214 | defer func() { configFiles = backConfigFiles }() | ||
246 | 215 | configFiles = map[string]string{"uboot": cfgFile} | ||
251 | 216 | 191 | ||
252 | 217 | backBootSystem := BootSystem | 192 | backBootSystem := BootSystem |
253 | 218 | defer func() { BootSystem = backBootSystem }() | 193 | defer func() { BootSystem = backBootSystem }() |
254 | @@ -228,20 +203,8 @@ | |||
255 | 228 | } | 203 | } |
256 | 229 | 204 | ||
257 | 230 | func (s *bootloaderTestSuite) TestModeReturnsSnappyModeFromConf(c *check.C) { | 205 | func (s *bootloaderTestSuite) TestModeReturnsSnappyModeFromConf(c *check.C) { |
272 | 231 | cfgFileContents := `blabla | 206 | s.fakeConf = map[string]string{ |
273 | 232 | snappy_mode=test_mode | 207 | "snappy_mode": "test_mode", |
260 | 233 | blabla` | ||
261 | 234 | cfgFile := createConfigFile(c, cfgFileContents) | ||
262 | 235 | defer os.Remove(cfgFile) | ||
263 | 236 | |||
264 | 237 | backConfigFiles := configFiles | ||
265 | 238 | defer func() { configFiles = backConfigFiles }() | ||
266 | 239 | configFiles = map[string]string{"test-system": cfgFile} | ||
267 | 240 | |||
268 | 241 | backBootSystem := BootSystem | ||
269 | 242 | defer func() { BootSystem = backBootSystem }() | ||
270 | 243 | BootSystem = func() (system string, err error) { | ||
271 | 244 | return "test-system", nil | ||
274 | 245 | } | 208 | } |
275 | 246 | 209 | ||
276 | 247 | mode, err := Mode() | 210 | mode, err := Mode() |
277 | @@ -251,40 +214,22 @@ | |||
278 | 251 | } | 214 | } |
279 | 252 | 215 | ||
280 | 253 | func (s *bootloaderTestSuite) TestCurrentPartitionNotOnTryMode(c *check.C) { | 216 | func (s *bootloaderTestSuite) TestCurrentPartitionNotOnTryMode(c *check.C) { |
296 | 254 | cfgFileContents := `blabla | 217 | s.fakeConf = map[string]string{ |
297 | 255 | snappy_mode=nottry | 218 | "snappy_mode": "nottry", |
298 | 256 | snappy_ab=test_partition | 219 | "snappy_ab": "test_partition", |
284 | 257 | blabla` | ||
285 | 258 | cfgFile := createConfigFile(c, cfgFileContents) | ||
286 | 259 | defer os.Remove(cfgFile) | ||
287 | 260 | |||
288 | 261 | backConfigFiles := configFiles | ||
289 | 262 | defer func() { configFiles = backConfigFiles }() | ||
290 | 263 | configFiles = map[string]string{"test-system": cfgFile} | ||
291 | 264 | |||
292 | 265 | backBootSystem := BootSystem | ||
293 | 266 | defer func() { BootSystem = backBootSystem }() | ||
294 | 267 | BootSystem = func() (system string, err error) { | ||
295 | 268 | return "test-system", nil | ||
299 | 269 | } | 220 | } |
300 | 270 | 221 | ||
302 | 271 | mode, err := CurrentPartition() | 222 | part, err := CurrentPartition() |
303 | 272 | 223 | ||
304 | 273 | c.Assert(err, check.IsNil, check.Commentf("Unexpected error %v", err)) | 224 | c.Assert(err, check.IsNil, check.Commentf("Unexpected error %v", err)) |
306 | 274 | c.Assert(mode, check.Equals, "test_partition", check.Commentf("Wrong partition")) | 225 | c.Assert(part, check.Equals, "test_partition", check.Commentf("Wrong partition")) |
307 | 275 | } | 226 | } |
308 | 276 | 227 | ||
309 | 277 | func (s *bootloaderTestSuite) TestCurrentPartitionOnTryModeReturnsSamePartitionForUboot(c *check.C) { | 228 | func (s *bootloaderTestSuite) TestCurrentPartitionOnTryModeReturnsSamePartitionForUboot(c *check.C) { |
320 | 278 | cfgFileContents := `blabla | 229 | s.fakeConf = map[string]string{ |
321 | 279 | snappy_mode=try | 230 | "snappy_mode": "try", |
322 | 280 | snappy_ab=a | 231 | "snappy_ab": "a", |
323 | 281 | blabla` | 232 | } |
314 | 282 | cfgFile := createConfigFile(c, cfgFileContents) | ||
315 | 283 | defer os.Remove(cfgFile) | ||
316 | 284 | |||
317 | 285 | backConfigFiles := configFiles | ||
318 | 286 | defer func() { configFiles = backConfigFiles }() | ||
319 | 287 | configFiles = map[string]string{"uboot": cfgFile} | ||
324 | 288 | 233 | ||
325 | 289 | backBootSystem := BootSystem | 234 | backBootSystem := BootSystem |
326 | 290 | defer func() { BootSystem = backBootSystem }() | 235 | defer func() { BootSystem = backBootSystem }() |
327 | @@ -298,17 +243,11 @@ | |||
328 | 298 | c.Assert(mode, check.Equals, "a", check.Commentf("Wrong partition")) | 243 | c.Assert(mode, check.Equals, "a", check.Commentf("Wrong partition")) |
329 | 299 | } | 244 | } |
330 | 300 | 245 | ||
342 | 301 | func (s *bootloaderTestSuite) TestCurrentPartitionOnTryModeReturnsOtherPartitionForUboot(c *check.C) { | 246 | func (s *bootloaderTestSuite) TestCurrentPartitionOnTryModeReturnsOtherPartitionForGrub(c *check.C) { |
343 | 302 | cfgFileContents := `blabla | 247 | s.fakeConf = map[string]string{ |
344 | 303 | snappy_mode=try | 248 | "snappy_mode": "try", |
345 | 304 | snappy_ab=a | 249 | "snappy_ab": "a", |
346 | 305 | blabla` | 250 | } |
336 | 306 | cfgFile := createConfigFile(c, cfgFileContents) | ||
337 | 307 | defer os.Remove(cfgFile) | ||
338 | 308 | |||
339 | 309 | backConfigFiles := configFiles | ||
340 | 310 | defer func() { configFiles = backConfigFiles }() | ||
341 | 311 | configFiles = map[string]string{"grub": cfgFile} | ||
347 | 312 | 251 | ||
348 | 313 | backBootSystem := BootSystem | 252 | backBootSystem := BootSystem |
349 | 314 | defer func() { BootSystem = backBootSystem }() | 253 | defer func() { BootSystem = backBootSystem }() |
350 | @@ -321,3 +260,79 @@ | |||
351 | 321 | c.Assert(err, check.IsNil, check.Commentf("Unexpected error %v", err)) | 260 | c.Assert(err, check.IsNil, check.Commentf("Unexpected error %v", err)) |
352 | 322 | c.Assert(mode, check.Equals, "b", check.Commentf("Wrong partition")) | 261 | c.Assert(mode, check.Equals, "b", check.Commentf("Wrong partition")) |
353 | 323 | } | 262 | } |
354 | 263 | |||
355 | 264 | type confTestSuite struct { | ||
356 | 265 | backBootSystem func() (string, error) | ||
357 | 266 | system string | ||
358 | 267 | backConfigFiles map[string]string | ||
359 | 268 | } | ||
360 | 269 | |||
361 | 270 | var _ = check.Suite(&confTestSuite{}) | ||
362 | 271 | |||
363 | 272 | func (s *confTestSuite) SetUpSuite(c *check.C) { | ||
364 | 273 | s.backBootSystem = BootSystem | ||
365 | 274 | BootSystem = s.fakeBootSystem | ||
366 | 275 | s.backConfigFiles = configFiles | ||
367 | 276 | } | ||
368 | 277 | |||
369 | 278 | func (s *confTestSuite) fakeBootSystem() (system string, err error) { | ||
370 | 279 | return s.system, nil | ||
371 | 280 | } | ||
372 | 281 | |||
373 | 282 | func (s *confTestSuite) TearDownSuite(c *check.C) { | ||
374 | 283 | BootSystem = s.backBootSystem | ||
375 | 284 | configFiles = s.backConfigFiles | ||
376 | 285 | } | ||
377 | 286 | |||
378 | 287 | func createConfigFile(c *check.C, system string, contents map[string]string) (name string) { | ||
379 | 288 | if system == "grub" { | ||
380 | 289 | name = createGrubConfigFile(c, contents) | ||
381 | 290 | } else if system == "uboot" { | ||
382 | 291 | name = createUbootConfigFile(c, contents) | ||
383 | 292 | } | ||
384 | 293 | return | ||
385 | 294 | } | ||
386 | 295 | |||
387 | 296 | func createGrubConfigFile(c *check.C, contents map[string]string) (name string) { | ||
388 | 297 | var contentsStr string | ||
389 | 298 | for key, value := range contents { | ||
390 | 299 | contentsStr += fmt.Sprintf("%s=%s\n", key, value) | ||
391 | 300 | } | ||
392 | 301 | file, err := ioutil.TempFile("", "snappy-grub-test") | ||
393 | 302 | c.Assert(err, check.IsNil, check.Commentf("Error creating temp file: %s", err)) | ||
394 | 303 | err = ioutil.WriteFile(file.Name(), []byte(contentsStr), 0644) | ||
395 | 304 | c.Assert(err, check.IsNil, check.Commentf("Error writing test bootloader file: %s", err)) | ||
396 | 305 | |||
397 | 306 | return file.Name() | ||
398 | 307 | } | ||
399 | 308 | |||
400 | 309 | func createUbootConfigFile(c *check.C, contents map[string]string) (name string) { | ||
401 | 310 | tmpDir, err := ioutil.TempDir("", "snappy-uboot-test") | ||
402 | 311 | c.Assert(err, check.IsNil, check.Commentf("Error creating temp dir: %s", err)) | ||
403 | 312 | fileName := path.Join(tmpDir, "uboot.env") | ||
404 | 313 | env, err := uenv.Create(fileName, 4096) | ||
405 | 314 | c.Assert(err, check.IsNil, check.Commentf("Error creating the uboot env file: %s", err)) | ||
406 | 315 | for key, value := range contents { | ||
407 | 316 | env.Set(key, value) | ||
408 | 317 | } | ||
409 | 318 | err = env.Save() | ||
410 | 319 | c.Assert(err, check.IsNil, check.Commentf("Error saving the uboot env file: %s", err)) | ||
411 | 320 | return fileName | ||
412 | 321 | } | ||
413 | 322 | |||
414 | 323 | func (s *confTestSuite) TestGetConfValue(c *check.C) { | ||
415 | 324 | for _, s.system = range []string{"grub", "uboot"} { | ||
416 | 325 | cfgFileContents := map[string]string{ | ||
417 | 326 | "blabla1": "bla", | ||
418 | 327 | "testkey": "testvalue", | ||
419 | 328 | "blabla2": "bla", | ||
420 | 329 | } | ||
421 | 330 | cfgFile := createConfigFile(c, s.system, cfgFileContents) | ||
422 | 331 | defer os.Remove(cfgFile) | ||
423 | 332 | configFiles = map[string]string{s.system: cfgFile} | ||
424 | 333 | |||
425 | 334 | value, err := confValue("testkey") | ||
426 | 335 | c.Check(err, check.IsNil, check.Commentf("Error getting configuration value: %s", err)) | ||
427 | 336 | c.Check(value, check.Equals, "testvalue", check.Commentf("Wrong configuration value")) | ||
428 | 337 | } | ||
429 | 338 | } | ||
430 | 324 | 339 | ||
431 | === modified file '_integration-tests/testutils/partition/partition_test.go' | |||
432 | --- _integration-tests/testutils/partition/partition_test.go 2015-10-02 13:10:24 +0000 | |||
433 | +++ _integration-tests/testutils/partition/partition_test.go 2015-10-16 00:47:50 +0000 | |||
434 | @@ -27,9 +27,9 @@ | |||
435 | 27 | ) | 27 | ) |
436 | 28 | 28 | ||
437 | 29 | const ( | 29 | const ( |
441 | 30 | path = "mypath" | 30 | testPath = "mypath" |
442 | 31 | writableCmd = "sudo mount -o remount,rw " + path | 31 | writableCmd = "sudo mount -o remount,rw " + testPath |
443 | 32 | readonlyCmd = "sudo mount -o remount,ro " + path | 32 | readonlyCmd = "sudo mount -o remount,ro " + testPath |
444 | 33 | waitCmd = lsofNotBeingWritten | 33 | waitCmd = lsofNotBeingWritten |
445 | 34 | ) | 34 | ) |
446 | 35 | 35 | ||
447 | @@ -86,14 +86,14 @@ | |||
448 | 86 | } | 86 | } |
449 | 87 | 87 | ||
450 | 88 | func (s *partitionTestSuite) TestMakeWritableCallsExecCommand(c *check.C) { | 88 | func (s *partitionTestSuite) TestMakeWritableCallsExecCommand(c *check.C) { |
452 | 89 | err := MakeWritable(c, path) | 89 | err := MakeWritable(c, testPath) |
453 | 90 | 90 | ||
454 | 91 | c.Assert(err, check.IsNil) | 91 | c.Assert(err, check.IsNil) |
455 | 92 | c.Assert(s.execCalls[writableCmd], check.Equals, 1) | 92 | c.Assert(s.execCalls[writableCmd], check.Equals, 1) |
456 | 93 | } | 93 | } |
457 | 94 | 94 | ||
458 | 95 | func (s *partitionTestSuite) TestMakeWritableWaitsForIdlePartition(c *check.C) { | 95 | func (s *partitionTestSuite) TestMakeWritableWaitsForIdlePartition(c *check.C) { |
460 | 96 | err := MakeWritable(c, path) | 96 | err := MakeWritable(c, testPath) |
461 | 97 | 97 | ||
462 | 98 | c.Assert(err, check.IsNil) | 98 | c.Assert(err, check.IsNil) |
463 | 99 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) | 99 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) |
464 | @@ -101,7 +101,7 @@ | |||
465 | 101 | 101 | ||
466 | 102 | func (s *partitionTestSuite) TestMakeWritableReturnsWaitError(c *check.C) { | 102 | func (s *partitionTestSuite) TestMakeWritableReturnsWaitError(c *check.C) { |
467 | 103 | s.waitError = true | 103 | s.waitError = true |
469 | 104 | err := MakeWritable(c, path) | 104 | err := MakeWritable(c, testPath) |
470 | 105 | 105 | ||
471 | 106 | c.Assert(err, check.NotNil) | 106 | c.Assert(err, check.NotNil) |
472 | 107 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) | 107 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) |
473 | @@ -109,14 +109,14 @@ | |||
474 | 109 | } | 109 | } |
475 | 110 | 110 | ||
476 | 111 | func (s *partitionTestSuite) TestMakeReadOnlyCallsExecCommand(c *check.C) { | 111 | func (s *partitionTestSuite) TestMakeReadOnlyCallsExecCommand(c *check.C) { |
478 | 112 | err := MakeReadonly(c, path) | 112 | err := MakeReadonly(c, testPath) |
479 | 113 | 113 | ||
480 | 114 | c.Assert(err, check.IsNil) | 114 | c.Assert(err, check.IsNil) |
481 | 115 | c.Assert(s.execCalls[readonlyCmd], check.Equals, 1) | 115 | c.Assert(s.execCalls[readonlyCmd], check.Equals, 1) |
482 | 116 | } | 116 | } |
483 | 117 | 117 | ||
484 | 118 | func (s *partitionTestSuite) TestMakeReadonlyWaitsForIdlePartition(c *check.C) { | 118 | func (s *partitionTestSuite) TestMakeReadonlyWaitsForIdlePartition(c *check.C) { |
486 | 119 | err := MakeReadonly(c, path) | 119 | err := MakeReadonly(c, testPath) |
487 | 120 | 120 | ||
488 | 121 | c.Assert(err, check.IsNil) | 121 | c.Assert(err, check.IsNil) |
489 | 122 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) | 122 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) |
490 | @@ -124,7 +124,7 @@ | |||
491 | 124 | 124 | ||
492 | 125 | func (s *partitionTestSuite) TestMakeReadonlyReturnsWaitError(c *check.C) { | 125 | func (s *partitionTestSuite) TestMakeReadonlyReturnsWaitError(c *check.C) { |
493 | 126 | s.waitError = true | 126 | s.waitError = true |
495 | 127 | err := MakeReadonly(c, path) | 127 | err := MakeReadonly(c, testPath) |
496 | 128 | 128 | ||
497 | 129 | c.Assert(err, check.NotNil) | 129 | c.Assert(err, check.NotNil) |
498 | 130 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) | 130 | c.Assert(s.waitCalls[waitCmd], check.Equals, 1) |
499 | @@ -147,7 +147,7 @@ | |||
500 | 147 | 147 | ||
501 | 148 | for _, testCase := range testCases { | 148 | for _, testCase := range testCases { |
502 | 149 | s.execOutput = testCase.execCommandOutput | 149 | s.execOutput = testCase.execCommandOutput |
504 | 150 | f := checkPathBusyFunc(path) | 150 | f := checkPathBusyFunc(testPath) |
505 | 151 | 151 | ||
506 | 152 | actual, err := f() | 152 | actual, err := f() |
507 | 153 | c.Check(err, check.IsNil) | 153 | c.Check(err, check.IsNil) |
508 | @@ -161,7 +161,7 @@ | |||
509 | 161 | s.execOutput = "not a lsof common output on not used partitions" | 161 | s.execOutput = "not a lsof common output on not used partitions" |
510 | 162 | s.execError = true | 162 | s.execError = true |
511 | 163 | 163 | ||
513 | 164 | f := checkPathBusyFunc(path) | 164 | f := checkPathBusyFunc(testPath) |
514 | 165 | 165 | ||
515 | 166 | actual, err := f() | 166 | actual, err := f() |
516 | 167 | 167 |
This fixes the queries to the uboot, but doens't yet make the test pass in bbb.
I'm proposing this now as a clear bug fix, and I'll start to think what to do for the bbb. The problem is that it's being extra slow, so we have to increase the timeout. It would be nice to have a solution so the timeout is not hardcoded. And it would be even nicer if the bug that causes this to happen is fixed. Bug #1498293