From 7ca1ae16efd27a57ca94e54bf65dabf971c285b8 Mon Sep 17 00:00:00 2001 From: Ev Kontsevoy Date: Wed, 2 Mar 2016 11:10:07 -0800 Subject: [PATCH] Comments and fixed tests --- lib/auth/srv.go | 4 ++-- lib/auth/srv_test.go | 10 +++++----- lib/srv/srv_test.go | 11 ++++++----- lib/utils/utils.go | 8 ++------ 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/auth/srv.go b/lib/auth/srv.go index d54b0c7d2ae..9fcc75ecd35 100644 --- a/lib/auth/srv.go +++ b/lib/auth/srv.go @@ -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 { diff --git a/lib/auth/srv_test.go b/lib/auth/srv_test.go index bd8fc689b89..97ffdf47ae4 100644 --- a/lib/auth/srv_test.go +++ b/lib/auth/srv_test.go @@ -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"}) } } diff --git a/lib/srv/srv_test.go b/lib/srv/srv_test.go index 778796344cb..90d7a47ff23 100644 --- a/lib/srv/srv_test.go +++ b/lib/srv/srv_test.go @@ -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) { diff --git a/lib/utils/utils.go b/lib/utils/utils.go index 5c4ca1e98c2..4a0c473ab54 100644 --- a/lib/utils/utils.go +++ b/lib/utils/utils.go @@ -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 {