Merge lp://staging/~hduran-8/juju-core/apiworker_force_local_connection 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: | 2814 |
Proposed branch: | lp://staging/~hduran-8/juju-core/apiworker_force_local_connection |
Merge into: | lp://staging/~go-bot/juju-core/trunk |
Diff against target: |
264 lines (+160/-9) 5 files modified
agent/agent.go (+17/-1) agent/agent_test.go (+34/-2) cmd/jujud/agent_test.go (+11/-5) state/api/apiclient.go (+18/-1) state/api/apiclient_test.go (+80/-0) |
To merge this branch: | bzr merge lp://staging/~hduran-8/juju-core/apiworker_force_local_connection |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+221221@code.staging.launchpad.net |
Commit message
APIWorker should only connect to API on localhost
In some cases, APIWorker might try to connect
to a different address than localhost in State
Servers, to achieve this, APIInfo was modified
to add localhost with the configured StateServerPort
to the Addrs list if not present. To make sure
localhost option will be picked first api.Open now
sorts the Addrs list before trying to connect
to make sure local ones will be tried first.
https:/
R=natefinch
Description of the change
APIWorker should only connect to API on localhost
In some cases, APIWorker might try to connect
to a different address than localhost in State
Servers, for this APIInfo was modified to add
localhost with the configured StateServerPort
to the Addrs list if not present. To make sure
localhost option will be picked first Open now
sorts the Addrs list before trying to connect
to make sure local ones will be tried first.
Reviewers: mp+221221_ code.launchpad. net,
Message:
Please take a look.
Description:
APIWorker should only connect to API on localhost
In some cases, APIWorker might try to connect
to a different address than localhost in machines
with the ManageEnviron job, in those cases we
change the api hostname from whatever is set
to localhost and keep the port.
https:/ /code.launchpad .net/~hduran- 8/juju- core/apiworker_ force_local_ connection/ +merge/ 221221
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/100810045/
Affected files (+83, -5 lines): agent_test. go
A [revision details]
M cmd/jujud/agent.go
M cmd/jujud/
Index: [revision details] 20140519143554- fd3fvpqfvhm5u64 2
=== 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: cmd/jujud/agent.go agent.go'
=== modified file 'cmd/jujud/
--- cmd/jujud/agent.go 2014-05-14 21:13:17 +0000
+++ cmd/jujud/agent.go 2014-05-28 19:00:09 +0000
@@ -6,7 +6,9 @@
import (
"fmt"
"io"
+ "net"
"path/filepath"
+ "strconv"
"sync"
"time"
@@ -191,6 +193,25 @@
type configChanger func(c *agent.Config)
+func pickBestHosts( apiInfo *api.Info, jobs []params. MachineJob) error { JobManageEnviro n { rt(firstAddr) fmt.Sprintf( "localhost: %d", portNum)} APIInfo( ) IsCodeUnauthori zed(err) {
+ for _, job := range jobs {
+ if job == params.
+ firstAddr := apiInfo.Addrs[0]
+ _, port, err := net.SplitHostPo
+ if err != nil {
+ return err
+ }
+ portNum, err := strconv.Atoi(port)
+ if err != nil {
+ return fmt.Errorf("bad port number %q", port)
+ }
+ apiInfo.Addrs = []string{
+ break
+ }
+ }
+ return nil
+}
+
// openAPIState opens the API using the given information, and
// returns the opened state and the api entity with
// the given tag. The given changeConfig function is
@@ -205,6 +226,12 @@
// then the worker that's calling this cannot
// be interrupted.
info := agentConfig.
+ // Ensure that we conect trough localhost
+ agentConfigJobs := agentConfig.Jobs()
+ if err := pickBestHosts(info, agentConfigJobs); err != nil {
+ return nil, nil, err
+ }
+
st, err := apiOpen(info, api.DialOpts{})
usedOldPassword := false
if params.
Index: cmd/jujud/ agent_test. go agent_test. go' agent_test. go 2014-04-30 23:18:40 +0000 agent_test. go 2014-05-28 19:02:43 +0000
=== modified file 'cmd/jujud/
--- cmd/jujud/
+++ cmd/jujud/
@@ -105,17 +105,23 @@
return "old"
}
+func (fakeAPIOpenConfig) Jobs() []params.MachineJob { MachineJob{ } &apiOpenSuite{ })
+ return []params.
+}
+
var _ = gc.Suite(
+type replaceErrors struct { eReplaceErrors( c *gc.C) { (&apiOpen, func(info *api.Info, opts api.DialOpts) Errorf( "blah") , nil,
+ openErr error
+ replaceErr error
+}
+
func (s *apiOpenSuite) TestOpenAPIStat
var apiError error
s.PatchValue
(*api.State, error) {
return nil, apiError
})
- for i, test := range []struct {
- openErr error
- replaceErr error
- }{{
+ errReplacePairs := []replaceErrors{{
fmt.
}, {
openErr: &p...