Comments and fixed tests

This commit is contained in:
Ev Kontsevoy
2016-03-02 11:10:07 -08:00
parent 7dd10c65ab
commit 7ca1ae16ef
4 changed files with 15 additions and 18 deletions
+2 -2
View File
@@ -197,8 +197,8 @@ func (s *APIServer) upsertServer(w http.ResponseWriter, r *http.Request, p httpr
}
log.Debugf("[AUTH API] upsertServer. RemoteAddr=%v", r.RemoteAddr)
// if server sent "local" IP address to us, replace it with the address taken from
// the connection
// if server sent "local" IP address to us, replace the ip/host part with the remote address we see
// on the socket, but keep the original port:
req.Server.Addr = utils.ReplaceLocalhost(req.Server.Addr, r.RemoteAddr)
if err := s.a.UpsertServer(req.Server, req.TTL); err != nil {
+5 -5
View File
@@ -278,12 +278,12 @@ func (s *APISuite) TestServers(c *C) {
c.Assert(err, IsNil)
// note: ID is getting overwritten by addr:
if out[0].ID == "host:1233" {
c.Assert(out[0], DeepEquals, services.Server{ID: "host:1233", Addr: "host:1233", Hostname: "host1"})
c.Assert(out[1], DeepEquals, services.Server{ID: "host:1234", Addr: "host:1234", Hostname: "host2"})
if out[0].ID == "id1" {
c.Assert(out[0], DeepEquals, services.Server{ID: "id1", Addr: "host:1233", Hostname: "host1"})
c.Assert(out[1], DeepEquals, services.Server{ID: "id2", Addr: "host:1234", Hostname: "host2"})
} else {
c.Assert(out[1], DeepEquals, services.Server{ID: "host:1233", Addr: "host:1233", Hostname: "host1"})
c.Assert(out[0], DeepEquals, services.Server{ID: "host:1234", Addr: "host:1234", Hostname: "host2"})
c.Assert(out[1], DeepEquals, services.Server{ID: "id1", Addr: "host:1233", Hostname: "host1"})
c.Assert(out[0], DeepEquals, services.Server{ID: "id2", Addr: "host:1234", Hostname: "host2"})
}
}
+6 -5
View File
@@ -495,6 +495,7 @@ func (s *SrvSuite) TestProxy(c *C) {
),
SetSessionServer(s.sessionServer),
)
srv2.uuid = bobAddr
c.Assert(err, IsNil)
c.Assert(srv2.Start(), IsNil)
defer srv2.Close()
@@ -526,7 +527,7 @@ func (s *SrvSuite) TestProxy(c *C) {
c.Assert(len(nodes), Equals, 2)
nmap := map[string]services.Server{}
for _, node := range nodes {
nmap[node.ID] = node
nmap[node.Addr] = node
}
c.Assert(nmap[bobAddr], DeepEquals, services.Server{
ID: bobAddr,
@@ -545,10 +546,10 @@ func (s *SrvSuite) TestProxy(c *C) {
Result: "5",
}}})
c.Assert(nmap[s.srvAddress], DeepEquals, services.Server{
ID: s.srvAddress,
Addr: s.srvAddress,
Hostname: "localhost"})
s2, ok := nmap[s.srvAddress]
c.Assert(ok, Equals, true)
c.Assert(s2.Addr, Equals, s.srvAddress)
c.Assert(s2.Hostname, Equals, "localhost")
}
func (s *SrvSuite) TestProxyRoundRobin(c *C) {
+2 -6
View File
@@ -26,7 +26,6 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
"github.com/gravitational/trace"
"github.com/pborman/uuid"
@@ -144,14 +143,11 @@ func ReadOrMakeHostUUID(dataDir string) (string, error) {
fp := filepath.Join(dataDir, HostUUIDFile)
bytes, err := ioutil.ReadFile(fp)
for try := 0; try < 5 && err != nil; try++ {
log.Debugf("Trying to read uuid file %s", fp)
if err != nil {
// uuid file not found? re-create it
if os.IsNotExist(err) {
bytes = []byte(uuid.New())
err = ioutil.WriteFile(fp, bytes, os.ModeExclusive|ModeReadonly)
} else {
time.Sleep(time.Millisecond * 10)
}
}
if err != nil {