-
Notifications
You must be signed in to change notification settings - Fork 0
/
two_stage_l3_clos_system_node_info_integration_test.go
295 lines (257 loc) · 8.74 KB
/
two_stage_l3_clos_system_node_info_integration_test.go
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//go:build integration
// +build integration
package apstra
import (
"context"
"log"
"math/rand"
"net"
"testing"
"time"
)
func TestSystemNodeInfo(t *testing.T) {
ctx := context.Background()
clients, err := getTestClients(ctx, t)
if err != nil {
t.Fatal(err)
}
for clientName, client := range clients {
log.Printf("testing ListAllBlueprintIds() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
bpIds, err := client.client.ListAllBlueprintIds(ctx)
if err != nil {
t.Fatal(err)
}
var bpClient *TwoStageL3ClosClient
if len(bpIds) > 0 {
log.Printf("testing NewTwoStageL3ClosClient() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
bpClient, err = client.client.NewTwoStageL3ClosClient(ctx, bpIds[0])
if err != nil {
t.Fatal(err)
}
} else {
var deleteFunc func(ctx2 context.Context) error
bpClient, deleteFunc = testBlueprintA(ctx, t, client.client)
defer deleteFunc(ctx)
}
log.Printf("testing GetAllSystemNodeInfos() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfos, err := bpClient.GetAllSystemNodeInfos(ctx)
if err != nil {
t.Fatal(err)
}
for nodeId := range nodeInfos {
log.Printf("testing GetSystemNodeInfo() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfo, err := bpClient.GetSystemNodeInfo(ctx, nodeId)
if err != nil {
t.Fatal(err)
}
log.Println(nodeInfo.Id)
}
}
}
func TestSetSystemAsn(t *testing.T) {
ctx := context.Background()
clients, err := getTestClients(ctx, t)
if err != nil {
t.Fatal(err)
}
for clientName, client := range clients {
//switch client.client.ApiVersion() {
//case "4.1.0":
// continue
//case "4.1.1":
// continue
//case "4.1.2":
//case "4.2.0":
// continue
//}
if client.client.ApiVersion() == "4.1.0" {
continue
}
bpClient, deleteFunc := testBlueprintB(ctx, t, client.client)
defer deleteFunc(ctx)
time.Sleep(2 * time.Second) // todo: fix this terrible workaround for 404s from
// /api/blueprints/<id>/experience/web/system-info
// shortly after blueprint creation:
// {"errors": "Cache for <id> blueprint staging not found"}
// see https://apstrktr.atlassian.net/browse/AOS-44024
// and https://apstra-eng.slack.com/archives/C2DFCFHJR/p1703621403168039
log.Printf("testing GetAllSystemNodeInfos() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfos, err := bpClient.GetAllSystemNodeInfos(ctx)
if err != nil {
t.Fatal(err)
}
var systemIds []ObjectId
for id, info := range nodeInfos {
if info.Role == SystemRoleGeneric {
systemIds = append(systemIds, id)
}
}
asnMap := make(map[ObjectId]uint32, len(systemIds))
for _, id := range systemIds {
for asnMap[id] == 0 {
asnMap[id] = rand.Uint32()
}
asn := asnMap[id]
log.Printf("testing SetGenericSystemAsn() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = bpClient.SetGenericSystemAsn(ctx, id, &asn)
if err != nil {
t.Fatal(err)
}
}
log.Printf("testing GetAllSystemNodeInfos() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfos, err = bpClient.GetAllSystemNodeInfos(ctx)
if err != nil {
t.Fatal(err)
}
for nodeId, asn := range asnMap {
if nodeInfos[nodeId].Asn == nil {
t.Fatalf("expected node %q to have asn %d, got nil", nodeId, asn)
}
if *nodeInfos[nodeId].Asn != asn {
t.Fatalf("expected node %q to have asn %d, got %d", nodeId, asn, nodeInfos[nodeId].Asn)
}
log.Printf("testing SetGenericSystemAsn() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = bpClient.SetGenericSystemAsn(ctx, nodeId, nil)
if err != nil {
t.Fatal(err)
}
}
log.Printf("testing GetAllSystemNodeInfos() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfos, err = bpClient.GetAllSystemNodeInfos(ctx)
if err != nil {
t.Fatal(err)
}
for _, id := range systemIds {
if nodeInfos[id].Asn != nil {
t.Fatalf("expected node %q to have no ASN, got %d", id, nodeInfos[id].Asn)
}
}
}
}
func randomIpv4() net.IP {
return []byte{
byte(rand.Intn(222) + 1),
byte(rand.Intn(256)),
byte(rand.Intn(256)),
byte(rand.Intn(256)),
}
}
func randomIpv6() net.IP {
return []byte{
0x20, 0x01,
0x0d, 0xb8,
byte(rand.Intn(256)), byte(rand.Intn(256)),
byte(rand.Intn(256)), byte(rand.Intn(256)),
byte(rand.Intn(256)), byte(rand.Intn(256)),
byte(rand.Intn(256)), byte(rand.Intn(256)),
byte(rand.Intn(256)), byte(rand.Intn(256)),
byte(rand.Intn(256)), byte(rand.Intn(256)),
}
}
func TestSetSystemLoopbackIpv4v6(t *testing.T) {
ctx := context.Background()
clients, err := getTestClients(ctx, t)
if err != nil {
t.Fatal(err)
}
for clientName, client := range clients {
bpClient, deleteFunc := testBlueprintG(ctx, t, client.client)
defer deleteFunc(ctx)
ipv6Enabled := true
err = bpClient.SetFabricAddressingPolicy(ctx, &TwoStageL3ClosFabricAddressingPolicy{Ipv6Enabled: &ipv6Enabled})
if err != nil {
t.Fatal(err)
}
log.Printf("testing GetAllSystemNodeInfos() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfos, err := bpClient.GetAllSystemNodeInfos(ctx)
if err != nil {
t.Fatal(err)
}
var systemIds []ObjectId
for id, info := range nodeInfos {
if info.Role == SystemRoleGeneric {
systemIds = append(systemIds, id)
}
}
ipv4Map := make(map[ObjectId]net.IPNet, len(systemIds))
ipv6Map := make(map[ObjectId]net.IPNet, len(systemIds))
for _, id := range systemIds {
ipv4Map[id] = net.IPNet{
IP: randomIpv4(),
Mask: net.CIDRMask(rand.Intn(9)+24, 32),
}
var v6Mask net.IPMask
if rand.Int()%2 == 0 {
v6Mask = net.CIDRMask(64, 128)
} else {
v6Mask = net.CIDRMask(128, 128)
}
ipv6Map[id] = net.IPNet{
IP: randomIpv6(),
Mask: v6Mask,
}
ipv4Net := ipv4Map[id]
log.Printf("testing SetGenericSystemLoopbackIpv4() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = bpClient.SetGenericSystemLoopbackIpv4(ctx, id, &ipv4Net, 0)
if err != nil {
t.Fatal(err)
}
ipv6Net := ipv6Map[id]
log.Printf("testing SetGenericSystemLoopbackIpv6() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = bpClient.SetGenericSystemLoopbackIpv6(ctx, id, &ipv6Net, 0)
if err != nil {
t.Fatal(err)
}
}
log.Printf("testing GetAllSystemNodeInfos() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfos, err = bpClient.GetAllSystemNodeInfos(ctx)
if err != nil {
t.Fatal(err)
}
for nodeId, ip := range ipv4Map {
if nodeInfos[nodeId].LoopbackIpv4 == nil {
t.Fatalf("expected node %q to have loopback %s, got nil", nodeId, ip.String())
}
if !nodeInfos[nodeId].LoopbackIpv4.IP.Equal(ip.IP) {
t.Fatalf("expected node %q to have loopback IP %s, got %s", nodeId, ip.IP, nodeInfos[nodeId].LoopbackIpv4.IP)
}
if nodeInfos[nodeId].LoopbackIpv4.Mask.String() != ip.Mask.String() {
t.Fatalf("expected node %q to have loopback IP %s, got %s", nodeId, ip.IP, nodeInfos[nodeId].LoopbackIpv4.IP)
}
log.Printf("testing SetGenericSystemLoopbackIpv4() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = bpClient.SetGenericSystemLoopbackIpv4(ctx, nodeId, nil, 0)
if err != nil {
t.Fatal(err)
}
}
for nodeId, ip := range ipv6Map {
if nodeInfos[nodeId].LoopbackIpv6 == nil {
t.Fatalf("expected node %q to have loopback %s, got nil", nodeId, ip.String())
}
if !nodeInfos[nodeId].LoopbackIpv6.IP.Equal(ip.IP) {
t.Fatalf("expected node %q to have loopback IP %s, got %s", nodeId, ip.IP, nodeInfos[nodeId].LoopbackIpv6.IP)
}
if nodeInfos[nodeId].LoopbackIpv6.Mask.String() != ip.Mask.String() {
t.Fatalf("expected node %q to have loopback IP %s, got %s", nodeId, ip.IP, nodeInfos[nodeId].LoopbackIpv6.IP)
}
log.Printf("testing SetGenericSystemLoopbackIpv6() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = bpClient.SetGenericSystemLoopbackIpv6(ctx, nodeId, nil, 0)
if err != nil {
t.Fatal(err)
}
}
log.Printf("testing GetAllSystemNodeInfos() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
nodeInfos, err = bpClient.GetAllSystemNodeInfos(ctx)
if err != nil {
t.Fatal(err)
}
for _, id := range systemIds {
if nodeInfos[id].LoopbackIpv4 != nil {
t.Fatalf("expected node %q to have no Loopback IPv4, got %s", id, nodeInfos[id].LoopbackIpv4)
}
if nodeInfos[id].LoopbackIpv6 != nil {
t.Fatalf("expected node %q to have no Loopback IPv6, got %s", id, nodeInfos[id].LoopbackIpv6)
}
}
}
}