/
ceph_utils.py
2173 lines (2084 loc) · 111 KB
/
ceph_utils.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/python
import platform
import os
import sys, select
import subprocess
import time
from distutils.version import LooseVersion
class SetupCephUtils(object):
global POOL_CRUSH_MAP
POOL_CRUSH_MAP = '/tmp/ma-crush-map-pool'
global POOL_CRUSH_MAP_TXT
POOL_CRUSH_MAP_TXT = '/tmp/ma-crush-map-pool.txt'
global POOL_CRUSH_MAP_MOD
POOL_CRUSH_MAP_MOD = '/tmp/ma-crush-map-pool-mod'
global POOL_CRUSH_MAP_MOD_TXT
POOL_CRUSH_MAP_MOD_TXT = '/tmp/ma-crush-map-pool-mod.txt'
global INIT_CRUSH_MAP
INIT_CRUSH_MAP = '/tmp/ma-crush-map-init'
global INIT_CRUSH_MAP_MOD
INIT_CRUSH_MAP_MOD = '/tmp/ma-crush-map-init-mod'
global INIT_CRUSH_MAP_TXT
INIT_CRUSH_MAP_TXT = '/tmp/ma-crush-map-init.txt'
global INIT_CRUSH_MAP_MOD_TXT
INIT_CRUSH_MAP_MOD_TXT = '/tmp/ma-crush-map-init-mod.txt'
global CS_CRUSH_MAP
CS_CRUSH_MAP = '/tmp/ma-crush-map-cs'
global CS_CRUSH_MAP_MOD
CS_CRUSH_MAP_MOD = '/tmp/ma-crush-map-cs-mod'
global CS_CRUSH_MAP_TXT
CS_CRUSH_MAP_TXT = '/tmp/ma-crush-map-cs.txt'
global CS_CRUSH_MAP_MOD_TXT
CS_CRUSH_MAP_MOD_TXT = '/tmp/ma-crush-map-cs-mod.txt'
global CS_CRUSH_MAP_MOD_TMP_TXT
CS_CRUSH_MAP_MOD_TMP_TXT = '/tmp/ma-crush-map-cs-mod-tmp.txt'
global CEPH_ADMIN_KEYRING
CEPH_ADMIN_KEYRING = '/etc/ceph/ceph.client.admin.keyring'
global RADOS_KEYRING
RADOS_KEYRING = '/etc/ceph/ceph.client.radosgw.keyring'
global CINDER_PATCH_FILE
CINDER_PATCH_FILE = '/tmp/manager.patch'
global CINDER_VOLUME_MGR_PY
CINDER_VOLUME_MGR_PY = '/usr/lib/python2.7/dist-packages/cinder/volume/manager.py'
global CEPH_DEPLOY_PATCH_FILE
CEPH_DEPLOY_PATCH_FILE = '/tmp/ceph_deploy.patch'
global ETC_CEPH_CONF
ETC_CEPH_CONF = '/etc/ceph/ceph.conf'
global RADOS_GW_LOG_FILE
RADOS_GW_LOG_FILE = '/var/log/radosgw/client.radosgw.gateway.log'
global RADOS_GW_FRONT_END
RADOS_GW_FRONT_END = 'fastcgi socket_port=9000 socket_host=0.0.0.0'
global RADOS_GW_SOCKET_PATH
RADOS_GW_SOCKET_PATH = '/var/run/ceph/ceph.radosgw.gateway.fastcgi.sock'
global LIB_RADOS_GW
LIB_RADOS_GW = '/var/lib/ceph/radosgw/ceph-radosgw.gateway'
global APACHE_RGW_CONF
APACHE_RGW_CONF = '/etc/apache2/conf-available/rgw.conf'
global OBJECT_STORAGE_USER_FILE
OBJECT_STORAGE_USER_FILE = '/etc/contrail/object_storage_swift_s3_auth.txt'
global TRUE
TRUE = 1
global FALSE
FALSE = 0
# Maximum number of pool that can be created for HDD and SSD
global MAX_POOL_COUNT
MAX_POOL_COUNT = 1024
global REPLICA_ONE
REPLICA_ONE = 1
global REPLICA_TWO
REPLICA_TWO = 2
global REPLICA_DEFAULT
REPLICA_DEFAULT = 2
# Host HDD/SSD dictionary/counters,
# populated during HDD/SSD pool configuration
global host_hdd_dict
host_hdd_dict = {}
global host_ssd_dict
host_ssd_dict = {}
global hdd_pool_count
hdd_pool_count = 0
global ssd_pool_count
ssd_pool_count = 0
# Chassis ruleset for each pool,
# populated during chassis configuration
# Used during pool configuration
global chassis_hdd_ruleset
chassis_hdd_ruleset = 0
global chassis_ssd_ruleset
chassis_ssd_ruleset = 0
# Crush id used during crush map changes
global crush_id
# HDD/SSD pool list, populated during HDD/SSD pool configuration
# Used during pool, virsh, pg/pgp count configurations
global ceph_pool_list
ceph_pool_list = []
global ceph_tier_list
ceph_tier_list = []
global ceph_object_store_pools
ceph_object_store_pools = ['.rgw.root',
'.rgw.control',
'.rgw.gc',
'.rgw.buckets',
'.rgw.buckets.index',
'.rgw.buckets.extra',
'.log',
'.intent-log',
'.usage',
'.users',
'.users.email',
'.users.swift',
'.users.uid',
'.rgw']
# Function to check if Chassis configuration is disabled or not
# Returns False if enabled
# Returns True if disabled
def is_chassis_disabled(self, chassis_config):
if chassis_config[0] == 'none':
return TRUE
else:
return FALSE
#end is_chassis_disabled()
# Function to check if multipool is disabled or not
# Returns False if enabled
# Returns True if disabled
# Checks for 'P' (for Pool) entry in the disk list in
# the 2nd or 3rd field.
def is_multi_pool_disabled(self, storage_disk_config,
storage_ssd_disk_config):
for disks in storage_disk_config:
journal_available = disks.count(':')
disksplit = disks.split(':')
diskcount = disks.count(':')
if diskcount == 3:
if disksplit[3][0] == 'P':
return FALSE
elif diskcount == 2:
if disksplit[2][0] == 'P':
return FALSE
for disks in storage_ssd_disk_config:
journal_available = disks.count(':')
disksplit = disks.split(':')
diskcount = disks.count(':')
if diskcount == 3:
if disksplit[3][0] == 'P':
return FALSE
elif diskcount == 2:
if disksplit[2][0] == 'P':
return FALSE
return TRUE
#end is_multi_pool_disabled()
# Function to check if SSD pool is disabled or not
# Returns False if enabled
# Returns True if disabled
def is_ssd_pool_disabled(self, storage_ssd_disk_config):
if storage_ssd_disk_config[0] == 'none':
return TRUE
else:
return FALSE
#end is_ssd_pool_disabled()
def exec_locals(self, arg):
ret = subprocess.Popen('%s' %(arg), shell=True,
stdout=subprocess.PIPE).stdout.read()
ret = ret[:-1]
return ret
#end exec_locals()
def exec_local(self, arg):
ret = subprocess.Popen('echo \"[localhost] local: %s\" 1>&2' %(arg), shell=True,
stdout=subprocess.PIPE).stdout.read()
ret = subprocess.Popen('%s' %(arg), shell=True,
stdout=subprocess.PIPE).stdout.read()
ret = ret[:-1]
return ret
#end exec_local()
# Function to set the PG count
# Verify whether the PGs are in creating state,
# else set the pg count to the new value
def set_pg_count_increment(self, pool, pg_count):
while True:
time.sleep(2);
creating_pgs = self.exec_local('sudo ceph -s | grep creating | wc -l')
if creating_pgs == '0':
break;
print 'Waiting for create pgs to complete'
self.exec_local('sudo ceph -k %s osd pool set %s pg_num %d'
%(CEPH_ADMIN_KEYRING, pool, pg_count))
#end set_pg_count_increment()
# Function to set the PGP count
# Verify whether the PGs are in creating state,
# else set the pgp count to the new value
def set_pgp_count_increment(self, pool, pg_count):
while True:
time.sleep(2);
creating_pgs = self.exec_local('sudo ceph -s | grep creating | wc -l')
if creating_pgs == '0':
break;
print 'Waiting for create pgs to complete'
self.exec_local('sudo ceph -k %s osd pool set %s pgp_num %d'
%(CEPH_ADMIN_KEYRING, pool, pg_count))
#end set_pgp_count_increment()
# First level Function to set the PG/PGP count
def set_pg_pgp_count(self, osd_num, pool, host_cnt):
# Calculate/Set PG count
# The pg/pgp set will not take into effect if ceph is already in the
# process of creating pgs. So its required to do ceph -s and check
# if the pgs are currently creating and if not set the values
# Set the num of pgs to 30 times the OSD count. This is based on
# Firefly release recomendation.
# Algorithm: PGs can be set to a incremental value of 30 times the
# current count. Set the value in increments matching 30 times the
# current value. Do this untill the value matches the required value
# of 30 times the OSD count.
while True:
time.sleep(5);
creating_pgs = self.exec_local('sudo ceph -s | grep creating | wc -l')
if creating_pgs == '0':
break;
print 'Waiting for create pgs to complete'
cur_pg = self.exec_local('sudo ceph -k %s osd pool get %s pg_num'
%(CEPH_ADMIN_KEYRING, pool))
cur_pg_cnt = int(cur_pg.split(':')[1])
max_pg_cnt = 30 * osd_num
if cur_pg_cnt >= max_pg_cnt:
return
while True:
cur_pg_cnt = 30 * cur_pg_cnt
if cur_pg_cnt > max_pg_cnt:
self.set_pg_count_increment(pool, max_pg_cnt)
break;
else:
self.set_pg_count_increment(pool, cur_pg_cnt)
# Set pgp count
while True:
time.sleep(5);
creating_pgs = self.exec_local('sudo ceph -s | grep creating | wc -l')
if creating_pgs == '0':
break;
print 'Waiting for create pgs to complete'
cur_pg = self.exec_local('sudo ceph -k %s osd pool get %s pgp_num'
%(CEPH_ADMIN_KEYRING, pool))
cur_pg_cnt = int(cur_pg.split(':')[1])
max_pg_cnt = 30 * osd_num
if cur_pg_cnt >= max_pg_cnt:
return
while True:
cur_pg_cnt = 30 * cur_pg_cnt
if cur_pg_cnt > max_pg_cnt:
self.set_pgp_count_increment(pool, max_pg_cnt)
break;
else:
self.set_pgp_count_increment(pool, cur_pg_cnt)
#end set_pg_pgp_count()
# Initialize Crush map to the Original state
# The crush map is initialized to the original state
# for further processing with multi-pool and chassis configurations
# This is done maintain the crush ids across multiple runs of the
# configuration.
# The function will get each line from 0 and writes to a new file
# INIT_CRUSH_MAP_MOD_TXT. All the host entries untill the "root default"
# entry are written to the new file and the new cursh is returned.
# The crush ids for each entry is re-initialized starting from 1 which
# is set for the "root default"
# Return value: modified crush.
# Note: This function doesnot apply the crush map
def initialize_crush(self):
global crush_id
self.exec_local('sudo ceph osd getcrushmap -o %s' %(INIT_CRUSH_MAP))
self.exec_local('sudo crushtool -d %s -o %s'
%(INIT_CRUSH_MAP, INIT_CRUSH_MAP_TXT))
# Reinitialize ids to avoid duplicates and unused
root_def_id = 1
crush_id = root_def_id + 1
default_reached = 0
line_num = 0
self.exec_local('echo "# Start" > %s' %(INIT_CRUSH_MAP_MOD_TXT))
while True:
# Get each line from the existing crush map
item_line = self.exec_local('cat %s | tail -n +%d | head -n 1'
%(INIT_CRUSH_MAP_TXT, line_num))
# Check if "root default" is reached.
if item_line.find('root default') != -1:
default_reached = 1
self.exec_local('echo %s >> %s' %(item_line, INIT_CRUSH_MAP_MOD_TXT))
# If the end '}' of "root default" is found, the new map can be
# returned
elif item_line.find('}') != -1:
self.exec_local('echo %s >> %s' %(item_line, INIT_CRUSH_MAP_MOD_TXT))
if default_reached == 1:
break
# Reinitialize the ids starting from 1. Use 1 for the "root default"
elif item_line.find('id -') != -1:
if default_reached == 1:
self.exec_local('echo " id -%d" >> %s' %(root_def_id,
INIT_CRUSH_MAP_MOD_TXT))
else:
self.exec_local('echo " id -%d" >> %s' %(crush_id,
INIT_CRUSH_MAP_MOD_TXT))
crush_id += 1
else:
self.exec_local('echo %s >> %s' %(item_line, INIT_CRUSH_MAP_MOD_TXT))
line_num += 1
# Compile the text file and return the crush map.
# This is done so that the intermediate text map is stored for debug
self.exec_local('sudo crushtool -c %s -o %s' %(INIT_CRUSH_MAP_MOD_TXT,
INIT_CRUSH_MAP_MOD))
return INIT_CRUSH_MAP_MOD
#end initialize_crush
# Function to apply the crush map after all the modifications
def apply_crush(self, input_crush):
# Apply crush map and return
self.exec_local('sudo ceph -k %s osd setcrushmap -i %s' %(CEPH_ADMIN_KEYRING,
input_crush))
return
#end apply_crush
# Crush map modification for Chassis support
# This ensures that the replica will not happen between nodes
# in a single chassis.
# The Chassis id given in the testbed.py for each host will
# be used to create virtual groups. Replica will not happen between hosts
# of the same chassis id.
# For eg., consider a Quanta system that has 4 nodes in a single chassis.
# All the nodes in a single chassis should be given the same chassis id.
# Based on the chassis id, a hdd-chassis-<chassis-id> entry will be
# created. The hdd-chassis-<x> will have the list hosts that are in the
# Chassis.
# The root entry for default/hdd(incase of hdd/ssd pools will be
# modified to use hdd-chassis-<x>
# instead of using the host directly.
# The leaf in the rule will be set to use chassis instead of host.
# Original crush map will be as below for a no hdd/ssd pool.
# host cmbu-ceph-1 {
# ...
# }
# host cmbu-ceph-2 {
# ...
# }
# host cmbu-ceph-3 {
# ...
# }
# host cmbu-ceph-4 {
# ...
# }
# root default {
# ...
# item cmbu-ceph-1 weight 1.090
# item cmbu-ceph-2 weight 1.090
# item cmbu-ceph-3 weight 1.090
# item cmbu-ceph-4 weight 1.090
# }
# rule replicated_ruleset {
# ...
# step chooseleaf firstn 0 type host
# step emit
# }
# Consider each chassis has 2 nodes. Host1 and Host2 are in same chassis.
# Host3 and Host4 are in a different chassis. Replica should not happen
# between Host1 and Host2, similarly it should not happen between Host3
# and Host4.
# So the above crushmap will be modified to the following
# host cmbu-ceph-1 {
# ...
# }
# host cmbu-ceph-2 {
# ...
# }
# host cmbu-ceph-3 {
# ...
# }
# host cmbu-ceph-4 {
# ...
# }
# chassis hdd-chassis-0 {
# ...
# item cmbu-ceph-1 weight 1.090
# item cmbu-ceph-2 weight 1.090
# }
# chassis hdd-chassis-1 {
# ...
# item cmbu-ceph-3 weight 1.090
# item cmbu-ceph-4 weight 1.090
# }
# root default {
# ...
# item hdd-chassis-0 weight 2.180
# item hdd-chassis-1 weight 2.180
# }
# rule replicated_ruleset {
# ...
# step chooseleaf firstn 0 type chassis
# step emit
# }
#
# The above change will ensure that the chassis is the leaf node, which
# means that the replica created for an object in cmbu-ceph-1 will not
# be created under cmb-ceph-2 as they belong to the same chassis. Instead
# it will be put under a node in hdd-chassis-1
# This code is Idempotent.
def do_chassis_config(self, input_crush, hosts, chassis_config):
global crush_id
global chassis_hdd_ruleset
global chassis_ssd_ruleset
if self.is_chassis_disabled(chassis_config) == True:
return input_crush
if input_crush == 'none':
# Get the decoded crush map in txt format
self.exec_local('sudo ceph osd getcrushmap -o %s' %(CS_CRUSH_MAP))
self.exec_local('sudo crushtool -d %s -o %s'
%(CS_CRUSH_MAP, CS_CRUSH_MAP_TXT))
else:
crush_present = self.exec_local('ls %s | wc -l' %(input_crush))
if crush_present == '0':
print 'Crush map not present. Aborting'
sys.exit(-1)
self.exec_local('sudo crushtool -d %s -o %s' %(input_crush, CS_CRUSH_MAP_TXT))
crush_txt_present = self.exec_local('ls %s | wc -l' %(CS_CRUSH_MAP_TXT))
if crush_txt_present == '0':
print 'Crush map not present. Aborting'
sys.exit(-1)
# If multipool is enabled, we cannot configure chassis
multipool_enabled = self.exec_local('sudo cat %s | grep hdd-P|wc -l'
%(CS_CRUSH_MAP_TXT))
if multipool_enabled != '0':
print 'Cannot have both multipool and Chassis config'
return input_crush
multipool_enabled = self.exec_local('sudo cat %s | grep ssd-P|wc -l'
%(CS_CRUSH_MAP_TXT))
if multipool_enabled != '0':
print 'Cannot have both multipool and Chassis config'
return input_crush
# Populate the chassis list with chassis id, indexed by hostname.
host_chassis_info = {}
chassis_list = {}
chassis_count = 0
for hostname in hosts:
# The chassis_config is the list of host:chassis.
# for eg: --storage-chassis-config host1:0 host2:0 host3:1 host4:1
# The loop goes over the entries and finds unique chassis id and
# creates the list 'chassis_list' indexed with an incrementing
# starting from 0.
for chassis in chassis_config:
chassissplit = chassis.split(':')
if chassissplit[0] == hostname:
host_chassis_info[hostname] = chassissplit[1]
#print 'Chassis - %s %s' %(hostname, chassissplit[1])
if chassis_count == 0:
chassis_list['%d' %(chassis_count)] = chassissplit[1]
chassis_count = chassis_count + 1
else:
tmp_chassis_count = 0
while tmp_chassis_count < chassis_count:
if chassis_list['%d' %(tmp_chassis_count)] == \
chassissplit[1]:
break
tmp_chassis_count = tmp_chassis_count + 1
if tmp_chassis_count >= chassis_count:
chassis_list['%d' %(chassis_count)] = \
chassissplit[1]
chassis_count = chassis_count + 1
# Find if we have HDD/SSD pools configured.
# If SSD pool is enabled, then it means that we have two pools
# otherwise there is only one pool, which is the 'default' pool.
ssd_pool_enabled = self.exec_local('sudo cat %s | grep "root ssd"|wc -l'
%(CS_CRUSH_MAP_TXT))
root_entries = []
pool_enabled = 0
if ssd_pool_enabled != '0':
pool_enabled = 1
root_entries.append('hdd')
root_entries.append('ssd')
else:
root_entries.append('default')
# The "root default", "root hdd" and the "root ssd" are the original root
# entries that has to be preserved, so that the hdd/ssd pool code or
# Ceph's osd add code will use them. Also the chassis code will look at
# the values in these entries and use them for the chassis
# configuration.
# Find Root default entry start and end.
# This will be maintained across modifications
def_line_str = self.exec_local('cat %s|grep -n ^root | grep -w default | tail -n 1'
%(CS_CRUSH_MAP_TXT))
def_line_start = int(def_line_str.split(':')[0])
def_line_end = def_line_start
while True:
item_line = self.exec_local('cat %s | tail -n +%d | head -n 1'
%(CS_CRUSH_MAP_TXT, def_line_end))
if item_line.find('}') != -1:
break
def_line_end += 1
# Find the "root hdd" entry start and end.
# This will be maintained across modifications
rhdd_line_str = self.exec_local('cat %s|grep -n ^root | grep -w hdd | tail -n 1'
%(CS_CRUSH_MAP_TXT))
rhdd_line_start = 0
rhdd_line_end = 0
if rhdd_line_str != '':
rhdd_line_start = int(rhdd_line_str.split(':')[0])
rhdd_line_end = rhdd_line_start
while True:
item_line = self.exec_local('cat %s | tail -n +%d | head -n 1'
%(CS_CRUSH_MAP_TXT, rhdd_line_end))
if item_line.find('}') != -1:
break
rhdd_line_end += 1
# Find the "root ssd" entry start and end.
# This will be maintained across modifications
rssd_line_str = self.exec_local('cat %s|grep -n ^root | grep -w ssd | tail -n 1'
%(CS_CRUSH_MAP_TXT))
rssd_line_start = 0
rssd_line_end = 0
if rssd_line_str != '':
rssd_line_start = int(rssd_line_str.split(':')[0])
rssd_line_end = rssd_line_start
while True:
item_line = self.exec_local('cat %s | tail -n +%d | head -n 1'
%(CS_CRUSH_MAP_TXT, rssd_line_end))
if item_line.find('}') != -1:
break
rssd_line_end += 1
# Find if there are any host configurations after the "root default"
# These are the hosts for the hdd/ssd pool and has to be maintained
# across modifications
# The following code greps for the 'host' entry after the "root default"
# entry and finds the line number which is storaged in host_line_start.
# It then finds the last 'host' entry and find the end of the entry by
# searching for the '}'. These host entries if present, should have been
# added as part of the HDD/SSD pool. These entries have to be preserved
# without any modifications. By finding the start and end, the whole
# section will be added to the modified crush map file.
host_line_str = self.exec_local('cat %s | tail -n +%d | grep -n ^host |head -n 1'
%(CS_CRUSH_MAP_TXT, def_line_start))
host_line_start = 0
host_line_end = 0
if host_line_str != '':
host_line_start = def_line_start + \
int(host_line_str.split(':')[0]) - 1
host_line_end_str = self.exec_local('cat %s | tail -n +%d | grep -n ^host | \
tail -n 1'
%(CS_CRUSH_MAP_TXT, def_line_start))
host_line_end = def_line_start + \
int(host_line_end_str.split(':')[0])
while True:
item_line = self.exec_local('cat %s | tail -n +%d | head -n 1'
%(CS_CRUSH_MAP_TXT, host_line_end))
if item_line.find('}') != -1:
break
host_line_end += 1
# Check if there is already a chassis configuration
# If present ignore as we'll create again.
skip_line_str = self.exec_local('cat %s|grep -n ^chassis |head -n 1'
%(CS_CRUSH_MAP_TXT))
if skip_line_str != '':
skip_line_num = int(skip_line_str.split(':')[0])
if skip_line_num > def_line_start:
skip_line_num = def_line_start
else:
skip_line_num = def_line_start
# Start populating the modified Crush map
# First populate from beginning till the "root default"
self.exec_local('cat %s | head -n %d > %s' %(CS_CRUSH_MAP_TXT,
(skip_line_num -1), CS_CRUSH_MAP_MOD_TXT))
# Populate "root default"
self.exec_local('cat %s | tail -n +%d | head -n %d >> %s' %(CS_CRUSH_MAP_TXT,
def_line_start, (def_line_end - def_line_start + 1),
CS_CRUSH_MAP_MOD_TXT))
# Populate host entries for hdd/ssd
if host_line_start != 0:
self.exec_local('cat %s | tail -n +%d | head -n %d >> %s' %(CS_CRUSH_MAP_TXT,
host_line_start, (host_line_end - host_line_start + 1),
CS_CRUSH_MAP_MOD_TXT))
# Populate "root hdd"
if rhdd_line_start != 0:
if rhdd_line_start > host_line_end:
self.exec_local('cat %s | tail -n +%d | head -n %d >> %s'
%(CS_CRUSH_MAP_TXT, rhdd_line_start,
(rhdd_line_end - rhdd_line_start + 1),
CS_CRUSH_MAP_MOD_TXT))
# Populate "root ssd"
if rssd_line_start != 0:
if rssd_line_start > host_line_end:
self.exec_local('cat %s | tail -n +%d | head -n %d >> %s'
%(CS_CRUSH_MAP_TXT, rssd_line_start,
(rssd_line_end - rssd_line_start + 1),
CS_CRUSH_MAP_MOD_TXT))
# Create new root entries for the chassis.
# use prefix of 'c' for the chassis entries
# The 'default' will be added as 'cdefault'
# The 'hdd' will be added as 'chdd'
# The 'ssd' will be added as 'cssd'
for entries in root_entries:
tmp_chassis_count = 0
self.exec_local('echo "root c%s {" > %s' %(entries,
CS_CRUSH_MAP_MOD_TMP_TXT))
self.exec_local('echo " id -%d #do not change unnecessarily" \
>> %s' %(crush_id, CS_CRUSH_MAP_MOD_TMP_TXT))
crush_id += 1
self.exec_local('echo " alg straw" >> %s' %(CS_CRUSH_MAP_MOD_TMP_TXT))
self.exec_local('echo " hash 0 #rjenkins1" >> %s'
%(CS_CRUSH_MAP_MOD_TMP_TXT))
while tmp_chassis_count < chassis_count:
total_weight = float('0')
self.exec_local('echo "chassis chassis-%s-%s {" >> %s' %(entries,
tmp_chassis_count, CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " id -%d #do not change unnecessarily" \
>> %s' %(crush_id, CS_CRUSH_MAP_MOD_TXT))
crush_id += 1
self.exec_local('echo " alg straw" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
entry_str = self.exec_local('cat %s|grep -n ^root |grep -w %s |tail -n 1'
%(CS_CRUSH_MAP_TXT, entries))
entry_line_num = int(entry_str.split(':')[0])
while True:
item_line = self.exec_local('cat %s | tail -n +%d | head -n 1'
%(CS_CRUSH_MAP_TXT, entry_line_num))
if item_line.find('}') != -1:
break
if item_line.find('item') != -1:
unmod_line = item_line
item_line.lstrip()
tmp_host_name = item_line.split(' ')[1]
tmp_host_name = tmp_host_name.replace('-hdd', '')
tmp_host_name = tmp_host_name.replace('-ssd', '')
#print tmp_host_name
#if tmp_host_name.find('-hdd') != -1 || \
# tmp_host_name.find('-ssd') != -1:
if host_chassis_info[tmp_host_name] == \
chassis_list['%d' %(tmp_chassis_count)]:
self.exec_local('echo " %s" >> %s' %(unmod_line,
CS_CRUSH_MAP_MOD_TXT))
total_weight += float(item_line.split(' ')[3])
entry_line_num += 1
self.exec_local('echo "}" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " item chassis-%s-%s weight %0.3f" >> %s'
%(entries, tmp_chassis_count, total_weight,
CS_CRUSH_MAP_MOD_TMP_TXT))
tmp_chassis_count += 1
self.exec_local('echo "}" >> %s' %(CS_CRUSH_MAP_MOD_TMP_TXT))
self.exec_local('cat %s >> %s' %(CS_CRUSH_MAP_MOD_TMP_TXT,
CS_CRUSH_MAP_MOD_TXT))
# Now that we have added all the root entries, add the rules
ruleset = 0
# Add the default rule
self.exec_local('echo "rule replicated_ruleset {" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " ruleset %d" >> %s' %(ruleset, CS_CRUSH_MAP_MOD_TXT))
ruleset += 1
self.exec_local('echo " type replicated" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " min_size 1" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " max_size 10" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
if pool_enabled == 0:
self.exec_local('echo " step take cdefault" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step chooseleaf firstn 0 type chassis" >> %s'
%(CS_CRUSH_MAP_MOD_TXT))
else:
self.exec_local('echo " step take default" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step chooseleaf firstn 0 type host" >> %s'
%(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step emit" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo "}" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
if pool_enabled == 1:
# Add the hdd rule
self.exec_local('echo "rule hdd {" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " ruleset %d" >> %s' %(ruleset, CS_CRUSH_MAP_MOD_TXT))
chassis_hdd_ruleset = ruleset
ruleset += 1
self.exec_local('echo " type replicated" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " min_size 1" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " max_size 10" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step take chdd" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step chooseleaf firstn 0 type chassis" >> %s'
%(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step emit" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo "}" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
# Add the ssd rule
self.exec_local('echo "rule ssd {" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " ruleset %d" >> %s' %(ruleset, CS_CRUSH_MAP_MOD_TXT))
chassis_ssd_ruleset = ruleset
ruleset += 1
self.exec_local('echo " type replicated" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " min_size 1" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " max_size 10" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step take cssd" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step chooseleaf firstn 0 type chassis" >> %s'
%(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo " step emit" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
self.exec_local('echo "}" >> %s' %(CS_CRUSH_MAP_MOD_TXT))
# Load the new crush map
self.exec_local('sudo crushtool -c %s -o %s' %(CS_CRUSH_MAP_MOD_TXT,
CS_CRUSH_MAP_MOD))
return CS_CRUSH_MAP_MOD
#end do_chassis_config()
# Create HDD/SSD Pool
# For HDD/SSD pool, the crush map has to be changed to accomodate the
# rules for the HDD/SSD pools. For this, new ssd, hdd specific hosts
# have to be added to the map. The ssd, hdd specific maps will then
# be linked to the root entry for SSD/HDD pool and finally which is linked
# to a rule entry. The rules will then be applied to the respective pools
# created using the mkpool command.
# For populating the map with the host/tier specific entries, A dictionary
# of host/tier specific entries will be created. This will include the
# Total tier specific count, tier specific count for a particular host
# and entries for the tier for a particular host.
# The host_<tier>_dict will have the tier specific entries and the count
# for a particular host.
# The HDD/SSD host/rules additions performed in a loop of pool count.
# The Pool count is derived from the number of unique pool configured in
# testbed.py.
# The pool option is given as part of the disk configuration in the form
# of '/dev/sdb:/dev/sdc:Pool_1' or '/dev/sdb:Pool_1', based on whether
# journal is present or not.
# The following operation is performed.
# - Get initalized crushmap.
# - Populate the host HDD/SSD pool entries
# - Populate the pool specific rules.
# - Return the modified crush map for further processing
# host cmbu-ceph-2 {
# ...
# item osd.4 weight 0.360
# }
# host cmbu-ceph-1 {
# ...
# item osd.5 weight 0.180
# }
# host cmbu-ceph-4 {
# ...
# item osd.6 weight 0.360
# }
# host cmbu-ceph-3 {
# ...
# item osd.7 weight 0.360
# }
# root default {
# ...
# item cmbu-ceph-1 weight 1.270
# item cmbu-ceph-2 weight 1.450
# item cmbu-ceph-4 weight 1.450
# item cmbu-ceph-3 weight 1.450
# }
# In addition to the above, the following will be added with the
# hdd/ssd pool based configuration
# host cmbu-ceph-1-hdd {
# ...
# item osd.1 weight 1.090
# }
#
# host cmbu-ceph-2-hdd {
# ...
# item osd.0 weight 1.090
# }
#
# host cmbu-ceph-3-hdd {
# ...
# item osd.3 weight 1.090
# }
#
# host cmbu-ceph-4-hdd {
# ...
# item osd.2 weight 1.090
# }
#
# host cmbu-ceph-1-ssd {
# ...
# item osd.5 weight 0.180
# }
#
# host cmbu-ceph-2-ssd {
# ...
# item osd.4 weight 0.360
# }
#
# host cmbu-ceph-3-ssd {
# ...
# item osd.7 weight 0.360
# }
#
# host cmbu-ceph-4-ssd {
# ...
# item osd.6 weight 0.360
# }
# root hdd {
# ...
# item cmbu-ceph-1-hdd weight 1.090
# item cmbu-ceph-2-hdd weight 1.090
# item cmbu-ceph-3-hdd weight 1.090
# item cmbu-ceph-4-hdd weight 1.090
# }
#
# root ssd {
# ...
# item cmbu-ceph-1-ssd weight 0.180
# item cmbu-ceph-2-ssd weight 0.360
# item cmbu-ceph-3-ssd weight 0.360
# item cmbu-ceph-4-ssd weight 0.360
# }
#
# rule replicated_ruleset {
# ...
# }
# rule hdd {
# ...
# }
#
# rule ssd {
# ...
# }
# Note: This function will not apply the crush map.
def do_pool_config(self, input_crush, storage_hostnames,
storage_disk_config,
storage_ssd_disk_config,
osd_map_config):
global host_hdd_dict
global host_ssd_dict
global hdd_pool_count
global ssd_pool_count
global crush_id
# If multipool/SSD pool is not enabled, return
if self.is_multi_pool_disabled(storage_disk_config,
storage_ssd_disk_config) and \
self.is_ssd_pool_disabled(storage_ssd_disk_config):
return input_crush
# Initialize the HDD/SSD pool dictionary.
# This is used acrros functions to finally
# set the rules, pg/pgp count, replica size etc.
pool_count = 0
while True:
host_hdd_dict[('totalcount', '%s' %(pool_count))] = 0
host_ssd_dict[('totalcount', '%s' %(pool_count))] = 0
host_hdd_dict[('ruleid', '%s' %(pool_count))] = 0
host_ssd_dict[('ruleid', '%s' %(pool_count))] = 0
host_hdd_dict[('hostcount', '%s' %(pool_count))] = 0
host_ssd_dict[('hostcount', '%s' %(pool_count))] = 0
host_hdd_dict[('poolname', '%s' %(pool_count))] = ''
host_ssd_dict[('poolname', '%s' %(pool_count))] = ''
host_hdd_dict[('osdweight', '%s' %(pool_count))] = float('0')
host_ssd_dict[('osdweight', '%s' %(pool_count))] = float('0')
if pool_count > MAX_POOL_COUNT:
break
pool_count = pool_count + 1
# Build the host/tier specific dictionary
for hostname in storage_hostnames:
host_hdd_dict[hostname, 'count'] = 0
host_ssd_dict[hostname, 'count'] = 0
pool_count = 0
while True:
host_hdd_dict[('hostcountadded', '%s' %(pool_count))] = 0
host_ssd_dict[('hostcountadded', '%s' %(pool_count))] = 0
if pool_count > MAX_POOL_COUNT:
break
pool_count = pool_count + 1
# Go over all the disk entries
# Find the unique pool names (for multi pool)
# Find host count for each pool
# Populate the corresponding dictionary
for disks in storage_disk_config:
diskcount = disks.count(':')
disksplit = disks.split(':')
pool_index = 0
# If there are 3 variables in the disk specification, check
# if the 3rd entry is a pool name. Always starts with 'P'
# if there are only 2 variable in the disk specification,
# check if the check the 2nd entry is the journal disk
# or the Pool name
if disksplit[0] == hostname:
if (diskcount == 3 and
disksplit[3][0] == 'P') or \
(diskcount == 2 and
disksplit[2][0] == 'P'):
if diskcount == 3:
pool_name = disksplit[3]
if diskcount == 2:
pool_name = disksplit[2]
# Check if the pool name is already in the dictionary
# Otherwise, add it to the dictionary
# The host_hdd_dict['poolname', index] will have the
# actual poolnames.
if hdd_pool_count != 0:
while True:
if pool_name == host_hdd_dict[('poolname', '%s'
%(pool_index))]:
break
pool_index = pool_index + 1
if pool_index == hdd_pool_count:
hdd_pool_count = hdd_pool_count + 1
break
else:
pool_index = hdd_pool_count
hdd_pool_count = hdd_pool_count + 1
host_hdd_dict[('poolname', '%s' %(pool_index))] = \
pool_name
# Populate the Host count for each pool in dictionary.
# The hostcountadded dictioary ensures that the host count
# is not incremented multiple times for the same host.
# The variable is initialized in the top of the loop
if host_hdd_dict[('hostcountadded', '%s' %(pool_index))] == 0:
host_hdd_dict[('hostcount', '%s' %(pool_index))] += 1
host_hdd_dict[('hostcountadded', '%s' %(pool_index))] = 1
for disks in storage_ssd_disk_config:
diskcount = disks.count(':')
disksplit = disks.split(':')
pool_index = 0
# If there are 3 variables in the disk specification, check
# if the 3rd entry is a pool name. Always starts with 'P'
# if there are only 2 variable in the disk specification,
# check if the check the 2nd entry is the journal disk
# or the Pool name
if disksplit[0] == hostname:
if (diskcount == 3 and
disksplit[3][0] == 'P') or \
(diskcount == 2 and
disksplit[2][0] == 'P'):
if diskcount == 3:
pool_name = disksplit[3]
if diskcount == 2:
pool_name = disksplit[2]
# Check if the pool name is already in the dictionary
# Otherwise, add it to the dictionary
# The host_hdd_dict['poolname', index] will have the
# actual poolnames.
if ssd_pool_count != 0:
while True:
if pool_name == host_ssd_dict[('poolname', '%s'
%(pool_index))]:
break
pool_index = pool_index + 1
if pool_index == ssd_pool_count:
ssd_pool_count = ssd_pool_count + 1
break
else:
pool_index = ssd_pool_count
ssd_pool_count = ssd_pool_count + 1
host_ssd_dict[('poolname', '%s' %(pool_index))] = \
pool_name
# Populate the Host count for each pool in dictionary.
# The hostcountadded dictioary ensures that the host count
# is not incremented multiple times for the same host.
# The variable is initialized in the top of the loop
if host_ssd_dict[('hostcountadded', '%s' %(pool_index))] == 0:
host_ssd_dict[('hostcount', '%s' %(pool_index))] += 1
host_ssd_dict[('hostcountadded', '%s' %(pool_index))] = 1
# Initalize the disk count for each host/pool combination for both HDD
# and SSD.
# The dictionary is indexed by the string 'host-pool' and
# the string 'count'
for hostname in storage_hostnames:
pool_index = 0
while True:
host_hdd_dict['%s-%s' %(hostname, pool_index), 'count'] = 0
pool_index = pool_index + 1
if pool_index >= hdd_pool_count:
break
pool_index = 0
while True:
host_ssd_dict['%s-%s' %(hostname, pool_index), 'count'] = 0
pool_index = pool_index + 1
if pool_index >= ssd_pool_count: