mirror of
https://github.com/gravitational/teleport
synced 2024-10-20 09:13:39 +00:00
Fixes for integration tests and discovery protocol.
This commit is contained in:
parent
f415aabeb6
commit
a446f97a37
|
@ -103,7 +103,7 @@ func (s *IntSuite) SetUpSuite(c *check.C) {
|
|||
s.priv, s.pub, err = testauthority.New().GenerateKeyPair("")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
// find 10 free litening ports to use
|
||||
// Find AllocatePortsNum free listening ports to use.
|
||||
s.ports, err = utils.GetFreeTCPPorts(AllocatePortsNum)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
|
@ -2044,6 +2044,7 @@ func (s *IntSuite) TestDiscoveryNode(c *check.C) {
|
|||
Host: "cluster-main-node",
|
||||
Proxy: &proxyConfig,
|
||||
}
|
||||
|
||||
output, err = runCommand(main, []string{"echo", "hello world"}, cfgProxy, 10)
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(output, check.Equals, "hello world\n")
|
||||
|
@ -2060,7 +2061,7 @@ func (s *IntSuite) TestDiscoveryNode(c *check.C) {
|
|||
output, err = runCommand(main, []string{"echo", "hello world"}, cfgProxy, 1)
|
||||
c.Assert(err, check.NotNil)
|
||||
|
||||
// Add second proxy back to LB, both should have a connection.
|
||||
// Add second proxy to LB, both should have a connection.
|
||||
lb.AddBackend(*proxyTwoBackend)
|
||||
waitForActiveTunnelConnections(c, main.Tunnel, Site, 1)
|
||||
waitForActiveTunnelConnections(c, proxyTunnel, Site, 1)
|
||||
|
@ -3674,7 +3675,7 @@ func runCommand(instance *TeleInstance, cmd []string, cfg ClientConfig, attempts
|
|||
if err == nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
return output.String(), trace.Wrap(err)
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ func (s *KubeSuite) SetUpSuite(c *check.C) {
|
|||
s.priv, s.pub, err = testauthority.New().GenerateKeyPair("")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
s.ports, err = utils.GetFreeTCPPorts(AllocatePortsNum, utils.PortStartingNumber+AllocatePortsNum+1)
|
||||
s.ports, err = utils.GetFreeTCPPorts(AllocatePortsNum)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -230,6 +230,21 @@ func (a *Agent) Wait() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *Agent) isDiscovering(proxy services.Server) bool {
|
||||
for _, discoverProxy := range a.DiscoverProxies {
|
||||
if a.getState() != agentStateDiscovering && a.getState() != agentStateConnecting {
|
||||
continue
|
||||
}
|
||||
|
||||
proxyID := fmt.Sprintf("%v.%v", proxy.GetName(), a.ClusterName)
|
||||
discoverID := fmt.Sprintf("%v.%v", discoverProxy.GetName(), a.ClusterName)
|
||||
if proxyID == discoverID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// connectedTo returns true if connected services.Server passed in.
|
||||
func (a *Agent) connectedTo(proxy services.Server) bool {
|
||||
principals := a.getPrincipals()
|
||||
|
@ -352,8 +367,10 @@ func (a *Agent) run() {
|
|||
conn.Close()
|
||||
return
|
||||
}
|
||||
a.Debugf("Agent discovered proxy: %v.", a.getPrincipalsList())
|
||||
a.setState(agentStateDiscovered)
|
||||
} else {
|
||||
a.Debugf("Agent connected to proxy: %v.", a.getPrincipalsList())
|
||||
a.setState(agentStateConnected)
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ func (m *AgentPool) processDiscoveryRequests() {
|
|||
|
||||
func foundInOneOf(proxy services.Server, agents []*Agent) bool {
|
||||
for _, agent := range agents {
|
||||
if agent.connectedTo(proxy) {
|
||||
if agent.isDiscovering(proxy) || agent.connectedTo(proxy) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -203,8 +203,8 @@ func (m *AgentPool) tryDiscover(req discoveryRequest) {
|
|||
|
||||
matchKey := req.key()
|
||||
|
||||
// if one of the proxies have been discovered or connected to
|
||||
// remove proxy from discovery request
|
||||
// If one of the proxies have been discovered or connected to
|
||||
// remove proxy from discovery request.
|
||||
var filtered Proxies
|
||||
agents := m.agents[matchKey]
|
||||
for i := range proxies {
|
||||
|
@ -234,9 +234,9 @@ func (m *AgentPool) tryDiscover(req discoveryRequest) {
|
|||
return true
|
||||
})
|
||||
|
||||
// if we haven't found any discovery agent
|
||||
// If not agent is running, add one.
|
||||
if !foundAgent {
|
||||
m.addAgent(req.key(), req.Proxies)
|
||||
m.addAgent(req.key(), filtered)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,11 @@ func (m *AgentPool) reportStats() {
|
|||
}
|
||||
|
||||
for key, agents := range m.agents {
|
||||
m.Debugf("Outbound tunnel for %v connected to %v proxies.", key.clusterName, len(agents))
|
||||
tunnelID := key.clusterName
|
||||
if m.cfg.Component == teleport.ComponentNode {
|
||||
tunnelID = m.cfg.HostUUID
|
||||
}
|
||||
m.Debugf("Outbound tunnel for %v connected to %v proxies.", tunnelID, len(agents))
|
||||
|
||||
countPerState := map[string]int{
|
||||
agentStateConnecting: 0,
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -329,19 +330,27 @@ func (p *PortList) PopIntSlice(num int) []int {
|
|||
return ports
|
||||
}
|
||||
|
||||
// PortStartingNumber is a starting port number for tests
|
||||
// PortStartingNumber is a smallest port number in tests.
|
||||
const PortStartingNumber = 20000
|
||||
|
||||
// PortEndingNumber is the largest port to use in tests.
|
||||
const PortEndingNumber = 50000
|
||||
|
||||
// GetFreeTCPPorts returns n ports starting from port 20000.
|
||||
func GetFreeTCPPorts(n int, offset ...int) (PortList, error) {
|
||||
func GetFreeTCPPorts(n int) (PortList, error) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
result := map[string]bool{}
|
||||
for i := 0; i < n; i++ {
|
||||
portNum := PortStartingNumber + rand.Intn(PortEndingNumber-PortStartingNumber)
|
||||
result[strconv.Itoa(portNum)] = true
|
||||
}
|
||||
|
||||
list := make(PortList, 0, n)
|
||||
start := PortStartingNumber
|
||||
if len(offset) != 0 {
|
||||
start = offset[0]
|
||||
}
|
||||
for i := start; i < start+n; i++ {
|
||||
list = append(list, strconv.Itoa(i))
|
||||
for k, _ := range result {
|
||||
list = append(list, k)
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue