Пример #1
0
// 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()
	}
}
Пример #2
0
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")
}
Пример #3
0
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)
}
Пример #4
0
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)
}
Пример #5
0
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 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 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)
	}
}
Пример #8
0
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"))
	}
}
Пример #9
0
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))
}
Пример #10
0
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 (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")
}
Пример #12
0
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)
}
Пример #13
0
func (s *fanTestSuite) removeBridgeFromDockerConf(c *check.C) {
	cfgFile := dockerCfgFile(c)

	cli.ExecCommand(c, "sudo", "sed", "-i",
		`s/DOCKER_OPTIONS=\".*\"/DOCKER_OPTIONS=\"\"/`,
		cfgFile)

	restartDocker(c)
}
Пример #14
0
func (s *fanTestSuite) TestContainersInTheFanAreReachable(c *check.C) {
	setUpDocker(c)
	defer tearDownDocker(c)
	s.configureDockerToUseBridge(c)
	defer s.removeBridgeFromDockerConf(c)

	// spin up first container
	cli.ExecCommand(c, "docker", "run", "-d", "-t", baseContainer)
	// the first assigned IP in the fan will end with ".2"
	firstIPAddr := strings.TrimRight(s.bridgeIP, ".1") + ".2"

	// ping from a second container
	output := cli.ExecCommand(c, "docker", "run", "-t", baseContainer, "ping", firstIPAddr, "-c", "1")

	expectedPattern := "(?ms).*1 packets transmitted, 1 packets received, 0% packet loss.*"

	c.Assert(output, check.Matches, expectedPattern,
		check.Commentf("Expected pattern %s not found in %s", expectedPattern, output))
}
Пример #15
0
func (s *installAppSuite) TestCallSuccessfulBinaryFromInstalledSnap(c *check.C) {
	snapPath, err := build.LocalSnap(c, data.BasicBinariesSnapName)
	defer os.Remove(snapPath)
	c.Assert(err, check.IsNil, check.Commentf("Error building local snap: %s", err))
	common.InstallSnap(c, snapPath)
	defer common.RemoveSnap(c, data.BasicBinariesSnapName)

	// Exec command does not fail.
	cli.ExecCommand(c, "basic-binaries.success")
}
Пример #16
0
func (s *listSuite) TestListMustPrintCoreVersion(c *check.C) {
	listOutput := cli.ExecCommand(c, "snappy", "list")

	expected := "(?ms)" +
		"Name +Date +Version +Developer *\n" +
		".*" +
		fmt.Sprintf("^ubuntu-core +.* +%s +ubuntu *\n", getVersionFromConfig(c)) +
		".*"
	c.Assert(listOutput, check.Matches, expected)
}
Пример #17
0
func (s *searchSuite) TestSearchFrameworkMustPrintMatch(c *check.C) {
	searchOutput := cli.ExecCommand(c, "snappy", "search", "hello-dbus-fwk")

	expected := "(?ms)" +
		"Name +Version +Summary *\n" +
		".*" +
		"^hello-dbus-fwk +.* +hello-dbus-fwk *\n" +
		".*"

	c.Assert(searchOutput, check.Matches, expected)
}
Пример #18
0
func (s *helloWorldExampleSuite) TestCallHelloWorldBinary(c *check.C) {
	common.InstallSnap(c, "hello-world")
	s.AddCleanup(func() {
		common.RemoveSnap(c, "hello-world")
	})

	echoOutput := cli.ExecCommand(c, "hello-world.echo")

	c.Assert(echoOutput, check.Equals, "Hello World!\n",
		check.Commentf("Wrong output from hello-world binary"))
}
Пример #19
0
// GetCurrentVersion returns the version of the installed and active package.
func GetCurrentVersion(c *check.C, packageName string) string {
	output := cli.ExecCommand(c, "snappy", "list")
	pattern := "(?mU)^" + packageName + " +(.*)$"
	re := regexp.MustCompile(pattern)
	match := re.FindStringSubmatch(string(output))
	c.Assert(match, check.NotNil, check.Commentf("Version not found in %s", output))

	// match is like "ubuntu-core   2015-06-18 93        ubuntu"
	items := strings.Fields(match[0])
	return items[2]
}
func installService(c *check.C, serviceName, serviceCfg, basePath string) {
	partition.MakeWritable(c, basePath)
	defer partition.MakeReadonly(c, basePath)

	// Create service file
	serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)
	cli.ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath))
	cli.ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg)

	// Create requires directory
	requiresDirPart := fmt.Sprintf("%s/%s", baseSystemdPath, systemdTargetRequiresDir)
	requiresDir := fmt.Sprintf("%s%s", basePath, requiresDirPart)
	cli.ExecCommand(c, "sudo", "mkdir", "-p", requiresDir)

	// Symlink from the requires dir to the service file (with chroot for being
	// usable in the other partition)
	cli.ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s",
		fmt.Sprintf("%s/%s.service", baseSystemdPath, serviceName),
		fmt.Sprintf("%s/%s.service", requiresDirPart, serviceName),
	)
}
Пример #21
0
func restartDocker(c *check.C) {
	dockerVersion := common.GetCurrentVersion(c, "docker")
	dockerService := fmt.Sprintf("docker_docker-daemon_%s.service", dockerVersion)

	cli.ExecCommand(c, "sudo", "systemctl", "restart", dockerService)

	// we need to wait until the socket is ready, an active systemctl status is not enough
	err := wait.ForActiveService(c, dockerService)
	c.Assert(err, check.IsNil, check.Commentf("Expected nil error, got %s", err))

	err = wait.ForCommand(c, `(?ms).*docker\.sock\s.*`, "ls", "/run")
	c.Assert(err, check.IsNil, check.Commentf("Expected nil error, got %s", err))
}
Пример #22
0
func setUpDocker(c *check.C) {
	common.InstallSnap(c, "docker")
	dockerVersion := common.GetCurrentVersion(c, "docker")
	dockerService := fmt.Sprintf("docker_docker-daemon_%s.service", dockerVersion)

	err := wait.ForActiveService(c, dockerService)
	c.Assert(err, check.IsNil, check.Commentf("Error waiting for service: %s", err))

	err = wait.ForCommand(c, `(?ms).*docker\.sock\s.*`, "ls", "/run")
	c.Assert(err, check.IsNil, check.Commentf("Expected nil error, got %s", err))

	cli.ExecCommand(c, "docker", "pull", baseContainer)
}
Пример #23
0
func (s *configExampleSuite) TestPrintMessageFromConfig(c *check.C) {
	for _, t := range configTests {
		common.InstallSnap(c, t.snap+t.origin)
		defer common.RemoveSnap(c, t.snap)

		config := fmt.Sprintf(`config:
  %s:
    msg: |
      %s`, t.snap, t.message)

		configFile, err := ioutil.TempFile("", "snappy-cfg")
		defer func() { configFile.Close(); os.Remove(configFile.Name()) }()
		c.Assert(err, check.IsNil, check.Commentf("Error creating temp file: %s", err))
		_, err = configFile.Write([]byte(config))
		c.Assert(err, check.IsNil, check.Commentf("Error writing the conf to the temp file: %s", err))

		cli.ExecCommand(c, "sudo", "snappy", "config", t.snap, configFile.Name())

		output := cli.ExecCommand(c, t.snap+".hello")
		c.Assert(output, check.Equals, t.message, check.Commentf("Wrong message"))
	}
}
Пример #24
0
func (s *infoSuite) TestInfoMustPrintInstalledFrameworks(c *check.C) {
	common.InstallSnap(c, "hello-dbus-fwk.canonical")
	s.AddCleanup(func() {
		common.RemoveSnap(c, "hello-dbus-fwk.canonical")
	})
	infoOutput := cli.ExecCommand(c, "snappy", "info")

	expected := "(?ms)" +
		".*" +
		"^frameworks: .*hello-dbus-fwk.*\n" +
		".*"
	c.Assert(infoOutput, check.Matches, expected)
}
Пример #25
0
func (s *initRAMFSSuite) TestFreeSpaceWithResize(c *check.C) {
	if common.BeforeReboot() {
		bootDir := getCurrentBootDir(c)
		writablePercent := "85"
		cli.ExecCommand(
			c, "sh", "-x", "_integration-tests/scripts/install-test-initramfs", bootDir, writablePercent)
		common.Reboot(c)
	} else if common.AfterReboot(c) {
		common.RemoveRebootMark(c)
		freeSpace := getFreeSpacePercent(c)
		c.Assert(freeSpace < 10, check.Equals, true,
			check.Commentf("The writable partition was not resized"))
	}
}
Пример #26
0
func (s *fanTestSuite) TestDockerCreatesAContainerInsideTheFan(c *check.C) {
	setUpDocker(c)
	defer tearDownDocker(c)
	s.configureDockerToUseBridge(c)
	defer s.removeBridgeFromDockerConf(c)

	output := cli.ExecCommand(c, "docker", "run", "-t", baseContainer, "ifconfig")

	expectedIP := strings.TrimRight(s.bridgeIP, ".1") + ".2"
	expectedPattern := fmt.Sprintf("(?ms).*inet addr:%s.*", expectedIP)

	c.Assert(output, check.Matches, expectedPattern,
		check.Commentf("Expected pattern %s not found in %s", expectedPattern, output))
}
Пример #27
0
func (s *frameworkExampleSuite) TestFrameworkClient(c *check.C) {
	common.InstallSnap(c, "hello-dbus-fwk.canonical")
	defer common.RemoveSnap(c, "hello-dbus-fwk.canonical")

	common.InstallSnap(c, "hello-dbus-app.canonical")
	defer common.RemoveSnap(c, "hello-dbus-app.canonical")

	output := cli.ExecCommand(c, "hello-dbus-app.client")

	expected := "PASS\n"

	c.Assert(output, check.Equals, expected,
		check.Commentf("Expected output %s not found, %s", expected, output))
}
Пример #28
0
func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {
	snapPath, err := build.LocalSnap(c, data.BasicSnapName)
	defer os.Remove(snapPath)
	c.Assert(err, check.IsNil, check.Commentf("Error building local snap: %s", err))
	common.InstallSnap(c, snapPath)
	defer common.RemoveSnap(c, data.BasicSnapName)

	infoOutput := cli.ExecCommand(c, "snappy", "info")

	expected := "(?ms)" +
		".*" +
		"^apps: .*" + data.BasicSnapName + "\\.sideload.*\n"
	c.Assert(infoOutput, check.Matches, expected)
}
Пример #29
0
func (s *listSuite) TestListMustPrintAppVersion(c *check.C) {
	common.InstallSnap(c, "hello-world")
	s.AddCleanup(func() {
		common.RemoveSnap(c, "hello-world")
	})

	listOutput := cli.ExecCommand(c, "snappy", "list")
	expected := "(?ms)" +
		"Name +Date +Version +Developer *\n" +
		".*" +
		"^hello-world +.* +(\\d+)(\\.\\d+)* +.* +.* *\n" +
		".*"

	c.Assert(listOutput, check.Matches, expected)
}
Пример #30
0
func switchChannelVersionWithBackup(c *check.C, newVersion int) {
	m := make(map[string]string)
	m["/"] = channelCfgBackupFile()
	m[BaseAltPartitionPath] = channelCfgOtherBackupFile()
	for target, backup := range m {
		file := filepath.Join(target, channelCfgFile)
		if _, err := os.Stat(file); err == nil {
			partition.MakeWritable(c, target)
			defer partition.MakeReadonly(c, target)
			// Back up the file. It will be restored during the test tear down.
			cli.ExecCommand(c, "cp", file, backup)
			replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion))
		}
	}
}