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")
}
示例#2
0
func switchSystemImageConf(c *check.C, release, channel, version string) {
	targets := []string{"/", BaseAltPartitionPath}
	for _, target := range targets {
		file := filepath.Join(target, channelCfgFile)
		if _, err := os.Stat(file); err == nil {
			partition.MakeWritable(c, target)
			defer partition.MakeReadonly(c, target)
			replaceSystemImageValues(c, file, release, channel, version)
		}
	}
}
示例#3
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))
		}
	}
}
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 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),
	)
}
示例#7
0
// TearDownTest cleans up the channel.ini files in case they were changed by
// the test.
// It also runs the cleanup handlers
func (s *SnappySuite) TearDownTest(c *check.C) {
	if !IsInRebootProcess() {
		// Only restore the channel config files if the reboot has been handled.
		m := make(map[string]string)
		m[channelCfgBackupFile()] = "/"
		m[channelCfgOtherBackupFile()] = BaseAltPartitionPath
		for backup, target := range m {
			if _, err := os.Stat(backup); err == nil {
				partition.MakeWritable(c, target)
				defer partition.MakeReadonly(c, target)
				original := filepath.Join(target, channelCfgFile)
				c.Logf("Restoring %s...", original)
				cli.ExecCommand(c, "sudo", "mv", backup, original)
			}
		}
	}

	// run cleanup handlers and clear the slice
	for _, f := range s.cleanupHandlers {
		f()
	}
	s.cleanupHandlers = nil
}
func (rcLocalCrash) unset(c *check.C) {
	partition.MakeWritable(c, common.BaseAltPartitionPath)
	defer partition.MakeReadonly(c, common.BaseAltPartitionPath)
	cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath))
}