Ejemplo n.º 1
0
func tearDownSnapd(fromBranch bool) error {
	if _, err := cli.ExecCommandErr("sudo", "systemctl", "stop",
		"snapd.service"); err != nil {
		return err
	}

	if _, err := cli.ExecCommandErr("sudo", "rm", "-rf", cfgDir); err != nil {
		return err
	}

	if fromBranch {
		if _, err := cli.ExecCommandErr("sudo", "umount", daemonBinaryPath); err != nil {
			return err
		}
	}

	if _, err := cli.ExecCommandErr("sudo", "systemctl", "daemon-reload"); err != nil {
		return err
	}

	if _, err := cli.ExecCommandErr("sudo", "systemctl", "start",
		"snapd.service"); err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 2
0
func (s *purgeSuite) TestPurgeRemovesDataForDeactivatedNotRemovedPackage(c *check.C) {
	defer common.RemoveSnap(c, data.BasicSnapName)
	_, err := cli.ExecCommandErr("sudo", "snappy", "deactivate", snap)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "snappy", "purge", snap)
	c.Assert(err, check.IsNil)

	_, err = os.Stat(snapDataPath)
	c.Assert(os.IsNotExist(err), check.Equals, true)
}
Ejemplo n.º 3
0
func (s *purgeSuite) TestPurgeHonoursInstalledFlagForNotRemovedPackage(c *check.C) {
	defer common.RemoveSnap(c, data.BasicSnapName)

	dataFile := filepath.Join(snapDataPath, "data")
	_, err := cli.ExecCommandErr("sudo", "touch", dataFile)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "snappy", "purge", snap, "--installed")
	c.Assert(err, check.IsNil)

	_, err = os.Stat(dataFile)
	c.Assert(os.IsNotExist(err), check.Equals, true, check.Commentf("Error %v instead of os.IsNotExist", err))

	_, err = os.Stat(snapDataPath)
	c.Assert(err, check.IsNil)
}
Ejemplo n.º 4
0
// 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
}
Ejemplo n.º 5
0
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
}
Ejemplo n.º 6
0
func (s *classicDimensionSuite) TestDestroyUnexistingClassicMustPrintError(c *check.C) {
	output, err := cli.ExecCommandErr("sudo", "snap", "destroy-classic")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to destroy unexisting classic dimension did not exit with an error"))
	c.Assert(string(output), check.Equals,
		"error: Classic dimension is not enabled.\n",
		check.Commentf("Wrong error message"))
}
Ejemplo n.º 7
0
func (s *purgeSuite) TestPurgeReturnsErrorForNotRemovedPackage(c *check.C) {
	defer common.RemoveSnap(c, data.BasicSnapName)

	_, err := cli.ExecCommandErr("sudo", "snappy", "purge", snap)
	c.Assert(err, check.NotNil)

	_, err = os.Stat(snapDataPath)
	c.Assert(err, check.IsNil)
}
Ejemplo n.º 8
0
func (s *installAppSuite) TestCallFailBinaryFromInstalledSnap(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)

	_, err = cli.ExecCommandErr("basic-binaries.fail")
	c.Assert(err, check.NotNil, check.Commentf("The binary did not fail"))
}
Ejemplo n.º 9
0
func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {
	output, err := cli.ExecCommandErr("sudo", "snappy", "install", "unexisting.canonical")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to install an unexisting snap did not exit with an error"))
	c.Assert(string(output), check.Equals,
		"Installing unexisting.canonical\n"+
			"unexisting.canonical failed to install: snappy package not found\n",
		check.Commentf("Wrong error message"))
}
Ejemplo n.º 10
0
func (s *installAppSuite) TestInstallUnexistingAppMustPrintError(c *check.C) {
	output, err := cli.ExecCommandErr("sudo", "snap", "install", "unexisting.canonical")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to install an unexisting snap did not exit with an error"))
	c.Assert(string(output), testutil.Contains,
		"error: cannot perform the following tasks:\n"+
			"- Download snap \"unexisting.canonical\" from channel \"stable\" (snap not found)\n",
		check.Commentf("Wrong error message"))
}
Ejemplo n.º 11
0
func determinePayload(payload string) (string, error) {
	if _, err := os.Stat(payload); err == nil {
		// payload is a file, in order to make the snap file available to http we need to move it to its $SNAP_DATA path
		snapAppDataPath := filepath.Join("/var/lib/snaps", httpClientSnap, "current")
		if _, err := cli.ExecCommandErr("sudo", "cp", payload, snapAppDataPath); err != nil {
			return "", err
		}
		return "@" + filepath.Join(snapAppDataPath, filepath.Base(payload)), nil
	}
	// payload is a string
	return payload, nil
}
Ejemplo n.º 12
0
func (s *classicDimensionSuite) TestReEnableClassicMustPrintError(c *check.C) {
	c.Skip("Skipping until LP: #1563193 is fixed")
	s.enableClassic(c)
	defer s.destroyClassic(c)
	output, err := cli.ExecCommandErr("sudo", "snap", "enable-classic")

	c.Check(err, check.NotNil,
		check.Commentf("Trying to re-enable classic dimension did not exit with an error"))
	c.Assert(string(output), check.Equals,
		"Classic dimension is already enabled.\n",
		check.Commentf("Wrong error message"))
}
Ejemplo n.º 13
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)
}
Ejemplo n.º 14
0
func setUpSnapd(c *check.C, fromBranch bool, extraEnv string) {
	cli.ExecCommand(c, "sudo", "systemctl", "stop",
		"snapd.service", "snapd.socket")

	if fromBranch {
		binPath, err := filepath.Abs("integration-tests/bin/snapd")
		c.Assert(err, check.IsNil)

		_, err = cli.ExecCommandErr("sudo", "mount", "-o", "bind",
			binPath, daemonBinaryPath)
		c.Assert(err, check.IsNil)
	}

	err := writeEnvConfig(extraEnv)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "systemctl", "daemon-reload")
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "systemctl", "start", "snapd.service")
	c.Assert(err, check.IsNil)
}
Ejemplo n.º 15
0
func (s *purgeSuite) TestPurgeRemovesDataFromRemovedPackage(c *check.C) {
	common.RemoveSnap(c, data.BasicSnapName)

	versionSnapDataPath, err := getVersionSnapDataPath(snap)
	c.Assert(err, check.IsNil)

	_, err = os.Stat(versionSnapDataPath)
	c.Assert(err, check.IsNil)

	_, err = cli.ExecCommandErr("sudo", "snappy", "purge", snap)
	c.Assert(err, check.IsNil)

	_, err = os.Stat(versionSnapDataPath)
	c.Assert(os.IsNotExist(err), check.Equals, true)
}
Ejemplo n.º 16
0
func writeEnvConfig(extraEnv string) error {
	if _, err := cli.ExecCommandErr("sudo", "mkdir", "-p", cfgDir); err != nil {
		return err
	}

	cfgFile := filepath.Join(cfgDir, "env.conf")
	// FIXME: for now pass a test-only trusted key through an env var
	trustedKey, err := filepath.Abs("integration-tests/data/trusted.acckey")
	if err != nil {
		return err
	}

	cfgContent := []byte(fmt.Sprintf(`[Service]
Environment="SNAPPY_TRUSTED_ACCOUNT_KEY=%s" "%s"
`, trustedKey, extraEnv))
	if err = ioutil.WriteFile("/tmp/snapd.env.conf", cfgContent, os.ModeExclusive); err != nil {
		return err
	}

	if _, err = cli.ExecCommandErr("sudo", "mv", "/tmp/snapd.env.conf", cfgFile); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 17
0
// GetCurrentVersion returns the version of the installed and active package.
func GetCurrentVersion(c *check.C, packageName string) string {
	output, err := cli.ExecCommandErr("snap", "list")
	if err != nil {
		// XXX: right now "snap list" on freshly booted is empty
		// because u-d-f installed aren't in state
		return "verUnknown"
	}
	pattern := "(?mU)^" + packageName + " +(.*)$"
	re := regexp.MustCompile(pattern)
	match := re.FindStringSubmatch(string(output))
	c.Assert(match, check.NotNil, check.Commentf("Version of %s not found in %s", packageName, output))

	// match is like "ubuntu-core   2015-06-18 93        ubuntu"
	items := strings.Fields(match[0])
	return items[2]
}
Ejemplo n.º 18
0
func (s *grubSuite) TestGrubBootDirMustNotContainKernelFiles(c *check.C) {
	bootSystem, err := partition.BootSystem()
	c.Assert(err, check.IsNil, check.Commentf("Error getting boot system: %s", err))

	if bootSystem != "grub" {
		c.Skip("This test checks properties of grub based systems")
	}

	bootDir := partition.BootDir(bootSystem)
	for _, targetFile := range []string{"vmlinuz", "initrd.img"} {
		output, err := cli.ExecCommandErr("find", bootDir, "-name", fmt.Sprintf(`"%s"`, targetFile))

		c.Check(err, check.IsNil)
		c.Check(output, check.Equals, "")
	}
}
Ejemplo n.º 19
0
func (s *helloWorldExampleSuite) TestCallHelloWorldEvilMustPrintPermissionDeniedError(c *check.C) {
	common.InstallSnap(c, "hello-world/edge")
	s.AddCleanup(func() {
		common.RemoveSnap(c, "hello-world")
	})

	echoOutput, err := cli.ExecCommandErr("hello-world.evil")
	c.Assert(err, check.NotNil, check.Commentf("hello-world.evil did not fail"))

	expected := "" +
		"Hello Evil World!\n" +
		"This example demonstrates the app confinement\n" +
		"You should see a permission denied error next\n" +
		"/snaps/hello-world.canonical/.*/bin/evil: \\d+: " +
		"/snaps/hello-world.canonical/.*/bin/evil: " +
		"cannot create /var/tmp/myevil.txt: Permission denied\n"

	c.Assert(string(echoOutput), check.Matches, expected)
}
Ejemplo n.º 20
0
// makeRequest makes a request to the API according to the provided options.
func makeRequest(options *requestOptions) (body []byte, err error) {
	cmd := []string{"sudo", "http.do",
		"--pretty", "none",
		"--body",
		"--ignore-stdin",
		options.verb, options.resource}

	if options.payload != "" {
		payload, err := determinePayload(options.payload)
		if err != nil {
			return nil, err
		}
		if strings.HasPrefix(payload, "@") {
			defer os.Remove(payload[1:])
		}
		cmd = append(cmd, payload)
	}

	bodyString, err := cli.ExecCommandErr(append(cmd, "X-Allow-Unsigned:1")...)

	return []byte(bodyString), err
}
Ejemplo n.º 21
0
func (s *loginSuite) setUpIPTables(c *check.C) {
	cmd := ipTablesAddCommand(s.serverAddrPort)
	_, err := cli.ExecCommandErr(cmd...)
	c.Assert(err, check.IsNil, check.Commentf("Error setting up iptables"))
}
Ejemplo n.º 22
0
func (s *loginSuite) tearDownIPTables(c *check.C) {
	cmd := ipTablesDelCommand(s.serverAddrPort)
	_, err := cli.ExecCommandErr(cmd...)
	c.Assert(err, check.IsNil, check.Commentf("Error tearing down iptables"))
}
Ejemplo n.º 23
0
func (s *loginSuite) TestEmptyLoginNameError(c *check.C) {
	output, err := cli.ExecCommandErr("snappy", "login")

	c.Assert(err, check.NotNil, check.Commentf("expecting empty login error"))
	c.Assert(output, check.Equals, "the required argument `userid` was not provided\n")
}