Merge lp:~axwalk/juju-core/agent-setapihostports into lp:~go-bot/juju-core/trunk

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 2518
Proposed branch: lp:~axwalk/juju-core/agent-setapihostports
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 91 lines (+52/-0)
2 files modified
agent/agent.go (+18/-0)
agent/agent_test.go (+34/-0)
To merge this branch: bzr merge lp:~axwalk/juju-core/agent-setapihostports
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+213409@code.launchpad.net

Commit message

agent: add ConfigSetterOnly.SetAPIHostPorts

We still only store addresses in the config,
so we lose some metadata. We make use of the
scope metadata before storing, though, to
prune the addresses to the internal ones.

https://codereview.appspot.com/82520043/

Description of the change

agent: add ConfigSetterOnly.SetAPIHostPorts

We still only store addresses in the config,
so we lose some metadata. We make use of the
scope metadata before storing, though, to
prune the addresses to the internal ones.

https://codereview.appspot.com/82520043/

To post a comment you must log in.
Revision history for this message
Dave Cheney (dave-cheney) wrote :

+ conf.SetAPIHostPorts([][]instance.HostPort{
+ instance.AddressesWithPort(server1, 123),
+ instance.AddressesWithPort(server2, 124),
+ instance.AddressesWithPort(server3, 125),
+ })
+ addrs, err = conf.APIAddresses()
+ c.Assert(err, gc.IsNil)
+ c.Assert(addrs, gc.DeepEquals, []string{"0.1.2.3:123", "0.1.2.5:125"})

Does conf.APIAddresses return a set or an ordered list ?

Revision history for this message
Andrew Wilkins (axwalk) wrote :
Download full text (3.9 KiB)

Reviewers: mp+213409_code.launchpad.net,

Message:
Please take a look.

Description:
agent: add ConfigSetterOnly.SetAPIHostPorts

We still only store addresses in the config,
so we lose some metadata. We make use of the
scope metadata before storing, though, to
prune the addresses to the internal ones.

https://code.launchpad.net/~axwalk/juju-core/agent-setapihostports/+merge/213409

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/82520043/

Affected files (+54, -0 lines):
   A [revision details]
   M agent/agent.go
   M agent/agent_test.go

Index: [revision details]
=== 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-20140330221944-tt65zj7hl6967aad
+New revision: <email address hidden>

Index: agent/agent.go
=== modified file 'agent/agent.go'
--- agent/agent.go 2014-03-28 08:55:45 +0000
+++ agent/agent.go 2014-03-31 06:30:43 +0000
@@ -16,6 +16,7 @@
   "github.com/errgo/errgo"
   "github.com/juju/loggo"

+ "launchpad.net/juju-core/instance"
   "launchpad.net/juju-core/state"
   "launchpad.net/juju-core/state/api"
   "launchpad.net/juju-core/state/api/params"
@@ -133,6 +134,9 @@
   // the agent has successfully upgraded to.
   SetUpgradedToVersion(newVersion version.Number)

+ // SetAPIHostPorts sets the API host/port addresses to connect to.
+ SetAPIHostPorts(servers [][]instance.HostPort)
+
   // Migrate takes an existing agent config and applies the given
   // parameters to change it.
   //
@@ -423,6 +427,20 @@
   c.upgradedToVersion = newVersion
  }

