Merge lp:~gz/juju-core/maas_missing_ip_addresses_1236734 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: 1959
Proposed branch: lp:~gz/juju-core/maas_missing_ip_addresses_1236734
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 116 lines (+56/-24)
2 files modified
provider/maas/instance.go (+6/-1)
provider/maas/instance_test.go (+50/-23)
To merge this branch: bzr merge lp:~gz/juju-core/maas_missing_ip_addresses_1236734
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+189847@code.launchpad.net

Commit message

provider/maas: Handle ip_addresses not existing

Older MAAS versions do not return the ip_addresses field in
their instance json. Update the provider to not treat this
as an error, but instead equivalent to having no further
addresses beyond the seperately exposed DNS name.

https://codereview.appspot.com/14543043/

R=fwereade, rogpeppe

Description of the change

provider/maas: Handle ip_addresses not existing

Older MAAS versions do not return the ip_addresses field in
their instance json. Update the provider to not treat this
as an error, but instead equivalent to having no further
addresses beyond the seperately exposed DNS name.

https://codereview.appspot.com/14543043/

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :
Download full text (3.7 KiB)

Reviewers: mp+189847_code.launchpad.net,

Message:
Please take a look.

Description:
provider/maas: Handle ip_addresses not existing

Older MAAS versions do not return the ip_addresses field in
their instance json. Update the provider to not treat this
as an error, but instead equivalent to having no further
addresses beyond the seperately exposed DNS name.

https://code.launchpad.net/~gz/juju-core/maas_missing_ip_addresses_1236734/+merge/189847

(do not edit description out of merge proposal)

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

Affected files (+59, -10 lines):
   A [revision details]
   M provider/maas/instance.go
   M provider/maas/instance_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-20131008120312-vr5sryx6voukx4o8
+New revision: <email address hidden>

