コード例 #1
0
ファイル: deploy.go プロジェクト: ineiti/prifi
// takes in list of unique hosts
func scpTestFiles(hostnames []string) map[string]bool {
	var wg sync.WaitGroup
	failed := make(map[string]bool)
	var mu sync.Mutex
	for _, host := range hostnames {
		wg.Add(1)
		log.Println("scp test files:", host, hostnames)

		go func(host string) {
			defer wg.Done()
			err := cliutils.TimeoutRun(10*time.Second,
				func() error { return cliutils.Scp(uname, host, "latency_test", "latency_test") })
			if err != nil {
				log.Println("Failed:", host, err)
				mu.Lock()
				failed[host] = true
				mu.Unlock()
				return
			}

			err = cliutils.TimeoutRun(10*time.Second,
				func() error { return cliutils.Scp(uname, host, hostfile, "hosts.txt") })
			if err != nil {
				log.Println("Failed:", host, err)
				mu.Lock()
				failed[host] = true
				mu.Unlock()
				return
			}
		}(host)
	}
	wg.Wait()
	return failed
}
コード例 #2
0
ファイル: deploy.go プロジェクト: ineiti/prifi
func testNodes(hostnames []string, failed map[string]bool) ([]string, []byte) {
	var mu sync.Mutex
	var edgelist []byte
	var wg sync.WaitGroup
	for _, host := range hostnames {
		log.Println("latency test:", host)
		if _, ok := failed[host]; ok {
			continue
		}
		wg.Add(1)
		go func(host string) {
			defer wg.Done()
			starttime := time.Now()
			// kill latent processes
			err := cliutils.TimeoutRun(10*time.Second,
				func() error {
					return cliutils.SshRunStdout(uname, host, "killall logserver; killall timeclient; killall latency_test; killall cocoexec; rm -rf cocoexec")
				})
			if err != nil {
				log.Println("Failed:", host, err)
				mu.Lock()
				failed[host] = true
				mu.Unlock()
				return
			}

			// run the latency test
			log.Println("running latency_test:", host)
			output, err := cliutils.SshRun(uname, host, "./latency_test -hostfile=hosts.txt -hostname="+host)
			if err != nil {
				log.Println("Failed:", host, err)
				mu.Lock()
				failed[host] = true
				mu.Unlock()
				return
			}

			// if this took to long say that this has failed
			if time.Since(starttime) > (20 * time.Minute) {
				log.Println("Failed:", host, err)
				mu.Lock()
				failed[host] = true
				mu.Unlock()
				return
			}
			fmt.Println("output:", string(output))
			mu.Lock()
			edgelist = append(edgelist, output...)
			mu.Unlock()
			return
		}(host)
	}
	wg.Wait()
	log.Println("latency test done")
	goodhosts := make([]string, 0, len(hostnames)-len(failed))
	for _, h := range hostnames {
		if !failed[h] {
			goodhosts = append(goodhosts, h)
		}
	}
	return goodhosts, edgelist
}