1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 | From 050e6559aa9c49e3341ed8f795a9d43187386e50 Mon Sep 17 00:00:00 2001
From: Andrew McDermott <andrew.mcdermott@canonical.com>
Date: Thu, 4 Feb 2016 16:40:47 +0000
Subject: [PATCH] Handle bonded interfaces when getting default space
---
provider/maas/interfaces.go | 12 +--
provider/maas/interfaces_test.go | 155 +++++++++++++++++++++++++++++++++++++++
2 files changed, 161 insertions(+), 6 deletions(-)
diff --git a/provider/maas/interfaces.go b/provider/maas/interfaces.go
index 21b30d6..9a348fb 100644
--- a/provider/maas/interfaces.go
+++ b/provider/maas/interfaces.go
@@ -205,15 +205,15 @@ func parseInterfacesForMAASObject(maasObject *gomaasapi.MAASObject) ([]maasInter
// otherwise.
func findPXEInterfaceSpace(interfaces []maasInterface, pxeMACAddress string) (string, error) {
for _, nic := range interfaces {
- isPhysical := nic.Type == "physical"
- sameMAC := nic.MACAddress == pxeMACAddress
-
- if !isPhysical || !sameMAC {
+ if nic.MACAddress != pxeMACAddress || len(nic.Links) < 1 {
continue
}
-
+ isBond := nic.Type == "bond"
+ isPhysical := nic.Type == "physical"
logger.Debugf("PXE interface found as %q (%s)", nic.Name, nic.MACAddress)
- return getPXEInterfaceSpace(&nic)
+ if isPhysical || (isBond && len(nic.Parents) > 0) {
+ return getPXEInterfaceSpace(&nic)
+ }
}
return "", errors.NotFoundf("PXE interface with MAC address %q", pxeMACAddress)
diff --git a/provider/maas/interfaces_test.go b/provider/maas/interfaces_test.go
index 8d32164..2b2c8ea 100644
--- a/provider/maas/interfaces_test.go
+++ b/provider/maas/interfaces_test.go
@@ -264,10 +264,102 @@ const exampleInterfaceSetJSON = `
"type": "vlan",
"children": [],
"resource_uri": "/MAAS/api/1.0/nodes/node-18489434-9eb0-11e5-bdef-00163e40c3b6/interfaces/152/"
+ },
+ {
+ "name": "eth1",
+ "links": [],
+ "tags": [],
+ "vlan": {
+ "name": "untagged",
+ "vid": 0,
+ "mtu": 1500,
+ "fabric": "fabric-0",
+ "id": 0,
+ "resource_uri": "/MAAS/api/1.0/vlans/0/"
+ },
+ "enabled": true,
+ "id": 38,
+ "discovered": [],
+ "mac_address": "52:54:00:c6:17:82",
+ "parents": [],
+ "effective_mtu": 1500,
+ "params": "",
+ "type": "physical",
+ "children": [
+ "bond1"
+ ],
+ "resource_uri": "/MAAS/api/1.0/nodes/node-770e97d0-9e69-11e5-9749-52540061e12f/interfaces/38/"
+ },
+ {
+ "name": "bond1",
+ "links": [
+ {
+ "subnet": {
+ "dns_servers": [
+ "10.17.20.200"
+ ],
+ "name": "10.17.20.0/24",
+ "space": "default",
+ "vlan": {
+ "name": "untagged",
+ "vid": 0,
+ "mtu": 1500,
+ "fabric": "fabric-0",
+ "id": 0,
+ "resource_uri": "/MAAS/api/1.0/vlans/0/"
+ },
+ "gateway_ip": "10.17.20.1",
+ "cidr": "10.17.20.0/24",
+ "id": 1,
+ "resource_uri": "/MAAS/api/1.0/subnets/1/"
+ },
+ "ip_address": "10.17.20.210",
+ "id": 525,
+ "mode": "static"
+ }
+ ],
+ "tags": [],
+ "vlan": {
+ "name": "untagged",
+ "vid": 0,
+ "mtu": 1500,
+ "fabric": "fabric-0",
+ "id": 0,
+ "resource_uri": "/MAAS/api/1.0/vlans/0/"
+ },
+ "enabled": true,
+ "id": 186,
+ "discovered": [],
+ "mac_address": "52:54:00:c6:17:82",
+ "parents": [
+ "eth1",
+ "eth2"
+ ],
+ "effective_mtu": 1500,
+ "params": {
+ "bond_miimon": 100,
+ "bond_downdelay": 0,
+ "bond_mode": "active-backup",
+ "bond_lacp_rate": "slow",
+ "bond_xmit_hash_policy": "layer2",
+ "bond_updelay": 0
+ },
+ "type": "bond",
+ "children": [],
+ "resource_uri": "/MAAS/api/1.0/nodes/node-770e97d0-9e69-11e5-9749-52540061e12f/interfaces/186/"
}
]`
var (
+ exampleBondVLAN = maasVLAN{
+ ID: 0,
+ Name: "untagged",
+ VID: 0,
+ MTU: 1500,
+ Fabric: "fabric-0",
+ ResourceURI: "/MAAS/api/1.0/vlans/0/",
+ }
+
exampleVLAN0 = maasVLAN{
ID: 5001,
Name: "untagged",
@@ -415,6 +507,44 @@ var (
Parents: []string{"eth0"},
Children: []string{},
ResourceURI: "/MAAS/api/1.0/nodes/node-18489434-9eb0-11e5-bdef-00163e40c3b6/interfaces/152/",
+ }, {
+ ID: 38,
+ Name: "eth1",
+ Type: "physical",
+ Enabled: true,
+ MACAddress: "52:54:00:c6:17:82",
+ VLAN: exampleBondVLAN,
+ EffectveMTU: 1500,
+ Links: []maasInterfaceLink{},
+ Parents: []string{},
+ Children: []string{"bond1"},
+ ResourceURI: "/MAAS/api/1.0/nodes/node-770e97d0-9e69-11e5-9749-52540061e12f/interfaces/38/",
+ }, {
+ ID: 186,
+ Name: "bond1",
+ Type: "bond",
+ Enabled: true,
+ MACAddress: "52:54:00:c6:17:82",
+ VLAN: exampleBondVLAN,
+ EffectveMTU: 1500,
+ Links: []maasInterfaceLink{{
+ ID: 525,
+ Subnet: &maasSubnet{
+ ID: 1,
+ Name: "10.17.20.0/24",
+ Space: "default",
+ VLAN: exampleBondVLAN,
+ GatewayIP: "10.17.20.1",
+ DNSServers: []string{"10.17.20.200"},
+ CIDR: "10.17.20.0/24",
+ ResourceURI: "/MAAS/api/1.0/subnets/1/",
+ },
+ IPAddress: "10.17.20.210",
+ Mode: "static",
+ }},
+ Parents: []string{"eth1", "eth2"},
+ Children: []string{},
+ ResourceURI: "/MAAS/api/1.0/nodes/node-770e97d0-9e69-11e5-9749-52540061e12f/interfaces/186/",
}}
)
@@ -517,6 +647,12 @@ func (s *interfacesSuite) TestFindPXEInterfaceSpaceSuccess(c *gc.C) {
c.Assert(foundSpace, gc.Equals, "default")
}
+func (s *interfacesSuite) TestFindPXEInterfaceSpaceSuccessOnBond(c *gc.C) {
+ foundSpace, err := findPXEInterfaceSpace(exampleInterfaces, "52:54:00:c6:17:82")
+ c.Assert(err, jc.ErrorIsNil)
+ c.Assert(foundSpace, gc.Equals, "default")
+}
+
func (s *interfacesSuite) TestFindPXEInterfaceSpaceSkipsExistingNonPhysicalNICs(c *gc.C) {
foundSpace, err := findPXEInterfaceSpace(exampleInterfaces, "52:54:00:70:9b:f1")
c.Assert(err, gc.ErrorMatches, `PXE interface with MAC address "52:54:00:70:9b:f1" not found`)
@@ -694,6 +830,25 @@ func (s *interfacesSuite) TestMAASObjectNetworkInterfaces(c *gc.C) {
MTU: 1500,
GatewayAddress: network.NewAddressOnSpace("storage", "10.250.19.2"),
ExtraConfig: nil,
+ }, {
+ DeviceIndex: 5,
+ MACAddress: "52:54:00:c6:17:82",
+ CIDR: "10.17.20.0/24",
+ NetworkName: "juju-private",
+ ProviderId: "186",
+ ProviderSubnetId: "1",
+ AvailabilityZones: nil,
+ VLANTag: 0,
+ InterfaceName: "bond1",
+ Disabled: false,
+ NoAutoStart: false,
+ ConfigType: "static",
+ Address: network.NewAddressOnSpace("default", "10.17.20.210"),
+ DNSServers: network.NewAddressesOnSpace("default", "10.17.20.200"),
+ DNSSearch: "",
+ MTU: 1500,
+ GatewayAddress: network.NewAddressOnSpace("default", "10.17.20.1"),
+ ExtraConfig: nil,
}}
infos, err := maasObjectNetworkInterfaces(&obj)
--
2.7.0
|