Index: provider/maas/instance.go
=== modified file 'provider/maas/instance.go'
--- provider/maas/instance.go 2013-09-30 19:40:06 +0000
+++ provider/maas/instance.go 2013-10-08 13:29:41 +0000
@@ -76,7 +76,12 @@

  func (mi *maasInstance) ipAddresses() ([]string, error) {
   // we have to do this the hard way, since maasObject doesn't have this
built-in yet
- objs, err := mi.maasObject.GetMap()["ip_addresses"].GetArray()
+ addressArray := mi.maasObject.GetMap()["ip_addresses"]
+ if addressArray.IsNil() {
+ // Older MAAS versions do not return ip_addresses.
+ return nil, nil
+ }
+ objs, err := addressArray.GetArray()
   if err != nil {
    return nil, err
   }

Index: provider/maas/instance_test.go
=== modified file 'provider/maas/instance_test.go'
--- provider/maas/instance_test.go 2013-09-09 07:02:57 +0000
+++ provider/maas/instance_test.go 2013-10-08 13:29:41 +0000
@@ -9,7 +9,6 @@
   gc "launchpad.net/gocheck"

   "launchpad.net/juju-core/instance"
- jc "launchpad.net/juju-core/testing/checkers"
  )

  type instanceTest struct {
@@ -88,6 +87,12 @@

   expected := []instance.Address{
    {
+ "DNS name",
+ instance.HostName,
+ "",
+ instance.NetworkPublic,
+ },
+ {
     "1.2.3.4",
     instance.Ipv4Address,
     "",
@@ -99,16 +104,53 @@
     "",
     instance.NetworkUnknown,
    },
- {
- "DNS name",
- instance.HostName,
- "",
- instance.NetworkPublic,
- },
   }

   addr, err := inst.Addresses()

- c.Check(err, gc.IsNil)
- c.Check(addr, jc.SameContents, expected)
+ c.Assert(err, gc.IsNil)
+ c.Check(addr, gc.DeepEquals, expected)
+}
+
+func (s *instanceTest) TestAddressesMissing(c *gc.C) {
+ // Older MAAS versions do not have ip_addresses returned, for these
+ // just the DNS name should be returned without error.
+ jsonValue := `{
+ "hostname": "testing.invalid",
+ "system_id": "system_id"
+ }`
+ obj := s.testMAASObject.TestServer.NewNode(jsonValue)
+ inst := maasInstance{&obj, s.environ}
+
+ addr, err := inst.Addresses()
+ c.Assert(err, gc.IsNil)
+ c.Check(addr, gc.DeepEquals, []instance.Address{
+ {"testing.invalid", instance.HostName, "", instance.NetworkPublic},
+ })
+}
+
+func (s *instanceTest) TestAddressesInvalid(c *gc.C) {
+ jsonV...

Read more...

Revision history for this message
Roger Peppe (rogpeppe) wrote :

LGTM with one minor suggestion.

https://codereview.appspot.com/14543043/diff/1/provider/maas/instance_test.go
File provider/maas/instance_test.go (right):

https://codereview.appspot.com/14543043/diff/1/provider/maas/instance_test.go#newcode90
provider/maas/instance_test.go:90: "DNS name",
I'd prefer tagged initialisers for Address here and below.

https://codereview.appspot.com/14543043/

Revision history for this message
William Reade (fwereade) wrote :

LGTM, thanks. Can you test this live?

https://codereview.appspot.com/14543043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'provider/maas/instance.go'
2--- provider/maas/instance.go 2013-09-30 19:40:06 +0000
3+++ provider/maas/instance.go 2013-10-08 13:58:51 +0000
4@@ -76,7 +76,12 @@
5
6 func (mi *maasInstance) ipAddresses() ([]string, error) {
7 // we have to do this the hard way, since maasObject doesn't have this built-in yet
8- objs, err := mi.maasObject.GetMap()["ip_addresses"].GetArray()
9+ addressArray := mi.maasObject.GetMap()["ip_addresses"]
10+ if addressArray.IsNil() {
11+ // Older MAAS versions do not return ip_addresses.
12+ return nil, nil
13+ }
14+ objs, err := addressArray.GetArray()
15 if err != nil {
16 return nil, err
17 }
18
19=== modified file 'provider/maas/instance_test.go'
20--- provider/maas/instance_test.go 2013-09-09 07:02:57 +0000
21+++ provider/maas/instance_test.go 2013-10-08 13:58:51 +0000
22@@ -9,7 +9,6 @@
23 gc "launchpad.net/gocheck"
24
25 "launchpad.net/juju-core/instance"
26- jc "launchpad.net/juju-core/testing/checkers"
27 )
28
29 type instanceTest struct {
30@@ -79,36 +78,64 @@
31
32 func (s *instanceTest) TestAddresses(c *gc.C) {
33 jsonValue := `{
34- "hostname": "DNS name",
35- "system_id": "system_id",
36+ "hostname": "testing.invalid",
37+ "system_id": "system_id",
38 "ip_addresses": [ "1.2.3.4", "fe80::d806:dbff:fe23:1199" ]
39 }`
40 obj := s.testMAASObject.TestServer.NewNode(jsonValue)
41 inst := maasInstance{&obj, s.environ}
42
43 expected := []instance.Address{
44- {
45- "1.2.3.4",
46- instance.Ipv4Address,
47- "",
48- instance.NetworkUnknown,
49- },
50- {
51- "fe80::d806:dbff:fe23:1199",
52- instance.Ipv6Address,
53- "",
54- instance.NetworkUnknown,
55- },
56- {
57- "DNS name",
58- instance.HostName,
59- "",
60- instance.NetworkPublic,
61- },
62+ {Value: "testing.invalid", Type: instance.HostName, NetworkScope: instance.NetworkPublic},
63+ instance.NewAddress("1.2.3.4"),
64+ instance.NewAddress("fe80::d806:dbff:fe23:1199"),
65 }
66
67 addr, err := inst.Addresses()
68
69- c.Check(err, gc.IsNil)
70- c.Check(addr, jc.SameContents, expected)
71+ c.Assert(err, gc.IsNil)
72+ c.Check(addr, gc.DeepEquals, expected)
73+}
74+
75+func (s *instanceTest) TestAddressesMissing(c *gc.C) {
76+ // Older MAAS versions do not have ip_addresses returned, for these
77+ // just the DNS name should be returned without error.
78+ jsonValue := `{
79+ "hostname": "testing.invalid",
80+ "system_id": "system_id"
81+ }`
82+ obj := s.testMAASObject.TestServer.NewNode(jsonValue)
83+ inst := maasInstance{&obj, s.environ}
84+
85+ addr, err := inst.Addresses()
86+ c.Assert(err, gc.IsNil)
87+ c.Check(addr, gc.DeepEquals, []instance.Address{
88+ {Value: "testing.invalid", Type: instance.HostName, NetworkScope: instance.NetworkPublic},
89+ })
90+}
91+
92+func (s *instanceTest) TestAddressesInvalid(c *gc.C) {
93+ jsonValue := `{
94+ "hostname": "testing.invalid",
95+ "system_id": "system_id",
96+ "ip_addresses": "incompatible"
97+ }`
98+ obj := s.testMAASObject.TestServer.NewNode(jsonValue)
99+ inst := maasInstance{&obj, s.environ}
100+
101+ _, err := inst.Addresses()
102+ c.Assert(err, gc.NotNil)
103+}
104+
105+func (s *instanceTest) TestAddressesInvalidContents(c *gc.C) {
106+ jsonValue := `{
107+ "hostname": "testing.invalid",
108+ "system_id": "system_id",
109+ "ip_addresses": [42]
110+ }`
111+ obj := s.testMAASObject.TestServer.NewNode(jsonValue)
112+ inst := maasInstance{&obj, s.environ}
113+
114+ _, err := inst.Addresses()
115+ c.Assert(err, gc.NotNil)
116 }

Subscribers

People subscribed via source and target branches

to status/vote changes: