Exemplo n.º 1
0
// UdfCreate forms and executes the UDF command for creating the image
func (img Image) UdfCreate() (string, error) {
	fmt.Println("Creating image...")

	imageDir := filepath.Join(img.baseDir, "image")

	testutils.PrepareTargetDir(imageDir)

	udfCommand := []string{"sudo", "ubuntu-device-flash", "--verbose"}

	if img.revision != "" {
		udfCommand = append(udfCommand, "--revision="+img.revision)
	}

	imagePath := img.imagePath(imageDir)

	coreOptions := []string{
		"core", img.release,
		"--output", imagePath,
		"--channel", img.channel,
		"--developer-mode",
	}

	err := testutils.ExecCommand(append(udfCommand, coreOptions...)...)

	return imagePath, err
}
Exemplo n.º 2
0
func main() {
	var (
		useSnappyFromBranch = flag.Bool("snappy-from-branch", false,
			"If this flag is used, snappy will be compiled from this branch, copied to the testbed and used for the tests. Otherwise, the snappy installed with the image will be used.")
		arch = flag.String("arch", "",
			"Architecture of the test bed. Defaults to use the same architecture as the host.")
		testbedIP = flag.String("ip", "",
			"IP of the testbed. If no IP is passed, a virtual machine will be created for the test.")
		testbedPort = flag.Int("port", defaultSSHPort,
			"SSH port of the testbed. Defaults to use port "+strconv.Itoa(defaultSSHPort))
		testFilter = flag.String("filter", "",
			"Suites or tests to run, for instance MyTestSuite, MyTestSuite.FirstCustomTest or MyTestSuite.*CustomTest")
		imgRelease = flag.String("release", defaultRelease,
			"Release of the image to be built, defaults to "+defaultRelease)
		imgChannel = flag.String("channel", defaultChannel,
			"Channel of the image to be built, defaults to "+defaultChannel)
		imgRevision = flag.String("revision", "",
			"Revision of the image to be built (can be relative to the latest available revision in the given release and channel as in -1), defaults to the empty string")
		update = flag.Bool("update", false,
			"If this flag is used, the image will be updated before running the tests.")
		targetRelease = flag.String("target-release", "",
			"If the update flag is used, the image will be updated to this release before running the tests.")
		targetChannel = flag.String("target-channel", "",
			"If the update flag is used, the image will be updated to this channel before running the tests.")
		rollback = flag.Bool("rollback", false,
			"If this flag is used, the image will be updated and then rolled back before running the tests.")
		outputDir = flag.String("output-dir", defaultOutputDir, "Directory where test artifacts will be stored.")
	)

	flag.Parse()

	build.Assets(*useSnappyFromBranch, *arch)

	// TODO: generate the files out of the source tree. --elopio - 2015-07-15
	testutils.PrepareTargetDir(dataOutputDir)
	defer os.RemoveAll(dataOutputDir)

	remoteTestbed := *testbedIP != ""

	// TODO: pass the config as arguments to the test binaries.
	// --elopio - 2015-07-15
	cfg := config.NewConfig(
		configFileName, *imgRelease, *imgChannel, *targetRelease, *targetChannel,
		remoteTestbed, *update, *rollback)
	cfg.Write()

	rootPath := testutils.RootPath()

	test := autopkgtest.NewAutopkgtest(rootPath, *outputDir, *testFilter, build.IntegrationTestName)
	if !remoteTestbed {
		img := image.NewImage(*imgRelease, *imgChannel, *imgRevision, *outputDir)

		if imagePath, err := img.UdfCreate(); err == nil {
			if err = test.AdtRunLocal(imagePath); err != nil {
				log.Panic(err.Error())
			}
		} else {
			log.Panic(err.Error())
		}
	} else {
		if err := test.AdtRunRemote(*testbedIP, *testbedPort); err != nil {
			log.Panic(err.Error())
		}
	}
}