@@ -16,6 +16,15 @@ global - - - - - - - -
16
16
master lx-amd64 4 1 4 4 0.31 15.6G 422.9M 1.5G 0.0
17
17
exec lx-amd64 4 1 4 4 0.31 15.6G 422.9M 1.5G 0.0
18
18
`
19
+
20
+ sampleWithUnknownHost := `
21
+ HOSTNAME ARCH NCPU NSOC NCOR NTHR LOAD MEMTOT MEMUSE SWAPTO SWAPUS
22
+ ----------------------------------------------------------------------------------------------
23
+ global - - - - - - - - - -
24
+ valid lx-amd64 4 1 4 4 0.31 15.6G 422.9M 1.5G 0.0
25
+ unknown lx-amd64 14 - - - - 7.7G - 1.5G -
26
+ `
27
+
19
28
Context ("ParseQhostOutput" , func () {
20
29
21
30
It ("should return error if output is invalid" , func () {
@@ -46,6 +55,35 @@ exec lx-amd64 4 1 4 4 0.31 15.6G 422.9M
46
55
Expect (hosts [1 ].SWAPUS ).To (Equal (int64 (0.0 )))
47
56
})
48
57
58
+ It ("should parse without issues when host is unknown" , func () {
59
+ hosts , err := qhost .ParseHosts (sampleWithUnknownHost )
60
+ Expect (err ).To (BeNil ())
61
+ Expect (hosts ).To (HaveLen (2 ))
62
+ Expect (hosts [0 ].Name ).To (Equal ("valid" ))
63
+ Expect (hosts [0 ].Arch ).To (Equal ("lx-amd64" ))
64
+ Expect (hosts [0 ].NCPU ).To (Equal (4 ))
65
+ Expect (hosts [0 ].NSOC ).To (Equal (1 ))
66
+ Expect (hosts [0 ].NCOR ).To (Equal (4 ))
67
+ Expect (hosts [0 ].NTHR ).To (Equal (4 ))
68
+ Expect (hosts [0 ].LOAD ).To (Equal (0.31 ))
69
+ Expect (hosts [0 ].MEMTOT ).To (Equal (int64 (156 * 1024 * 1024 * 1024 / 10 )))
70
+ Expect (hosts [0 ].MEMUSE ).To (Equal (int64 (4229 * 1024 * 1024 / 10 )))
71
+ Expect (hosts [0 ].SWAPTO ).To (Equal (int64 (1.5 * 1024 * 1024 * 1024 )))
72
+ Expect (hosts [0 ].SWAPUS ).To (Equal (int64 (0.0 )))
73
+ Expect (hosts [1 ].Name ).To (Equal ("unknown" ))
74
+ Expect (hosts [1 ].Arch ).To (Equal ("lx-amd64" ))
75
+ Expect (hosts [1 ].NCPU ).To (Equal (14 ))
76
+ Expect (hosts [1 ].NSOC ).To (Equal (0 ))
77
+ Expect (hosts [1 ].NCOR ).To (Equal (0 ))
78
+ Expect (hosts [1 ].NTHR ).To (Equal (0 ))
79
+ Expect (hosts [1 ].LOAD ).To (Equal (0.0 ))
80
+ Expect (hosts [1 ].MEMTOT ).To (Equal (int64 (77 * 1024 * 1024 * 1024 / 10 )))
81
+ Expect (hosts [1 ].MEMUSE ).To (Equal (int64 (0 )))
82
+ Expect (hosts [1 ].SWAPTO ).To (Equal (int64 (1.5 * 1024 * 1024 * 1024 )))
83
+ Expect (hosts [1 ].SWAPUS ).To (Equal (int64 (0.0 )))
84
+
85
+ })
86
+
49
87
})
50
88
51
89
Context ("ParseHostFullMetrics" , func () {
@@ -435,6 +473,9 @@ master lx-amd64 14 1 14 14 1.50 7.7G 2.0G 1
435
473
hl:np_load_short=0.119286
436
474
hl:np_load_medium=0.107143
437
475
hl:np_load_long=0.078571
476
+ unknown lx-amd64 14 - - - - 7.7G - 1024.0M -
477
+ hl:arch=lx-amd64
478
+ hl:num_proc=14.000000
438
479
`
439
480
440
481
It ("should return error if output is invalid" , func () {
@@ -455,20 +496,12 @@ master lx-amd64 14 1 14 14 1.50 7.7G 2.0G 1
455
496
It ("should parse host full metrics with global host values" , func () {
456
497
hosts , err := qhost .ParseHostFullMetrics (qhostFOutput2 )
457
498
Expect (err ).To (BeNil ())
458
- Expect (hosts ).To (HaveLen (2 ))
499
+ Expect (hosts ).To (HaveLen (3 ))
459
500
Expect (hosts [0 ].Name ).To (Equal ("global" ))
460
501
Expect (hosts [1 ].Name ).To (Equal ("master" ))
461
- Expect (len (hosts [0 ].Resources )).To (Equal (1 ))
462
- Expect (hosts [0 ].Resources ["testc" ]).To (Equal (
463
- qhost.ResourceAvailability {
464
- Name : "testc" ,
465
- StringValue : "100000.000000" ,
466
- FloatValue : 100000.000000 ,
467
- ResourceAvailabilityLimitedBy : "g" ,
468
- Source : "c" ,
469
- FullString : "gc:testc=100000.000000" ,
470
- },
471
- ))
502
+ Expect (hosts [2 ].Name ).To (Equal ("unknown" ))
503
+ Expect (len (hosts [2 ].Resources )).To (Equal (0 ))
504
+ Expect (hosts [2 ].MemUsed ).To (Equal (int64 (0 )))
472
505
})
473
506
474
507
})
0 commit comments