/
traffic_controller.go
77 lines (67 loc) · 2.28 KB
/
traffic_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package testservers
import (
"fmt"
"os"
"os/exec"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
envstruct "code.cloudfoundry.org/go-envstruct"
tcConf "code.cloudfoundry.org/loggregator-release/src/trafficcontroller/app"
)
func BuildTrafficControllerConf(routerAddr string, agentPort int) tcConf.Config {
return tcConf.Config{
IP: "127.0.0.1",
RouterAddrs: []string{routerAddr},
SystemDomain: "vcap.me",
SkipCertVerify: true,
ApiHost: "http://127.0.0.1:65530",
UaaHost: "http://127.0.0.1:65531",
UaaCACert: LoggregatorTestCerts.CA(),
UaaClient: "bob",
UaaClientSecret: "yourUncle",
DisableAccessControl: true,
OutgoingDropsondePort: 0,
OutgoingCertFile: LoggregatorTestCerts.Cert("trafficcontroller"),
OutgoingKeyFile: LoggregatorTestCerts.Key("trafficcontroller"),
CCTLSClientConfig: tcConf.CCTLSClientConfig{
CertFile: LoggregatorTestCerts.Cert("trafficcontroller"),
KeyFile: LoggregatorTestCerts.Key("trafficcontroller"),
CAFile: LoggregatorTestCerts.CA(),
ServerName: "cloud-controller",
},
Agent: tcConf.Agent{
GRPCAddress: fmt.Sprintf("localhost:%d", agentPort),
},
GRPC: tcConf.GRPC{
CertFile: LoggregatorTestCerts.Cert("trafficcontroller"),
KeyFile: LoggregatorTestCerts.Key("trafficcontroller"),
CAFile: LoggregatorTestCerts.CA(),
},
}
}
type TrafficControllerPorts struct {
WS int
PProf int
}
func StartTrafficController(conf tcConf.Config) (cleanup func(), tp TrafficControllerPorts) {
By("making sure trafficcontroller was built")
tcPath := os.Getenv("TRAFFIC_CONTROLLER_BUILD_PATH")
Expect(tcPath).ToNot(BeEmpty())
By("starting trafficcontroller")
tcCommand := exec.Command(tcPath)
tcCommand.Env = envstruct.ToEnv(&conf)
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")
tp.WS = waitForPortBinding("ws", tcSession.Err)
tp.PProf = waitForPortBinding("pprof", tcSession.Err)
cleanup = func() {
tcSession.Kill().Wait()
}
return cleanup, tp
}