Merge lp:~gz/juju-core/unit_publicaddress_from_machine into lp:~go-bot/juju-core/trunk
Proposed by
Martin Packman
Status: | Merged |
---|---|
Approved by: | Martin Packman |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1623 |
Proposed branch: | lp:~gz/juju-core/unit_publicaddress_from_machine |
Merge into: | lp:~go-bot/juju-core/trunk |
Prerequisite: | lp:~gz/juju-core/machine_doc_addresses |
Diff against target: |
89 lines (+42/-2) 3 files modified
state/machine_test.go (+2/-1) state/unit.go (+18/-1) state/unit_test.go (+22/-0) |
To merge this branch: | bzr merge lp:~gz/juju-core/unit_publicaddress_from_machine |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+177983@code.launchpad.net |
Commit message
state: Use machine addresses from unit
Make Unit.PublicAddress check for addresses an associated machine
by preference and select an appropriate one. This is the first
step towards removing PublicAddress and PrivateAddress from unit.
https:/
R=dimitern, wallyworld
Description of the change
state: Use machine addresses from unit
Make Unit.PublicAddress check for addresses an associated machine
by preference and select an appropriate one. This is the first
step towards removing PublicAddress and PrivateAddress from unit.
To post a comment you must log in.
Reviewers: mp+177983_ code.launchpad. net,
Message:
Please take a look.
Description:
Attempt at using machine addresses from unit
Non-working attempt at getting Unit.PublicAddress to take the
value from the addresses stored on a related Machine where
available.
The test added fails as the machineDoc created from the unit
does not contain the addresses just assigned. Have they ever
reached mongo? Does the machine need constructing differently,
or the test need some added magic?
https:/ /code.launchpad .net/~gz/ juju-core/ unit_publicaddr ess_from_ machine/ +merge/ 177983
Requires: /code.launchpad .net/~gz/ juju-core/ machine_ doc_addresses/ +merge/ 177978
https:/
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/12218043/
Affected files: unit_test. go
[revision details]
state/unit.go
state/
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: <email address hidden>
+New revision: <email address hidden>
Index: state/unit.go
=== modified file 'state/unit.go'
--- state/unit.go 2013-07-31 14:19:29 +0000
+++ state/unit.go 2013-08-01 01:42:09 +0000
@@ -442,7 +442,16 @@
// PublicAddress returns the public address of the unit and whether it is ress, u.doc.PublicAddress != "" u.doc.MachineId ) SelectPublicAdd ress(m. Addresses( ))
valid.
func (u *Unit) PublicAddress() (string, bool) {
- return u.doc.PublicAdd
+ publicaddress := u.doc.PublicAddress
+ if u.doc.MachineId != "" {
+ m, err := u.st.Machine(
+ if err != nil {
+ // XXX(gz) Or treat as not having an address?
+ panic(err)
+ }
+ publicaddress = instance.
+ }
+ return publicaddress, publicaddress != ""
}
// PrivateAddress returns the private address of the unit and whether it
is valid.
Index: state/unit_test.go unit_test. go'
=== modified file 'state/
--- state/unit_test.go 2013-07-31 14:19:29 +0000
+++ state/unit_test.go 2013-08-01 01:42:09 +0000
@@ -169,6 +169,29 @@
c.Assert(err, ErrorMatches, `cannot set public address of
unit "wordpress/0": unit not found`)
}
+func (s *UnitSuite) TestGetPublicAd dressFromMachin e(c *C) { AddMachine( "series" , state.JobHostUnits) AssignToMachine (machine) PublicAddress( ) NewAddress( "127.0. 0.1"), NewAddress( "8.8.8. 8"), SetAddresses( addresses) PublicAddress( ) teAddress( c *C) { PrivateAddress( )
+ machine, err := s.State.
+ c.Assert(err, IsNil)
+ err = s.unit.
+ c.Assert(err, IsNil)
+
+ address, ok := s.unit.
+ c.Check(address, Equals, "")
+ c.Assert(ok, Equals, false)
+
+ addresses := []instance.Address{
+ instance.
+ instance.
+ }
+ err = machine.
+ c.Assert(err, IsNil)
+
+ // XXX(gz) Following fails, machine doc lacks addresses when read, why?
+ address, ok = s.unit.
+ c.Check(address, Equals, "8.8.8.8")
+ c.Assert(ok, Equals, true)
+}
+
func (s *UnitSuite) TestGetSetPriva
_, ok := s.unit.
c.Assert(ok, Equals, false)