예제 #1
0
func (r *StagerRunner) Start(args ...string) {
	if r.session != nil {
		panic("starting more than one stager runner!!!")
	}

	stagerSession, err := gexec.Start(
		exec.Command(
			r.Config.StagerBin,
			append([]string{
				"-bbsAddress", r.Config.BBSURL,
				"-listenAddress", r.Config.ListenAddress,
				"-stagingTaskCallbackURL", r.Config.TaskCallbackURL,
				"-ccBaseURL", r.Config.CCBaseURL,
				"-dockerStagingStack", r.Config.DockerStagingStack,
				"-consulCluster", r.Config.ConsulCluster,
			}, args...)...,
		),
		gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[95m[stager]\x1b[0m ", ginkgo.GinkgoWriter),
		gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[95m[stager]\x1b[0m ", ginkgo.GinkgoWriter),
	)

	Expect(err).NotTo(HaveOccurred())

	r.session = stagerSession
}
예제 #2
0
func (runner *NATSRunner) Start() {
	if runner.natsSession != nil {
		panic("starting an already started NATS runner!!!")
	}

	_, err := exec.LookPath("gnatsd")
	if err != nil {
		fmt.Println("You need gnatsd installed!")
		os.Exit(1)
	}

	cmd := exec.Command("gnatsd", "-p", strconv.Itoa(runner.port))
	sess, err := gexec.Start(
		cmd,
		gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[34m[gnatsd]\x1b[0m ", ginkgo.GinkgoWriter),
		gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[34m[gnatsd]\x1b[0m ", ginkgo.GinkgoWriter),
	)
	Expect(err).NotTo(HaveOccurred(), "Make sure to have gnatsd on your path")

	runner.natsSession = sess

	Expect(err).NotTo(HaveOccurred())

	var messageBus *nats.Conn
	Eventually(func() error {
		messageBus, err = nats.Connect(fmt.Sprintf("nats://127.0.0.1:%d", runner.port))
		return err
	}, 5, 0.1).ShouldNot(HaveOccurred())

	runner.MessageBus = messageBus
}
func startComponent(path string, shortName string, colorCode uint64, arg ...string) *gexec.Session {
	var session *gexec.Session
	var err error
	startCommand := exec.Command(path, arg...)
	session, err = gexec.Start(
		startCommand,
		gexec.NewPrefixedWriter(fmt.Sprintf("\x1b[32m[o]\x1b[%dm[%s]\x1b[0m ", colorCode, shortName), GinkgoWriter),
		gexec.NewPrefixedWriter(fmt.Sprintf("\x1b[91m[e]\x1b[%dm[%s]\x1b[0m ", colorCode, shortName), GinkgoWriter))
	Expect(err).ShouldNot(HaveOccurred())
	return session
}
예제 #4
0
func SetupEtcd() (func(), string) {
	By("making sure etcd was build")
	etcdPath := os.Getenv("ETCD_BUILD_PATH")
	Expect(etcdPath).ToNot(BeEmpty())

	By("starting etcd")
	etcdPort := getPort(etcdPortOffset)
	etcdPeerPort := getPort(etcdPeerPortOffset)
	etcdClientURL := fmt.Sprintf("http://localhost:%d", etcdPort)
	etcdPeerURL := fmt.Sprintf("http://localhost:%d", etcdPeerPort)
	etcdDataDir, err := ioutil.TempDir("", "etcd-data")
	Expect(err).ToNot(HaveOccurred())

	etcdCommand := exec.Command(
		etcdPath,
		"--data-dir", etcdDataDir,
		"--listen-client-urls", etcdClientURL,
		"--listen-peer-urls", etcdPeerURL,
		"--advertise-client-urls", etcdClientURL,
	)
	etcdSession, err := gexec.Start(
		etcdCommand,
		gexec.NewPrefixedWriter(color("o", "etcd", green, yellow), GinkgoWriter),
		gexec.NewPrefixedWriter(color("e", "etcd", red, yellow), GinkgoWriter),
	)
	Expect(err).ToNot(HaveOccurred())

	By("waiting for etcd to respond via http")
	Eventually(func() error {
		req, reqErr := http.NewRequest("PUT", etcdClientURL+"/v2/keys/test", strings.NewReader("value=test"))
		if reqErr != nil {
			return reqErr
		}
		resp, reqErr := http.DefaultClient.Do(req)
		if reqErr != nil {
			return reqErr
		}
		defer resp.Body.Close()
		if resp.StatusCode == http.StatusInternalServerError {
			return errors.New(fmt.Sprintf("got %d response from etcd", resp.StatusCode))
		}
		return nil
	}, 10).Should(Succeed())

	return func() {
		os.RemoveAll(etcdDataDir)
		etcdSession.Kill().Wait()
	}, etcdClientURL
}
예제 #5
0
파일: configure.go 프로젝트: dpb587/fly
func diff(existingConfig atc.Config, newConfig atc.Config) {
	indent := gexec.NewPrefixedWriter("  ", os.Stdout)

	groupDiffs := diffIndices(GroupIndex(existingConfig.Groups), GroupIndex(newConfig.Groups))
	if len(groupDiffs) > 0 {
		fmt.Println("groups:")

		for _, diff := range groupDiffs {
			diff.WriteTo(indent, "group")
		}
	}

	resourceDiffs := diffIndices(ResourceIndex(existingConfig.Resources), ResourceIndex(newConfig.Resources))
	if len(resourceDiffs) > 0 {
		fmt.Println("resources:")

		for _, diff := range resourceDiffs {
			diff.WriteTo(indent, "resource")
		}
	}

	jobDiffs := diffIndices(JobIndex(existingConfig.Jobs), JobIndex(newConfig.Jobs))
	if len(jobDiffs) > 0 {
		fmt.Println("jobs:")

		for _, diff := range jobDiffs {
			diff.WriteTo(indent, "job")
		}
	}

	if !askToConfirm("apply configuration?") {
		println("bailing out")
		os.Exit(1)
	}
}
예제 #6
0
파일: atc_config.go 프로젝트: aemengo/fly
func diff(existingConfig atc.Config, newConfig atc.Config) {
	indent := gexec.NewPrefixedWriter("  ", os.Stdout)

	groupDiffs := diffIndices(GroupIndex(existingConfig.Groups), GroupIndex(newConfig.Groups))
	if len(groupDiffs) > 0 {
		fmt.Println("groups:")

		for _, diff := range groupDiffs {
			diff.Render(indent, "group")
		}
	}

	resourceDiffs := diffIndices(ResourceIndex(existingConfig.Resources), ResourceIndex(newConfig.Resources))
	if len(resourceDiffs) > 0 {
		fmt.Println("resources:")

		for _, diff := range resourceDiffs {
			diff.Render(indent, "resource")
		}
	}

	jobDiffs := diffIndices(JobIndex(existingConfig.Jobs), JobIndex(newConfig.Jobs))
	if len(jobDiffs) > 0 {
		fmt.Println("jobs:")

		for _, diff := range jobDiffs {
			diff.Render(indent, "job")
		}
	}
}
예제 #7
0
func (etcd *ETCDRunner) start(nuke bool) {
	etcd.mutex.RLock()
	running := etcd.running
	etcd.mutex.RUnlock()

	if running {
		return
	}

	etcd.mutex.Lock()
	defer etcd.mutex.Unlock()

	etcd.etcdSessions = make([]*gexec.Session, etcd.numNodes)

	for i := 0; i < etcd.numNodes; i++ {
		if nuke {
			etcd.nukeArtifacts(i)
		}

		if etcd.detectRunningEtcd(i) {
			log.Fatalf("Detected an ETCD already running on %s", etcd.clientUrl(i))
		}

		os.MkdirAll(etcd.tmpPath(i), 0700)
		args := []string{"-data-dir", etcd.tmpPath(i), "-addr", etcd.clientUrl(i), "-peer-addr", etcd.serverUrl(i), "-name", etcd.nodeName(i)}
		if i != 0 {
			args = append(args, "-peers", etcd.serverUrl(0))
		}

		session, err := gexec.Start(
			exec.Command("etcd", args...),
			gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[33m[etcd_cluster]\x1b[0m ", ginkgo.GinkgoWriter),
			gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[33m[etcd_cluster]\x1b[0m ", ginkgo.GinkgoWriter),
		)
		Ω(err).ShouldNot(HaveOccurred(), "Make sure etcd is compiled and on your $PATH.")

		etcd.etcdSessions[i] = session

		Eventually(func() bool {
			return etcd.detectRunningEtcd(i)
		}, 3, 0.05).Should(BeTrue(), "Expected ETCD to be up and running")
	}

	etcd.client = etcdclient.NewClient(etcd.NodeURLS())
	etcd.running = true
}
예제 #8
0
func setupMetron() *gexec.Session {
	pathToMetronExecutable, err := gexec.Build("metron")
	Expect(err).ShouldNot(HaveOccurred())

	command := exec.Command(pathToMetronExecutable, "--config=fixtures/metron.json", "--debug")
	metronSession, err := gexec.Start(command, gexec.NewPrefixedWriter("[o][metron]", GinkgoWriter), gexec.NewPrefixedWriter("[e][metron]", GinkgoWriter))
	Expect(err).ShouldNot(HaveOccurred())

	return metronSession
}
예제 #9
0
파일: runner.go 프로젝트: jiangytcn/rep
func (r *Runner) Start() {
	if r.Session != nil && r.Session.ExitCode() == -1 {
		panic("starting more than one rep!!!")
	}

	args := []string{
		"-cellID", r.config.CellID,
		"-listenAddr", fmt.Sprintf("0.0.0.0:%d", r.config.ServerPort),
		"-bbsAddress", r.config.BBSAddress,
		"-logLevel", r.config.LogLevel,
		"-pollingInterval", r.config.PollingInterval.String(),
		"-evacuationTimeout", r.config.EvacuationTimeout.String(),
		"-lockRetryInterval", "1s",
		"-consulCluster", r.config.ConsulCluster,
		"-containerMaxCpuShares", "1024",
		"-gardenNetwork", "tcp",
		"-gardenAddr", r.config.GardenAddr,
		"-gardenHealthcheckProcessUser", "me",
		"-gardenHealthcheckProcessPath", "ls",
	}
	for _, rootfs := range r.config.PreloadedRootFSes {
		args = append(args, "-preloadedRootFS", rootfs)
	}
	for _, provider := range r.config.RootFSProviders {
		args = append(args, "-rootFSProvider", provider)
	}

	repSession, err := gexec.Start(
		exec.Command(
			r.binPath,
			args...,
		),
		gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[32m[rep]\x1b[0m ", ginkgo.GinkgoWriter),
		gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[32m[rep]\x1b[0m ", ginkgo.GinkgoWriter),
	)

	Expect(err).NotTo(HaveOccurred())
	r.Session = repSession

	Eventually(r.Session.Buffer(), 2).Should(gbytes.Say(r.StartCheck))
}
예제 #10
0
func (m *MetronRunner) Configure() *ginkgomon.Runner {
	cfgFile, err := ioutil.TempFile(m.TempDir, "metron")
	Expect(err).NotTo(HaveOccurred())
	config := config.Config{
		Index: "42",
		Job:   "test-component",
		LoggregatorDropsondePort:  m.DropsondePort,
		IncomingUDPPort:           m.MetronPort,
		SharedSecret:              "shared_secret",
		EtcdUrls:                  m.EtcdRunner.NodeURLS(),
		EtcdMaxConcurrentRequests: 1,
		Zone:                             "z1",
		Deployment:                       "deployment-name",
		Protocols:                        m.Protocols,
		MetricBatchIntervalMilliseconds:  50,
		RuntimeStatsIntervalMilliseconds: 500,
		TCPBatchSizeBytes:                1024,
		TLSConfig: config.TLSConfig{
			CertFile: m.CertFile,
			KeyFile:  m.KeyFile,
			CAFile:   m.CAFile,
		},
	}
	configBytes, err := json.Marshal(config)
	_, err = cfgFile.Write(configBytes)
	Expect(err).NotTo(HaveOccurred())
	cfgFile.Close()

	command := exec.Command(m.Path, "--config", cfgFile.Name(), "--debug")
	command.Stdout = gexec.NewPrefixedWriter("[o][metron]", GinkgoWriter)
	command.Stderr = gexec.NewPrefixedWriter("[e][metron]", GinkgoWriter)
	m.Runner = ginkgomon.New(ginkgomon.Config{
		Name:          "metron",
		AnsiColorCode: "97m",
		StartCheck:    "metron started",
		Command:       command,
	})

	return m.Runner
}
예제 #11
0
func (atcConfig ATCConfig) showHelpfulMessage(resp *http.Response, paused PipelineAction) {
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		fmt.Println("configuration updated")
	case http.StatusCreated:
		pipelineWebReq, _ := atcConfig.webRequestGenerator.CreateRequest(
			atcroutes.Pipeline,
			rata.Params{"pipeline_name": atcConfig.pipelineName},
			nil,
		)

		fmt.Println("pipeline created!")

		pipelineURL := pipelineWebReq.URL
		// don't show username and password
		pipelineURL.User = nil

		fmt.Printf("you can view your pipeline here: %s\n", pipelineURL.String())

		if paused == DoNotChangePipeline || paused == PausePipeline {
			fmt.Println("")
			fmt.Println("the pipeline is currently paused. to unpause, either:")
			fmt.Println("  - run again with --paused=false")
			fmt.Println("  - click play next to the pipeline in the web ui")
		}
	default:
		fmt.Fprintln(os.Stderr, "failed to update configuration.")

		indent := gexec.NewPrefixedWriter("  ", os.Stderr)
		fmt.Fprintf(indent, "response code: %s\n", resp.Status)
		fmt.Fprintf(indent, "response body:\n")

		indentAgain := gexec.NewPrefixedWriter("  ", indent)
		io.Copy(indentAgain, resp.Body)
		os.Exit(1)
	}
}
예제 #12
0
func setupMetron() *gexec.Session {
	pathToMetronExecutable, err := gexec.Build("metron")
	Expect(err).ShouldNot(HaveOccurred())

	command := exec.Command(pathToMetronExecutable, "--config=fixtures/metron.json", "--debug")
	metronSession, err := gexec.Start(command, gexec.NewPrefixedWriter("[o][metron]", GinkgoWriter), gexec.NewPrefixedWriter("[e][metron]", GinkgoWriter))
	Expect(err).ShouldNot(HaveOccurred())

	Eventually(metronSession.Buffer).Should(gbytes.Say("Chose protocol"))
	Consistently(metronSession.Exited).ShouldNot(BeClosed())

	return metronSession
}
예제 #13
0
func setupMetron() *gexec.Session {
	pathToMetronExecutable, err := gexec.Build("metron")
	Expect(err).ShouldNot(HaveOccurred())

	command := exec.Command(pathToMetronExecutable, "--config=fixtures/metron.json", "--debug")
	metronSession, err := gexec.Start(command, gexec.NewPrefixedWriter("[o][metron]", GinkgoWriter), gexec.NewPrefixedWriter("[e][metron]", GinkgoWriter))
	Expect(err).ShouldNot(HaveOccurred())

	localIPAddress, _ := localip.LocalIP()

	// wait for server to be up
	Eventually(func() error {
		_, err := http.Get("http://" + localIPAddress + ":1234")
		return err
	}, 3).ShouldNot(HaveOccurred())

	return metronSession
}
예제 #14
0
파일: atc_config.go 프로젝트: mmb/fly
func diff(existingConfig atc.Config, newConfig atc.Config) {
	indent := gexec.NewPrefixedWriter("  ", os.Stdout)

	groupDiffs := diffIndices(GroupIndex(existingConfig.Groups), GroupIndex(newConfig.Groups))
	if len(groupDiffs) > 0 {
		fmt.Println("groups:")

		for _, diff := range groupDiffs {
			diff.Render(indent, "group")
		}
	}

	resourceDiffs := diffIndices(ResourceIndex(existingConfig.Resources), ResourceIndex(newConfig.Resources))
	if len(resourceDiffs) > 0 {
		fmt.Println("resources:")

		for _, diff := range resourceDiffs {
			diff.Render(indent, "resource")
		}
	}

	jobDiffs := diffIndices(JobIndex(existingConfig.Jobs), JobIndex(newConfig.Jobs))
	if len(jobDiffs) > 0 {
		fmt.Println("jobs:")

		for _, diff := range jobDiffs {
			diff.Render(indent, "job")
		}
	}

	confirm := false
	err := interact.NewInteraction("apply configuration?").Resolve(&confirm)
	if err != nil || !confirm {
		fmt.Println("bailing out")
		os.Exit(1)
	}
}
예제 #15
0
파일: diff.go 프로젝트: aemengo/fly
func (diff Diff) Render(to io.Writer, label string) {
	indent := gexec.NewPrefixedWriter("  ", to)

	if diff.Before != nil && diff.After != nil {
		fmt.Fprintf(to, ansi.Color("%s %s has changed:", "yellow")+"\n", label, name(diff.Before))

		payloadA, _ := yaml.Marshal(diff.Before)
		payloadB, _ := yaml.Marshal(diff.After)

		renderDiff(indent, string(payloadA), string(payloadB))
	} else if diff.Before != nil {
		fmt.Fprintf(to, ansi.Color("%s %s has been removed:", "yellow")+"\n", label, name(diff.Before))

		payloadA, _ := yaml.Marshal(diff.Before)

		renderDiff(indent, string(payloadA), "")
	} else {
		fmt.Fprintf(to, ansi.Color("%s %s has been added:", "yellow")+"\n", label, name(diff.After))

		payloadB, _ := yaml.Marshal(diff.After)

		renderDiff(indent, "", string(payloadB))
	}
}
var session *gexec.Session

func TestIntegrationTests(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Bosh HM Forwarder - Integration Tests Suite")
}

var _ = BeforeSuite(func() {
	boshForwarderExecutable, err := gexec.Build("boshhmforwarder", "-race")
	Expect(err).ToNot(HaveOccurred())

	createConfig()
	command := exec.Command(boshForwarderExecutable, "--configPath", "./integration_config.json")

	session, err = gexec.Start(command, gexec.NewPrefixedWriter("[o][boshhmforwarder]", GinkgoWriter), gexec.NewPrefixedWriter("[e][boshhmforwarder]", GinkgoWriter))
	Expect(err).ToNot(HaveOccurred())
	Consistently(session.Exited).ShouldNot(BeClosed())
})

var _ = AfterSuite(func() {
	if session != nil {
		session.Kill().Wait()
	}

	gexec.CleanupBuildArtifacts()
	err := os.Remove("integration_config.json")
	Expect(err).ToNot(HaveOccurred())
})

func createConfig() {
var etcdRunner *etcdstorerunner.ETCDClusterRunner
var etcdPort int
var localIPAddress string

var pathToGoStatsdClient string

var _ = BeforeSuite(func() {
	pathToMetronExecutable, err := gexec.Build("metron")
	Expect(err).ShouldNot(HaveOccurred())

	pathToGoStatsdClient, err = gexec.Build("statsd-injector/tools/statsdGoClient")
	Expect(err).NotTo(HaveOccurred())

	command := exec.Command(pathToMetronExecutable, "--config=fixtures/metron.json", "--debug")

	metronSession, err = gexec.Start(command, gexec.NewPrefixedWriter("[o][metron]", GinkgoWriter), gexec.NewPrefixedWriter("[e][metron]", GinkgoWriter))
	Expect(err).ShouldNot(HaveOccurred())

	pathToStatsdInjectorExecutable, err := gexec.Build("statsd-injector")
	Expect(err).NotTo(HaveOccurred())
	command = exec.Command(pathToStatsdInjectorExecutable, "-statsdPort=51162", "-metronPort=51161", "-logLevel=debug")

	statsdInjectorSession, err = gexec.Start(command, gexec.NewPrefixedWriter("[o][statsdInjector]", GinkgoWriter), gexec.NewPrefixedWriter("[e][statsdInjector]", GinkgoWriter))
	Expect(err).ShouldNot(HaveOccurred())

	localIPAddress, _ = localip.LocalIP()

	etcdPort = 5800 + (config.GinkgoConfig.ParallelNode-1)*10
	etcdRunner = etcdstorerunner.NewETCDClusterRunner(etcdPort, 1, nil)
	etcdRunner.Start()
예제 #18
0
func SetupMetron(etcdClientURL, proto string) (func(), int, func()) {
	By("making sure metron was build")
	metronPath := os.Getenv("METRON_BUILD_PATH")
	Expect(metronPath).ToNot(BeEmpty())

	By("starting metron")
	protocols := metronConfig.Protocols{
		metronConfig.Protocol(proto): struct{}{},
	}
	metronPort := getPort(metronPortOffset)
	metronConf := metronConfig.Config{
		Index:        jobIndex,
		Job:          jobName,
		Zone:         availabilityZone,
		SharedSecret: sharedSecret,

		Protocols:       metronConfig.Protocols(protocols),
		IncomingUDPPort: metronPort,
		Deployment:      "deployment",

		EtcdUrls:                  []string{etcdClientURL},
		EtcdMaxConcurrentRequests: 1,

		MetricBatchIntervalMilliseconds:  10,
		RuntimeStatsIntervalMilliseconds: 10,
		TCPBatchSizeBytes:                1024,
		TCPBatchIntervalMilliseconds:     10,
	}

	switch proto {
	case "udp":
	case "tls":
		metronConf.TLSConfig = metronConfig.TLSConfig{
			CertFile: "../fixtures/client.crt",
			KeyFile:  "../fixtures/client.key",
			CAFile:   "../fixtures/loggregator-ca.crt",
		}
		fallthrough
	case "tcp":
		metronConf.TCPBatchIntervalMilliseconds = 100
		metronConf.TCPBatchSizeBytes = 10240
	}

	metronCfgFile, err := ioutil.TempFile("", "metron-config")
	Expect(err).ToNot(HaveOccurred())

	err = json.NewEncoder(metronCfgFile).Encode(metronConf)
	Expect(err).ToNot(HaveOccurred())
	err = metronCfgFile.Close()
	Expect(err).ToNot(HaveOccurred())

	metronCommand := exec.Command(metronPath, "--debug", "--config", metronCfgFile.Name())
	metronSession, err := gexec.Start(
		metronCommand,
		gexec.NewPrefixedWriter(color("o", "metron", green, magenta), GinkgoWriter),
		gexec.NewPrefixedWriter(color("e", "metron", red, magenta), GinkgoWriter),
	)
	Expect(err).ToNot(HaveOccurred())

	Eventually(metronSession.Buffer).Should(gbytes.Say("metron started"))

	By("waiting for metron to listen")
	Eventually(func() error {
		c, reqErr := net.Dial("udp4", fmt.Sprintf(":%d", metronPort))
		if reqErr == nil {
			c.Close()
		}
		return reqErr
	}, 3).Should(Succeed())

	return func() {
			os.Remove(metronCfgFile.Name())
			metronSession.Kill().Wait()
		}, metronPort, func() {
			Eventually(metronSession.Buffer).Should(gbytes.Say(" from last etcd event, updating writer..."))
		}
}
		nozzleSession.Kill().Wait()
	})

	Context("with an HTTP OpenTSDB endpoint", func() {
		BeforeEach(func() {
			fakeOpentsdb = &http.Server{
				Addr:    ":8087",
				Handler: http.HandlerFunc(fakeOpentsdbHandler),
			}
			go fakeOpentsdb.ListenAndServe()

			var err error
			nozzleCommand := exec.Command(pathToNozzleExecutable, "-config", "fixtures/http-test-config.json")
			nozzleSession, err = gexec.Start(
				nozzleCommand,
				gexec.NewPrefixedWriter("[o][nozzle] ", GinkgoWriter),
				gexec.NewPrefixedWriter("[e][nozzle] ", GinkgoWriter),
			)
			Expect(err).NotTo(HaveOccurred())
		})
		It("forwards metrics in a batch", func(done Done) {
			sendEventsThroughFirehose(fakeFirehoseInputChan)

			// eventually receive a batch from fake DD
			var messageBytes []byte
			Eventually(fakeOpenTSDBChan, "2s").Should(Receive(&messageBytes))

			// Break JSON blob into a list of blobs, one for each metric
			var metrics []poster.Metric

			log.Printf("Received message is: %s\n", string(messageBytes))
예제 #20
0
	AfterEach(func() {
		if readerSession != nil {
			readerSession.Terminate()
		}
		if writerSession != nil {
			writerSession.Terminate()
		}

		gexec.CleanupBuildArtifacts()
	})

	It("compiles, sends and receives messages via UDP", func() {
		executablePath, err := gexec.Build("github.com/myshkin5/netspel/netspel")
		Expect(err).NotTo(HaveOccurred())

		readerCommand := exec.Command(executablePath, "--config", "./simple.json", "read")
		readerSession, err = gexec.Start(readerCommand,
			gexec.NewPrefixedWriter("\x1b[37m[o]\x1b[32m[reader]\x1b[0m ", GinkgoWriter),
			gexec.NewPrefixedWriter("\x1b[31m[e]\x1b[32m[reader]\x1b[0m ", GinkgoWriter))
		Expect(err).NotTo(HaveOccurred())
		writerCommand := exec.Command(executablePath, "--config", "./simple.json", "write")
		writerSession, err = gexec.Start(writerCommand,
			gexec.NewPrefixedWriter("\x1b[37m[o]\x1b[31m[writer]\x1b[0m ", GinkgoWriter),
			gexec.NewPrefixedWriter("\x1b[31m[e]\x1b[31m[writer]\x1b[0m ", GinkgoWriter))
		Expect(err).NotTo(HaveOccurred())

		Eventually(readerSession, 10*time.Second).Should(gexec.Exit(0))
		Eventually(writerSession, 10*time.Second).Should(gexec.Exit(0))
	})
})
예제 #21
0
				mkdir $tmpdir/graph

				./bin/garden-linux \
					-bin /root/binpath/bin \
					-rootfs /root/rootfs \
					-depot  $tmpdir/depot \
					-snapshots $tmpdir/snapshots \
					-stateDir $tmpdir/state \
					-graph $tmpdir/graph \
					-tag n \
					-listenNetwork tcp \
					-listenAddr 0.0.0.0:7778
				`),
			},
		}, garden.ProcessIO{
			Stdout: io.MultiWriter(nestedServerOutput, gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[34m[nested-garden-linux]\x1b[0m ", GinkgoWriter)),
			Stderr: gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[34m[nested-garden-linux]\x1b[0m ", GinkgoWriter),
		})

		info, err := container.Info()
		Expect(err).ToNot(HaveOccurred())

		nestedGardenAddress := fmt.Sprintf("%s:7778", info.ContainerIP)
		Eventually(nestedServerOutput, "60s").Should(gbytes.Say("garden-linux.started"))

		return container, nestedGardenAddress
	}

	It("can start a nested garden-linux and run a container inside it", func() {
		container, nestedGardenAddress := startNestedGarden()
		defer func() {
예제 #22
0
		rootfsPath, err = ioutil.TempDir("", "testdir")
		Expect(err).NotTo(HaveOccurred())

		dir1 = "potayto"
		dir2 = path.Join("poTARto", "banarna")

		SetDefaultEventuallyTimeout(5 * time.Second)
	})

	AfterEach(func() {
		Expect(os.RemoveAll(rootfsPath)).To(Succeed())
	})

	run := func(rootfsPath string, uid, gid int, mode os.FileMode, recreate bool, args ...string) *gexec.Session {
		cmd := preparerootfs.Command(rootfsPath, uid, gid, mode, recreate, args...)
		sess, err := gexec.Start(cmd, gexec.NewPrefixedWriter("reexec-stdout: ", GinkgoWriter), gexec.NewPrefixedWriter("reexec-stderr: ", GinkgoWriter))
		Expect(err).NotTo(HaveOccurred())
		return sess
	}

	It("creates each directory", func() {
		Eventually(run(rootfsPath, 0, 0, 0755, true, dir1, dir2)).Should(gexec.Exit(0))

		Expect(path.Join(rootfsPath, dir1)).To(BeADirectory())
		Expect(path.Join(rootfsPath, dir2)).To(BeADirectory())
	})

	It("creates the directories as the requested uid and gid", func() {
		Eventually(run(rootfsPath, 12, 24, 0777, true, dir1, dir2)).Should(gexec.Exit(0))

		stat, err := os.Stat(path.Join(rootfsPath, dir2))
예제 #23
0
파일: ginkgomon.go 프로젝트: cwlbraa/ifrit
func (r *Runner) Run(sigChan <-chan os.Signal, ready chan<- struct{}) error {
	defer ginkgo.GinkgoRecover()

	allOutput := gbytes.NewBuffer()

	debugWriter := gexec.NewPrefixedWriter(
		fmt.Sprintf("\x1b[32m[d]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name),
		ginkgo.GinkgoWriter,
	)

	session, err := gexec.Start(
		r.Command,
		gexec.NewPrefixedWriter(
			fmt.Sprintf("\x1b[32m[o]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name),
			io.MultiWriter(allOutput, ginkgo.GinkgoWriter),
		),
		gexec.NewPrefixedWriter(
			fmt.Sprintf("\x1b[91m[e]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name),
			io.MultiWriter(allOutput, ginkgo.GinkgoWriter),
		),
	)

	Ω(err).ShouldNot(HaveOccurred())

	fmt.Fprintf(debugWriter, "spawned %s (pid: %d)\n", r.Command.Path, r.Command.Process.Pid)

	r.session = session
	if r.sessionReady != nil {
		close(r.sessionReady)
	}

	startCheckDuration := r.StartCheckTimeout
	if startCheckDuration == 0 {
		startCheckDuration = 5 * time.Second
	}

	var startCheckTimeout <-chan time.Time
	if r.StartCheck != "" {
		startCheckTimeout = time.After(startCheckDuration)
	}

	detectStartCheck := allOutput.Detect(r.StartCheck)

	for {
		select {
		case <-detectStartCheck: // works even with empty string
			allOutput.CancelDetects()
			startCheckTimeout = nil
			detectStartCheck = nil
			close(ready)

		case <-startCheckTimeout:
			// clean up hanging process
			session.Kill().Wait()

			// fail to start
			return fmt.Errorf(
				"did not see %s in command's output within %s. full output:\n\n%s",
				r.StartCheck,
				startCheckDuration,
				string(allOutput.Contents()),
			)

		case signal := <-sigChan:
			session.Signal(signal)

		case <-session.Exited:
			if r.Cleanup != nil {
				r.Cleanup()
			}

			if session.ExitCode() == 0 {
				return nil
			}

			return fmt.Errorf("exit status %d", session.ExitCode())
		}
	}
}
예제 #24
0
func SetupTrafficcontroller(etcdClientURL string, dopplerPort, metronPort int) (func(), int) {
	By("making sure trafficcontroller was build")
	tcPath := os.Getenv("TRAFFIC_CONTROLLER_BUILD_PATH")
	Expect(tcPath).ToNot(BeEmpty())

	By("starting trafficcontroller")
	tcPort := getPort(trafficcontrollerPortOffset)
	tcConfig := trafficcontrollerConfig.Config{
		Index:   jobIndex,
		JobName: jobName,

		DopplerPort:           uint32(dopplerPort),
		OutgoingDropsondePort: uint32(tcPort),
		MetronHost:            "localhost",
		MetronPort:            metronPort,

		EtcdUrls:                  []string{etcdClientURL},
		EtcdMaxConcurrentRequests: 5,

		SystemDomain:   "vcap.me",
		SkipCertVerify: true,

		ApiHost:         "http://127.0.0.1:65530",
		UaaHost:         "http://127.0.0.1:65531",
		UaaClient:       "bob",
		UaaClientSecret: "yourUncle",
	}

	tcCfgFile, err := ioutil.TempFile("", "trafficcontroller-config")
	Expect(err).ToNot(HaveOccurred())

	err = json.NewEncoder(tcCfgFile).Encode(tcConfig)
	Expect(err).ToNot(HaveOccurred())
	err = tcCfgFile.Close()
	Expect(err).ToNot(HaveOccurred())

	tcCommand := exec.Command(tcPath, "--debug", "--disableAccessControl", "--config", tcCfgFile.Name())
	tcSession, err := gexec.Start(
		tcCommand,
		gexec.NewPrefixedWriter(color("o", "tc", green, cyan), GinkgoWriter),
		gexec.NewPrefixedWriter(color("e", "tc", red, cyan), GinkgoWriter),
	)
	Expect(err).ToNot(HaveOccurred())

	By("waiting for trafficcontroller to listen")
	ip, err := localip.LocalIP()
	Expect(err).ToNot(HaveOccurred())
	Eventually(func() error {
		url := fmt.Sprintf("http://%s:%d", ip, tcPort)
		resp, err := http.Get(url)
		if err == nil {
			resp.Body.Close()
		}
		return err
	}, 3).Should(Succeed())

	return func() {
		os.Remove(tcCfgFile.Name())
		tcSession.Kill().Wait()
	}, tcPort
}
예제 #25
0
func SetupDoppler(etcdClientURL string, metronPort int) (func(), int) {
	By("making sure doppler was build")
	dopplerPath := os.Getenv("DOPPLER_BUILD_PATH")
	Expect(dopplerPath).ToNot(BeEmpty())

	By("starting doppler")
	dopplerUDPPort := getPort(dopplerUDPPortOffset)
	dopplerTCPPort := getPort(dopplerTCPPortOffset)
	dopplerTLSPort := getPort(dopplerTLSPortOffset)
	dopplerOutgoingPort := getPort(dopplerOutgoingPortOffset)
	dopplerGRPCPort := getPort(dopplerGRPCPortOffset)

	dopplerConf := dopplerConfig.Config{
		Index:        jobIndex,
		JobName:      jobName,
		Zone:         availabilityZone,
		SharedSecret: sharedSecret,

		IncomingUDPPort: uint32(dopplerUDPPort),
		IncomingTCPPort: uint32(dopplerTCPPort),
		OutgoingPort:    uint32(dopplerOutgoingPort),
		GRPCPort:        uint32(dopplerGRPCPort),

		EtcdUrls:                  []string{etcdClientURL},
		EtcdMaxConcurrentRequests: 10,
		MetronAddress:             fmt.Sprintf("127.0.0.1:%d", metronPort),

		EnableTLSTransport: true,
		TLSListenerConfig: dopplerConfig.TLSListenerConfig{
			Port: uint32(dopplerTLSPort),
			// TODO: move these files as source code and write them to tmp files
			CertFile: "../fixtures/server.crt",
			KeyFile:  "../fixtures/server.key",
			CAFile:   "../fixtures/loggregator-ca.crt",
		},

		MetricBatchIntervalMilliseconds: 10,
		ContainerMetricTTLSeconds:       120,
		MaxRetainedLogMessages:          10,
		MessageDrainBufferSize:          100,
		SinkDialTimeoutSeconds:          10,
		SinkIOTimeoutSeconds:            10,
		SinkInactivityTimeoutSeconds:    120,
		SinkSkipCertVerify:              true,
		UnmarshallerCount:               5,
		BlackListIps:                    make([]iprange.IPRange, 0),
		Syslog:                          "",
	}

	dopplerCfgFile, err := ioutil.TempFile("", "doppler-config")
	Expect(err).ToNot(HaveOccurred())

	err = json.NewEncoder(dopplerCfgFile).Encode(dopplerConf)
	Expect(err).ToNot(HaveOccurred())
	err = dopplerCfgFile.Close()
	Expect(err).ToNot(HaveOccurred())

	dopplerCommand := exec.Command(dopplerPath, "--config", dopplerCfgFile.Name())
	dopplerSession, err := gexec.Start(
		dopplerCommand,
		gexec.NewPrefixedWriter(color("o", "doppler", green, blue), GinkgoWriter),
		gexec.NewPrefixedWriter(color("e", "doppler", red, blue), GinkgoWriter),
	)
	Expect(err).ToNot(HaveOccurred())

	// a terrible hack
	Eventually(dopplerSession.Buffer).Should(gbytes.Say("doppler server started"))

	By("waiting for doppler to listen")
	Eventually(func() error {
		c, reqErr := net.Dial("tcp", fmt.Sprintf(":%d", dopplerOutgoingPort))
		if reqErr == nil {
			c.Close()
		}
		return reqErr
	}, 3).Should(Succeed())

	return func() {
		os.Remove(dopplerCfgFile.Name())
		dopplerSession.Kill().Wait()
	}, dopplerOutgoingPort
}
예제 #26
0
파일: postgresrunner.go 프로젝트: ACPK/atc
func (runner Runner) Run(signals <-chan os.Signal, ready chan<- struct{}) error {
	defer ginkgo.GinkgoRecover()

	tmpdir, err := ioutil.TempDir("", "postgres")
	Expect(err).NotTo(HaveOccurred())

	currentUser, err := user.Current()
	Expect(err).NotTo(HaveOccurred())

	var initCmd, startCmd *exec.Cmd

	initdbPath, err := exec.LookPath("initdb")
	Expect(err).NotTo(HaveOccurred())

	postgresPath, err := exec.LookPath("postgres")
	Expect(err).NotTo(HaveOccurred())

	initdb := initdbPath + " -U postgres -D " + tmpdir
	postgres := fmt.Sprintf("%s -D %s -h 127.0.0.1 -p %d", postgresPath, tmpdir, runner.Port)

	if currentUser.Uid == "0" {
		pgUser, err := user.Lookup("postgres")
		Expect(err).NotTo(HaveOccurred())

		uid, err := strconv.Atoi(pgUser.Uid)
		Expect(err).NotTo(HaveOccurred())

		gid, err := strconv.Atoi(pgUser.Gid)
		Expect(err).NotTo(HaveOccurred())

		err = os.Chown(tmpdir, uid, gid)
		Expect(err).NotTo(HaveOccurred())

		initCmd = exec.Command("su", "postgres", "-c", initdb)
		startCmd = exec.Command("su", "postgres", "-c", postgres)
	} else {
		initCmd = exec.Command("bash", "-c", initdb)
		startCmd = exec.Command("bash", "-c", postgres)
	}

	session, err := gexec.Start(
		initCmd,
		gexec.NewPrefixedWriter("[o][initdb] ", ginkgo.GinkgoWriter),
		gexec.NewPrefixedWriter("[e][initdb] ", ginkgo.GinkgoWriter),
	)
	Expect(err).NotTo(HaveOccurred())

	<-session.Exited

	Expect(session).To(gexec.Exit(0))

	ginkgoRunner := &ginkgomon.Runner{
		Name:          "postgres",
		Command:       startCmd,
		AnsiColorCode: "90m",
		StartCheck:    "database system is ready to accept connections",
		Cleanup: func() {
			os.RemoveAll(tmpdir)
		},
	}

	return ginkgoRunner.Run(signals, ready)
}
예제 #27
0
func getStyledWriter(prefix string) io.Writer {
	return gexec.NewPrefixedWriter(fmt.Sprintf("[%s] ", colors.Yellow(prefix)), GinkgoWriter)
}
예제 #28
0
파일: main_test.go 프로젝트: savaki/tsa
					"127.0.0.1",
					"-p", strconv.Itoa(tsaPort),
					"-o", "UserKnownHostsFile=" + userKnownHostsFile,
				}
			})

			JustBeforeEach(func() {
				ssh := exec.Command("ssh", sshArgv...)

				var err error
				sshStdin, err = ssh.StdinPipe()
				Ω(err).ShouldNot(HaveOccurred())

				sshSess, err = gexec.Start(
					ssh,
					gexec.NewPrefixedWriter("\x1b[32m[o]\x1b[0m\x1b[33m[ssh]\x1b[0m ", GinkgoWriter),
					gexec.NewPrefixedWriter("\x1b[91m[e]\x1b[0m\x1b[33m[ssh]\x1b[0m ", GinkgoWriter),
				)
				Ω(err).ShouldNot(HaveOccurred())
			})

			AfterEach(func() {
				sshSess.Interrupt().Wait(10 * time.Second)
			})

			Context("with a valid key", func() {
				BeforeEach(func() {
					sshArgv = append(sshArgv, "-i", userKey)
				})

				Context("when running register-worker", func() {