Merge lp://staging/~hduran-8/juju-core/apiworker_force_local_only into lp://staging/~go-bot/juju-core/trunk
Status: | Merged |
---|---|
Approved by: | Horacio Durán |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2823 |
Proposed branch: | lp://staging/~hduran-8/juju-core/apiworker_force_local_only |
Merge into: | lp://staging/~go-bot/juju-core/trunk |
Diff against target: |
152 lines (+22/-69) 2 files modified
state/api/apiclient.go (+9/-15) state/api/apiclient_test.go (+13/-54) |
To merge this branch: | bzr merge lp://staging/~hduran-8/juju-core/apiworker_force_local_only |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+221788@code.staging.launchpad.net |
Commit message
Use localhost only if pressent for opening state
Recently a change was made so localhost is added in the list
of addresses to open state if we are servingstatus.
In that change the addresses where sorted to favor localhost
ones, with this new change, if localhost is present, its the
only one used and the other ones are discarded.
https:/
R=jameinel, thumper
Description of the change
Use localhost only if pressent for opening state
Recently a change was made so localhost is added in the list
of addresses to open state if we are servingstatus.
In that change the addresses where sorted to favor localhost
ones, with this new change, if localhost is present, its the
only one used and the other ones are discarded.
Reviewers: mp+221788_ code.launchpad. net,
Message:
Please take a look.
Description:
Use localhost only if pressent for opening state
Recently a change was made so localhost is added in the list
of addresses to open state if we are servingstatus.
In that change the addresses where sorted to favor localhost
ones, with this new change, if localhost is present, its the
only one used and the other ones are discarded.
https:/ /code.launchpad .net/~hduran- 8/juju- core/apiworker_ force_local_ only/+merge/ 221788
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/103820044/
Affected files (+11, -66 lines): apiclient. go apiclient_ test.go
A [revision details]
M state/api/
M state/api/
Index: [revision details] 20140602172913- xpffu1jxxw059h3 p
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: state/api/ apiclient. go api/apiclient. go' apiclient. go 2014-05-30 16:12:13 +0000 apiclient. go 2014-06-02 20:54:43 +0000
=== modified file 'state/
--- state/api/
+++ state/api/
@@ -8,7 +8,6 @@
"crypto/x509"
"fmt"
"io"
- "sort"
"strings"
"time"
@@ -110,18 +109,6 @@
}
}
-type LocalFirst []string HasPrefix( l[i], "localhost") HasPrefix( l[j], "localhost") LocalFirst( addrs)) HasPrefix( addr, "localhost:") {
-
-func (l LocalFirst) Len() int {
- return len(l)
-}
-func (l LocalFirst) Swap(i, j int) {
- l[i], l[j] = l[j], l[i]
-}
-func (l LocalFirst) Less(i, j int) bool {
- return strings.
&& !strings.
-}
-
func Open(info *Info, opts DialOpts) (*State, error) {
if len(info.Addrs) == 0 {
return nil, fmt.Errorf("no API addresses to connect to")
@@ -137,8 +124,15 @@
try := parallel.NewTry(0, nil)
defer try.Kill()
var addrs []string
- addrs = append(addrs, info.Addrs...)
- sort.Sort(
+ for _, addr := range info.Addrs {
+ if strings.
+ addrs = append(addrs, addr)
+ break
+ }
+ }
+ if len(addrs) == 0 {
+ addrs = info.Addrs
+ }
for _, addr := range addrs {
err := dialWebsocket(addr, opts, pool, try)
if err == parallel.ErrStopped {
Index: state/api/ apiclient_ test.go api/apiclient_ test.go' apiclient_ test.go 2014-05-30 16:12:13 +0000 apiclient_ test.go 2014-06-02 20:39:13 +0000
=== modified file 'state/
--- state/api/
+++ state/api/
@@ -6,7 +6,6 @@
import (
"io"
"net"
- "sort"
gc "launchpad. net/gocheck"
@@ -21,56 +20,6 @@
var _ = gc.Suite( &apiclientSuite {})
-func (s *apiclientSuite) TestSortLocalhost(c *gc.C) { api.LocalFirst( sortedAddrs) ) gc.DeepEquals) , sortedAddrs) sortedAddrs, gc.HasLen, 6) sortedAddrs, gc.DeepEquals, expectedAddrs)
- addrs := []string{
- "notlocalhost1",
- "notlocalhost2",
- "notlocalhost3",
- "localhost1",
- "localhost2",
- "localhost3",
- }
- expectedAddrs := []string{
- "localhost1",
- "localhost2",
- "localhost3",
- "notlocalhost1",
- "notlocalhost2",
- "notlocalhost3",
- }
- var sortedAddrs []string
- sortedAddrs = append(sortedAddrs, addrs...)
- sort.Sort(
- c.Assert(addrs, gc.Not(
- c.Assert(
- c.Assert(
-
-}
-
-func (s *apicl...