-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Expand file tree
/
Copy pathceph.py
More file actions
2032 lines (1809 loc) · 68.4 KB
/
ceph.py
File metadata and controls
2032 lines (1809 loc) · 68.4 KB
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
"""
Ceph cluster task.
Handle the setup, starting, and clean-up of a Ceph cluster.
"""
from copy import deepcopy
from io import BytesIO
from io import StringIO
import argparse
import configobj
import contextlib
import errno
import logging
import os
import json
import time
import gevent
import re
import socket
import yaml
from paramiko import SSHException
from tasks.ceph_manager import CephManager, write_conf, get_valgrind_args
from tarfile import ReadError
from tasks.cephfs.filesystem import MDSCluster, Filesystem
from teuthology import misc as teuthology
from teuthology import contextutil
from teuthology import exceptions
from teuthology.orchestra import run
from teuthology.util.scanner import ValgrindScanner
from tasks import ceph_client as cclient
from teuthology.orchestra.daemon import DaemonGroup
from tasks.daemonwatchdog import DaemonWatchdog
CEPH_ROLE_TYPES = ['mon', 'mgr', 'osd', 'mds', 'rgw']
DATA_PATH = '/var/lib/ceph/{type_}/{cluster}-{id_}'
log = logging.getLogger(__name__)
def generate_caps(type_):
"""
Each call will return the next capability for each system type
(essentially a subset of possible role values). Valid types are osd,
mds and client.
"""
defaults = dict(
osd=dict(
mon='allow profile osd',
mgr='allow profile osd',
osd='allow *',
),
mgr=dict(
mon='allow profile mgr',
osd='allow *',
mds='allow *',
),
mds=dict(
mon='allow *',
mgr='allow *',
osd='allow *',
mds='allow',
),
client=dict(
mon='allow rw',
mgr='allow r',
osd='allow rwx',
mds='allow',
),
)
for subsystem, capability in defaults[type_].items():
yield '--cap'
yield subsystem
yield capability
def update_archive_setting(ctx, key, value):
"""
Add logs directory to job's info log file
"""
if ctx.archive is None:
return
with open(os.path.join(ctx.archive, 'info.yaml'), 'r+') as info_file:
info_yaml = yaml.safe_load(info_file)
info_file.seek(0)
if 'archive' in info_yaml:
info_yaml['archive'][key] = value
else:
info_yaml['archive'] = {key: value}
yaml.safe_dump(info_yaml, info_file, default_flow_style=False)
@contextlib.contextmanager
def ceph_crash(ctx, config):
"""
Gather crash dumps from /var/lib/ceph/crash
"""
# Add crash directory to job's archive
update_archive_setting(ctx, 'crash', '/var/lib/ceph/crash')
try:
yield
finally:
if ctx.archive is not None:
log.info('Archiving crash dumps...')
path = os.path.join(ctx.archive, 'remote')
try:
os.makedirs(path)
except OSError:
pass
for remote in ctx.cluster.remotes.keys():
sub = os.path.join(path, remote.shortname)
try:
os.makedirs(sub)
except OSError:
pass
try:
teuthology.pull_directory(remote, '/var/lib/ceph/crash',
os.path.join(sub, 'crash'))
except ReadError:
pass
@contextlib.contextmanager
def ceph_log(ctx, config):
"""
Create /var/log/ceph log directory that is open to everyone.
Add valgrind and profiling-logger directories.
:param ctx: Context
:param config: Configuration
"""
log.info('Making ceph log dir writeable by non-root...')
run.wait(
ctx.cluster.run(
args=[
'sudo',
'chmod',
'777',
'/var/log/ceph',
],
wait=False,
)
)
log.info('Disabling ceph logrotate...')
run.wait(
ctx.cluster.run(
args=[
'sudo',
'rm', '-f', '--',
'/etc/logrotate.d/ceph',
],
wait=False,
)
)
log.info('Creating extra log directories...')
run.wait(
ctx.cluster.run(
args=[
'sudo',
'install', '-d', '-m0777', '--',
'/var/log/ceph/valgrind',
'/var/log/ceph/profiling-logger',
],
wait=False,
)
)
# Add logs directory to job's info log file
update_archive_setting(ctx, 'log', '/var/log/ceph')
class Rotater(object):
stop_event = gevent.event.Event()
def invoke_logrotate(self):
# 1) install ceph-test.conf in /etc/logrotate.d
# 2) continuously loop over logrotate invocation with ceph-test.conf
while not self.stop_event.is_set():
self.stop_event.wait(timeout=30)
try:
procs = ctx.cluster.run(
args=['sudo', 'logrotate', '/etc/logrotate.d/ceph-test.conf'],
wait=False,
stderr=StringIO()
)
run.wait(procs)
except exceptions.ConnectionLostError as e:
# Some tests may power off nodes during test, in which
# case we will see connection errors that we should ignore.
log.debug("Missed logrotate, node '{0}' is offline".format(
e.node))
except EOFError:
# Paramiko sometimes raises this when it fails to
# connect to a node during open_session. As with
# ConnectionLostError, we ignore this because nodes
# are allowed to get power cycled during tests.
log.debug("Missed logrotate, EOFError")
except SSHException:
log.debug("Missed logrotate, SSHException")
except run.CommandFailedError as e:
for p in procs:
if p.finished and p.exitstatus != 0:
err = p.stderr.getvalue()
if 'error: error renaming temp state file' in err:
log.info('ignoring transient state error: %s', e)
else:
raise
except socket.error as e:
if e.errno in (errno.EHOSTUNREACH, errno.ECONNRESET):
log.debug("Missed logrotate, host unreachable")
else:
raise
def begin(self):
self.thread = gevent.spawn(self.invoke_logrotate)
def end(self):
self.stop_event.set()
self.thread.get()
def write_rotate_conf(ctx, daemons):
testdir = teuthology.get_testdir(ctx)
remote_logrotate_conf = '%s/logrotate.ceph-test.conf' % testdir
rotate_conf_path = os.path.join(os.path.dirname(__file__), 'logrotate.conf')
with open(rotate_conf_path) as f:
conf = ""
for daemon, size in daemons.items():
log.info('writing logrotate stanza for {}'.format(daemon))
conf += f.read().format(daemon_type=daemon,
max_size=size)
f.seek(0, 0)
for remote in ctx.cluster.remotes.keys():
remote.write_file(remote_logrotate_conf, BytesIO(conf.encode()))
remote.sh(
f'sudo mv {remote_logrotate_conf} /etc/logrotate.d/ceph-test.conf && '
'sudo chmod 0644 /etc/logrotate.d/ceph-test.conf && '
'sudo chown root.root /etc/logrotate.d/ceph-test.conf')
remote.chcon('/etc/logrotate.d/ceph-test.conf',
'system_u:object_r:etc_t:s0')
if ctx.config.get('log-rotate'):
daemons = ctx.config.get('log-rotate')
log.info('Setting up log rotation with ' + str(daemons))
write_rotate_conf(ctx, daemons)
logrotater = Rotater()
logrotater.begin()
try:
yield
finally:
if ctx.config.get('log-rotate'):
log.info('Shutting down logrotate')
logrotater.end()
ctx.cluster.sh('sudo rm /etc/logrotate.d/ceph-test.conf')
if ctx.archive is not None and \
not (ctx.config.get('archive-on-error') and ctx.summary['success']):
# and logs
log.info('Compressing logs...')
run.wait(
ctx.cluster.run(
args=[
'time',
'sudo',
'find',
'/var/log/ceph',
'-name',
'*.log',
'-print0',
run.Raw('|'),
'sudo',
'xargs',
'--max-args=1',
'--max-procs=0',
'--verbose',
'-0',
'--no-run-if-empty',
'--',
'gzip',
'-5',
'--verbose',
'--',
],
wait=False,
),
)
log.info('Archiving logs...')
path = os.path.join(ctx.archive, 'remote')
try:
os.makedirs(path)
except OSError:
pass
for remote in ctx.cluster.remotes.keys():
sub = os.path.join(path, remote.shortname)
try:
os.makedirs(sub)
except OSError:
pass
teuthology.pull_directory(remote, '/var/log/ceph',
os.path.join(sub, 'log'))
def assign_devs(roles, devs):
"""
Create a dictionary of devs indexed by roles
:param roles: List of roles
:param devs: Corresponding list of devices.
:returns: Dictionary of devs indexed by roles.
"""
return dict(zip(roles, devs))
@contextlib.contextmanager
def valgrind_post(ctx, config):
"""
After the tests run, look through all the valgrind logs. Exceptions are raised
if textual errors occurred in the logs, or if valgrind exceptions were detected in
the logs.
:param ctx: Context
:param config: Configuration
"""
try:
yield
finally:
valgrind_exception = None
valgrind_yaml = os.path.join(ctx.archive, 'valgrind.yaml')
for remote in ctx.cluster.remotes.keys():
scanner = ValgrindScanner(remote)
errors = scanner.scan_all_files('/var/log/ceph/valgrind/*')
scanner.write_summary(valgrind_yaml)
if errors and not valgrind_exception:
log.debug('valgrind exception message: %s', errors[0])
valgrind_exception = Exception(errors[0])
if config.get('expect_valgrind_errors'):
if not valgrind_exception:
raise Exception('expected valgrind issues and found none')
else:
if valgrind_exception:
raise valgrind_exception
@contextlib.contextmanager
def crush_setup(ctx, config):
cluster_name = config['cluster']
first_mon = teuthology.get_first_mon(ctx, config, cluster_name)
(mon_remote,) = ctx.cluster.only(first_mon).remotes.keys()
profile = config.get('crush_tunables', 'default')
log.info('Setting crush tunables to %s', profile)
mon_remote.run(
args=['sudo', 'ceph', '--cluster', cluster_name,
'osd', 'crush', 'tunables', profile])
yield
@contextlib.contextmanager
def module_setup(ctx, config):
cluster_name = config['cluster']
first_mon = teuthology.get_first_mon(ctx, config, cluster_name)
(mon_remote,) = ctx.cluster.only(first_mon).remotes.keys()
modules = config.get('mgr-modules', [])
for m in modules:
m = str(m)
cmd = [
'sudo',
'ceph',
'--cluster',
cluster_name,
'mgr',
'module',
'enable',
m,
]
log.info("enabling module %s", m)
mon_remote.run(args=cmd)
yield
@contextlib.contextmanager
def conf_setup(ctx, config):
cluster_name = config['cluster']
first_mon = teuthology.get_first_mon(ctx, config, cluster_name)
(mon_remote,) = ctx.cluster.only(first_mon).remotes.keys()
configs = config.get('cluster-conf', {})
procs = []
for section, confs in configs.items():
section = str(section)
for k, v in confs.items():
k = str(k).replace(' ', '_') # pre-pacific compatibility
v = str(v)
cmd = [
'sudo',
'ceph',
'--cluster',
cluster_name,
'config',
'set',
section,
k,
v,
]
log.info("setting config [%s] %s = %s", section, k, v)
procs.append(mon_remote.run(args=cmd, wait=False))
log.debug("set %d configs", len(procs))
for p in procs:
log.debug("waiting for %s", p)
p.wait()
cmd = [
'sudo',
'ceph',
'--cluster',
cluster_name,
'config',
'dump',
]
mon_remote.run(args=cmd)
yield
@contextlib.contextmanager
def conf_epoch(ctx, config):
cm = ctx.managers[config['cluster']]
cm.save_conf_epoch()
yield
@contextlib.contextmanager
def check_enable_crimson(ctx, config):
# enable crimson-osds if crimson
log.info("check_enable_crimson: {}".format(is_crimson(config)))
if is_crimson(config):
cluster_name = config['cluster']
first_mon = teuthology.get_first_mon(ctx, config, cluster_name)
(mon_remote,) = ctx.cluster.only(first_mon).remotes.keys()
log.info('check_enable_crimson: setting set-allow-crimson')
mon_remote.run(
args=[
'sudo', 'ceph', '--cluster', cluster_name,
'osd', 'set-allow-crimson', '--yes-i-really-mean-it'
]
)
yield
@contextlib.contextmanager
def setup_manager(ctx, config):
first_mon = teuthology.get_first_mon(ctx, config, config['cluster'])
(mon,) = ctx.cluster.only(first_mon).remotes.keys()
if not hasattr(ctx, 'managers'):
ctx.managers = {}
ctx.managers[config['cluster']] = CephManager(
mon,
ctx=ctx,
logger=log.getChild('ceph_manager.' + config['cluster']),
cluster=config['cluster'],
)
yield
@contextlib.contextmanager
def create_rbd_pool(ctx, config):
cluster_name = config['cluster']
first_mon = teuthology.get_first_mon(ctx, config, cluster_name)
(mon_remote,) = ctx.cluster.only(first_mon).remotes.keys()
log.info('Waiting for OSDs to come up')
teuthology.wait_until_osds_up(
ctx,
cluster=ctx.cluster,
remote=mon_remote,
ceph_cluster=cluster_name,
)
if config.get('create_rbd_pool', True):
log.info('Creating RBD pool')
mon_remote.run(
args=['sudo', 'ceph', '--cluster', cluster_name,
'osd', 'pool', 'create', 'rbd', '8'])
mon_remote.run(
args=['rbd', '--cluster', cluster_name, 'pool', 'init', 'rbd'])
yield
@contextlib.contextmanager
def cephfs_setup(ctx, config):
cluster_name = config['cluster']
first_mon = teuthology.get_first_mon(ctx, config, cluster_name)
(mon_remote,) = ctx.cluster.only(first_mon).remotes.keys()
mdss = ctx.cluster.only(teuthology.is_type('mds', cluster_name))
# If there are any MDSs, then create a filesystem for them to use
# Do this last because requires mon cluster to be up and running
if mdss.remotes:
log.info('Setting up CephFS filesystem(s)...')
cephfs_config = config.get('cephfs', {})
fs_configs = cephfs_config.pop('fs', [{'name': 'cephfs'}])
# wait for standbys to become available (slow due to valgrind, perhaps)
mdsc = MDSCluster(ctx)
mds_count = len(list(teuthology.all_roles_of_type(ctx.cluster, 'mds')))
with contextutil.safe_while(sleep=2,tries=150) as proceed:
while proceed():
if len(mdsc.get_standby_daemons()) >= mds_count:
break
fss = []
for fs_config in fs_configs:
assert isinstance(fs_config, dict)
name = fs_config.pop('name')
temp = deepcopy(cephfs_config)
teuthology.deep_merge(temp, fs_config)
subvols = config.get('subvols', None)
if subvols:
teuthology.deep_merge(temp, {'subvols': subvols})
fs = Filesystem(ctx, fs_config=temp, name=name, create=True)
fss.append(fs)
yield
for fs in fss:
fs.destroy()
else:
yield
@contextlib.contextmanager
def watchdog_setup(ctx, config):
ctx.ceph[config['cluster']].thrashers = []
ctx.ceph[config['cluster']].watched_processes = []
ctx.ceph[config['cluster']].watchdog = DaemonWatchdog(ctx, config)
ctx.ceph[config['cluster']].watchdog.start()
yield
def get_mons(roles, ips, cluster_name,
mon_bind_msgr2=False,
mon_bind_addrvec=False):
"""
Get monitors and their associated addresses
"""
mons = {}
v1_ports = {}
v2_ports = {}
is_mon = teuthology.is_type('mon', cluster_name)
for idx, roles in enumerate(roles):
for role in roles:
if not is_mon(role):
continue
if ips[idx] not in v1_ports:
v1_ports[ips[idx]] = 6789
else:
v1_ports[ips[idx]] += 1
if mon_bind_msgr2:
if ips[idx] not in v2_ports:
v2_ports[ips[idx]] = 3300
addr = '{ip}'.format(ip=ips[idx])
else:
assert mon_bind_addrvec
v2_ports[ips[idx]] += 1
addr = '[v2:{ip}:{port2},v1:{ip}:{port1}]'.format(
ip=ips[idx],
port2=v2_ports[ips[idx]],
port1=v1_ports[ips[idx]],
)
elif mon_bind_addrvec:
addr = '[v1:{ip}:{port}]'.format(
ip=ips[idx],
port=v1_ports[ips[idx]],
)
else:
addr = '{ip}:{port}'.format(
ip=ips[idx],
port=v1_ports[ips[idx]],
)
mons[role] = addr
assert mons
return mons
def skeleton_config(ctx, roles, ips, mons, cluster='ceph'):
"""
Returns a ConfigObj that is prefilled with a skeleton config.
Use conf[section][key]=value or conf.merge to change it.
Use conf.write to write it out, override .filename first if you want.
"""
path = os.path.join(os.path.dirname(__file__), 'ceph.conf.template')
conf = configobj.ConfigObj(path, file_error=True)
mon_hosts = []
for role, addr in mons.items():
mon_cluster, _, _ = teuthology.split_role(role)
if mon_cluster != cluster:
continue
name = teuthology.ceph_role(role)
conf.setdefault(name, {})
mon_hosts.append(addr)
conf.setdefault('global', {})
conf['global']['mon host'] = ','.join(mon_hosts)
# set up standby mds's
is_mds = teuthology.is_type('mds', cluster)
for roles_subset in roles:
for role in roles_subset:
if is_mds(role):
name = teuthology.ceph_role(role)
conf.setdefault(name, {})
return conf
def create_simple_monmap(ctx, remote, conf, mons,
path=None,
mon_bind_addrvec=False):
"""
Writes a simple monmap based on current ceph.conf into path, or
<testdir>/monmap by default.
Assumes ceph_conf is up to date.
Assumes mon sections are named "mon.*", with the dot.
:return the FSID (as a string) of the newly created monmap
"""
addresses = list(mons.items())
assert addresses, "There are no monitors in config!"
log.debug('Ceph mon addresses: %s', addresses)
try:
log.debug('writing out conf {c}'.format(c=conf))
except:
log.debug('my conf logging attempt failed')
testdir = teuthology.get_testdir(ctx)
tmp_conf_path = '{tdir}/ceph.tmp.conf'.format(tdir=testdir)
conf_fp = BytesIO()
conf.write(conf_fp)
conf_fp.seek(0)
teuthology.write_file(remote, tmp_conf_path, conf_fp)
args = [
'adjust-ulimits',
'ceph-coverage',
'{tdir}/archive/coverage'.format(tdir=testdir),
'monmaptool',
'-c',
'{conf}'.format(conf=tmp_conf_path),
'--create',
'--clobber',
]
if mon_bind_addrvec:
args.extend(['--enable-all-features'])
for (role, addr) in addresses:
_, _, n = teuthology.split_role(role)
if mon_bind_addrvec and (',' in addr or 'v' in addr or ':' in addr):
args.extend(('--addv', n, addr))
else:
args.extend(('--add', n, addr))
if not path:
path = '{tdir}/monmap'.format(tdir=testdir)
args.extend([
'--print',
path
])
monmap_output = remote.sh(args)
fsid = re.search("generated fsid (.+)$",
monmap_output, re.MULTILINE).group(1)
teuthology.delete_file(remote, tmp_conf_path)
return fsid
def is_crimson(config):
return config.get('crimson_compat', False)
def maybe_redirect_stderr(config, type_, args, log_path):
if type_ == 'osd' and is_crimson(config):
# teuthworker uses ubuntu:ubuntu to access the test nodes
create_log_cmd = \
f'sudo install -b -o ubuntu -g ubuntu /dev/null {log_path}'
return create_log_cmd, args + [run.Raw('2>>'), log_path]
else:
return None, args
@contextlib.contextmanager
def cluster(ctx, config):
"""
Handle the creation and removal of a ceph cluster.
On startup:
Create directories needed for the cluster.
Create remote journals for all osds.
Create and set keyring.
Copy the monmap to the test systems.
Setup mon nodes.
Setup mds nodes.
Mkfs osd nodes.
Add keyring information to monmaps
Mkfs mon nodes.
On exit:
If errors occurred, extract a failure message and store in ctx.summary.
Unmount all test files and temporary journaling files.
Save the monitor information and archive all ceph logs.
Cleanup the keyring setup, and remove all monitor map and data files left over.
:param ctx: Context
:param config: Configuration
"""
if ctx.config.get('use_existing_cluster', False) is True:
log.info("'use_existing_cluster' is true; skipping cluster creation")
yield
testdir = teuthology.get_testdir(ctx)
cluster_name = config['cluster']
data_dir = '{tdir}/{cluster}.data'.format(tdir=testdir, cluster=cluster_name)
log.info('Creating ceph cluster %s...', cluster_name)
log.info('config %s', config)
log.info('ctx.config %s', ctx.config)
run.wait(
ctx.cluster.run(
args=[
'install', '-d', '-m0755', '--',
data_dir,
],
wait=False,
)
)
run.wait(
ctx.cluster.run(
args=[
'sudo',
'install', '-d', '-m0777', '--', '/var/run/ceph',
],
wait=False,
)
)
devs_to_clean = {}
remote_to_roles_to_devs = {}
osds = ctx.cluster.only(teuthology.is_type('osd', cluster_name))
for remote, roles_for_host in osds.remotes.items():
devs = teuthology.get_scratch_devices(remote)
roles_to_devs = assign_devs(
teuthology.cluster_roles_of_type(roles_for_host, 'osd', cluster_name), devs
)
devs_to_clean[remote] = []
log.info('osd dev map: {}'.format(roles_to_devs))
assert roles_to_devs, \
"remote {} has osd roles, but no osd devices were specified!".format(remote.hostname)
remote_to_roles_to_devs[remote] = roles_to_devs
log.info("remote_to_roles_to_devs: {}".format(remote_to_roles_to_devs))
for osd_role, dev_name in remote_to_roles_to_devs.items():
assert dev_name, "{} has no associated device!".format(osd_role)
log.info('Generating config...')
remotes_and_roles = ctx.cluster.remotes.items()
roles = [role_list for (remote, role_list) in remotes_and_roles]
ips = [host for (host, port) in
(remote.ssh.get_transport().getpeername() for (remote, role_list) in remotes_and_roles)]
mons = get_mons(
roles, ips, cluster_name,
mon_bind_msgr2=config.get('mon_bind_msgr2'),
mon_bind_addrvec=config.get('mon_bind_addrvec'),
)
conf = skeleton_config(
ctx, roles=roles, ips=ips, mons=mons, cluster=cluster_name,
)
for section, keys in config['conf'].items():
for key, value in keys.items():
log.info("[%s] %s = %s" % (section, key, value))
if section not in conf:
conf[section] = {}
conf[section][key] = value
if not hasattr(ctx, 'ceph'):
ctx.ceph = {}
ctx.ceph[cluster_name] = argparse.Namespace()
ctx.ceph[cluster_name].conf = conf
ctx.ceph[cluster_name].mons = mons
default_keyring = '/etc/ceph/{cluster}.keyring'.format(cluster=cluster_name)
keyring_path = config.get('keyring_path', default_keyring)
coverage_dir = '{tdir}/archive/coverage'.format(tdir=testdir)
firstmon = teuthology.get_first_mon(ctx, config, cluster_name)
log.info('Setting up %s...' % firstmon)
ctx.cluster.only(firstmon).run(
args=[
'sudo',
'adjust-ulimits',
'ceph-coverage',
coverage_dir,
'ceph-authtool',
'--create-keyring',
keyring_path,
],
)
ctx.cluster.only(firstmon).run(
args=[
'sudo',
'adjust-ulimits',
'ceph-coverage',
coverage_dir,
'ceph-authtool',
'--gen-key',
'--name=mon.',
keyring_path,
],
)
ctx.cluster.only(firstmon).run(
args=[
'sudo',
'chmod',
'0644',
keyring_path,
],
)
(mon0_remote,) = ctx.cluster.only(firstmon).remotes.keys()
monmap_path = '{tdir}/{cluster}.monmap'.format(tdir=testdir,
cluster=cluster_name)
fsid = create_simple_monmap(
ctx,
remote=mon0_remote,
conf=conf,
mons=mons,
path=monmap_path,
mon_bind_addrvec=config.get('mon_bind_addrvec'),
)
ctx.ceph[cluster_name].fsid = fsid
if not 'global' in conf:
conf['global'] = {}
conf['global']['fsid'] = fsid
default_conf_path = '/etc/ceph/{cluster}.conf'.format(cluster=cluster_name)
conf_path = config.get('conf_path', default_conf_path)
log.info('Writing %s for FSID %s...' % (conf_path, fsid))
write_conf(ctx, conf_path, cluster_name)
log.info('Creating admin key on %s...' % firstmon)
ctx.cluster.only(firstmon).run(
args=[
'sudo',
'adjust-ulimits',
'ceph-coverage',
coverage_dir,
'ceph-authtool',
'--gen-key',
'--name=client.admin',
'--cap', 'mon', 'allow *',
'--cap', 'osd', 'allow *',
'--cap', 'mds', 'allow *',
'--cap', 'mgr', 'allow *',
keyring_path,
],
)
log.info('Copying monmap to all nodes...')
keyring = mon0_remote.read_file(keyring_path)
monmap = mon0_remote.read_file(monmap_path)
for rem in ctx.cluster.remotes.keys():
# copy mon key and initial monmap
log.info('Sending monmap to node {remote}'.format(remote=rem))
rem.write_file(keyring_path, keyring, mode='0644', sudo=True)
rem.write_file(monmap_path, monmap)
log.info('Setting up mon nodes...')
mons = ctx.cluster.only(teuthology.is_type('mon', cluster_name))
if not config.get('skip_mgr_daemons', False):
log.info('Setting up mgr nodes...')
mgrs = ctx.cluster.only(teuthology.is_type('mgr', cluster_name))
for remote, roles_for_host in mgrs.remotes.items():
for role in teuthology.cluster_roles_of_type(roles_for_host, 'mgr',
cluster_name):
_, _, id_ = teuthology.split_role(role)
mgr_dir = DATA_PATH.format(
type_='mgr', cluster=cluster_name, id_=id_)
remote.run(
args=[
'sudo',
'mkdir',
'-p',
mgr_dir,
run.Raw('&&'),
'sudo',
'adjust-ulimits',
'ceph-coverage',
coverage_dir,
'ceph-authtool',
'--create-keyring',
'--gen-key',
'--name=mgr.{id}'.format(id=id_),
mgr_dir + '/keyring',
],
)
log.info('Setting up mds nodes...')
mdss = ctx.cluster.only(teuthology.is_type('mds', cluster_name))
for remote, roles_for_host in mdss.remotes.items():
for role in teuthology.cluster_roles_of_type(roles_for_host, 'mds',
cluster_name):
_, _, id_ = teuthology.split_role(role)
mds_dir = DATA_PATH.format(
type_='mds', cluster=cluster_name, id_=id_)
remote.run(
args=[
'sudo',
'mkdir',
'-p',
mds_dir,
run.Raw('&&'),
'sudo',
'adjust-ulimits',
'ceph-coverage',
coverage_dir,
'ceph-authtool',
'--create-keyring',
'--gen-key',
'--name=mds.{id}'.format(id=id_),
mds_dir + '/keyring',
],
)
remote.run(args=[
'sudo', 'chown', '-R', 'ceph:ceph', mds_dir
])
cclient.create_keyring(ctx, cluster_name)
log.info('Running mkfs on osd nodes...')
if not hasattr(ctx, 'disk_config'):
ctx.disk_config = argparse.Namespace()
if not hasattr(ctx.disk_config, 'remote_to_roles_to_dev'):
ctx.disk_config.remote_to_roles_to_dev = {}
if not hasattr(ctx.disk_config, 'remote_to_roles_to_dev_mount_options'):
ctx.disk_config.remote_to_roles_to_dev_mount_options = {}
if not hasattr(ctx.disk_config, 'remote_to_roles_to_dev_fstype'):
ctx.disk_config.remote_to_roles_to_dev_fstype = {}
teuthology.deep_merge(ctx.disk_config.remote_to_roles_to_dev, remote_to_roles_to_devs)
log.info("ctx.disk_config.remote_to_roles_to_dev: {r}".format(r=str(ctx.disk_config.remote_to_roles_to_dev)))
for remote, roles_for_host in osds.remotes.items():
roles_to_devs = remote_to_roles_to_devs[remote]
for role in teuthology.cluster_roles_of_type(roles_for_host, 'osd', cluster_name):
_, _, id_ = teuthology.split_role(role)
mnt_point = DATA_PATH.format(
type_='osd', cluster=cluster_name, id_=id_)
remote.run(
args=[
'sudo',
'mkdir',
'-p',
mnt_point,
])
log.info('roles_to_devs: {}'.format(roles_to_devs))
log.info('role: {}'.format(role))
if roles_to_devs.get(role):
dev = roles_to_devs[role]
fs = config.get('fs')
package = None
mkfs_options = config.get('mkfs_options')
mount_options = config.get('mount_options')
if fs == 'btrfs':
# package = 'btrfs-tools'
if mount_options is None:
mount_options = ['noatime', 'user_subvol_rm_allowed']
if mkfs_options is None:
mkfs_options = ['-m', 'single',
'-l', '32768',
'-n', '32768']
if fs == 'xfs':
# package = 'xfsprogs'
if mount_options is None:
mount_options = ['noatime']
if mkfs_options is None:
mkfs_options = ['-f', '-i', 'size=2048']
if fs == 'ext4' or fs == 'ext3':
if mount_options is None:
mount_options = ['noatime', 'user_xattr']
if mount_options is None:
mount_options = []
if mkfs_options is None:
mkfs_options = []
mkfs = ['mkfs.%s' % fs] + mkfs_options
log.info('%s on %s on %s' % (mkfs, dev, remote))
if package is not None:
remote.sh('sudo apt-get install -y %s' % package)
try:
remote.run(args=['yes', run.Raw('|')] + ['sudo'] + mkfs + [dev])
except run.CommandFailedError:
if fs != 'btrfs':
raise
# Newer btrfs-tools doesn't prompt for overwrite, use -f
if '-f' not in mount_options: