-
Notifications
You must be signed in to change notification settings - Fork 12
/
koet.py
executable file
·2005 lines (1848 loc) · 69.8 KB
/
koet.py
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
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
import json
import os
import sys
import socket
import datetime
import subprocess
import platform
import shlex
import time
from shutil import copyfile
from decimal import Decimal
import argparse
import operator
from math import sqrt, ceil
from functools import reduce
import re
import csv
# Colorful constants
RED = '\033[91m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
NOCOLOR = '\033[0m'
# KPI + runtime acceptance values
MAX_AVG_LATENCY = 1.00 # Acceptance value should be 1 msec or less
FPING_COUNT = 500 # Acceptance value should be 500 or more
PERF_RUNTIME = 1200 # Acceptance value should be 1200 or more
MIN_NSD_THROUGHPUT = 2000 # Acceptance value with lots of margin
# GITHUB URL
GIT_URL = "https://github.com/IBM/SpectrumScale_NETWORK_READINESS"
# IP RE
IPPATT = re.compile('.*inet\s+(?P<ip>.*)\/\d+')
# devnull redirect destination
DEVNULL = open(os.devnull, 'w')
# This script version, independent from the JSON versions
KOET_VERSION = "1.17"
raw_input = input
PYTHON3 = True
if PYTHON3:
import statistics
try:
import distro
except ImportError:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Cannot import distro. Check python3-distro is installed\n")
def load_json(json_file_str):
# Loads JSON into a dictionary or quits the program if it cannot. Future
# might add a try to donwload the JSON if not available before quitting
try:
with open(json_file_str, "r") as json_file:
json_variable = json.load(json_file)
return json_variable
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Cannot open JSON file: " + json_file_str)
def json_file_loads(json_file_str):
# We try to load the JSON and return the success of failure
try:
with open(json_file_str, "r") as json_file_test:
json_variable = json.load(json_file_test)
json_file_test.close()
json_loads = True
except Exception:
json_loads = False
return json_loads
def write_json_file_from_dictionary(hosts_dictionary, json_file_str):
# We are going to generate or overwrite the hosts JSON file
try:
with open(json_file_str, "w") as json_file:
json.dump(hosts_dictionary, json_file)
print(GREEN + "OK: " + NOCOLOR + "JSON file: " + json_file_str +
" [over]written")
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Cannot write JSON file: " + json_file_str)
def check_localnode_is_in(hosts_dictionary):
localNode = None
try:
raw_out = os.popen("ip addr show").read()
except BaseException:
sys.exit(RED + "QUIT: " + NOCOLOR + "cannot list ip " +
"address on local node\n")
# create a list of allip addresses for local node
iplist = IPPATT.findall(raw_out)
# check for match with one of input ip addresses
for node in hosts_dictionary.keys():
if node in iplist:
localNode = node
break
if localNode is None:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Local node is not part of the test\n")
def estimate_runtime(hosts_dictionary, fp_count, perf_runtime):
number_of_hosts = len(hosts_dictionary)
estimated_rt_fp = number_of_hosts * fp_count
# use number of hosts + 1 to include N:N iteration of nsdperf
# add 20 sec per node as startup, shutdown, compile overhead
estimated_rt_perf = (number_of_hosts + 1) * (20 + perf_runtime)
estimated_runtime = estimated_rt_fp + estimated_rt_perf
# minutes we always return 2 even for short test runs
estimated_runtime_minutes = int(ceil(estimated_runtime / 60.))
return max(estimated_runtime_minutes, 2)
def parse_arguments():
parser = argparse.ArgumentParser()
# We include number of runs and KPI as optional arguments
parser.add_argument(
'-l',
'--latency',
action='store',
dest='max_avg_latency',
help='The KPI latency value as float. ' +
'The maximum required value for certification is ' +
str(MAX_AVG_LATENCY) +
' msec',
metavar='KPI_LATENCY',
type=float,
default=1.0)
parser.add_argument(
'-c',
'--fping_count',
action='store',
dest='fping_count',
help='The number of fping counts to run per node and test. ' +
'The value has to be at least 2 seconds.' +
'The minimum required value for certification is ' +
str(FPING_COUNT),
metavar='FPING_COUNT',
type=int,
default=500)
parser.add_argument(
'--hosts',
action='store',
dest='hosts',
help='IP addresses of hosts on CSV format. ' +
'Using this overrides the hosts.json file.',
metavar='HOSTS_CSV',
type=str,
default="")
parser.add_argument(
'-m',
'--min_throughput',
action='store',
dest='perf_throughput',
help='The minimum MB/sec required to pass the test. ' +
'The minimum required value for certification is ' +
str(MIN_NSD_THROUGHPUT),
metavar='KPI_THROUGHPUT',
type=int,
default=2000)
parser.add_argument(
'-p',
'--perf_runtime',
action='store',
dest='perf_runtime',
help='The seconds of nsdperf runtime per test. ' +
'The value has to be at least 10 seconds. ' +
'The minimum required value for certification is ' +
str(PERF_RUNTIME),
metavar='PERF_RUNTIME',
type=int,
default=1200)
parser.add_argument(
'--rdma',
action='store',
dest='rdma',
help='Enables RDMA and ports to be check on CSV format ' +
'(ib0,ib1,...). Must be using OS device names, not mlx names.',
metavar='PORTS_CSV',
default="")
parser.add_argument(
'--rpm_check_disabled',
action='store_true',
dest='no_rpm_check',
help='Disables the RPM prerequisites check. Use only if you are ' +
'sure all required software is installed and no RPM were used ' +
'to install the required prerequisites',
default=False)
parser.add_argument(
'--save-hosts',
action='store_true',
dest='save_hosts',
help='[over]writes hosts.json with the hosts passed with ' +
'--hosts. It does not prompt for confirmation when overwriting',
default=False)
parser.add_argument('-v', '--version', action='version',
version='KOET ' + KOET_VERSION)
args = parser.parse_args()
if args.max_avg_latency <= 0:
sys.exit(RED + "QUIT: " + NOCOLOR +
"KPI latency cannot be zero or negative number\n")
if args.fping_count <= 1:
sys.exit(RED + "QUIT: " + NOCOLOR +
"fping count cannot be less than 2\n")
if args.perf_throughput <= 0:
sys.exit(RED + "QUIT: " + NOCOLOR +
"KPI throughput cannot be zero or negative number\n")
if args.perf_runtime <= 9:
sys.exit(RED + "QUIT: " + NOCOLOR +
"nsdperf runtime cannot be less than 10 seconds\n")
if 'mlx' in args.rdma:
sys.exit(RED + "QUIT: " + NOCOLOR +
"RDMA ports must be OS names (ib0,ib1,...)\n")
# we check is a CSV string and if so we put it on dictionary
cli_hosts = False
hosts_dictionary = {}
if args.hosts != "":
cli_hosts = True
try:
host_raw = args.hosts
hosts = host_raw.split(",")
for host_key in hosts:
hosts_dictionary.update({host_key: "ECE"})
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"hosts parameter is not on CSV format")
rdma_ports_list = []
if args.rdma != "":
rdma_test = True
rdma_ports_raw = args.rdma
try:
rdma_ports_list = rdma_ports_raw.split(",")
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"rdma parameter is not on CSV format")
else:
rdma_test = False
if args.save_hosts and not cli_hosts:
sys.exit(RED + "QUIT: " + NOCOLOR +
"cannot generate hosts file if hosts not passed with --hosts")
return (round(args.max_avg_latency, 2), args.fping_count,
args.perf_runtime, args.perf_throughput,
cli_hosts, hosts_dictionary, rdma_test, rdma_ports_list,
args.no_rpm_check, args.save_hosts)
def check_kpi_is_ok(max_avg_latency, fping_count, perf_bw, perf_rt):
if max_avg_latency > MAX_AVG_LATENCY:
latency_kpi_certifies = False
else:
latency_kpi_certifies = True
if fping_count < FPING_COUNT:
fping_count_certifies = False
else:
fping_count_certifies = True
if perf_bw < MIN_NSD_THROUGHPUT:
perf_bw_certifies = False
else:
perf_bw_certifies = True
if perf_rt < PERF_RUNTIME:
perf_rt_certifies = False
else:
perf_rt_certifies = True
return (latency_kpi_certifies, fping_count_certifies, perf_bw_certifies,
perf_rt_certifies)
def show_header(koet_h_version, json_version,
estimated_runtime_str, max_avg_latency,
fping_count, perf_throughput, perf_runtime):
# Say hello and give chance to disagree
while True:
print("")
print(GREEN + "Welcome to KOET, version " + koet_h_version + NOCOLOR)
print("")
print("JSON files versions:")
print("\tsupported OS:\t\t" + json_version['supported_OS'])
print("\tpackages: \t\t" + json_version['packages'])
print("\tpackages RDMA:\t\t" + json_version['packages_rdma'])
print("")
print("Please use " + GIT_URL +
" to get latest versions and report issues about this tool.")
print("")
print(
"The purpose of KOET is to obtain network metrics " +
"for a number of nodes.")
print("")
lat_kpi_ok, fping_kpi_ok, perf_kpi_ok, perf_rt_ok = check_kpi_is_ok(
max_avg_latency, fping_count, perf_throughput, perf_runtime)
if lat_kpi_ok:
print(GREEN + "The latency KPI value of " + str(max_avg_latency) +
" msec is good to certify the environment" + NOCOLOR)
else:
print(
YELLOW +
"WARNING: " +
NOCOLOR +
"The latency KPI value of " +
str(max_avg_latency) +
" msec is too high to certify the environment")
print("")
if fping_kpi_ok:
print(
GREEN +
"The fping count value of " +
str(fping_count) +
" ping per test and node is good to certify the " +
"environment" + NOCOLOR)
else:
print(
YELLOW +
"WARNING: " +
NOCOLOR +
"The fping count value of " +
str(fping_count) +
" ping per test and node is not enough " +
"to certify the environment")
print("")
if perf_kpi_ok:
print(
GREEN +
"The throughput value of " +
str(perf_throughput) +
" MB/sec is good to certify the environment" +
NOCOLOR)
else:
print(
YELLOW +
"WARNING: " +
NOCOLOR +
"The throughput value of " +
str(perf_throughput) +
" MB/sec is not enough to certify the environment")
print("")
if perf_rt_ok:
print(
GREEN +
"The performance runtime value of " +
str(perf_runtime) +
" second per test and node is good to certify the " +
"environment" + NOCOLOR)
else:
print(
YELLOW +
"WARNING: " +
NOCOLOR +
"The performance runtime value of " +
str(perf_runtime) +
" second per test and node is not enough " +
"to certify the environment")
print("")
print(
YELLOW +
"It requires remote ssh passwordless between all nodes for user " +
"root already configured" +
NOCOLOR)
print("")
print(YELLOW + "This test run estimation is " +
estimated_runtime_str + " minutes" + NOCOLOR)
print("")
print(
RED +
"This software comes with absolutely no warranty of any kind. " +
"Use it at your own risk" +
NOCOLOR)
print("")
print(
RED +
"NOTE: The bandwidth numbers shown in this tool are for a very " +
"specific test. This is not a storage benchmark." +
NOCOLOR)
print(
RED +
"They do not necessarily reflect the numbers you would see with " +
"Spectrum Scale and your particular workload" +
NOCOLOR)
print("")
run_this = raw_input("Do you want to continue? (y/n): ")
if run_this.lower() == 'y':
break
if run_this.lower() == 'n':
print
sys.exit("Have a nice day! Bye.\n")
print("")
def check_os_redhat(os_dictionary):
redhat8 = False
# Check redhat-release vs dictionary list
redhat_distribution = platform.linux_distribution()
redhat_distribution_str = redhat_distribution[0] + \
" " + redhat_distribution[1]
error_message = RED + "QUIT: " + NOCOLOR + " " + \
redhat_distribution_str + " is not a supported OS for this tool\n"
try:
if os_dictionary[redhat_distribution_str] == 'OK':
#print(GREEN + "OK: " + NOCOLOR + redhat_distribution_str +
# " is a supported OS for this tool")
#print("")
if "8." in redhat_distribution[1]:
redhat8 = True
else:
sys.exit(error_message)
except Exception:
sys.exit(error_message)
return redhat8
def get_json_versions(
os_dictionary,
packages_dictionary,
packages_rdma_dict):
# Gets the versions of the json files into a dictionary
json_version = {}
# Lets see if we can load version, if not quit
try:
json_version['supported_OS'] = os_dictionary['json_version']
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Cannot load version from supported OS JSON")
try:
json_version['packages'] = packages_dictionary['json_version']
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Cannot load version from packages JSON")
try:
json_version['packages_rdma'] = packages_rdma_dict['json_version']
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Cannot load version from packages RDMA JSON")
# If we made it this far lets return the dictionary. This was being stored
# in its own file before
return json_version
def check_distribution():
# Decide if this is a redhat or a CentOS. We only checking the running
# node, that might be a problem
if PYTHON3:
what_dist = distro.distro_release_info()['id']
else:
what_dist = platform.dist()[0]
if what_dist == "redhat" or "centos":
return what_dist
else: # everything esle we fail
sys.exit(RED + "QUIT: " + NOCOLOR +
"this only runs on RedHat at this moment")
def ssh_rpm_is_installed(host, rpm_package):
# returns the RC of rpm -q rpm_package or quits if it cannot run rpm
errors = 0
try:
return_code = subprocess.call(['ssh',
'-o',
'StrictHostKeyChecking=no',
'-o',
'LogLevel=error',
host,
'rpm',
'-q',
rpm_package],
stdout=DEVNULL,
stderr=DEVNULL)
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"cannot run rpm over ssh on host " + host)
return return_code
def ssh_service_is_up(host, service_name):
try:
return_code = subprocess.call(['ssh',
'-o',
'StrictHostKeyChecking=no',
'-o',
'LogLevel=error',
host,
'systemctl',
'is-active',
'--quiet',
service_name],
stdout=DEVNULL,
stderr=DEVNULL)
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"cannot run systemctl over ssh on host " + host)
if return_code == 0:
service_is_up = True
else:
service_is_up = False
return service_is_up
def firewalld_check(hosts_dictionary):
# Checks if if firewalld is up on any node
errors = 0
for host in hosts_dictionary.keys():
firewalld_is_up = ssh_service_is_up(host, "firewalld")
if firewalld_is_up:
print(
RED +
"ERROR: " +
NOCOLOR +
"on host " +
host +
" the firewalld service is running")
errors = errors + 1
else:
print(
GREEN +
"OK: " +
NOCOLOR +
"on host " +
host +
" the firewalld service is not running" )
if errors > 0:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Fix the firewalld status before running this tool again.\n")
def check_tcp_port_free(hosts_dictionary, tcpport):
errors = 0
# Checks certain port is not in use
for host in hosts_dictionary.keys():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)
openit = sock.connect_ex((host, tcpport))
if openit == 0: # I can connect so it is NOT free
errors = errors + 1
print(RED +
"ERROR: " +
NOCOLOR +
"on host " +
str(host) +
" TCP port " +
str(tcpport) +
" seems to be not free")
else: # cannot connect so not in used or not accesible
print(
GREEN +
"OK: " +
NOCOLOR +
"on host " +
str(host) +
" TCP port " +
str(tcpport) +
" seems to be free")
if errors > 0:
sys.exit(RED + "QUIT: " + NOCOLOR +
"TCP port " + str(tcpport) + " is not free in all hosts")
def check_permission_files():
#Check executable bits and read bits for files
readable_files=["hosts.json", "makefile", "nsdperf.C", "packages.json",
"packages_rdma.json", "packages_rdma_rh8.json",
"supported_OS.json"]
executable_files=["nsdperfTool.py"]
read_error = False
for file in readable_files:
if not os.access(file,os.R_OK):
read_error = True
print(RED +
"ERROR: " +
NOCOLOR +
"cannot read file " +
str(file) +
". Have the POSIX ACL been changed?")
exec_error = False
for file in executable_files:
if not os.access(file,os.X_OK):
exec_error = True
print(RED +
"ERROR: " +
NOCOLOR +
"cannot execute file " +
str(file) +
". Have the POSIX ACL been changed?")
if read_error or exec_error:
fatal_error = True
else:
fatal_error = False
return fatal_error
def host_packages_check(hosts_dictionary, packages_dictionary):
# Checks if packages from JSON are installed or not based on the input
# data ont eh JSON
errors = 0
for host in hosts_dictionary.keys():
for rpm_package in packages_dictionary.keys():
if rpm_package != "json_version":
current_package_rc = ssh_rpm_is_installed(host, rpm_package)
expected_package_rc = packages_dictionary[rpm_package]
if current_package_rc == expected_package_rc:
print(
GREEN +
"OK: " +
NOCOLOR +
"on host " +
host +
" the " +
rpm_package +
" installation status is as expected")
else:
print(
RED +
"ERROR: " +
NOCOLOR +
"on host " +
host +
" the " +
rpm_package +
" installation status is *NOT* as expected")
errors = errors + 1
if errors > 0:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Fix the packages before running this tool again.\n")
def ssh_file_exists(host, fileurl):
# returns the RC of ssh+ls of a file or quits if any error
try:
return_code = subprocess.call(['ssh',
'-o',
'StrictHostKeyChecking=no',
'-o',
'LogLevel=error',
host,
'which',
fileurl],
stdout=DEVNULL,
stderr=DEVNULL)
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"cannot run ls over ssh on host " + host)
return return_code
def ssh_rdma_ports_are_up(host, rdma_ports_list):
errors = 0
for port in rdma_ports_list:
return_code = subprocess.call(['ssh',
'-o',
'StrictHostKeyChecking=no',
'-o',
'LogLevel=error',
host,
'ibdev2netdev',
'|',
'grep',
port,
'|',
'grep',
'"(Up)"'],
stdout=DEVNULL,
stderr=DEVNULL)
if return_code == 0:
print(
GREEN +
"OK: " +
NOCOLOR +
"on host " +
host +
" the RDMA port " +
port +
" is on UP state")
else:
print(
RED +
"ERROR: " +
NOCOLOR +
"on host " +
host +
" the RDMA port " +
port +
" is *NOT* on UP state")
errors = errors + 1
if errors == 0:
all_ports_up = True
else:
all_ports_up = False
return all_ports_up
def check_rdma_port_mode(hosts_ports_dict):
errors = 0
for host in hosts_ports_dict.keys():
ssh_command = ('ssh -o StrictHostKeyChecking=no ' +
'-o LogLevel=error ' + host + ' ')
# we remove the port bit
for port in hosts_ports_dict[host].keys():
card_str = str(hosts_ports_dict[host][port].split('/')[0])
try:
raw_out = os.popen(
ssh_command + '/usr/sbin/ibstat ' +
card_str).read()
except BaseException:
sys.exit(RED + "QUIT: " + NOCOLOR +
"There was an issue to query rdma ports on "
+ host + "\n")
if 'Ethernet' in raw_out:
print(
RED +
"ERROR: " +
NOCOLOR +
"host " +
host +
" has Mellanox ports " +
port +
" on Ethernet mode")
errors = errors + 1
return errors
def map_ib_to_mlx(host, rdma_ports_list):
port_pair_dict = {}
ssh_command = ('ssh -o StrictHostKeyChecking=no ' +
'-o LogLevel=error ' + host + ' ')
try:
raw_os = os.popen(
ssh_command +
"ibdev2netdev|awk '{print$5}'").read()
raw_mlx = os.popen(
ssh_command +
"ibdev2netdev|awk '{print$1}'").read()
raw_port = os.popen(
ssh_command +
"ibdev2netdev|awk '{print$3}'").read()
except BaseException:
sys.exit(RED + "QUIT: " + NOCOLOR +
"There was an issue to query rdma cards on " + host + "\n")
raw_list_os = raw_os.strip().split("\n")
raw_list_mlx = raw_mlx.strip().split("\n")
raw_list_port = raw_port.strip().split("\n")
port_pair_dict = {osdev: '{}/{}'.format(raw_list_mlx[osidx],
raw_list_port[osidx])
for osidx, osdev in
enumerate(raw_list_os) if osdev in rdma_ports_list}
for osdev in port_pair_dict:
print(
GREEN +
"OK: " +
NOCOLOR +
"on host " +
host +
" the RDMA port " +
osdev +
" is CA " +
port_pair_dict[osdev])
return port_pair_dict
def check_rdma_ports_OS(host, port):
# Lets check we have the tool we need
try:
return_code = subprocess.call(['ssh',
'-o',
'StrictHostKeyChecking=no',
'-o',
'LogLevel=error',
host,
'ifconfig',
port],
stdout=DEVNULL,
stderr=DEVNULL)
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"cannot check port over ssh on host " + host)
if return_code == 0:
error = False
else:
error = True
return error
def check_rdma_tools(host, toolpath):
# Given the host returns a list of the IB ports on up status
errors = 0
# Lets check we have the tool we need
rc_tool = ssh_file_exists(host, toolpath)
if rc_tool == 0:
print(
GREEN +
"OK: " +
NOCOLOR +
"on host " +
host +
" the file " +
toolpath +
" exists")
else:
print(
RED +
"ERROR: " +
NOCOLOR +
"on host " +
host +
" the file " +
toolpath +
" does *NOT* exists")
errors = errors + 1
return errors
def unique_items_list(my_list):
unique_items_list = []
for item in my_list:
if item not in unique_items_list:
unique_items_list.append(item)
return unique_items_list
def create_mlx_csv(hosts_ports_dict, rdma_ports_list):
mlx_list = []
for host in hosts_ports_dict.keys():
for os_port in hosts_ports_dict[host].keys():
if os_port in rdma_ports_list:
mlx_list.append(hosts_ports_dict[host][os_port])
# so we have a list with mlx ports
mlx_list_unique = unique_items_list(mlx_list)
mlx_list_unique_csv = ','.join(mlx_list_unique)
return mlx_list_unique_csv
def check_rdma_ports(hosts_dictionary, rdma_ports_list):
errors_tool = 0
fatal_error = False
for host in hosts_dictionary.keys():
ibdev2netdev_filepath = "ibdev2netdev"
error_tool_ibdev = check_rdma_tools(host, ibdev2netdev_filepath)
ibstat_filepath = "ibstat"
error_tool_ibstat = check_rdma_tools(host, ibstat_filepath)
errors_tool = error_tool_ibdev + error_tool_ibstat
if errors_tool > 0:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Fix the missing files before running this tool again.\n")
# Lets see if does exist on the node or hard fail
not_OS_port = False
for host in hosts_dictionary.keys():
for port in rdma_ports_list:
not_OS_port = check_rdma_ports_OS(host, port)
if not_OS_port:
sys.exit(RED + "QUIT: " + NOCOLOR + "On host " +
str(host) + " port " + port + " not found\n")
# Lets check the ports are UP on all nodes, or fail
errors_ports = 0
errors_port_mode = 0
for host in hosts_dictionary.keys():
ports_are_up = ssh_rdma_ports_are_up(host, rdma_ports_list)
if not ports_are_up:
errors_ports = errors_ports + 1
if errors_ports > 0:
fatal_error = True
hosts_ports_dict = {}
for host in hosts_dictionary.keys():
hosts_ports_dict[host] = map_ib_to_mlx(host, rdma_ports_list)
# Create list of mlx ports
rdma_ports_csv_mlx = create_mlx_csv(hosts_ports_dict, rdma_ports_list)
# Check Ethernet mode and status UP
errors_port_mode = check_rdma_port_mode(hosts_ports_dict)
if errors_port_mode > 0:
sys.exit(RED + "QUIT: " + NOCOLOR +
"Fix the port mode or disconnect the link " +
"before running this tool again.\n")
return fatal_error, rdma_ports_csv_mlx
def is_IP_address(ip):
# Lets check is a full ip by counting dots
if ip.count('.') != 3:
return False
try:
socket.inet_aton(ip)
return True
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"cannot check IP address " + ip + "\n")
def check_hosts_are_ips(hosts_dictionary):
for host in hosts_dictionary.keys():
is_IP = is_IP_address(host)
if not is_IP:
sys.exit(
RED +
"QUIT: " +
NOCOLOR +
"on hosts JSON file or CLI parameter '" +
host +
"' is not a valid IPv4. Fix before running this tool again.\n")
def check_hosts_number(hosts_dictionary):
number_unique_hosts = len(hosts_dictionary)
number_unique_hosts_str = str(number_unique_hosts)
if len(hosts_dictionary) > 64 or len(hosts_dictionary) < 2:
sys.exit(
RED +
"QUIT: " +
NOCOLOR +
"the number of hosts is not valid. It is " +
number_unique_hosts_str +
" and should be between 2 and 64 unique hosts.\n")
def create_local_log_dir(log_dir_timestamp):
logdir = os.path.join(
os.getcwd(),
'log',
log_dir_timestamp)
try:
os.makedirs(logdir)
return logdir
except Exception:
sys.exit(RED + "QUIT: " + NOCOLOR +
"cannot create local directory " + logdir + "\n")
def create_log_dir(hosts_dictionary, log_dir_timestamp):
# datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
print ("Creating log dir on hosts:")
errors = 0
logdir = os.path.join(
os.getcwd(),
'log',
log_dir_timestamp)
for host in hosts_dictionary:
return_code = subprocess.call(['ssh',
'-o',
'StrictHostKeyChecking=no',
'-o',
'LogLevel=error',
host,
'mkdir',
'-p',
logdir],
stdout=DEVNULL,
stderr=DEVNULL)
if return_code == 0:
print(
GREEN +
"OK: " +
NOCOLOR +
"on host " +
host +
" logdir " +
logdir +
" has been created")
else:
print(
RED +
"ERROR: " +
NOCOLOR +
"on host " +
host +
" logdir " +
logdir +
" has *NOT* been created")
errors = errors + 1
if errors > 0:
sys.exit(RED +
"QUIT: " +
NOCOLOR +
"we cannot continue without all the log directories created")
else:
return logdir
def latency_test(hosts_dictionary, logdir, fping_count):
fping_count_str = str(fping_count)
hosts_fping = ""
for host in sorted(hosts_dictionary.keys()): # we ping ourselvels as well