// 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 *snapRefreshAppSuite) TestAppUpdate(c *check.C) { c.Skip("port to snapd") snap := "hello-world.canonical" storeSnap := fmt.Sprintf("%s", snap) // install edge version from the store (which is squshfs) cli.ExecCommand(c, "sudo", "snap", "install", storeSnap) defer cli.ExecCommand(c, "sudo", "snap", "remove", snap) // make a fakestore and make it available to snapd // use /var/tmp is not a tempfs for space reasons blobDir, err := ioutil.TempDir("/var/tmp", "snap-fake-store-blobs-") c.Assert(err, check.IsNil) defer cli.ExecCommand(c, "sudo", "rm", "-rf", blobDir) fakeStore := store.NewStore(blobDir) err = fakeStore.Start() c.Assert(err, check.IsNil) defer fakeStore.Stop() env := fmt.Sprintf(`SNAPPY_FORCE_CPI_URL=%s`, fakeStore.URL()) cfg, _ := config.ReadConfig(config.DefaultFileName) tearDownSnapd(cfg.FromBranch) setUpSnapd(c, cfg.FromBranch, env) // run the fake update output := updates.CallFakeSnapRefresh(c, snap, updates.NoOp, fakeStore) c.Assert(output, check.Matches, "(?ms).*^hello-world.*fake1.*") }
// Test that there is a proper message if autoupdate runs in the // background func (s *autoupdateMsgSuite) TestAutoUpdateMessageIsPrinted(c *check.C) { cli.ExecCommand(c, "sudo", "systemctl", "start", "snappy-autopilot") s.AddCleanup(func() { cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot") // do not pollute the other tests with hello-world, in case it is installed _, err := exec.Command("sudo", "snappy", "remove", "hello-world").CombinedOutput() if err != nil { fmt.Println("hello-world didn't get installed") } }) // FIXME: risk of race // (i.e. systemctl start finishes before install runs) snappyOutput, _ := exec.Command("sudo", "snappy", "install", "hello-world").CombinedOutput() var expectedTxt string if common.Release(c) == "15.04" { expectedTxt = "another snappy is running, try again later" } else { expectedTxt = "Snappy is updating your system" } expectedPattern := "(?ms).*^" + expectedTxt + ".*\n.*" c.Assert(string(snappyOutput), check.Matches, expectedPattern) }
// 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() } }
// 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 { switchSystemImageConf(c, Cfg.TargetRelease, Cfg.TargetChannel, "0") // 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") 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", "ubuntu-core") 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 init() { c := &check.C{} // Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293 // TODO remove once the bug is fixed // originally added by elopio - 2015-09-30 to the rollback test, moved // here by --fgimenez - 2015-10-15 wait.ForFunction(c, "regular", partition.Mode) cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") cli.ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer") }
func (s *updateAppSuite) TestAppUpdate(c *check.C) { snap := "hello-world.canonical" storeSnap := fmt.Sprintf("%s/edge", snap) // install edge version from the store (which is squshfs) cli.ExecCommand(c, "sudo", "snappy", "install", storeSnap) defer cli.ExecCommand(c, "sudo", "snappy", "remove", snap) output := updates.CallFakeUpdate(c, snap, updates.NoOp) c.Assert(output, check.Matches, "(?ms).*^hello-world.*fake1.*") }
func (s *activateSuite) TestActivateBringsBinaryBack(c *check.C) { cli.ExecCommand(c, "sudo", "snappy", "deactivate", activateSnapName) cli.ExecCommand(c, "sudo", "snappy", "activate", activateSnapName) output := cli.ExecCommand(c, activateBinName) c.Assert(output, check.Equals, activateEchoOutput, check.Commentf("Wrong output from active snap binary")) list := cli.ExecCommand(c, "snappy", "list", "-v") c.Assert(list, check.Matches, activatedPattern) }
// CallFakeSnapRefresh calls snappy update after faking a new version available for the specified snap. // The fake is made copying the currently installed snap. // changeFunc can be used to modify the snap before it is built and served. func CallFakeSnapRefresh(c *check.C, snap string, changeFunc ChangeFakeUpdateSnap, fakeStore *store.Store) string { c.Log("Preparing fake and calling update.") blobDir := fakeStore.SnapsDir() makeFakeUpdateForSnap(c, snap, blobDir, changeFunc) // FIMXE: there is no "snap refresh" that updates all snaps cli.ExecCommand(c, "sudo", "TMPDIR=/var/tmp", "snap", "refresh", snap) // FIXME: do we want an automatic `snap list` output after // `snap update` (like in the old snappy world)? return cli.ExecCommand(c, "snap", "list") }
func (s *activateSuite) TestDeactivateRemovesBinary(c *check.C) { cli.ExecCommand(c, "sudo", "snappy", "deactivate", activateSnapName) defer cli.ExecCommand(c, "sudo", "snappy", "activate", activateSnapName) output, err := cli.ExecCommandErr(activateBinName) c.Assert(err, check.NotNil, check.Commentf("Deactivated snap binary did not exit with an error")) c.Assert(output, check.Not(check.Equals), activateEchoOutput, check.Commentf("Deactivated snap binary was not removed")) list := cli.ExecCommand(c, "snappy", "list", "-v") c.Assert(list, check.Matches, deActivatedPattern) }
func (s *installAppSuite) TestInstallFromStoreMetadata(c *check.C) { common.InstallSnap(c, "hello-world/edge") defer common.RemoveSnap(c, "hello-world") output := cli.ExecCommand(c, "snappy", "info", "hello-world") c.Check(string(output), check.Matches, "(?ms)^channel: edge") }
func renameFile(c *check.C, basePath, oldFilename, newFilename string, keepOld bool) { // Only need to make writable and revert for BaseAltPartitionPath, // kernel files' boot directory is writable if basePath == common.BaseAltPartitionPath { partition.MakeWritable(c, basePath) defer partition.MakeReadonly(c, basePath) } cli.ExecCommand(c, "sudo", "mv", oldFilename, newFilename) if keepOld { cli.ExecCommand(c, "sudo", "touch", oldFilename) mode := getFileMode(c, newFilename) cli.ExecCommand(c, "sudo", "chmod", fmt.Sprintf("%o", mode), oldFilename) } }
func unInstallService(c *check.C, serviceName, basePath string) { partition.MakeWritable(c, basePath) defer partition.MakeReadonly(c, basePath) // Disable the service cli.ExecCommand(c, "sudo", "chroot", basePath, "systemctl", "disable", fmt.Sprintf("%s.service", serviceName)) // Remove the service file cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)) // Remove the requires symlink cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s%s/%s/%s.service", basePath, baseSystemdPath, systemdTargetRequiresDir, serviceName)) }
func (s *initRAMFSSuite) SetUpTest(c *check.C) { s.SnappySuite.SetUpTest(c) if common.BeforeReboot() { bootDir := getCurrentBootDir(c) cli.ExecCommand(c, "cp", path.Join(bootDir, "initrd.img"), os.Getenv("ADT_ARTIFACTS")) } }
func installService(c *check.C, serviceName, serviceCfg, servicesPath string) { // Create service file. cli.ExecCommand(c, "sudo", "chmod", "a+w", servicesPath) serviceFileName := fmt.Sprintf("%s.service", serviceName) serviceFilePath := filepath.Join(servicesPath, serviceFileName) cli.ExecCommandToFile(c, serviceFilePath, "sudo", "echo", serviceCfg) // Create requires directory. requiresDir := filepath.Join(servicesPath, systemdTargetRequiresDir) cli.ExecCommand(c, "sudo", "mkdir", "-p", requiresDir) // Symlink from the requires dir to the service file. cli.ExecCommand(c, "sudo", "ln", "-s", serviceFilePath, filepath.Join(requiresDir, serviceFileName), ) }
// RemoveSnap executes the required command to remove the specified snap func RemoveSnap(c *check.C, packageName string) string { cli.ExecCommand(c, "sudo", "snap", "remove", packageName) // XXX: right now "snap list" on freshly booted is empty // because u-d-f installed aren't in state out, _ := cli.ExecCommandErr("snap", "list") return out }
func buildSnap(c *check.C, snapDir, targetDir string) { helpers.ChDir(targetDir, func() error { // build in /var/tmp (which is not a tempfs) cli.ExecCommand(c, "sudo", "TMPDIR=/var/tmp", "snappy", "build", "--squashfs", snapDir) return nil }) }
func replaceSystemImageValues(c *check.C, file, release, channel, version string) { c.Log("Switching the system image conf...") replaceRegex := map[string]string{ release: `s#channel: ubuntu-core/.*/\(.*\)#channel: ubuntu-core/%s/\1#`, channel: `s#channel: ubuntu-core/\(.*\)/.*#channel: ubuntu-core/\1/%s#`, version: `s/build_number: .*/build_number: %s/`, } for value, regex := range replaceRegex { if value != "" { cli.ExecCommand(c, "sudo", "sed", "-i", fmt.Sprintf(regex, value), file) } } // Leave the new file in the test log. cli.ExecCommand(c, "cat", file) }
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)) } }
func (s *initRAMFSSuite) TearDownTest(c *check.C) { s.SnappySuite.TearDownTest(c) if !common.IsInRebootProcess() { bootDir := getCurrentBootDir(c) cli.ExecCommand( c, "sudo", "mv", path.Join(os.Getenv("ADT_ARTIFACTS"), "initrd.img"), bootDir) } }
func (s *fanTestSuite) TestFanCommandCreatesFanBridge(c *check.C) { output := cli.ExecCommand(c, "ifconfig") expectedPattern := fmt.Sprintf("(?msi).*%s.*%s.*", s.fanName(), s.bridgeIP) c.Assert(output, check.Matches, expectedPattern, check.Commentf("Expected pattern %s not found in %s", expectedPattern, output)) }
// FIXME: remove once "snappy" the command is gone func CallFakeUpdate(c *check.C, snap string, changeFunc ChangeFakeUpdateSnap) string { c.Log("Preparing fake and calling update.") // use /var/tmp is not a tempfs blobDir, err := ioutil.TempDir("/var/tmp", "snap-fake-store-blobs-") c.Assert(err, check.IsNil) defer cli.ExecCommand(c, "sudo", "rm", "-rf", blobDir) fakeStore := store.NewStore(blobDir) err = fakeStore.Start() c.Assert(err, check.IsNil) defer fakeStore.Stop() makeFakeUpdateForSnap(c, snap, blobDir, changeFunc) return cli.ExecCommand(c, "sudo", "TMPDIR=/var/tmp", fmt.Sprintf("SNAPPY_FORCE_CPI_URL=%s", fakeStore.URL()), "snap", "refresh", snap) }
func copySnap(c *check.C, snap, targetDir string) { sourceDir := filepath.Join("/snaps", snap, "current") files, err := filepath.Glob(filepath.Join(sourceDir, "*")) c.Assert(err, check.IsNil) for _, m := range files { cli.ExecCommand(c, "sudo", "cp", "-a", m, targetDir) } }
func (rcLocalCrash) set(c *check.C) { partition.MakeWritable(c, common.BaseAltPartitionPath) defer partition.MakeReadonly(c, common.BaseAltPartitionPath) targetFile := fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath) cli.ExecCommand(c, "sudo", "chmod", "a+xw", targetFile) cli.ExecCommandToFile(c, targetFile, "sudo", "echo", "#!bin/sh\nprintf c > /proc/sysrq-trigger") }
func (s *licensedExampleSuite) isSnapInstalled(c *check.C) bool { infoOutput := cli.ExecCommand(c, "snappy", "info") expectedInfo := "(?ms)" + ".*" + "^apps: .*licensed\\.canonical.*\n" matches, _ := regexp.MatchString("^"+expectedInfo+"$", infoOutput) return matches }
func init() { c := &check.C{} // Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293 // TODO remove once the bug is fixed // originally added by elopio - 2015-09-30 to the rollback test, moved // here by --fgimenez - 2015-10-15 wait.ForFunction(c, "regular", partition.Mode) if _, err := os.Stat(config.DefaultFileName); err == nil { cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") cli.ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer") cfg, err := config.ReadConfig(config.DefaultFileName) c.Assert(err, check.IsNil, check.Commentf("Error reading config: %v", err)) setUpSnapd(c, cfg.FromBranch, "") } }
func (s *fanTestSuite) configureDockerToUseBridge(c *check.C) { cfgFile := dockerCfgFile(c) cli.ExecCommand(c, "sudo", "sed", "-i", fmt.Sprintf(`s/DOCKER_OPTIONS=\"\"/DOCKER_OPTIONS=\"%s\"/`, s.dockerOptions()), cfgFile) restartDocker(c) }
func (s *fanTestSuite) removeBridgeFromDockerConf(c *check.C) { cfgFile := dockerCfgFile(c) cli.ExecCommand(c, "sudo", "sed", "-i", `s/DOCKER_OPTIONS=\".*\"/DOCKER_OPTIONS=\"\"/`, cfgFile) restartDocker(c) }
func (s *classicDimensionSuite) enableClassic(c *check.C) { output := cli.ExecCommand(c, "sudo", "env", "https_proxy="+os.Getenv("https_proxy"), "snap", "enable-classic") expected := "(?ms)" + ".*" + "Classic dimension enabled on this snappy system.\n" + "Use \"snap shell classic\" to enter the classic dimension.\n" c.Assert(output, check.Matches, expected) }
func removeSnap(c *check.C, packageName string) string { cli.ExecCommand(c, "sudo", "snap", "remove", packageName) // FIXME: should `snap remove` shold show a list afterards? // like `snappy install`? // right now "snap list" on freshly booted is empty // because u-d-f installed aren't in state out, _ := cli.ExecCommandErr("snap", "list") return out }