@@ -40,6 +40,10 @@ func TestEgressIP(t *testing.T) {
40
40
eip .deleteNamespaceEgress (42 )
41
41
eip .deleteNamespaceEgress (43 )
42
42
43
+ if len (eip .nodesByNodeIP ) != 0 || len (eip .nodesByEgressIP ) != 0 || len (eip .namespacesByVNID ) != 0 || len (eip .namespacesByEgressIP ) != 0 {
44
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
45
+ }
46
+
43
47
// No namespaces use egress yet, so should be no changes
44
48
err := assertNoNetlinkChanges (eip )
45
49
if err != nil {
@@ -74,6 +78,11 @@ func TestEgressIP(t *testing.T) {
74
78
t .Fatalf ("Unexpected flow changes: %v" , err )
75
79
}
76
80
81
+ ns42 := eip .namespacesByVNID [42 ]
82
+ if ns42 == nil || eip .namespacesByEgressIP ["172.17.0.100" ] != ns42 || eip .nodesByEgressIP ["172.17.0.100" ] != nil {
83
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
84
+ }
85
+
77
86
eip .updateNodeEgress ("172.17.0.3" , []string {"172.17.0.100" })
78
87
err = assertNoNetlinkChanges (eip )
79
88
if err != nil {
@@ -94,6 +103,11 @@ func TestEgressIP(t *testing.T) {
94
103
}
95
104
origFlows = flows
96
105
106
+ node3 := eip .nodesByNodeIP ["172.17.0.3" ]
107
+ if node3 == nil || eip .namespacesByEgressIP ["172.17.0.100" ] != ns42 || eip .nodesByEgressIP ["172.17.0.100" ] != node3 {
108
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
109
+ }
110
+
97
111
// Assign HostSubnet.EgressIP first, then NetNamespace.EgressIP, with a remote EgressIP
98
112
eip .updateNodeEgress ("172.17.0.3" , []string {"172.17.0.101" , "172.17.0.100" })
99
113
err = assertNoNetlinkChanges (eip )
@@ -109,6 +123,10 @@ func TestEgressIP(t *testing.T) {
109
123
t .Fatalf ("Unexpected flow changes: %v" , err )
110
124
}
111
125
126
+ if eip .nodesByEgressIP ["172.17.0.100" ] != node3 || eip .nodesByEgressIP ["172.17.0.101" ] != node3 {
127
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
128
+ }
129
+
112
130
eip .updateNamespaceEgress (43 , "172.17.0.101" )
113
131
err = assertNoNetlinkChanges (eip )
114
132
if err != nil {
@@ -129,6 +147,11 @@ func TestEgressIP(t *testing.T) {
129
147
}
130
148
origFlows = flows
131
149
150
+ ns43 := eip .namespacesByVNID [43 ]
151
+ if ns43 == nil || eip .namespacesByEgressIP ["172.17.0.101" ] != ns43 || eip .nodesByEgressIP ["172.17.0.101" ] != node3 {
152
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
153
+ }
154
+
132
155
// Assign NetNamespace.EgressIP first, then HostSubnet.EgressIP, with a local EgressIP
133
156
eip .updateNamespaceEgress (44 , "172.17.0.102" )
134
157
err = assertNoNetlinkChanges (eip )
@@ -149,6 +172,11 @@ func TestEgressIP(t *testing.T) {
149
172
t .Fatalf ("Unexpected flow changes: %v" , err )
150
173
}
151
174
175
+ ns44 := eip .namespacesByVNID [44 ]
176
+ if ns44 == nil || eip .namespacesByEgressIP ["172.17.0.102" ] != ns44 || eip .nodesByEgressIP ["172.17.0.102" ] != nil {
177
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
178
+ }
179
+
152
180
eip .updateNodeEgress ("172.17.0.4" , []string {"172.17.0.102" })
153
181
err = assertNetlinkChange (eip , "claim 172.17.0.102" )
154
182
if err != nil {
@@ -169,6 +197,11 @@ func TestEgressIP(t *testing.T) {
169
197
}
170
198
origFlows = flows
171
199
200
+ node4 := eip .nodesByNodeIP ["172.17.0.4" ]
201
+ if node4 == nil || eip .nodesByEgressIP ["172.17.0.102" ] != node4 {
202
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
203
+ }
204
+
172
205
// Assign HostSubnet.EgressIP first, then NetNamespace.EgressIP, with a local EgressIP
173
206
eip .updateNodeEgress ("172.17.0.4" , []string {"172.17.0.102" , "172.17.0.103" })
174
207
err = assertNoNetlinkChanges (eip )
@@ -184,6 +217,10 @@ func TestEgressIP(t *testing.T) {
184
217
t .Fatalf ("Unexpected flow changes: %v" , err )
185
218
}
186
219
220
+ if eip .nodesByEgressIP ["172.17.0.102" ] != node4 || eip .nodesByEgressIP ["172.17.0.103" ] != node4 {
221
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
222
+ }
223
+
187
224
eip .updateNamespaceEgress (45 , "172.17.0.103" )
188
225
err = assertNetlinkChange (eip , "claim 172.17.0.103" )
189
226
if err != nil {
@@ -204,6 +241,11 @@ func TestEgressIP(t *testing.T) {
204
241
}
205
242
origFlows = flows
206
243
244
+ ns45 := eip .namespacesByVNID [45 ]
245
+ if ns45 == nil || eip .namespacesByEgressIP ["172.17.0.103" ] != ns45 || eip .nodesByEgressIP ["172.17.0.103" ] != node4 {
246
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
247
+ }
248
+
207
249
// Drop namespace EgressIP
208
250
eip .deleteNamespaceEgress (44 )
209
251
err = assertNetlinkChange (eip , "release 172.17.0.102" )
@@ -225,6 +267,10 @@ func TestEgressIP(t *testing.T) {
225
267
}
226
268
origFlows = flows
227
269
270
+ if eip .namespacesByVNID [44 ] != nil || eip .namespacesByEgressIP ["172.17.0.102" ] != nil || eip .nodesByEgressIP ["172.17.0.102" ] != node4 {
271
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
272
+ }
273
+
228
274
// Drop remote node EgressIP
229
275
eip .updateNodeEgress ("172.17.0.3" , []string {"172.17.0.100" })
230
276
err = assertNoNetlinkChanges (eip )
@@ -250,6 +296,10 @@ func TestEgressIP(t *testing.T) {
250
296
}
251
297
origFlows = flows
252
298
299
+ if eip .namespacesByVNID [43 ] != ns43 || eip .namespacesByEgressIP ["172.17.0.101" ] != ns43 || eip .nodesByEgressIP ["172.17.0.101" ] != nil {
300
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
301
+ }
302
+
253
303
// Drop local node EgressIP
254
304
eip .updateNodeEgress ("172.17.0.4" , []string {"172.17.0.102" })
255
305
err = assertNetlinkChange (eip , "release 172.17.0.103" )
@@ -275,6 +325,10 @@ func TestEgressIP(t *testing.T) {
275
325
}
276
326
origFlows = flows
277
327
328
+ if eip .namespacesByVNID [45 ] != ns45 || eip .namespacesByEgressIP ["172.17.0.103" ] != ns45 || eip .nodesByEgressIP ["172.17.0.103" ] != nil {
329
+ t .Fatalf ("Unexpected eip state: %#v" , eip )
330
+ }
331
+
278
332
// Trying to assign node IP as egress IP should fail. (It will log an error but this test doesn't notice that.)
279
333
eip .updateNodeEgress ("172.17.0.4" , []string {"172.17.0.4" , "172.17.0.102" })
280
334
err = assertNoNetlinkChanges (eip )
0 commit comments