forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_manager_dtc_pool_test.go
431 lines (399 loc) · 16.9 KB
/
object_manager_dtc_pool_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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
package ibclient
import (
"fmt"
"github.com/infobloxopen/infoblox-go-client/v2/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Object Manager DTC Pool", func() {
Describe("Create dtc pool with minimal parameters", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
name := "dtc_pool_20"
lbPreferredMethod := "ROUND_ROBIN"
var fakeRefReturn = fmt.Sprintf(
"dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s",
name)
eas := EA{"Site": "blr"}
useTtl := true
ttl := uint32(70)
autoConsolidatedMonitors := false
objectAsResult := NewDtcPool(comment, name, lbPreferredMethod, nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", nil, ttl, true, false, 0)
objectAsResult.Ref = fakeRefReturn
aniFakeConnector := &fakeConnector{
createObjectObj: NewDtcPool(comment, name, lbPreferredMethod, nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", nil, ttl, true, false, 0),
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyDtcPool(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: objectAsResult,
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(aniFakeConnector, cmpType, tenantID)
var PoolDtc *DtcPool
var err error
It("should pass expected DTC pool Object to CreateObject", func() {
PoolDtc, err = objMgr.CreateDtcPool(comment, name, lbPreferredMethod, nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", ttl, useTtl, false, 0)
})
It("should return expected DTC pool Object", func() {
Expect(err).To(BeNil())
Expect(PoolDtc).To(Equal(aniFakeConnector.resultObject))
})
})
Describe("Create DTC pool with with TOPOLOGY as preferred load balancing method ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
name := "dtc_pool_20"
var fakeRefReturn = fmt.Sprintf(
"dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s",
name)
lbPreferredMethod := "TOPOLOGY"
serverRef := "dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:test-server"
topologyRef := "dtc:topology/ZG5zLmhvc3QkLmNvbS5hcGkudjI6dGVzdC1wb29s:test-topo"
topologyName := "test-topo"
createObjServers := []*DtcServerLink{{Server: serverRef, Ratio: 3}}
servers := []*DtcServerLink{{Server: "test-server", Ratio: 3}}
monitor := []Monitor{{Name: "snmp", Type: "snmp"}}
monitorRef := "dtc:monitor:snmp/ZG5zLmlkbnNfbW9uaXRvcl9odHRwJGh0dHA:snmp"
createMonitor := []*DtcMonitorHttp{{
Ref: monitorRef,
}}
eas := EA{"Site": "blr"}
dynamicRatioPreferred := map[string]interface{}{
"monitor": Monitor{Name: "snmp", Type: "snmp"},
"method": "MONITOR",
"monitor_metric": ".1.1",
"monitor_invert_monitor": false,
}
lbDynamicRatioPreferred := &SettingDynamicratio{
Method: "MONITOR",
Monitor: monitorRef,
MonitorMetric: ".1.1",
InvertMonitorMetric: false,
}
objAsResult := NewDtcPool(comment, name, lbPreferredMethod, nil, createObjServers, createMonitor, &topologyRef, "DYNAMIC_RATIO", nil, lbDynamicRatioPreferred, eas, false, "", nil, 20, true, false, 2)
objAsResult.Ref = fakeRefReturn
conn := &fakeConnector{
createObjectObj: NewDtcPool(comment, name, lbPreferredMethod, nil, createObjServers, createMonitor, &topologyRef, "DYNAMIC_RATIO", nil, lbDynamicRatioPreferred, eas, false, "", nil, 20, true, false, 2),
getObjectObj: map[string]interface{}{
"DtcServer": &DtcServer{},
"DtcTopology": &DtcTopology{},
"DtcMonitor": &DtcMonitorHttp{},
},
getObjectQueryParams: map[string]*QueryParams{
"DtcServer": NewQueryParams(false, map[string]string{"name": "test-server"}),
"DtcTopology": NewQueryParams(false, map[string]string{"name": "test-topo"}),
"DtcMonitor": NewQueryParams(false, map[string]string{"name": "snmp"}),
},
resultObject: map[string]interface{}{
"DtcTopology": []DtcTopology{{
Ref: topologyRef,
Name: utils.StringPtr("test-topo"),
}},
"DtcMonitor": []DtcMonitorHttp{{
Ref: monitorRef,
}},
"DtcServer": []DtcServer{{
Ref: serverRef,
Name: utils.StringPtr("test-server"),
}},
"DtcPool": objAsResult,
},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should pass expected DtcPool Object to CreateObject", func() {
actualRecord, err := objMgr.CreateDtcPool(comment, name, lbPreferredMethod, nil, servers, monitor, &topologyName, "DYNAMIC_RATIO", nil, dynamicRatioPreferred, eas, false, "", 20, true, false, 2)
Expect(actualRecord).To(Equal(conn.resultObject.(map[string]interface{})["DtcPool"]))
Expect(err).To(BeNil())
})
})
Describe("Create DTC pool with with DYNAMIC_RATIO as preferred load balancing method ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
name := "dtc_pool_20"
var fakeRefReturn = fmt.Sprintf(
"dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s",
name)
lbPreferredMethod := "DYNAMIC_RATIO"
serverRef := "dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:test-server"
monitor := []Monitor{{Name: "snmp", Type: "snmp"}}
monitorRef := "dtc:monitor:snmp/ZG5zLmlkbnNfbW9uaXRvcl9odHRwJGh0dHA:snmp"
createMonitor := []*DtcMonitorHttp{{
Ref: monitorRef,
}}
dynamicRatioPreferred := map[string]interface{}{
"monitor": Monitor{Name: "snmp", Type: "snmp"},
"method": "MONITOR",
"monitor_metric": ".1.1",
"monitor_invert_monitor": false,
}
lbDynamicRatioPreferred := &SettingDynamicratio{
Method: "MONITOR",
Monitor: monitorRef,
MonitorMetric: ".1.1",
InvertMonitorMetric: false,
}
createObjServers := []*DtcServerLink{{Server: serverRef, Ratio: 3}}
servers := []*DtcServerLink{{Server: "test-server", Ratio: 3}}
objAsResult := NewDtcPool(comment, name, lbPreferredMethod, lbDynamicRatioPreferred, createObjServers, createMonitor, nil, "", nil, nil, nil, false, "", nil, 20, true, false, 2)
objAsResult.Ref = fakeRefReturn
conn := &fakeConnector{
createObjectObj: NewDtcPool(comment, name, lbPreferredMethod, lbDynamicRatioPreferred, createObjServers, createMonitor, nil, "", nil, nil, nil, false, "", nil, 20, true, false, 2),
getObjectObj: map[string]interface{}{
"DtcServer": &DtcServer{},
"DtcMonitor": &DtcMonitorHttp{},
},
getObjectQueryParams: map[string]*QueryParams{
"DtcServer": NewQueryParams(false, map[string]string{"name": "test-server"}),
"DtcMonitor": NewQueryParams(false, map[string]string{"name": "snmp"}),
},
resultObject: map[string]interface{}{
"DtcServer": []DtcServer{{
Ref: serverRef,
Name: utils.StringPtr("test-server"),
}},
"DtcMonitor": []DtcMonitorHttp{{
Ref: monitorRef,
}},
"DtcPool": objAsResult,
},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should pass expected DtcPool Object to CreateObject", func() {
actualRecord, err := objMgr.CreateDtcPool(comment, name, lbPreferredMethod, dynamicRatioPreferred, servers, monitor, nil, "", nil, nil, nil, false, "", 20, true, false, 2)
Expect(actualRecord).To(Equal(conn.resultObject.(map[string]interface{})["DtcPool"]))
Expect(err).To(BeNil())
})
})
Describe("Negative case : Create dtc pool gives error when all the required fields are not passed ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
name := "dtc_pool_20"
var fakeRefReturn = fmt.Sprintf(
"dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s",
name)
eas := EA{"Site": "blr"}
useTtl := true
ttl := uint32(70)
autoConsolidatedMonitors := false
objectAsResult := NewDtcPool(comment, name, "", nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", nil, ttl, true, false, 0)
objectAsResult.Ref = fakeRefReturn
aniFakeConnector := &fakeConnector{
createObjectObj: NewDtcPool(comment, name, "", nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", nil, ttl, true, false, 0),
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyDtcPool(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: objectAsResult,
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(aniFakeConnector, cmpType, tenantID)
_, err := objMgr.CreateDtcPool(comment, name, "", nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", ttl, useTtl, false, 0)
It("Should throw expected error when all the fields are not provided", func() {
Expect(err).ToNot(BeNil())
})
})
Describe("Negative case: return an error message when preferred method is DYNAMIC_RATIO and required parameters are not provided ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
name := "dtc_pool_20"
eas := EA{"Site": "blr"}
useTtl := true
ttl := uint32(70)
lbPreferredMethod := "DYNAMIC_RATIO"
autoConsolidatedMonitors := false
conn := &fakeConnector{
createObjectObj: NewDtcPool(comment, name, lbPreferredMethod, nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", nil, ttl, true, false, 0),
createObjectError: fmt.Errorf("lbDynamicRatioPreferred cannot be nil when lbPreferredMethod is set to DYNAMIC_RATIO"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *DtcPool
var err error
expectedObj = nil
It("should pass expected DTC pool Object to CreateObject", func() {
actualRecord, err = objMgr.CreateDtcPool(comment, name, lbPreferredMethod, nil, nil, nil, nil, "", nil, nil, eas, autoConsolidatedMonitors, "", ttl, useTtl, false, 0)
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.createObjectError))
})
})
Describe("Update Dtc pool", func() {
var (
err error
objMgr IBObjectManager
conn *fakeConnector
ref string
actualObj *DtcPool
)
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_pool_20"
autoConsolidatedMonitors := false
It("Updating dtc_pool_20, ttl, useTtl, comment ,LB preferred method and EAs", func() {
ref = fmt.Sprintf("dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s", name)
initialEas := EA{"Site": "Blr"}
initialLbPreferredMethod := "ROUND_ROBIN"
initialTtl := uint32(70)
initObj := NewDtcPool("old comment", name, initialLbPreferredMethod, nil, nil, nil, nil, "", nil, nil, initialEas, autoConsolidatedMonitors, "", nil, initialTtl, false, false, 0)
initObj.Ref = ref
expectedEas := EA{"Site": "Blr"}
updateName := "dtc_pool_21"
updateComment := "new comment"
updateUseTtl := true
updateTtl := uint32(10)
updateLbPreferredMethod := "ALL_AVAILABLE"
updatedRef := fmt.Sprintf("dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s", name)
monitor := []Monitor{{Name: "snmp", Type: "snmp"}}
monitorRef := "dtc:monitor:snmp/ZG5zLmlkbnNfbW9uaXRvcl9odHRwJGh0dHA:snmp"
createMonitor := []*DtcMonitorHttp{{
Ref: monitorRef,
}}
consolidatedMonitor := []map[string]interface{}{
{
"monitor": Monitor{Name: "snmp", Type: "snmp"},
"availability": "ALL",
"full_health_communication": false,
"members": []string{"infoblox.localdomain"},
},
}
consolidatedMonitorStruct := []*DtcPoolConsolidatedMonitorHealth{
{
Monitor: monitorRef,
Members: []string{"infoblox.localdomain"},
Availability: "ALL",
FullHealthCommunication: false,
},
}
updateObjIn := NewDtcPool(updateComment, updateName, updateLbPreferredMethod, nil, nil, createMonitor, nil, "", nil, nil, expectedEas, autoConsolidatedMonitors, "", consolidatedMonitorStruct, updateTtl, updateUseTtl, false, 0)
updateObjIn.Ref = ref
expectedObj := NewDtcPool(updateComment, updateName, updateLbPreferredMethod, nil, nil, createMonitor, nil, "", nil, nil, expectedEas, autoConsolidatedMonitors, "", consolidatedMonitorStruct, updateTtl, updateUseTtl, false, 0)
expectedObj.Ref = updatedRef
conn = &fakeConnector{
getObjectObj: map[string]interface{}{
"DtcMonitor": &DtcMonitorHttp{},
"DtcPool": NewEmptyDtcPool(),
},
getObjectQueryParams: map[string]*QueryParams{
"DtcMonitor": NewQueryParams(false, map[string]string{"name": "snmp"}),
"DtcPool": NewQueryParams(false, nil),
},
getObjectRef: updatedRef,
getObjectError: nil,
resultObject: map[string]interface{}{
"DtcMonitor": []DtcMonitorHttp{{
Ref: monitorRef,
}},
"DtcPool": expectedObj,
},
updateObjectObj: updateObjIn,
updateObjectRef: ref,
updateObjectError: nil,
fakeRefReturn: updatedRef,
}
objMgr = NewObjectManager(conn, cmpType, tenantID)
actualObj, err = objMgr.UpdateDtcPool(ref, updateComment, updateName, updateLbPreferredMethod, nil, nil, monitor, nil, "", nil, nil, expectedEas, autoConsolidatedMonitors, "", consolidatedMonitor, updateTtl, updateUseTtl, false, 0)
Expect(err).To(BeNil())
Expect(*actualObj).To(BeEquivalentTo(*expectedObj))
})
})
Describe("Get pool", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_pool_20"
comment := "get pools"
autoConsolidatedMonitors := false
fakeRefReturn := fmt.Sprintf("dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s", name)
queryParams := NewQueryParams(
false,
map[string]string{
"name": name,
"comment": comment,
})
conn := &fakeConnector{
createObjectObj: NewDtcPool(comment, name, "ROUND_ROBIN", nil, nil, nil, nil, "", nil, nil, nil, autoConsolidatedMonitors, "", nil, 20, true, false, 0),
getObjectRef: "",
getObjectObj: NewEmptyDtcPool(),
resultObject: []DtcPool{*NewDtcPool(comment, name, "ROUND_ROBIN", nil, nil, nil, nil, "", nil, nil, nil, autoConsolidatedMonitors, "", nil, 20, true, false, 0)},
fakeRefReturn: fakeRefReturn,
getObjectQueryParams: queryParams,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
conn.resultObject.([]DtcPool)[0].Ref = fakeRefReturn
var actualRecord []DtcPool
var err error
It("should pass expected Dtc Pool Object to GetObject", func() {
actualRecord, err = objMgr.GetAllDtcPool(queryParams)
Expect(err).To(BeNil())
Expect(actualRecord).To(Equal(conn.resultObject))
})
})
Describe("Get Dtc Pool by name", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_pool_21"
comment := "get pools"
autoConsolidatedMonitors := false
fakeRefReturn := fmt.Sprintf("dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s", name)
res := NewDtcPool(comment, name, "ROUND_ROBIN", nil, nil, nil, nil, "", nil, nil, nil, autoConsolidatedMonitors, "", nil, 20, true, false, 0)
queryParams := NewQueryParams(false, map[string]string{"name": name})
conn := &fakeConnector{
getObjectObj: NewEmptyDtcPool(),
getObjectQueryParams: NewQueryParams(false, map[string]string{"name": name}),
resultObject: []DtcPool{*res},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should get expected DtcPool Object from getObject", func() {
conn.getObjectQueryParams = queryParams
actualRecord, err := objMgr.GetDtcPool(name)
Expect(*actualRecord).To(Equal(conn.resultObject.([]DtcPool)[0]))
Expect(err).To(BeNil())
})
})
Describe("Get Dtc Pool by name, negative scenario", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
conn := &fakeConnector{
getObjectRef: "",
getObjectObj: NewEmptyDtcPool(),
getObjectQueryParams: NewQueryParams(false, map[string]string{"name": ""}),
getObjectError: fmt.Errorf("name of the record is required to retrieve a unique Dtc Pool record"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *DtcPool
var err error
expectedObj = nil
It("should pass expected Dtc Pool record Object to Getobject", func() {
actualRecord, err = objMgr.GetDtcPool("")
})
It("should return expected Dtc Pool record Object", func() {
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.getObjectError))
})
})
Describe("Delete DTC pool", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_pool_20"
deleteRef := fmt.Sprintf("dtc:pool/ZG5zLmlkbnNfcG9vbCRkdGNfcG9vbF8x:%s", name)
fakeRefReturn := deleteRef
nwFakeConnector := &fakeConnector{
deleteObjectRef: deleteRef,
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(nwFakeConnector, cmpType, tenantID)
var actualRef string
var err error
It("should pass expected DTC pool Ref to DeleteObject", func() {
actualRef, err = objMgr.DeleteDtcPool(deleteRef)
})
It("should return expected DTC pool Ref", func() {
Expect(actualRef).To(Equal(fakeRefReturn))
Expect(err).To(BeNil())
})
})
})