Merge lp:~fgimenez/snappy/failover-tests into lp:~snappy-dev/snappy/snappy-moved-to-github
- failover-tests
- Merge into snappy-moved-to-github
Proposed by
Federico Gimenez
on 2015-06-17
| Status: | Merged |
|---|---|
| Approved by: | Leo Arias on 2015-06-26 |
| Approved revision: | 530 |
| Merged at revision: | 523 |
| Proposed branch: | lp:~fgimenez/snappy/failover-tests |
| Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
| Prerequisite: | lp:~fgimenez/snappy/go-functional-tests |
| Diff against target: |
717 lines (+522/-85) 10 files modified
_integration-tests/README (+0/-2) _integration-tests/main.go (+1/-3) _integration-tests/tests/80_test_failover (+0/-48) _integration-tests/tests/common_test.go (+74/-0) _integration-tests/tests/failover_rclocal_crash_test.go (+47/-0) _integration-tests/tests/failover_systemd_loop_test.go (+114/-0) _integration-tests/tests/failover_test.go (+151/-0) _integration-tests/tests/failover_zero_size_file_test.go (+120/-0) _integration-tests/tests/install_test.go (+14/-31) debian/integration-tests/control (+1/-1) |
| To merge this branch: | bzr merge lp:~fgimenez/snappy/failover-tests |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Leo Arias | 2015-06-17 | Approve on 2015-06-24 | |
|
Review via email:
|
|||
Commit Message
Extended failover tests
Description of the Change
Extended failover tests
To post a comment you must log in.
lp:~fgimenez/snappy/failover-tests
updated
on 2015-06-23
- 528. By Federico Gimenez on 2015-06-23
-
Added comment for boot path depending on arch
- 529. By Federico Gimenez on 2015-06-23
-
merged trunk
lp:~fgimenez/snappy/failover-tests
updated
on 2015-06-26
- 530. By Federico Gimenez on 2015-06-26
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file '_integration-tests/README' |
| 2 | --- _integration-tests/README 2015-06-25 14:40:02 +0000 |
| 3 | +++ _integration-tests/README 2015-06-26 07:39:36 +0000 |
| 4 | @@ -1,6 +1,5 @@ |
| 5 | # Automatic testing for snappy |
| 6 | |
| 7 | - |
| 8 | ## qemu based x86 testing |
| 9 | |
| 10 | Run locally with: |
| 11 | @@ -20,4 +19,3 @@ |
| 12 | shell tests) with: |
| 13 | |
| 14 | $ go run _integration-test/main.go |
| 15 | - |
| 16 | |
| 17 | === modified file '_integration-tests/main.go' |
| 18 | --- _integration-tests/main.go 2015-06-25 16:10:28 +0000 |
| 19 | +++ _integration-tests/main.go 2015-06-26 07:39:36 +0000 |
| 20 | @@ -40,7 +40,6 @@ |
| 21 | imageDir = filepath.Join(baseDir, "image") |
| 22 | outputDir = filepath.Join(baseDir, "output") |
| 23 | imageTarget = filepath.Join(imageDir, "snappy.img") |
| 24 | - testFile = filepath.Join(testsDir, "snappy.tests") |
| 25 | ) |
| 26 | |
| 27 | func execCommand(cmds ...string) { |
| 28 | @@ -56,7 +55,7 @@ |
| 29 | fmt.Println("Building tests") |
| 30 | prepareTargetDir(testsDir) |
| 31 | execCommand("go", "test", "-c", "./_integration-tests/tests") |
| 32 | - execCommand("mv", "tests.test", testFile) |
| 33 | + os.Rename("tests.test", "snappy.tests") |
| 34 | } |
| 35 | |
| 36 | func createImage(release, channel string) { |
| 37 | @@ -80,7 +79,6 @@ |
| 38 | "--override-control", "debian/integration-tests/control", |
| 39 | "--built-tree", rootPath, |
| 40 | "--output-dir", outputDir, |
| 41 | - fmt.Sprintf("--copy=%s:%s", testsDir, testsDir), |
| 42 | "---", |
| 43 | "ssh", "-s", "/usr/share/autopkgtest/ssh-setup/snappy", |
| 44 | "--", "-i", imageTarget) |
| 45 | |
| 46 | === removed file '_integration-tests/tests/80_test_failover' |
| 47 | --- _integration-tests/tests/80_test_failover 2015-06-15 15:36:29 +0000 |
| 48 | +++ _integration-tests/tests/80_test_failover 1970-01-01 00:00:00 +0000 |
| 49 | @@ -1,48 +0,0 @@ |
| 50 | -# Test that we rollback on failed upgrades |
| 51 | -# (needs autopkgtest with a supporting runner). |
| 52 | - |
| 53 | -test() { |
| 54 | - can_reboot || { echo "SKIP: cannot reboot testbed"; return; } |
| 55 | - |
| 56 | - # debug |
| 57 | - version_info |
| 58 | - boot_info |
| 59 | - |
| 60 | - if after_reboot; then |
| 61 | - # reboot: ensure we booted back into original |
| 62 | - orig_current=$(cat "${ADT_ARTIFACTS}/current") |
| 63 | - if [ "$orig_current" != "$current" ]; then |
| 64 | - fail "did not failover to good version (\"$orig_current\" != \"$current\")" |
| 65 | - fi |
| 66 | - |
| 67 | - # FIXME: grep log(other partition) for the crash to ensure it |
| 68 | - # really worked |
| 69 | - # FIXME2: reboot again as regression test for #1449904 |
| 70 | - |
| 71 | - # we booted, cleanup the panic for the next tests to work |
| 72 | - sudo mount -o remount,rw /writable/cache/system |
| 73 | - sudo rm /writable/cache/system/etc/rc.local |
| 74 | - return |
| 75 | - fi |
| 76 | - |
| 77 | - # fake new available version by doing a current-- |
| 78 | - switch_channel "s/build_number: $current/build_number: $((current-1))/" /etc/system-image/channel.ini |
| 79 | - |
| 80 | - # we should have something now :) |
| 81 | - version_info |
| 82 | - |
| 83 | - [ $avail -gt $current ] || fail "$avail is not newer than $current" |
| 84 | - |
| 85 | - # save version for post-upgrade test |
| 86 | - save_version_info $avail $current |
| 87 | - |
| 88 | - echo "upgrading..." |
| 89 | - sudo snappy update |
| 90 | - |
| 91 | - # break the upgrade by inserting a broken rc.local file onto the other |
| 92 | - # partition |
| 93 | - sudo mount -o remount,rw /writable/cache/system/ |
| 94 | - printf "#!/bin/sh\nprintf c > /proc/sysrq-trigger" | sudo tee /writable/cache/system/etc/rc.local |
| 95 | - |
| 96 | - reboot |
| 97 | -} |
| 98 | |
| 99 | === added file '_integration-tests/tests/common_test.go' |
| 100 | --- _integration-tests/tests/common_test.go 1970-01-01 00:00:00 +0000 |
| 101 | +++ _integration-tests/tests/common_test.go 2015-06-26 07:39:36 +0000 |
| 102 | @@ -0,0 +1,74 @@ |
| 103 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
| 104 | + |
| 105 | +/* |
| 106 | + * Copyright (C) 2015 Canonical Ltd |
| 107 | + * |
| 108 | + * This program is free software: you can redistribute it and/or modify |
| 109 | + * it under the terms of the GNU General Public License version 3 as |
| 110 | + * published by the Free Software Foundation. |
| 111 | + * |
| 112 | + * This program is distributed in the hope that it will be useful, |
| 113 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 114 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 115 | + * GNU General Public License for more details. |
| 116 | + * |
| 117 | + * You should have received a copy of the GNU General Public License |
| 118 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 119 | + * |
| 120 | + */ |
| 121 | + |
| 122 | +package tests |
| 123 | + |
| 124 | +import ( |
| 125 | + "fmt" |
| 126 | + "os" |
| 127 | + "os/exec" |
| 128 | + "testing" |
| 129 | + |
| 130 | + . "gopkg.in/check.v1" |
| 131 | +) |
| 132 | + |
| 133 | +type CommonSuite struct{} |
| 134 | + |
| 135 | +// Hook up gocheck into the "go test" runner |
| 136 | +func Test(t *testing.T) { TestingT(t) } |
| 137 | + |
| 138 | +func execCommand(c *C, cmds ...string) string { |
| 139 | + cmd := exec.Command(cmds[0], cmds[1:len(cmds)]...) |
| 140 | + output, err := cmd.CombinedOutput() |
| 141 | + stringOutput := string(output) |
| 142 | + c.Assert(err, IsNil, Commentf("Error: %v", stringOutput)) |
| 143 | + return stringOutput |
| 144 | +} |
| 145 | + |
| 146 | +func execCommandToFile(c *C, filename string, cmds ...string) { |
| 147 | + cmd := exec.Command(cmds[0], cmds[1:len(cmds)]...) |
| 148 | + outfile, err := os.Create(filename) |
| 149 | + c.Assert(err, IsNil, Commentf("Error creating output file %s", filename)) |
| 150 | + |
| 151 | + defer outfile.Close() |
| 152 | + cmd.Stdout = outfile |
| 153 | + |
| 154 | + err = cmd.Run() |
| 155 | + c.Assert(err, IsNil, Commentf("Error executing command '%v': %v", cmds, err)) |
| 156 | +} |
| 157 | + |
| 158 | +func (s *CommonSuite) SetUpSuite(c *C) { |
| 159 | + execCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") |
| 160 | + execCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer") |
| 161 | +} |
| 162 | + |
| 163 | +func (s *CommonSuite) SetUpTest(c *C) { |
| 164 | + afterReboot := os.Getenv("ADT_REBOOT_MARK") |
| 165 | + |
| 166 | + if afterReboot == "" { |
| 167 | + c.Logf("****** Running %s", c.TestName()) |
| 168 | + } else { |
| 169 | + if afterReboot == c.TestName() { |
| 170 | + c.Logf("****** Resuming %s after reboot", c.TestName()) |
| 171 | + } else { |
| 172 | + c.Skip(fmt.Sprintf("****** Skipped %s after reboot caused by %s", |
| 173 | + c.TestName(), afterReboot)) |
| 174 | + } |
| 175 | + } |
| 176 | +} |
| 177 | |
| 178 | === added file '_integration-tests/tests/failover_rclocal_crash_test.go' |
| 179 | --- _integration-tests/tests/failover_rclocal_crash_test.go 1970-01-01 00:00:00 +0000 |
| 180 | +++ _integration-tests/tests/failover_rclocal_crash_test.go 2015-06-26 07:39:36 +0000 |
| 181 | @@ -0,0 +1,47 @@ |
| 182 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
| 183 | + |
| 184 | +/* |
| 185 | + * Copyright (C) 2015 Canonical Ltd |
| 186 | + * |
| 187 | + * This program is free software: you can redistribute it and/or modify |
| 188 | + * it under the terms of the GNU General Public License version 3 as |
| 189 | + * published by the Free Software Foundation. |
| 190 | + * |
| 191 | + * This program is distributed in the hope that it will be useful, |
| 192 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 193 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 194 | + * GNU General Public License for more details. |
| 195 | + * |
| 196 | + * You should have received a copy of the GNU General Public License |
| 197 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 198 | + * |
| 199 | + */ |
| 200 | + |
| 201 | +package tests |
| 202 | + |
| 203 | +import ( |
| 204 | + "fmt" |
| 205 | + |
| 206 | + . "gopkg.in/check.v1" |
| 207 | +) |
| 208 | + |
| 209 | +type rcLocalCrash struct{} |
| 210 | + |
| 211 | +func (rcLocalCrash) set(c *C) { |
| 212 | + makeWritable(c, baseOtherPath) |
| 213 | + targetFile := fmt.Sprintf("%s/etc/rc.local", baseOtherPath) |
| 214 | + execCommand(c, "sudo", "chmod", "a+xw", targetFile) |
| 215 | + execCommandToFile(c, targetFile, |
| 216 | + "sudo", "echo", "#!bin/sh\nprintf c > /proc/sysrq-trigger") |
| 217 | + makeReadonly(c, baseOtherPath) |
| 218 | +} |
| 219 | + |
| 220 | +func (rcLocalCrash) unset(c *C) { |
| 221 | + makeWritable(c, baseOtherPath) |
| 222 | + execCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", baseOtherPath)) |
| 223 | + makeReadonly(c, baseOtherPath) |
| 224 | +} |
| 225 | + |
| 226 | +func (s *FailoverSuite) TestRCLocalCrash(c *C) { |
| 227 | + commonFailoverTest(c, rcLocalCrash{}) |
| 228 | +} |
| 229 | |
| 230 | === added file '_integration-tests/tests/failover_systemd_loop_test.go' |
| 231 | --- _integration-tests/tests/failover_systemd_loop_test.go 1970-01-01 00:00:00 +0000 |
| 232 | +++ _integration-tests/tests/failover_systemd_loop_test.go 2015-06-26 07:39:36 +0000 |
| 233 | @@ -0,0 +1,114 @@ |
| 234 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
| 235 | + |
| 236 | +/* |
| 237 | + * Copyright (C) 2015 Canonical Ltd |
| 238 | + * |
| 239 | + * This program is free software: you can redistribute it and/or modify |
| 240 | + * it under the terms of the GNU General Public License version 3 as |
| 241 | + * published by the Free Software Foundation. |
| 242 | + * |
| 243 | + * This program is distributed in the hope that it will be useful, |
| 244 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 245 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 246 | + * GNU General Public License for more details. |
| 247 | + * |
| 248 | + * You should have received a copy of the GNU General Public License |
| 249 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 250 | + * |
| 251 | + */ |
| 252 | + |
| 253 | +package tests |
| 254 | + |
| 255 | +import ( |
| 256 | + "fmt" |
| 257 | + |
| 258 | + . "gopkg.in/check.v1" |
| 259 | +) |
| 260 | + |
| 261 | +const ( |
| 262 | + deadlockService = `[Unit] |
| 263 | +Before=sysinit.target |
| 264 | +DefaultDependencies=no |
| 265 | + |
| 266 | +[Service] |
| 267 | +Type=oneshot |
| 268 | +ExecStartPre=-/bin/sh -c "echo 'DEBUG: $(date): deadlocked system' >/dev/console" |
| 269 | +ExecStartPre=-/bin/sh -c "echo 'DEBUG: $(date): deadlocked system' >/dev/ttyS0" |
| 270 | +ExecStart=/bin/systemctl start deadlock.service |
| 271 | +RemainAfterExit=yes |
| 272 | + |
| 273 | +[Install] |
| 274 | +RequiredBy=sysinit.target |
| 275 | +` |
| 276 | + rebootService = `[Unit] |
| 277 | +DefaultDependencies=no |
| 278 | +Description=Hack to force reboot if booting did not finish after 20s |
| 279 | + |
| 280 | +[Service] |
| 281 | +Type=oneshot |
| 282 | +ExecStartPre=/bin/sleep 20 |
| 283 | +ExecStart=-/bin/sh -c 'if ! systemctl is-active default.target; then wall "EMERGENCY REBOOT"; reboot -f; fi' |
| 284 | + |
| 285 | +[Install] |
| 286 | +RequiredBy=sysinit.target |
| 287 | +` |
| 288 | + baseSystemdPath = "/lib/systemd/system" |
| 289 | + systemdTargetRequiresDir = "sysinit.target.requires" |
| 290 | +) |
| 291 | + |
| 292 | +type systemdDependencyLoop struct{} |
| 293 | + |
| 294 | +func (systemdDependencyLoop) set(c *C) { |
| 295 | + installService(c, "deadlock", deadlockService, baseOtherPath) |
| 296 | + installService(c, "emerg-reboot", rebootService, baseOtherPath) |
| 297 | +} |
| 298 | + |
| 299 | +func (systemdDependencyLoop) unset(c *C) { |
| 300 | + unInstallService(c, "deadlock", baseOtherPath) |
| 301 | + unInstallService(c, "emerg-reboot", baseOtherPath) |
| 302 | +} |
| 303 | + |
| 304 | +func installService(c *C, serviceName, serviceCfg, basePath string) { |
| 305 | + makeWritable(c, basePath) |
| 306 | + |
| 307 | + // Create service file |
| 308 | + serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName) |
| 309 | + execCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath)) |
| 310 | + execCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg) |
| 311 | + |
| 312 | + // Create requires directory |
| 313 | + requiresDirPart := fmt.Sprintf("%s/%s", baseSystemdPath, systemdTargetRequiresDir) |
| 314 | + requiresDir := fmt.Sprintf("%s%s", basePath, requiresDirPart) |
| 315 | + execCommand(c, "sudo", "mkdir", "-p", requiresDir) |
| 316 | + |
| 317 | + // Symlink from the requires dir to the service file (with chroot for being |
| 318 | + // usable in the other partition) |
| 319 | + execCommand(c, "sudo", "chroot", basePath, "ln", "-s", |
| 320 | + fmt.Sprintf("%s/%s.service", baseSystemdPath, serviceName), |
| 321 | + fmt.Sprintf("%s/%s.service", requiresDirPart, serviceName), |
| 322 | + ) |
| 323 | + |
| 324 | + makeReadonly(c, basePath) |
| 325 | +} |
| 326 | + |
| 327 | +func unInstallService(c *C, serviceName, basePath string) { |
| 328 | + makeWritable(c, basePath) |
| 329 | + |
| 330 | + // Disable the service |
| 331 | + execCommand(c, "sudo", "chroot", basePath, |
| 332 | + "systemctl", "disable", fmt.Sprintf("%s.service", serviceName)) |
| 333 | + |
| 334 | + // Remove the service file |
| 335 | + execCommand(c, "sudo", "rm", |
| 336 | + fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)) |
| 337 | + |
| 338 | + // Remove the requires symlink |
| 339 | + execCommand(c, "sudo", "rm", |
| 340 | + fmt.Sprintf("%s%s/%s/%s.service", basePath, baseSystemdPath, systemdTargetRequiresDir, serviceName)) |
| 341 | + |
| 342 | + makeReadonly(c, basePath) |
| 343 | +} |
| 344 | + |
| 345 | +func (s *FailoverSuite) TestSystemdDependencyLoop(c *C) { |
| 346 | + commonFailoverTest(c, systemdDependencyLoop{}) |
| 347 | +} |
| 348 | |
| 349 | === added file '_integration-tests/tests/failover_test.go' |
| 350 | --- _integration-tests/tests/failover_test.go 1970-01-01 00:00:00 +0000 |
| 351 | +++ _integration-tests/tests/failover_test.go 2015-06-26 07:39:36 +0000 |
| 352 | @@ -0,0 +1,151 @@ |
| 353 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
| 354 | + |
| 355 | +/* |
| 356 | + * Copyright (C) 2015 Canonical Ltd |
| 357 | + * |
| 358 | + * This program is free software: you can redistribute it and/or modify |
| 359 | + * it under the terms of the GNU General Public License version 3 as |
| 360 | + * published by the Free Software Foundation. |
| 361 | + * |
| 362 | + * This program is distributed in the hope that it will be useful, |
| 363 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 364 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 365 | + * GNU General Public License for more details. |
| 366 | + * |
| 367 | + * You should have received a copy of the GNU General Public License |
| 368 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 369 | + * |
| 370 | + */ |
| 371 | + |
| 372 | +package tests |
| 373 | + |
| 374 | +import ( |
| 375 | + "fmt" |
| 376 | + "io/ioutil" |
| 377 | + "os" |
| 378 | + "path/filepath" |
| 379 | + "regexp" |
| 380 | + "strconv" |
| 381 | + "strings" |
| 382 | + |
| 383 | + . "gopkg.in/check.v1" |
| 384 | +) |
| 385 | + |
| 386 | +type FailoverSuite struct { |
| 387 | + CommonSuite |
| 388 | +} |
| 389 | + |
| 390 | +var _ = Suite(&FailoverSuite{}) |
| 391 | + |
| 392 | +const ( |
| 393 | + baseOtherPath = "/writable/cache/system" |
| 394 | + channelCfgFile = "/etc/system-image/channel.ini" |
| 395 | +) |
| 396 | + |
| 397 | +// The types that implement this interface can be used in the test logic |
| 398 | +type failer interface { |
| 399 | + // Sets the failure conditions |
| 400 | + set(c *C) |
| 401 | + // Unsets the failure conditions |
| 402 | + unset(c *C) |
| 403 | +} |
| 404 | + |
| 405 | +// This is the logic common to all the failover tests. Each of them has define a |
| 406 | +// type implementing the failer interface and call this function with an instance |
| 407 | +// of it |
| 408 | +func commonFailoverTest(c *C, f failer) { |
| 409 | + currentVersion := getCurrentVersion(c) |
| 410 | + |
| 411 | + if afterReboot(c) { |
| 412 | + removeRebootMark(c) |
| 413 | + f.unset(c) |
| 414 | + c.Assert(getSavedVersion(c), Equals, currentVersion) |
| 415 | + } else { |
| 416 | + switchChannelVersion(c, currentVersion, currentVersion-1) |
| 417 | + setSavedVersion(c, currentVersion-1) |
| 418 | + |
| 419 | + callUpdate(c) |
| 420 | + f.set(c) |
| 421 | + reboot(c) |
| 422 | + } |
| 423 | +} |
| 424 | + |
| 425 | +func reboot(c *C) { |
| 426 | + // This will write the name of the current test as a reboot mark |
| 427 | + execCommand(c, "sudo", "/tmp/autopkgtest-reboot", c.TestName()) |
| 428 | +} |
| 429 | + |
| 430 | +func removeRebootMark(c *C) { |
| 431 | + err := os.Setenv("ADT_REBOOT_MARK", "") |
| 432 | + c.Assert(err, IsNil, Commentf("Error unsetting ADT_REBOOT_MARK")) |
| 433 | +} |
| 434 | + |
| 435 | +func afterReboot(c *C) bool { |
| 436 | + // $ADT_REBOOT_MARK contains the reboot mark, if we have rebooted it'll be the test name |
| 437 | + return os.Getenv("ADT_REBOOT_MARK") == c.TestName() |
| 438 | +} |
| 439 | + |
| 440 | +func getCurrentVersion(c *C) int { |
| 441 | + output := execCommand(c, "snappy", "list") |
| 442 | + pattern := "(?mU)^ubuntu-core (.*)$" |
| 443 | + re := regexp.MustCompile(pattern) |
| 444 | + match := re.FindStringSubmatch(output) |
| 445 | + c.Assert(match, NotNil, Commentf("Version not found in %s", output)) |
| 446 | + |
| 447 | + // match is like "ubuntu-core 2015-06-18 93 ubuntu" |
| 448 | + items := strings.Fields(match[0]) |
| 449 | + version, err := strconv.Atoi(items[2]) |
| 450 | + c.Assert(err, IsNil, Commentf("Error converting version to int %v", version)) |
| 451 | + return version |
| 452 | +} |
| 453 | + |
| 454 | +func setSavedVersion(c *C, version int) { |
| 455 | + versionFile := getVersionFile() |
| 456 | + err := ioutil.WriteFile(versionFile, []byte(strconv.Itoa(version)), 0777) |
| 457 | + c.Assert(err, IsNil, Commentf("Error writing version file %s with %s", versionFile, version)) |
| 458 | +} |
| 459 | + |
| 460 | +func getSavedVersion(c *C) int { |
| 461 | + versionFile := getVersionFile() |
| 462 | + contents, err := ioutil.ReadFile(versionFile) |
| 463 | + c.Assert(err, IsNil, Commentf("Error reading version file %s", versionFile)) |
| 464 | + |
| 465 | + version, err := strconv.Atoi(string(contents)) |
| 466 | + c.Assert(err, IsNil, Commentf("Error converting version %v", contents)) |
| 467 | + |
| 468 | + return version |
| 469 | +} |
| 470 | + |
| 471 | +func getVersionFile() string { |
| 472 | + return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "version") |
| 473 | +} |
| 474 | + |
| 475 | +func switchChannelVersion(c *C, oldVersion, newVersion int) { |
| 476 | + targets := []string{"/", baseOtherPath} |
| 477 | + for _, target := range targets { |
| 478 | + file := filepath.Join(target, channelCfgFile) |
| 479 | + if _, err := os.Stat(file); err == nil { |
| 480 | + makeWritable(c, target) |
| 481 | + execCommand(c, |
| 482 | + "sudo", "sed", "-i", |
| 483 | + fmt.Sprintf( |
| 484 | + "s/build_number: %d/build_number: %d/g", |
| 485 | + oldVersion, newVersion), |
| 486 | + file) |
| 487 | + makeReadonly(c, target) |
| 488 | + } |
| 489 | + } |
| 490 | +} |
| 491 | + |
| 492 | +func callUpdate(c *C) { |
| 493 | + c.Log("Calling snappy update...") |
| 494 | + execCommand(c, "sudo", "snappy", "update") |
| 495 | +} |
| 496 | + |
| 497 | +func makeWritable(c *C, path string) { |
| 498 | + execCommand(c, "sudo", "mount", "-o", "remount,rw", path) |
| 499 | +} |
| 500 | + |
| 501 | +func makeReadonly(c *C, path string) { |
| 502 | + execCommand(c, "sudo", "mount", "-o", "remount,ro", path) |
| 503 | +} |
| 504 | |
| 505 | === added file '_integration-tests/tests/failover_zero_size_file_test.go' |
| 506 | --- _integration-tests/tests/failover_zero_size_file_test.go 1970-01-01 00:00:00 +0000 |
| 507 | +++ _integration-tests/tests/failover_zero_size_file_test.go 2015-06-26 07:39:36 +0000 |
| 508 | @@ -0,0 +1,120 @@ |
| 509 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
| 510 | + |
| 511 | +/* |
| 512 | + * Copyright (C) 2015 Canonical Ltd |
| 513 | + * |
| 514 | + * This program is free software: you can redistribute it and/or modify |
| 515 | + * it under the terms of the GNU General Public License version 3 as |
| 516 | + * published by the Free Software Foundation. |
| 517 | + * |
| 518 | + * This program is distributed in the hope that it will be useful, |
| 519 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 520 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 521 | + * GNU General Public License for more details. |
| 522 | + * |
| 523 | + * You should have received a copy of the GNU General Public License |
| 524 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 525 | + * |
| 526 | + */ |
| 527 | + |
| 528 | +package tests |
| 529 | + |
| 530 | +import ( |
| 531 | + "fmt" |
| 532 | + "path/filepath" |
| 533 | + "strings" |
| 534 | + |
| 535 | + . "gopkg.in/check.v1" |
| 536 | +) |
| 537 | + |
| 538 | +const ( |
| 539 | + // TODO: take into account arch for the boot path pattern |
| 540 | + origBootFilenamePattern = "boot/%s%s*" |
| 541 | + origSystemdFilenamePattern = "lib/systemd/%s%s" |
| 542 | + kernelFilename = "vmlinuz" |
| 543 | + initrdFilename = "initrd" |
| 544 | + systemdFilename = "systemd" |
| 545 | + destFilenamePrefix = "snappy-selftest-" |
| 546 | +) |
| 547 | + |
| 548 | +type zeroSizeKernel struct{} |
| 549 | +type zeroSizeInitrd struct{} |
| 550 | +type zeroSizeSystemd struct{} |
| 551 | + |
| 552 | +func (zeroSizeKernel) set(c *C) { |
| 553 | + commonSet(c, origBootFilenamePattern, kernelFilename) |
| 554 | +} |
| 555 | + |
| 556 | +func (zeroSizeKernel) unset(c *C) { |
| 557 | + commonUnset(c, origBootFilenamePattern, kernelFilename) |
| 558 | +} |
| 559 | + |
| 560 | +func (zeroSizeInitrd) set(c *C) { |
| 561 | + commonSet(c, origBootFilenamePattern, initrdFilename) |
| 562 | +} |
| 563 | + |
| 564 | +func (zeroSizeInitrd) unset(c *C) { |
| 565 | + commonUnset(c, origBootFilenamePattern, initrdFilename) |
| 566 | +} |
| 567 | + |
| 568 | +func (zeroSizeSystemd) set(c *C) { |
| 569 | + commonSet(c, origSystemdFilenamePattern, systemdFilename) |
| 570 | +} |
| 571 | + |
| 572 | +func (zeroSizeSystemd) unset(c *C) { |
| 573 | + commonUnset(c, origSystemdFilenamePattern, systemdFilename) |
| 574 | +} |
| 575 | + |
| 576 | +func commonSet(c *C, origPattern, filename string) { |
| 577 | + filenamePattern := fmt.Sprintf(origPattern, "", filename) |
| 578 | + completePattern := filepath.Join( |
| 579 | + baseOtherPath, |
| 580 | + filenamePattern) |
| 581 | + oldFilename := getSingleFilename(c, completePattern) |
| 582 | + filenameSuffix := fmt.Sprintf( |
| 583 | + strings.Replace(origPattern, "*", "", 1), destFilenamePrefix, filepath.Base(oldFilename)) |
| 584 | + newFilename := fmt.Sprintf( |
| 585 | + "%s/%s", baseOtherPath, filenameSuffix) |
| 586 | + |
| 587 | + renameFile(c, baseOtherPath, oldFilename, newFilename) |
| 588 | +} |
| 589 | + |
| 590 | +func commonUnset(c *C, origPattern, filename string) { |
| 591 | + completePattern := filepath.Join( |
| 592 | + baseOtherPath, |
| 593 | + fmt.Sprintf(origPattern, destFilenamePrefix, filename)) |
| 594 | + oldFilename := getSingleFilename(c, completePattern) |
| 595 | + newFilename := strings.Replace(oldFilename, destFilenamePrefix, "", 1) |
| 596 | + |
| 597 | + renameFile(c, baseOtherPath, oldFilename, newFilename) |
| 598 | +} |
| 599 | + |
| 600 | +func renameFile(c *C, basePath, oldFilename, newFilename string) { |
| 601 | + makeWritable(c, basePath) |
| 602 | + execCommand(c, "sudo", "mv", oldFilename, newFilename) |
| 603 | + execCommand(c, "sudo", "touch", oldFilename) |
| 604 | + makeReadonly(c, basePath) |
| 605 | +} |
| 606 | + |
| 607 | +func getSingleFilename(c *C, pattern string) string { |
| 608 | + matches, err := filepath.Glob(pattern) |
| 609 | + |
| 610 | + c.Assert(err, IsNil, Commentf("Error: %v", err)) |
| 611 | + c.Assert(len(matches), Equals, 1) |
| 612 | + |
| 613 | + return matches[0] |
| 614 | +} |
| 615 | + |
| 616 | +/* |
| 617 | +func (s *FailoverSuite) TestZeroSizeKernel(c *C) { |
| 618 | + commonFailoverTest(c, zeroSizeKernel{}) |
| 619 | +} |
| 620 | +*/ |
| 621 | + |
| 622 | +func (s *FailoverSuite) TestZeroSizeInitrd(c *C) { |
| 623 | + commonFailoverTest(c, zeroSizeInitrd{}) |
| 624 | +} |
| 625 | + |
| 626 | +func (s *FailoverSuite) TestZeroSizeSystemd(c *C) { |
| 627 | + commonFailoverTest(c, zeroSizeSystemd{}) |
| 628 | +} |
| 629 | |
| 630 | === renamed file '_integration-tests/tests/snappy_test.go' => '_integration-tests/tests/install_test.go' |
| 631 | --- _integration-tests/tests/snappy_test.go 2015-06-25 14:50:18 +0000 |
| 632 | +++ _integration-tests/tests/install_test.go 2015-06-26 07:39:36 +0000 |
| 633 | @@ -19,42 +19,24 @@ |
| 634 | |
| 635 | package tests |
| 636 | |
| 637 | -import ( |
| 638 | - "os/exec" |
| 639 | - "testing" |
| 640 | - |
| 641 | - . "gopkg.in/check.v1" |
| 642 | -) |
| 643 | - |
| 644 | -// Hook up gocheck into the "go test" runner |
| 645 | -func Test(t *testing.T) { TestingT(t) } |
| 646 | +import . "gopkg.in/check.v1" |
| 647 | |
| 648 | var _ = Suite(&InstallSuite{}) |
| 649 | |
| 650 | -type InstallSuite struct{} |
| 651 | - |
| 652 | -func (s *InstallSuite) installSnap(c *C, packageName string) string { |
| 653 | - return s.execCommand(c, "sudo", "snappy", "install", packageName) |
| 654 | -} |
| 655 | - |
| 656 | -func (s *InstallSuite) execCommand(c *C, cmds ...string) string { |
| 657 | - cmd := exec.Command(cmds[0], cmds[1:]...) |
| 658 | - output, err := cmd.CombinedOutput() |
| 659 | - stringOutput := string(output) |
| 660 | - c.Assert(err, IsNil, Commentf("Error: %v", stringOutput)) |
| 661 | - return stringOutput |
| 662 | -} |
| 663 | - |
| 664 | -func (s *InstallSuite) SetUpSuite(c *C) { |
| 665 | - s.execCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") |
| 666 | +type InstallSuite struct { |
| 667 | + CommonSuite |
| 668 | +} |
| 669 | + |
| 670 | +func installSnap(c *C, packageName string) string { |
| 671 | + return execCommand(c, "sudo", "snappy", "install", packageName) |
| 672 | } |
| 673 | |
| 674 | func (s *InstallSuite) TearDownTest(c *C) { |
| 675 | - s.execCommand(c, "sudo", "snappy", "remove", "hello-world") |
| 676 | + execCommand(c, "sudo", "snappy", "remove", "hello-world") |
| 677 | } |
| 678 | |
| 679 | func (s *InstallSuite) TestInstallSnapMustPrintPackageInformation(c *C) { |
| 680 | - installOutput := s.installSnap(c, "hello-world") |
| 681 | + installOutput := installSnap(c, "hello-world") |
| 682 | |
| 683 | expected := "" + |
| 684 | "Installing hello-world\n" + |
| 685 | @@ -66,18 +48,19 @@ |
| 686 | } |
| 687 | |
| 688 | func (s *InstallSuite) TestCallBinaryFromInstalledSnap(c *C) { |
| 689 | - s.installSnap(c, "hello-world") |
| 690 | + installSnap(c, "hello-world") |
| 691 | |
| 692 | - echoOutput := s.execCommand(c, "hello-world.echo") |
| 693 | + echoOutput := execCommand(c, "hello-world.echo") |
| 694 | |
| 695 | c.Assert(echoOutput, Equals, "Hello World!\n") |
| 696 | } |
| 697 | |
| 698 | func (s *InstallSuite) TestInfoMustPrintInstalledPackageInformation(c *C) { |
| 699 | - s.installSnap(c, "hello-world") |
| 700 | + installSnap(c, "hello-world") |
| 701 | |
| 702 | - infoOutput := s.execCommand(c, "snappy", "info") |
| 703 | + infoOutput := execCommand(c, "snappy", "info") |
| 704 | |
| 705 | expected := "(?ms).*^apps: hello-world\n" |
| 706 | + |
| 707 | c.Assert(infoOutput, Matches, expected) |
| 708 | } |
| 709 | |
| 710 | === modified file 'debian/integration-tests/control' |
| 711 | --- debian/integration-tests/control 2015-06-25 12:09:04 +0000 |
| 712 | +++ debian/integration-tests/control 2015-06-26 07:39:36 +0000 |
| 713 | @@ -1,4 +1,4 @@ |
| 714 | -Test-Command: /tmp/snappy-test/tests/snappy.tests -gocheck.vv -test.outputdir=$ADT_ARTIFACTS |
| 715 | +Test-Command: ./snappy.tests -gocheck.vv -test.outputdir=$ADT_ARTIFACTS |
| 716 | Restrictions: allow-stderr |
| 717 | Depends: ubuntu-snappy-tests |
| 718 |


Nicely done Federico. In particular, the SetUpTest to handle reboots, that looks nice.