+func (c *configInternal) SetAPIHostPorts(servers [][]instance.HostPort) {
+ if c.apiDetails == nil {
+ return
+ }
+ var addrs []string
+ for _, serverHostPorts := range servers {
+ addr := instance.SelectInternalHostPort(serverHostPorts, false)
+ if addr != "" {
+ addrs = append(addrs, addr)
+ }
+ }
+ c.apiDetails.addresses = addrs
+}
+
  func (c *configInternal) SetValue(key, value string) {
   if value == "" {
    delete(c.values, key)

Index: agent/agent_test.go
=== modified file 'agent/agent_test.go'
--- agent/agent_test.go 2014-03-28 08:28:04 +0000
+++ agent/agent_test.go 2014-03-31 06:30:43 +0000
@@ -10,6 +10,7 @@
   gc "launchpad.net/gocheck"

   "launchpad.net/juju-core/agent"
+ "launchpad.net/juju-core/instance"
   "launchpad.net/juju-core/state"
   "launchpad.net/juju-core/state/api"
   "launchpad.net/juju-core/state/api/params"
@@ -430,3 +431,36 @@
   conf.SetUpgradedToVersion(expectVers)
   c.Assert(conf.UpgradedToVersion(), gc.Equals, expectVers)
  }
+
+func (*suite) TestSetAPIHostPorts(c *gc.C) {
+ conf, err := agent.NewAgentConfig(attributeParams)
+ c.Assert(err, gc.IsNil)
+
+ addrs, err := conf.APIAddresses()
+ c.Assert(err, gc.IsNil)
+ c.Assert(addrs, gc.DeepEquals, attributeParams.APIAddresses)
+
+ // The first cloud-local address for each server is used,
+ // else if there are none then the first public- or unknown-
+ // scope address.
+ //
+ // If a server has only machine-local addresses, or none
+ // at all, then it will be excluded.
+ server1 := instan...

Read more...

Revision history for this message
Dave Cheney (dave-cheney) wrote :

https://codereview.appspot.com/82520043/diff/1/agent/agent_test.go
File agent/agent_test.go (right):

https://codereview.appspot.com/82520043/diff/1/agent/agent_test.go#newcode465
agent/agent_test.go:465: c.Assert(addrs, gc.DeepEquals,
[]string{"0.1.2.3:123", "0.1.2.5:125"})
Does conf.APIAddresses return a set or an ordered list ?

https://codereview.appspot.com/82520043/

Revision history for this message
Andrew Wilkins (axwalk) wrote :

On 2014/03/31 06:44:02, dfc wrote:
> https://codereview.appspot.com/82520043/diff/1/agent/agent_test.go
> File agent/agent_test.go (right):

https://codereview.appspot.com/82520043/diff/1/agent/agent_test.go#newcode465
> agent/agent_test.go:465: c.Assert(addrs, gc.DeepEquals,
[]string{"0.1.2.3:123",
> "0.1.2.5:125"})
> Does conf.APIAddresses return a set or an ordered list ?

APIAddresses returns the same order as specified in the list in the
config file.
I'm told order is important for addresses, which is why I've done it
with DeepEquals.

https://codereview.appspot.com/82520043/

Revision history for this message
Dave Cheney (dave-cheney) wrote :

Fair enough.

On Mon, Mar 31, 2014 at 6:24 PM, <email address hidden> wrote:
> On 2014/03/31 06:44:02, dfc wrote:
>>
>> https://codereview.appspot.com/82520043/diff/1/agent/agent_test.go
>> File agent/agent_test.go (right):
>
>
>
> https://codereview.appspot.com/82520043/diff/1/agent/agent_test.go#newcode465
>>
>> agent/agent_test.go:465: c.Assert(addrs, gc.DeepEquals,
>
> []string{"0.1.2.3:123",
>>
>> "0.1.2.5:125"})
>> Does conf.APIAddresses return a set or an ordered list ?
>
>
> APIAddresses returns the same order as specified in the list in the
> config file.
> I'm told order is important for addresses, which is why I've done it
> with DeepEquals.
>
> https://codereview.appspot.com/82520043/

Revision history for this message
Dimiter Naydenov (dimitern) wrote :
Revision history for this message
John A Meinel (jameinel) wrote :

This feels like an incorrect layer to be doing the validation of
addresses.

I won't block it, but I'd like you to consider if the config level
should just take a list, write it down, and read it back again, and
instead the callers of this would be the ones doing the filtering.

https://codereview.appspot.com/82520043/diff/1/agent/agent.go
File agent/agent.go (right):

https://codereview.appspot.com/82520043/diff/1/agent/agent.go#newcode435
agent/agent.go:435: for _, serverHostPorts := range servers {
It feels like the wrong layer for *configInternal* to be the thing that
decides that we save CloudLocal only addresses.

Shouldn't this be done in the layer *above* config, and config is just
about "write this stuff to disk and read it back again" ?

https://codereview.appspot.com/82520043/

Revision history for this message
Andrew Wilkins (axwalk) wrote :

https://codereview.appspot.com/82520043/diff/1/agent/agent.go
File agent/agent.go (right):

https://codereview.appspot.com/82520043/diff/1/agent/agent.go#newcode432
agent/agent.go:432: return
On 2014/03/31 11:57:11, dimitern wrote:
> Why return here rather than creating apiDetails?

Because apiDetails should be != nil if we're the API (i.e. always). We
should probably just error out if Addresses is empty in NewAgentConfig.

https://codereview.appspot.com/82520043/diff/1/agent/agent.go#newcode435
agent/agent.go:435: for _, serverHostPorts := range servers {
On 2014/03/31 12:26:15, jameinel wrote:
> It feels like the wrong layer for *configInternal* to be the thing
that decides
> that we save CloudLocal only addresses.

> Shouldn't this be done in the layer *above* config, and config is just
about
> "write this stuff to disk and read it back again" ?

You're right, I think, but I think it'd be unhelpful to change that now.
Eventually we should store [][]instance.HostPort in agent.conf, and then
use that in api.Open.

https://codereview.appspot.com/82520043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'agent/agent.go'
--- agent/agent.go 2014-03-28 08:55:45 +0000
+++ agent/agent.go 2014-03-31 06:35:35 +0000
@@ -16,6 +16,7 @@
16 "github.com/errgo/errgo"16 "github.com/errgo/errgo"
17 "github.com/juju/loggo"17 "github.com/juju/loggo"
1818
19 "launchpad.net/juju-core/instance"
19 "launchpad.net/juju-core/state"20 "launchpad.net/juju-core/state"
20 "launchpad.net/juju-core/state/api"21 "launchpad.net/juju-core/state/api"
21 "launchpad.net/juju-core/state/api/params"22 "launchpad.net/juju-core/state/api/params"
@@ -133,6 +134,9 @@
133 // the agent has successfully upgraded to.134 // the agent has successfully upgraded to.
134 SetUpgradedToVersion(newVersion version.Number)135 SetUpgradedToVersion(newVersion version.Number)
135136
137 // SetAPIHostPorts sets the API host/port addresses to connect to.
138 SetAPIHostPorts(servers [][]instance.HostPort)
139
136 // Migrate takes an existing agent config and applies the given140 // Migrate takes an existing agent config and applies the given
137 // parameters to change it.141 // parameters to change it.
138 //142 //
@@ -423,6 +427,20 @@
423 c.upgradedToVersion = newVersion427 c.upgradedToVersion = newVersion
424}428}
425429
430func (c *configInternal) SetAPIHostPorts(servers [][]instance.HostPort) {
431 if c.apiDetails == nil {
432 return
433 }
434 var addrs []string
435 for _, serverHostPorts := range servers {
436 addr := instance.SelectInternalHostPort(serverHostPorts, false)
437 if addr != "" {
438 addrs = append(addrs, addr)
439 }
440 }
441 c.apiDetails.addresses = addrs
442}
443
426func (c *configInternal) SetValue(key, value string) {444func (c *configInternal) SetValue(key, value string) {
427 if value == "" {445 if value == "" {
428 delete(c.values, key)446 delete(c.values, key)
429447
=== modified file 'agent/agent_test.go'
--- agent/agent_test.go 2014-03-28 08:28:04 +0000
+++ agent/agent_test.go 2014-03-31 06:35:35 +0000
@@ -10,6 +10,7 @@
10 gc "launchpad.net/gocheck"10 gc "launchpad.net/gocheck"
1111
12 "launchpad.net/juju-core/agent"12 "launchpad.net/juju-core/agent"
13 "launchpad.net/juju-core/instance"
13 "launchpad.net/juju-core/state"14 "launchpad.net/juju-core/state"
14 "launchpad.net/juju-core/state/api"15 "launchpad.net/juju-core/state/api"
15 "launchpad.net/juju-core/state/api/params"16 "launchpad.net/juju-core/state/api/params"
@@ -430,3 +431,36 @@
430 conf.SetUpgradedToVersion(expectVers)431 conf.SetUpgradedToVersion(expectVers)
431 c.Assert(conf.UpgradedToVersion(), gc.Equals, expectVers)432 c.Assert(conf.UpgradedToVersion(), gc.Equals, expectVers)
432}433}
434
435func (*suite) TestSetAPIHostPorts(c *gc.C) {
436 conf, err := agent.NewAgentConfig(attributeParams)
437 c.Assert(err, gc.IsNil)
438
439 addrs, err := conf.APIAddresses()
440 c.Assert(err, gc.IsNil)
441 c.Assert(addrs, gc.DeepEquals, attributeParams.APIAddresses)
442
443 // The first cloud-local address for each server is used,
444 // else if there are none then the first public- or unknown-
445 // scope address.
446 //
447 // If a server has only machine-local addresses, or none
448 // at all, then it will be excluded.
449 server1 := instance.NewAddresses("0.1.2.3", "0.1.2.4", "zeroonetwothree")
450 server1[0].NetworkScope = instance.NetworkCloudLocal
451 server1[1].NetworkScope = instance.NetworkCloudLocal
452 server1[2].NetworkScope = instance.NetworkPublic
453 server2 := instance.NewAddresses("127.0.0.1")
454 server2[0].NetworkScope = instance.NetworkMachineLocal
455 server3 := instance.NewAddresses("0.1.2.5", "zeroonetwofive")
456 server3[0].NetworkScope = instance.NetworkUnknown
457 server3[1].NetworkScope = instance.NetworkUnknown
458 conf.SetAPIHostPorts([][]instance.HostPort{
459 instance.AddressesWithPort(server1, 123),
460 instance.AddressesWithPort(server2, 124),
461 instance.AddressesWithPort(server3, 125),
462 })
463 addrs, err = conf.APIAddresses()
464 c.Assert(err, gc.IsNil)
465 c.Assert(addrs, gc.DeepEquals, []string{"0.1.2.3:123", "0.1.2.5:125"})
466}

Subscribers

People subscribed via source and target branches

to status/vote changes: