forked from yukirii/go-tmsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ltm_test.go
669 lines (637 loc) · 16.3 KB
/
ltm_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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
package tmsh
import (
"reflect"
"testing"
"github.com/k0kubun/pp"
)
func TestGetNode(t *testing.T) {
//show ltm node dev-web01.example.com field-fmt
retStr := `ltm node dev-web01.example.com {
addr 192.0.2.1
cur-sessions 0
monitor-rule none
monitor-status unchecked
name dev-web01.example.com
serverside.bits-in 0
serverside.bits-out 0
serverside.cur-conns 0
serverside.max-conns 0
serverside.pkts-in 0
serverside.pkts-out 0
serverside.tot-conns 0
session-status enabled
status.availability-state unknown
status.enabled-state enabled
status.status-reason Node address does not have service checking enabled
tot-requests 0
}`
expect := &Node{
Addr: "192.0.2.1",
Name: "dev-web01.example.com",
MonitorRule: "none",
MonitorStatus: "unchecked",
EnabledState: "enabled",
}
bigip := &BigIP{
host: "example.com",
user: "admin",
sshconn: &TestSSHConnection{
ret: []byte(retStr),
},
}
node, err := bigip.GetNode("dev-web01.example.com")
if err != nil {
t.Errorf("%v", err)
}
if !reflect.DeepEqual(node, expect) {
t.Errorf("got :" + pp.Sprint(node))
t.Errorf("want :" + pp.Sprint(expect))
}
}
func TestGetPool(t *testing.T) {
// show ltm pool api.example.com_8080 members field-fmt
retStr := `ltm pool api.example.com_8080 {
active-member-cnt 2
connq-all.age-edm 0
connq-all.age-ema 0
connq-all.age-head 0
connq-all.age-max 0
connq-all.depth 0
connq-all.serviced 0
connq.age-edm 0
connq.age-ema 0
connq.age-head 0
connq.age-max 0
connq.depth 0
connq.serviced 0
cur-sessions 0
members {
api01.example.com:8080 {
addr 192.0.2.1
connq.age-edm 0
connq.age-ema 0
connq.age-head 0
connq.age-max 0
connq.depth 0
connq.serviced 0
cur-sessions 0
monitor-rule /Common/tcp (pool monitor)
monitor-status up
node-name api01.example.com
pool-name api.example.com_8080
port 8080
serverside.bits-in 36.2K
serverside.bits-out 87.9K
serverside.cur-conns 0
serverside.max-conns 3
serverside.pkts-in 20
serverside.pkts-out 20
serverside.tot-conns 3
session-status enabled
status.availability-state available
status.enabled-state enabled
status.status-reason Pool member is available
tot-requests 0
}
api02.example.com:8080 {
addr 192.0.2.2
connq.age-edm 0
connq.age-ema 0
connq.age-head 0
connq.age-max 0
connq.depth 0
connq.serviced 0
cur-sessions 0
monitor-rule none
monitor-status unchecked
node-name api02.example.com
pool-name api.example.com_8080
port 8080
serverside.bits-in 7.8M
serverside.bits-out 44.5M
serverside.cur-conns 0
serverside.max-conns 42
serverside.pkts-in 9.0K
serverside.pkts-out 7.8K
serverside.tot-conns 1.4K
session-status user-disabled
status.availability-state unknown
status.enabled-state disabled
status.status-reason Pool member does not have service checking enabled
tot-requests 0
}
}
min-active-members 0
monitor-rule /Common/tcp
name api.example.com_8080
serverside.bits-in 7.8M
serverside.bits-out 44.5M
serverside.cur-conns 0
serverside.max-conns 45
serverside.pkts-in 9.0K
serverside.pkts-out 7.8K
serverside.tot-conns 1.4K
status.availability-state available
status.enabled-state enabled
status.status-reason The pool is available
tot-requests 0
}`
expect := &Pool{
ActiveMemberCount: 2,
MonitorRule: "/Common/tcp",
Name: "api.example.com_8080",
AvailabilityState: "available",
EnabledState: "enabled",
StatusReason: "The pool is available",
PoolMembers: []PoolMember{
PoolMember{
Name: "api01.example.com",
Addr: "192.0.2.1",
Port: 8080,
MonitorRule: "/Common/tcp (pool monitor)",
MonitorStatus: "up",
EnabledState: "enabled",
AvailabilityState: "available",
StatusReason: "Pool member is available",
},
PoolMember{
Name: "api02.example.com",
Addr: "192.0.2.2",
Port: 8080,
MonitorRule: "none",
MonitorStatus: "unchecked",
EnabledState: "disabled",
AvailabilityState: "unknown",
StatusReason: "Pool member does not have service checking enabled",
},
},
}
bigip := &BigIP{
host: "example.com",
user: "admin",
sshconn: &TestSSHConnection{
ret: []byte(retStr),
},
}
pool, err := bigip.GetPool("api.example.com_8080")
if err != nil {
t.Errorf("%v", err)
}
if !reflect.DeepEqual(pool, expect) {
t.Errorf("got :" + pp.Sprint(pool))
t.Errorf("want :" + pp.Sprint(expect))
}
}
func TestGetVirtual(t *testing.T) {
// list ltm virtual api.example.com_443
retStr := `ltm virtual api.example.com_443 {
destination 203.0.113.1:https
ip-protocol tcp
mask 255.255.255.255
partition partition1
pool api.example.com_443
profiles {
/Common/tcp {
context all
}
wildcard.example.com {
context clientside
}
}
source 0.0.0.0/0
vs-index 1234
}`
expect := &VirtualServer{
Name: "api.example.com_443",
Destination: "203.0.113.1:https",
IpProtocol: "tcp",
Mask: "255.255.255.255",
Partition: "partition1",
Pool: "api.example.com_443",
Profiles: map[string]Profile{
"/Common/tcp": Profile{Context: "all"},
"wildcard.example.com": Profile{Context: "clientside"},
},
}
bigip := &BigIP{
host: "example.com",
user: "admin",
sshconn: &TestSSHConnection{
ret: []byte(retStr),
},
}
vs, err := bigip.GetVirtualServer("api.example.com_443")
if err != nil {
t.Errorf("%v", err)
}
if !reflect.DeepEqual(vs, expect) {
t.Errorf("got :" + pp.Sprint(vs))
t.Errorf("want :" + pp.Sprint(expect))
}
}
func TestGetAllNodes(t *testing.T) {
// show ltm node field-fmt
retStr := `ltm node dev-web01.example.com {
addr 192.0.2.1
cur-sessions 0
monitor-rule none
monitor-status unchecked
name dev-web01.example.com
serverside.bits-in 0
serverside.bits-out 0
serverside.cur-conns 0
serverside.max-conns 0
serverside.pkts-in 0
serverside.pkts-out 0
serverside.tot-conns 0
session-status enabled
status.availability-state unknown
status.enabled-state enabled
status.status-reason Node address does not have service checking enabled
tot-requests 0
}
ltm node dev-web02.example.com {
addr 192.0.2.2
cur-sessions 0
monitor-rule none
monitor-status unchecked
name dev-web02.example.com
serverside.bits-in 0
serverside.bits-out 0
serverside.cur-conns 0
serverside.max-conns 0
serverside.pkts-in 0
serverside.pkts-out 0
serverside.tot-conns 0
session-status enabled
status.availability-state unknown
status.enabled-state enabled
status.status-reason Node address does not have service checking enabled
tot-requests 0
}`
expect := []Node{
Node{
Addr: "192.0.2.1",
Name: "dev-web01.example.com",
MonitorRule: "none",
MonitorStatus: "unchecked",
EnabledState: "enabled",
},
Node{
Addr: "192.0.2.2",
Name: "dev-web02.example.com",
MonitorRule: "none",
MonitorStatus: "unchecked",
EnabledState: "enabled",
},
}
bigip := &BigIP{
host: "example.com",
user: "admin",
sshconn: &TestSSHConnection{
ret: []byte(retStr),
},
}
nodes, err := bigip.GetAllNodes()
if err != nil {
t.Errorf("%v", err)
}
if !reflect.DeepEqual(nodes, expect) {
t.Errorf("got :" + pp.Sprint(nodes))
t.Errorf("want :" + pp.Sprint(expect))
}
}
func TestGetAllPools(t *testing.T) {
// show ltm pool members field-fmt
retStr := `ltm pool api.example.com_8080 {
active-member-cnt 1
connq-all.age-edm 0
connq-all.age-ema 0
connq-all.age-head 0
connq-all.age-max 0
connq-all.depth 0
connq-all.serviced 0
connq.age-edm 0
connq.age-ema 0
connq.age-head 0
connq.age-max 0
connq.depth 0
connq.serviced 0
cur-sessions 0
members {
api01.example.com:8080 {
addr 192.0.2.1
connq.age-edm 0
connq.age-ema 0
connq.age-head 0
connq.age-max 0
connq.depth 0
connq.serviced 0
cur-sessions 0
monitor-rule /Common/tcp (pool monitor)
monitor-status up
node-name api01.example.com
pool-name api.example.com_8080
port 8080
serverside.bits-in 0
serverside.bits-out 0
serverside.cur-conns 0
serverside.max-conns 0
serverside.pkts-in 0
serverside.pkts-out 0
serverside.tot-conns 0
session-status enabled
status.availability-state available
status.enabled-state enabled
status.status-reason Pool member is available
tot-requests 0
}
}
min-active-members 0
monitor-rule /Common/tcp
name api.example.com_8080
serverside.bits-in 0
serverside.bits-out 0
serverside.cur-conns 0
serverside.max-conns 0
serverside.pkts-in 0
serverside.pkts-out 0
serverside.tot-conns 0
status.availability-state available
status.enabled-state enabled
status.status-reason The pool is available
tot-requests 0
}
ltm pool web.example.com_80 {
active-member-cnt 1
connq-all.age-edm 0
connq-all.age-ema 0
connq-all.age-head 0
connq-all.age-max 0
connq-all.depth 0
connq-all.serviced 0
connq.age-edm 0
connq.age-ema 0
connq.age-head 0
connq.age-max 0
connq.depth 0
connq.serviced 0
cur-sessions 0
members {
web.example.com:80 {
addr 192.0.2.2
connq.age-edm 0
connq.age-ema 0
connq.age-head 0
connq.age-max 0
connq.depth 0
connq.serviced 0
cur-sessions 0
monitor-rule /Common/tcp (pool monitor)
monitor-status up
node-name web01.example.com
pool-name web.example.com_80
port 80
serverside.bits-in 0
serverside.bits-out 0
serverside.cur-conns 0
serverside.max-conns 0
serverside.pkts-in 0
serverside.pkts-out 0
serverside.tot-conns 0
session-status enabled
status.availability-state available
status.enabled-state enabled
status.status-reason Pool member is available
tot-requests 0
}
}
min-active-members 0
monitor-rule /Common/tcp
name web.example.com_80
serverside.bits-in 0
serverside.bits-out 0
serverside.cur-conns 0
serverside.max-conns 0
serverside.pkts-in 0
serverside.pkts-out 0
serverside.tot-conns 0
status.availability-state available
status.enabled-state enabled
status.status-reason The pool is available
tot-requests 0
}`
expect := []Pool{
Pool{
ActiveMemberCount: 1,
MonitorRule: "/Common/tcp",
Name: "api.example.com_8080",
AvailabilityState: "available",
EnabledState: "enabled",
StatusReason: "The pool is available",
PoolMembers: []PoolMember{
PoolMember{
Name: "api01.example.com",
Addr: "192.0.2.1",
Port: 8080,
MonitorRule: "/Common/tcp (pool monitor)",
MonitorStatus: "up",
EnabledState: "enabled",
AvailabilityState: "available",
StatusReason: "Pool member is available",
},
},
},
Pool{
ActiveMemberCount: 1,
MonitorRule: "/Common/tcp",
Name: "web.example.com_80",
AvailabilityState: "available",
EnabledState: "enabled",
StatusReason: "The pool is available",
PoolMembers: []PoolMember{
PoolMember{
Name: "web01.example.com",
Addr: "192.0.2.2",
Port: 80,
MonitorRule: "/Common/tcp (pool monitor)",
MonitorStatus: "up",
EnabledState: "enabled",
AvailabilityState: "available",
StatusReason: "Pool member is available",
},
},
},
}
bigip := &BigIP{
host: "example.com",
user: "admin",
sshconn: &TestSSHConnection{
ret: []byte(retStr),
},
}
pools, err := bigip.GetAllPools()
if err != nil {
t.Errorf("%v", err)
}
if !reflect.DeepEqual(pools, expect) {
t.Errorf("got :" + pp.Sprint(pools))
t.Errorf("want :" + pp.Sprint(expect))
}
}
func TestGetAllVirtualServers(t *testing.T) {
// list ltm virtual all-properties
retStr := `ltm virtual api.example.com_443 {
address-status yes
app-service none
auth none
auto-lasthop default
bwc-policy none
clone-pools none
cmp-enabled yes
connection-limit 0
description none
destination 203.0.113.1:https
enabled
fallback-persistence none
fw-enforced-policy api.example.com_443
fw-staged-policy none
gtm-score 0
ip-intelligence-policy none
ip-protocol tcp
last-hop-pool none
mask 255.255.255.255
metadata none
mirror disabled
mobile-app-tunnel disabled
nat64 disabled
partition partition1
persist none
policies none
pool api.example.com_8080
profiles {
/Common/tcp {
context all
}
}
rate-class none
rate-limit disabled
rate-limit-dst-mask 0
rate-limit-mode object
rate-limit-src-mask 0
related-rules none
rules none
security-log-profiles none
source 0.0.0.0/0
source-address-translation {
pool /Common/partition1_snat
type snat
}
source-port change
syn-cookie-status not-activated
traffic-classes none
translate-address enabled
translate-port enabled
vlans none
vlans-disabled
vs-index 222
}
ltm virtual web.example.com_80 {
address-status yes
app-service none
auth none
auto-lasthop default
bwc-policy none
clone-pools none
cmp-enabled yes
connection-limit 0
description none
destination 203.0.113.2:http
enabled
fallback-persistence none
fw-enforced-policy web.example.com_80
fw-staged-policy none
gtm-score 0
ip-intelligence-policy none
ip-protocol tcp
last-hop-pool none
mask 255.255.255.255
metadata none
mirror disabled
mobile-app-tunnel disabled
nat64 disabled
partition partition1
persist none
policies none
pool web.example.com_80
profiles {
/Common/tcp {
context all
}
}
rate-class none
rate-limit disabled
rate-limit-dst-mask 0
rate-limit-mode object
rate-limit-src-mask 0
related-rules none
rules none
security-log-profiles none
source 0.0.0.0/0
source-address-translation {
pool /Common/partition1_snat
type snat
}
source-port change
syn-cookie-status not-activated
traffic-classes none
translate-address enabled
translate-port enabled
vlans none
vlans-disabled
vs-index 222
}`
expect := []VirtualServer{
VirtualServer{
Name: "api.example.com_443",
Destination: "203.0.113.1:https",
IpProtocol: "tcp",
Mask: "255.255.255.255",
Partition: "partition1",
Pool: "api.example.com_8080",
Profiles: map[string]Profile{
"/Common/tcp": Profile{
Context: "all",
},
},
},
VirtualServer{
Name: "web.example.com_80",
Destination: "203.0.113.2:http",
IpProtocol: "tcp",
Mask: "255.255.255.255",
Partition: "partition1",
Pool: "web.example.com_80",
Profiles: map[string]Profile{
"/Common/tcp": Profile{
Context: "all",
},
},
},
}
bigip := &BigIP{
host: "example.com",
user: "admin",
sshconn: &TestSSHConnection{
ret: []byte(retStr),
},
}
vss, err := bigip.GetAllVirtualServers()
if err != nil {
t.Errorf("%v", err)
}
if !reflect.DeepEqual(vss, expect) {
t.Errorf("got :" + pp.Sprint(vss))
t.Errorf("want :" + pp.Sprint(expect))
}
}