Example #1
0
func main() {
	// Setup coloring
	stat, _ := os.Stdout.Stat()
	useColor := (stat.Mode() & os.ModeCharDevice) != 0
	blue := ""
	noColour := ""
	if useColor {
		blue = "\033[0;34m"
		noColour = "\033[0m"
	}

	flag.Parse()
	if *hosts == "" {
		fmt.Printf("Must specific --hosts flag")
	}
	archive := e2e_node.CreateTestArchive()
	defer os.Remove(archive)

	results := make(chan *TestResult)
	hs := strings.Split(*hosts, ",")
	for _, h := range hs {
		fmt.Printf("Starting tests on host %s.", h)
		go func(host string) {
			output, err := e2e_node.RunRemote(archive, host)
			results <- &TestResult{
				output: output,
				err:    err,
				host:   host,
			}
		}(h)
	}

	// Wait for all tests to complete and emit the results
	errCount := 0
	for i := 0; i < len(hs); i++ {
		tr := <-results
		host := tr.host
		fmt.Printf("%s================================================================%s\n", blue, noColour)
		if tr.err != nil {
			errCount++
			fmt.Printf("Failure Finished Host %s Test Suite %s %v\n", host, tr.output, tr.err)
		} else {
			fmt.Printf("Success Finished Host %s Test Suite %s\n", host, tr.output)
		}
		fmt.Printf("%s================================================================%s\n", blue, noColour)
	}

	// Set the exit code if there were failures
	if errCount > 0 {
		fmt.Printf("Failure: %d errors encountered.", errCount)
		os.Exit(1)
	}
}
Example #2
0
func main() {
	flag.Parse()
	rand.Seed(time.Now().UTC().UnixNano())
	if *buildOnly {
		// Build the archive and exit
		e2e_node.CreateTestArchive()
		return
	}

	if *hosts == "" && *images == "" {
		glog.Fatalf("Must specify one of --images or --hosts flag.")
	}
	if *images != "" && *zone == "" {
		glog.Fatal("Must specify --zone flag")
	}
	if *images != "" && *project == "" {
		glog.Fatal("Must specify --project flag")
	}
	if *instanceNamePrefix == "" {
		*instanceNamePrefix = "tmp-node-e2e-" + uuid.NewUUID().String()[:8]
	}

	// Setup coloring
	stat, _ := os.Stdout.Stat()
	useColor := (stat.Mode() & os.ModeCharDevice) != 0
	blue := ""
	noColour := ""
	if useColor {
		blue = "\033[0;34m"
		noColour = "\033[0m"
	}

	archive := e2e_node.CreateTestArchive()
	defer os.Remove(archive)

	results := make(chan *TestResult)
	running := 0
	if *images != "" {
		// Setup the gce client for provisioning instances
		// Getting credentials on gce jenkins is flaky, so try a couple times
		var err error
		for i := 0; i < 10; i++ {
			var client *http.Client
			client, err = google.DefaultClient(oauth2.NoContext, compute.ComputeScope)
			if err != nil {
				continue
			}
			computeService, err = compute.New(client)
			if err != nil {
				continue
			}
			time.Sleep(time.Second * 6)
		}
		if err != nil {
			glog.Fatalf("Unable to create gcloud compute service using defaults.  Make sure you are authenticated. %v", err)
		}

		for _, image := range strings.Split(*images, ",") {
			running++
			fmt.Printf("Initializing e2e tests using image %s.\n", image)
			go func(image string) { results <- testImage(image, archive) }(image)
		}
	}
	if *hosts != "" {
		for _, host := range strings.Split(*hosts, ",") {
			fmt.Printf("Initializing e2e tests using host %s.\n", host)
			running++
			go func(host string) {
				results <- testHost(host, archive, *cleanup)
			}(host)
		}
	}

	// Wait for all tests to complete and emit the results
	errCount := 0
	for i := 0; i < running; i++ {
		tr := <-results
		host := tr.host
		fmt.Printf("%s================================================================%s\n", blue, noColour)
		if tr.err != nil {
			errCount++
			fmt.Printf("Failure Finished Host %s Test Suite\n%s\n%v\n", host, tr.output, tr.err)
		} else {
			fmt.Printf("Success Finished Host %s Test Suite\n%s\n", host, tr.output)
		}
		fmt.Printf("%s================================================================%s\n", blue, noColour)
	}

	// Set the exit code if there were failures
	if errCount > 0 {
		fmt.Printf("Failure: %d errors encountered.", errCount)
		os.Exit(1)
	}
}
Example #3
0
func main() {
	flag.Parse()
	rand.Seed(time.Now().UTC().UnixNano())
	if *buildOnly {
		// Build the archive and exit
		e2e_node.CreateTestArchive()
		return
	}

	if *hosts == "" && *imageConfigFile == "" && *images == "" {
		glog.Fatalf("Must specify one of --image-config-file, --hosts, --images.")
	}
	gceImages := &ImageConfig{
		Images: make(map[string]GCEImage),
	}
	if *imageConfigFile != "" {
		// parse images
		imageConfigData, err := ioutil.ReadFile(*imageConfigFile)
		if err != nil {
			glog.Fatalf("Could not read image config file provided: %v", err)
		}
		err = yaml.Unmarshal(imageConfigData, gceImages)
		if err != nil {
			glog.Fatalf("Could not parse image config file: %v", err)
		}
	}

	// Allow users to specify additional images via cli flags for local testing
	// convenience; merge in with config file
	if *images != "" {
		if *imageProject == "" {
			glog.Fatal("Must specify --image-project if you specify --images")
		}
		cliImages := strings.Split(*images, ",")
		for _, img := range cliImages {
			gceImages.Images[img] = GCEImage{
				Image:   img,
				Project: *imageProject,
			}
		}
	}

	if len(gceImages.Images) != 0 && *zone == "" {
		glog.Fatal("Must specify --zone flag")
	}
	for shortName, image := range gceImages.Images {
		if image.Project == "" {
			glog.Fatalf("Invalid config for %v; must specify a project", shortName)
		}
	}
	if len(gceImages.Images) != 0 {
		if *project == "" {
			glog.Fatal("Must specify --project flag to launch images into")
		}
	}
	if *instanceNamePrefix == "" {
		*instanceNamePrefix = "tmp-node-e2e-" + uuid.NewUUID().String()[:8]
	}

	// Setup coloring
	stat, _ := os.Stdout.Stat()
	useColor := (stat.Mode() & os.ModeCharDevice) != 0
	blue := ""
	noColour := ""
	if useColor {
		blue = "\033[0;34m"
		noColour = "\033[0m"
	}

	go arc.getArchive()
	defer arc.deleteArchive()

	var err error
	computeService, err = getComputeClient()
	if err != nil {
		glog.Fatalf("Unable to create gcloud compute service using defaults.  Make sure you are authenticated. %v", err)
	}

	results := make(chan *TestResult)
	running := 0
	for shortName, image := range gceImages.Images {
		running++
		fmt.Printf("Initializing e2e tests using image %s.\n", shortName)
		go func(image, imageProject string, junitFileNum int) {
			results <- testImage(image, imageProject, junitFileNum)
		}(image.Image, image.Project, running)
	}
	if *hosts != "" {
		for _, host := range strings.Split(*hosts, ",") {
			fmt.Printf("Initializing e2e tests using host %s.\n", host)
			running++
			go func(host string, junitFileNum int) {
				results <- testHost(host, *cleanup, junitFileNum, *setupNode)
			}(host, running)
		}
	}

	// Wait for all tests to complete and emit the results
	errCount := 0
	exitOk := true
	for i := 0; i < running; i++ {
		tr := <-results
		host := tr.host
		fmt.Printf("%s================================================================%s\n", blue, noColour)
		if tr.err != nil {
			errCount++
			fmt.Printf("Failure Finished Host %s Test Suite\n%s\n%v\n", host, tr.output, tr.err)
		} else {
			fmt.Printf("Success Finished Host %s Test Suite\n%s\n", host, tr.output)
		}
		exitOk = exitOk && tr.exitOk
		fmt.Printf("%s================================================================%s\n", blue, noColour)
	}

	// Set the exit code if there were failures
	if !exitOk {
		fmt.Printf("Failure: %d errors encountered.", errCount)
		os.Exit(1)
	}
}
Example #4
0
func (a *Archive) getArchive() (string, error) {
	a.Do(func() { a.path, a.err = e2e_node.CreateTestArchive() })
	return a.path, a.err
}
Example #5
0
func main() {
	flag.Parse()
	rand.Seed(time.Now().UTC().UnixNano())
	if *buildOnly {
		// Build the archive and exit
		e2e_node.CreateTestArchive()
		return
	}

	if *hosts == "" && *images == "" {
		glog.Fatalf("Must specify one of --images or --hosts flag.")
	}
	if *images != "" && *zone == "" {
		glog.Fatal("Must specify --zone flag")
	}
	if *images != "" {
		if *imageProject == "" {
			glog.Fatal("Must specify --image-project flag")
		}
		if *project == "" {
			glog.Fatal("Must specify --project flag")
		}
	}
	if *instanceNamePrefix == "" {
		*instanceNamePrefix = "tmp-node-e2e-" + uuid.NewUUID().String()[:8]
	}

	// Setup coloring
	stat, _ := os.Stdout.Stat()
	useColor := (stat.Mode() & os.ModeCharDevice) != 0
	blue := ""
	noColour := ""
	if useColor {
		blue = "\033[0;34m"
		noColour = "\033[0m"
	}

	go arc.getArchive()
	defer arc.deleteArchive()

	var err error
	computeService, err = getComputeClient()
	if err != nil {
		glog.Fatalf("Unable to create gcloud compute service using defaults.  Make sure you are authenticated. %v", err)
	}

	results := make(chan *TestResult)
	running := 0
	if *images != "" {
		for _, image := range strings.Split(*images, ",") {
			running++
			fmt.Printf("Initializing e2e tests using image %s.\n", image)
			go func(image string, junitFileNum int) { results <- testImage(image, junitFileNum) }(image, running)
		}
	}
	if *hosts != "" {
		for _, host := range strings.Split(*hosts, ",") {
			fmt.Printf("Initializing e2e tests using host %s.\n", host)
			running++
			go func(host string, junitFileNum int) {
				results <- testHost(host, *cleanup, junitFileNum, *setupNode)
			}(host, running)
		}
	}

	// Wait for all tests to complete and emit the results
	errCount := 0
	exitOk := true
	for i := 0; i < running; i++ {
		tr := <-results
		host := tr.host
		fmt.Printf("%s================================================================%s\n", blue, noColour)
		if tr.err != nil {
			errCount++
			fmt.Printf("Failure Finished Host %s Test Suite\n%s\n%v\n", host, tr.output, tr.err)
		} else {
			fmt.Printf("Success Finished Host %s Test Suite\n%s\n", host, tr.output)
		}
		exitOk = exitOk && tr.exitOk
		fmt.Printf("%s================================================================%s\n", blue, noColour)
	}

	// Set the exit code if there were failures
	if !exitOk {
		fmt.Printf("Failure: %d errors encountered.", errCount)
		os.Exit(1)
	}
}