예제 #1
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)
		}
	}
}
예제 #2
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())
		}
	}
}