コード例 #1
0
ファイル: image.go プロジェクト: robert-ancell/snapd
// 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 != "" {
		panic("img.revision not supported")
	}

	imagePath := img.imagePath(imageDir)

	coreOptions := []string{
		"core", img.Release,
		"--output", imagePath,
		"--channel", img.Channel,
		"--gadget", img.Gadget,
		"--os", img.OS,
		"--kernel", img.Kernel,
		"--developer-mode",
	}

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

	return imagePath, err
}
コード例 #2
0
ファイル: image.go プロジェクト: General-Beck/snappy
// 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
}
コード例 #3
0
ファイル: main.go プロジェクト: dholbach/snappy
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")

		imgOS = flag.String("os", defaultOS,
			"OS snap of the image to be built, defaults to "+defaultOS)
		imgKernel = flag.String("kernel", defaultKernel,
			"Kernel snap of the image to be built, defaults to "+defaultKernel)
		imgGadget = flag.String("gadget", defaultGadget,
			"Gadget snap of the image to be built, defaults to "+defaultGadget)

		update = flag.Bool("update", false,
			"If this flag is used, the image will be updated 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.")
		shellOnFail   = flag.Bool("shell-fail", false, "Run a shell in the testbed if the suite fails.")
		testBuildTags = flag.String("test-build-tags", "", "Build tags to be passed to the go test command")
		httpProxy     = flag.String("http-proxy", "", "HTTP proxy to set in the testbed.")
	)

	flag.Parse()

	build.Assets(&build.Config{
		UseSnappyFromBranch: *useSnappyFromBranch,
		Arch:                *arch,
		TestBuildTags:       *testBuildTags})

	// 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.Config{
		FileName:      config.DefaultFileName,
		Release:       *imgRelease,
		Channel:       *imgChannel,
		RemoteTestbed: remoteTestbed,
		Update:        *update,
		Rollback:      *rollback,
		FromBranch:    *useSnappyFromBranch,
	}
	cfg.Write()

	rootPath := testutils.RootPath()

	test := &autopkgtest.AutoPkgTest{
		SourceCodePath:      rootPath,
		TestArtifactsPath:   *outputDir,
		TestFilter:          *testFilter,
		IntegrationTestName: build.IntegrationTestName,
		ShellOnFail:         *shellOnFail,
		Env: map[string]string{
			"http_proxy":  *httpProxy,
			"https_proxy": *httpProxy,
			"no_proxy":    "127.0.0.1,127.0.1.1,localhost,login.ubuntu.com",
		},
	}
	if !remoteTestbed {
		img := &image.Image{
			Release:  *imgRelease,
			Channel:  *imgChannel,
			Revision: *imgRevision,
			OS:       *imgOS,
			Kernel:   *imgKernel,
			Gadget:   *imgGadget,
			BaseDir:  *outputDir}

		if imagePath, err := img.UdfCreate(); err == nil {
			if err = test.AdtRunLocal(imagePath); err != nil {
				log.Panicf("%s", err)
			}
		} else {
			log.Panicf("%s", err)
		}
	} else {
		if err := test.AdtRunRemote(*testbedIP, *testbedPort); err != nil {
			log.Panicf("%s", err)
		}
	}
}
コード例 #4
0
ファイル: main.go プロジェクト: General-Beck/snappy
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.")
		shellOnFail = flag.Bool("shell-fail", false, "Run a shell in the testbed if the suite fails.")
	)

	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, *shellOnFail)
	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())
		}
	}
}