// SetUpSuite disables the snappy autopilot. It will run before all the // integration suites. func (s *SnappySuite) SetUpSuite(c *check.C) { var err error Cfg, err = config.ReadConfig(config.DefaultFileName) c.Assert(err, check.IsNil, check.Commentf("Error reading config: %v", err)) if !IsInRebootProcess() { if Cfg.Update || Cfg.Rollback { // TODO handle updates to a different release and channel. // Always use the installed snappy because we are updating from an old // image, so we should not use the snappy from the branch. output := cli.ExecCommand(c, "sudo", "/usr/bin/snappy", "update") expected := "(?ms)" + ".*" + fmt.Sprintf("^Reboot to use %s version .*\\.\n", partition.OSSnapName(c)) c.Assert(output, check.Matches, expected) RebootWithMark(c, "setupsuite-update") } } else if CheckRebootMark("setupsuite-update") { RemoveRebootMark(c) // Update was already executed. Update the config so it's not triggered again. Cfg.Update = false Cfg.Write() if Cfg.Rollback { cli.ExecCommand(c, "sudo", "snappy", "rollback", partition.OSSnapName(c)) RebootWithMark(c, "setupsuite-rollback") } } else if CheckRebootMark("setupsuite-rollback") { RemoveRebootMark(c) // Rollback was already executed. Update the config so it's not triggered again. Cfg.Rollback = false Cfg.Write() } }
func (s *rollbackSuite) TestRollbackMustRebootToOtherVersion(c *check.C) { if common.BeforeReboot() { // here we upgrade updates.CallFakeOSUpdate(c) common.Reboot(c) } else if common.CheckRebootMark(c.TestName()) { // after the first reboot we check that it actually booted // a newer version than before common.RemoveRebootMark(c) currentVersion := common.GetCurrentUbuntuCoreVersion(c) savedVersion := common.GetSavedVersion(c) c.Assert(snappy.VersionCompare(currentVersion, savedVersion), check.Equals, 1, check.Commentf("First reboot to the wrong version: %s <= %s", currentVersion, savedVersion)) // now we rollback to the previous version cli.ExecCommand(c, "sudo", "snappy", "rollback", partition.OSSnapName(c), common.GetSavedVersion(c)) common.RebootWithMark(c, c.TestName()+"-rollback") } else if common.CheckRebootMark(c.TestName() + "-rollback") { // and on the second reboot we check that the rollback // did indeed rolled us back to the previous version common.RemoveRebootMark(c) currentVersion := common.GetCurrentUbuntuCoreVersion(c) savedVersion := common.GetSavedVersion(c) c.Assert(currentVersion, check.Equals, savedVersion, check.Commentf("Second reboot to the wrong version: %s != %s", currentVersion, savedVersion)) } }
// SetUpSuite disables the snappy autopilot. It will run before all the // integration suites. func (s *SnappySuite) SetUpSuite(c *check.C) { var err error Cfg, err = config.ReadConfig( "integration-tests/data/output/testconfig.json") c.Assert(err, check.IsNil, check.Commentf("Error reading config: %v", err)) if !IsInRebootProcess() { if Cfg.Update || Cfg.Rollback { // TODO handle updates to a different release and channel. // Always use the installed snappy because we are updating from an old // image, so we should not use the snappy from the branch. output := cli.ExecCommand(c, "sudo", "/usr/bin/snappy", "update") // TODO raise an error if there is no available update. if output != "" { RebootWithMark(c, "setupsuite-update") } } } else if CheckRebootMark("setupsuite-update") { RemoveRebootMark(c) // Update was already executed. Update the config so it's not triggered again. Cfg.Update = false Cfg.Write() if Cfg.Rollback { cli.ExecCommand(c, "sudo", "snappy", "rollback", partition.OSSnapName(c)) RebootWithMark(c, "setupsuite-rollback") } } else if CheckRebootMark("setupsuite-rollback") { RemoveRebootMark(c) // Rollback was already executed. Update the config so it's not triggered again. Cfg.Rollback = false Cfg.Write() } }
func (s *listSuite) TestListMustPrintCoreVersion(c *check.C) { listOutput := cli.ExecCommand(c, "snappy", "list") expected := "(?ms)" + "Name +Date +Version +Developer *\n" + ".*" + fmt.Sprintf("^%s +.* +%s +canonical *\n", partition.OSSnapName(c), verRegexp) + ".*" c.Assert(listOutput, check.Matches, expected) }
// Test that the ubuntu-core update to the same release and channel must install a newer // version. If there is no update available, the channel version will be // modified to fake an update. If there is a version available, the image will // be up-to-date after running this test. func (s *updateOSSuite) TestUpdateToSameReleaseAndChannel(c *check.C) { if common.BeforeReboot() { updateOutput := updates.CallFakeOSUpdate(c) expected := "(?ms)" + ".*" + fmt.Sprintf("^Reboot to use %s version .*\\.\n", partition.OSSnapName(c)) c.Assert(updateOutput, check.Matches, expected) s.assertBootDirContents(c) common.Reboot(c) } else if common.AfterReboot(c) { common.RemoveRebootMark(c) currentVersion := common.GetCurrentUbuntuCoreVersion(c) c.Assert(snappy.VersionCompare(currentVersion, common.GetSavedVersion(c)), check.Equals, 1, check.Commentf("Rebooted to the wrong version: %d", currentVersion)) } }
func (s *rollbackSuite) TestRollbackMustRebootToOtherVersion(c *check.C) { c.Skip("KNOWN BUG FIXME: https://bugs.launchpad.net/snappy/+bug/1534029") if common.BeforeReboot() { updates.CallFakeOSUpdate(c) common.Reboot(c) } else if common.CheckRebootMark(c.TestName()) { common.RemoveRebootMark(c) currentVersion := common.GetCurrentUbuntuCoreVersion(c) c.Assert(snappy.VersionCompare(currentVersion, common.GetSavedVersion(c)), check.Equals, -1, check.Commentf("Rebooted to the wrong version: %s", currentVersion)) cli.ExecCommand(c, "sudo", "snappy", "rollback", partition.OSSnapName(c), common.GetSavedVersion(c)) common.RebootWithMark(c, c.TestName()+"-rollback") } else if common.CheckRebootMark(c.TestName() + "-rollback") { common.RemoveRebootMark(c) currentVersion := common.GetCurrentUbuntuCoreVersion(c) c.Assert(snappy.VersionCompare(currentVersion, common.GetSavedVersion(c)), check.Equals, 0, check.Commentf("Rebooted to the wrong version: %s", currentVersion)) } }
// GetCurrentUbuntuCoreVersion returns the version number of the installed and // active ubuntu-core. func GetCurrentUbuntuCoreVersion(c *check.C) string { if snap := partition.OSSnapName(c); snap != "" { return GetCurrentVersion(c, snap) } return "" }
func (s *configSuite) SetUpTest(c *check.C) { s.SnappySuite.SetUpTest(c) c.Skip("FIXME: port to snap") s.osSnap = partition.OSSnapName(c) s.backConfig = currentConfig(c, s.osSnap) }
// CallFakeOSUpdate calls snappy update after faking a new version available for the OS snap. func CallFakeOSUpdate(c *check.C) string { currentVersion := common.GetCurrentUbuntuCoreVersion(c) common.SetSavedVersion(c, currentVersion) return CallFakeUpdate(c, partition.OSSnapName(c)+".canonical", NoOp) }
// GetCurrentUbuntuCoreVersion returns the version number of the installed and // active ubuntu-core. func GetCurrentUbuntuCoreVersion(c *check.C) string { return GetCurrentVersion(c, partition.OSSnapName(c)) }
func (s *configSuite) SetUpTest(c *check.C) { s.SnappySuite.SetUpTest(c) s.osSnap = partition.OSSnapName(c) s.backConfig = currentConfig(c, s.osSnap) }