]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/ceph_deploy.py
2 Execute ceph-deploy as a task
4 from cStringIO
import StringIO
12 from teuthology
import misc
as teuthology
13 from teuthology
import contextutil
14 from teuthology
.config
import config
as teuth_config
15 from teuthology
.task
import install
as install_fn
16 from teuthology
.orchestra
import run
17 from tasks
.cephfs
.filesystem
import Filesystem
19 log
= logging
.getLogger(__name__
)
22 @contextlib.contextmanager
23 def download_ceph_deploy(ctx
, config
):
25 Downloads ceph-deploy from the ceph.com git mirror and (by default)
26 switches to the master branch. If the `ceph-deploy-branch` is specified, it
27 will use that instead. The `bootstrap` script is ran, with the argument
28 obtained from `python_version`, if specified.
30 ceph_admin
= ctx
.cluster
.only(teuthology
.get_first_mon(ctx
, config
))
33 py_ver
= str(config
['python_version'])
37 supported_versions
= ['2', '3']
38 if py_ver
not in supported_versions
:
39 raise ValueError("python_version must be: {}, not {}".format(
40 ' or '.join(supported_versions
), py_ver
43 log
.info("Installing Python")
44 for admin
in ceph_admin
.remotes
:
45 system_type
= teuthology
.get_system_type(admin
)
47 if system_type
== 'rpm':
48 package
= 'python34' if py_ver
== '3' else 'python'
49 ctx
.cluster
.run(args
=[
50 'sudo', 'yum', '-y', 'install',
51 package
, 'python-virtualenv'
54 package
= 'python3' if py_ver
== '3' else 'python'
55 ctx
.cluster
.run(args
=[
56 'sudo', 'apt-get', '-y', '--force-yes', 'install',
57 package
, 'python-virtualenv'
60 log
.info('Downloading ceph-deploy...')
61 testdir
= teuthology
.get_testdir(ctx
)
62 ceph_deploy_branch
= config
.get('ceph-deploy-branch', 'master')
66 'git', 'clone', '-b', ceph_deploy_branch
,
67 teuth_config
.ceph_git_base_url
+ 'ceph-deploy.git',
68 '{tdir}/ceph-deploy'.format(tdir
=testdir
),
73 '{tdir}/ceph-deploy'.format(tdir
=testdir
),
78 args
.append(str(config
['python_version']))
81 ceph_admin
.run(args
=args
)
86 log
.info('Removing ceph-deploy ...')
91 '{tdir}/ceph-deploy'.format(tdir
=testdir
),
96 def is_healthy(ctx
, config
):
97 """Wait until a Ceph cluster is healthy."""
98 testdir
= teuthology
.get_testdir(ctx
)
99 ceph_admin
= teuthology
.get_first_mon(ctx
, config
)
100 (remote
,) = ctx
.cluster
.only(ceph_admin
).remotes
.keys()
101 max_tries
= 90 # 90 tries * 10 secs --> 15 minutes
105 if tries
>= max_tries
:
106 msg
= "ceph health was unable to get 'HEALTH_OK' after waiting 15 minutes"
110 '{tdir}'.format(tdir
=testdir
),
116 raise RuntimeError(msg
)
121 '{tdir}'.format(tdir
=testdir
),
127 logger
=log
.getChild('health'),
129 out
= r
.stdout
.getvalue()
130 log
.info('Ceph health: %s', out
.rstrip('\n'))
131 if out
.split(None, 1)[0] == 'HEALTH_OK':
136 def get_nodes_using_role(ctx
, target_role
):
138 Extract the names of nodes that match a given role from a cluster, and modify the
139 cluster's service IDs to match the resulting node-based naming scheme that ceph-deploy
140 uses, such that if "mon.a" is on host "foo23", it'll be renamed to "mon.foo23".
143 # Nodes containing a service of the specified role
144 nodes_of_interest
= []
146 # Prepare a modified version of cluster.remotes with ceph-deploy-ized names
147 modified_remotes
= {}
149 for _remote
, roles_for_host
in ctx
.cluster
.remotes
.iteritems():
150 modified_remotes
[_remote
] = []
151 for svc_id
in roles_for_host
:
152 if svc_id
.startswith("{0}.".format(target_role
)):
153 fqdn
= str(_remote
).split('@')[-1]
154 nodename
= str(str(_remote
).split('.')[0]).split('@')[1]
155 if target_role
== 'mon':
156 nodes_of_interest
.append(fqdn
)
158 nodes_of_interest
.append(nodename
)
160 modified_remotes
[_remote
].append(
161 "{0}.{1}".format(target_role
, nodename
))
163 modified_remotes
[_remote
].append(svc_id
)
165 ctx
.cluster
.remotes
= modified_remotes
167 return nodes_of_interest
170 def get_dev_for_osd(ctx
, config
):
171 """Get a list of all osd device names."""
173 for remote
, roles_for_host
in ctx
.cluster
.remotes
.iteritems():
174 host
= remote
.name
.split('@')[-1]
175 shortname
= host
.split('.')[0]
176 devs
= teuthology
.get_scratch_devices(remote
)
177 num_osd_per_host
= list(
178 teuthology
.roles_of_type(
179 roles_for_host
, 'osd'))
180 num_osds
= len(num_osd_per_host
)
181 if config
.get('separate_journal_disk') is not None:
182 num_devs_reqd
= 2 * num_osds
183 assert num_devs_reqd
<= len(
184 devs
), 'fewer data and journal disks than required ' + shortname
185 for dindex
in range(0, num_devs_reqd
, 2):
186 jd_index
= dindex
+ 1
187 dev_short
= devs
[dindex
].split('/')[-1]
188 jdev_short
= devs
[jd_index
].split('/')[-1]
189 osd_devs
.append((shortname
, dev_short
, jdev_short
))
191 assert num_osds
<= len(devs
), 'fewer disks than osds ' + shortname
192 for dev
in devs
[:num_osds
]:
193 dev_short
= dev
.split('/')[-1]
194 osd_devs
.append((shortname
, dev_short
))
198 def get_all_nodes(ctx
, config
):
199 """Return a string of node names separated by blanks"""
201 for t
, k
in ctx
.config
['targets'].iteritems():
202 host
= t
.split('@')[-1]
203 simple_host
= host
.split('.')[0]
204 nodelist
.append(simple_host
)
205 nodelist
= " ".join(nodelist
)
209 @contextlib.contextmanager
210 def build_ceph_cluster(ctx
, config
):
211 """Build a ceph cluster"""
213 # Expect to find ceph_admin on the first mon by ID, same place that the download task
214 # puts it. Remember this here, because subsequently IDs will change from those in
215 # the test config to those that ceph-deploy invents.
216 (ceph_admin
,) = ctx
.cluster
.only(
217 teuthology
.get_first_mon(ctx
, config
)).remotes
.iterkeys()
219 def execute_ceph_deploy(cmd
):
220 """Remotely execute a ceph_deploy command"""
221 return ceph_admin
.run(
224 '{tdir}/ceph-deploy'.format(tdir
=testdir
),
232 log
.info('Building ceph cluster using ceph-deploy...')
233 testdir
= teuthology
.get_testdir(ctx
)
235 if config
.get('branch') is not None:
236 cbranch
= config
.get('branch')
237 for var
, val
in cbranch
.iteritems():
238 ceph_branch
= '--{var}={val}'.format(var
=var
, val
=val
)
239 all_nodes
= get_all_nodes(ctx
, config
)
240 mds_nodes
= get_nodes_using_role(ctx
, 'mds')
241 mds_nodes
= " ".join(mds_nodes
)
242 mon_node
= get_nodes_using_role(ctx
, 'mon')
243 mon_nodes
= " ".join(mon_node
)
244 new_mon
= './ceph-deploy new' + " " + mon_nodes
245 mon_hostname
= mon_nodes
.split(' ')[0]
246 mon_hostname
= str(mon_hostname
)
247 gather_keys
= './ceph-deploy gatherkeys' + " " + mon_hostname
248 deploy_mds
= './ceph-deploy mds create' + " " + mds_nodes
251 if mon_nodes
is None:
252 raise RuntimeError("no monitor nodes in the config file")
254 estatus_new
= execute_ceph_deploy(new_mon
)
256 raise RuntimeError("ceph-deploy: new command failed")
258 log
.info('adding config inputs...')
259 testdir
= teuthology
.get_testdir(ctx
)
260 conf_path
= '{tdir}/ceph-deploy/ceph.conf'.format(tdir
=testdir
)
262 if config
.get('conf') is not None:
263 confp
= config
.get('conf')
264 for section
, keys
in confp
.iteritems():
265 lines
= '[{section}]\n'.format(section
=section
)
266 teuthology
.append_lines_to_file(ceph_admin
, conf_path
, lines
,
268 for key
, value
in keys
.iteritems():
269 log
.info("[%s] %s = %s" % (section
, key
, value
))
270 lines
= '{key} = {value}\n'.format(key
=key
, value
=value
)
271 teuthology
.append_lines_to_file(
272 ceph_admin
, conf_path
, lines
, sudo
=True)
275 dev_branch
= ctx
.config
['branch']
276 branch
= '--dev={branch}'.format(branch
=dev_branch
)
281 install_nodes
= './ceph-deploy install ' + option
+ " " + all_nodes
282 estatus_install
= execute_ceph_deploy(install_nodes
)
283 if estatus_install
!= 0:
284 raise RuntimeError("ceph-deploy: Failed to install ceph")
285 # install ceph-test package too
286 install_nodes2
= './ceph-deploy install --tests ' + option
+ \
288 estatus_install
= execute_ceph_deploy(install_nodes2
)
289 if estatus_install
!= 0:
290 raise RuntimeError("ceph-deploy: Failed to install ceph-test")
292 mon_create_nodes
= './ceph-deploy mon create-initial'
293 # If the following fails, it is OK, it might just be that the monitors
294 # are taking way more than a minute/monitor to form quorum, so lets
295 # try the next block which will wait up to 15 minutes to gatherkeys.
296 execute_ceph_deploy(mon_create_nodes
)
298 # create-keys is explicit now
299 # http://tracker.ceph.com/issues/16036
300 mons
= ctx
.cluster
.only(teuthology
.is_type('mon'))
301 for remote
in mons
.remotes
.iterkeys():
302 remote
.run(args
=['sudo', 'ceph-create-keys', '--cluster', 'ceph',
303 '--id', remote
.shortname
])
305 estatus_gather
= execute_ceph_deploy(gather_keys
)
307 estatus_mds
= execute_ceph_deploy(deploy_mds
)
309 raise RuntimeError("ceph-deploy: Failed to deploy mds")
311 if config
.get('test_mon_destroy') is not None:
312 for d
in range(1, len(mon_node
)):
313 mon_destroy_nodes
= './ceph-deploy mon destroy' + \
315 estatus_mon_d
= execute_ceph_deploy(mon_destroy_nodes
)
316 if estatus_mon_d
!= 0:
317 raise RuntimeError("ceph-deploy: Failed to delete monitor")
319 node_dev_list
= get_dev_for_osd(ctx
, config
)
320 for d
in node_dev_list
:
323 zap
= './ceph-deploy disk zap ' + node
+ ':' + disk
324 estatus
= execute_ceph_deploy(zap
)
326 raise RuntimeError("ceph-deploy: Failed to zap osds")
327 osd_create_cmd
= './ceph-deploy osd create '
328 if config
.get('dmcrypt') is not None:
329 osd_create_cmd
+= '--dmcrypt '
330 osd_create_cmd
+= ":".join(d
)
331 estatus_osd
= execute_ceph_deploy(osd_create_cmd
)
333 log
.info('successfully created osd')
336 raise RuntimeError("ceph-deploy: Failed to create osds")
338 if config
.get('wait-for-healthy', True) and no_of_osds
>= 2:
339 is_healthy(ctx
=ctx
, config
=None)
341 log
.info('Setting up client nodes...')
342 conf_path
= '/etc/ceph/ceph.conf'
343 admin_keyring_path
= '/etc/ceph/ceph.client.admin.keyring'
344 first_mon
= teuthology
.get_first_mon(ctx
, config
)
345 (mon0_remote
,) = ctx
.cluster
.only(first_mon
).remotes
.keys()
346 conf_data
= teuthology
.get_file(
351 admin_keyring
= teuthology
.get_file(
353 path
=admin_keyring_path
,
357 clients
= ctx
.cluster
.only(teuthology
.is_type('client'))
358 for remot
, roles_for_host
in clients
.remotes
.iteritems():
359 for id_
in teuthology
.roles_of_type(roles_for_host
, 'client'):
361 '/etc/ceph/ceph.client.{id}.keyring'.format(id=id_
)
365 '{tdir}'.format(tdir
=testdir
),
367 'sudo', 'bash', '-c',
368 run
.Raw('"'), 'ceph',
371 'client.{id}'.format(id=id_
),
380 key_data
= teuthology
.get_file(
385 teuthology
.sudo_write_file(
391 teuthology
.sudo_write_file(
393 path
=admin_keyring_path
,
397 teuthology
.sudo_write_file(
405 log
.info('Configuring CephFS...')
406 ceph_fs
= Filesystem(ctx
, create
=True)
407 elif not config
.get('only_mon'):
409 "The cluster is NOT operational due to insufficient OSDs")
414 "Error encountered, logging exception before tearing down ceph-deploy")
415 log
.info(traceback
.format_exc())
418 if config
.get('keep_running'):
420 log
.info('Stopping ceph...')
421 ctx
.cluster
.run(args
=['sudo', 'stop', 'ceph-all', run
.Raw('||'),
422 'sudo', 'service', 'ceph', 'stop', run
.Raw('||'),
423 'sudo', 'systemctl', 'stop', 'ceph.target'])
425 # Are you really not running anymore?
426 # try first with the init tooling
427 # ignoring the status so this becomes informational only
430 'sudo', 'status', 'ceph-all', run
.Raw('||'),
431 'sudo', 'service', 'ceph', 'status', run
.Raw('||'),
432 'sudo', 'systemctl', 'status', 'ceph.target'],
435 # and now just check for the processes themselves, as if upstart/sysvinit
436 # is lying to us. Ignore errors if the grep fails
437 ctx
.cluster
.run(args
=['sudo', 'ps', 'aux', run
.Raw('|'),
438 'grep', '-v', 'grep', run
.Raw('|'),
439 'grep', 'ceph'], check_status
=False)
441 if ctx
.archive
is not None:
442 # archive mon data, too
443 log
.info('Archiving mon data...')
444 path
= os
.path
.join(ctx
.archive
, 'data')
446 mons
= ctx
.cluster
.only(teuthology
.is_type('mon'))
447 for remote
, roles
in mons
.remotes
.iteritems():
449 if role
.startswith('mon.'):
450 teuthology
.pull_directory_tarball(
453 path
+ '/' + role
+ '.tgz')
455 log
.info('Compressing logs...')
478 log
.info('Archiving logs...')
479 path
= os
.path
.join(ctx
.archive
, 'remote')
481 for remote
in ctx
.cluster
.remotes
.iterkeys():
482 sub
= os
.path
.join(path
, remote
.shortname
)
484 teuthology
.pull_directory(remote
, '/var/log/ceph',
485 os
.path
.join(sub
, 'log'))
487 # Prevent these from being undefined if the try block fails
488 all_nodes
= get_all_nodes(ctx
, config
)
489 purge_nodes
= './ceph-deploy purge' + " " + all_nodes
490 purgedata_nodes
= './ceph-deploy purgedata' + " " + all_nodes
492 log
.info('Purging package...')
493 execute_ceph_deploy(purge_nodes
)
494 log
.info('Purging data...')
495 execute_ceph_deploy(purgedata_nodes
)
498 @contextlib.contextmanager
499 def cli_test(ctx
, config
):
501 ceph-deploy cli to exercise most commonly use cli's and ensure
502 all commands works and also startup the init system.
505 log
.info('Ceph-deploy Test')
509 conf_dir
= teuthology
.get_testdir(ctx
) + "/cdtest"
511 def execute_cdeploy(admin
, cmd
, path
):
512 """Execute ceph-deploy commands """
513 """Either use git path or repo path """
514 args
= ['cd', conf_dir
, run
.Raw(';')]
516 args
.append('{path}/ceph-deploy/ceph-deploy'.format(path
=path
));
518 args
.append('ceph-deploy')
519 args
.append(run
.Raw(cmd
))
520 ec
= admin
.run(args
=args
, check_status
=False).exitstatus
523 "failed during ceph-deploy cmd: {cmd} , ec={ec}".format(cmd
=cmd
, ec
=ec
))
525 if config
.get('rhbuild'):
528 path
= teuthology
.get_testdir(ctx
)
529 # test on branch from config eg: wip-* , master or next etc
530 # packages for all distro's should exist for wip*
531 if ctx
.config
.get('branch'):
532 branch
= ctx
.config
.get('branch')
533 test_branch
= ' --dev={branch} '.format(branch
=branch
)
534 mons
= ctx
.cluster
.only(teuthology
.is_type('mon'))
535 for node
, role
in mons
.remotes
.iteritems():
537 admin
.run(args
=['mkdir', conf_dir
], check_status
=False)
538 nodename
= admin
.shortname
539 system_type
= teuthology
.get_system_type(admin
)
540 if config
.get('rhbuild'):
541 admin
.run(args
=['sudo', 'yum', 'install', 'ceph-deploy', '-y'])
542 log
.info('system type is %s', system_type
)
543 osds
= ctx
.cluster
.only(teuthology
.is_type('osd'))
545 for remote
, roles
in osds
.remotes
.iteritems():
546 devs
= teuthology
.get_scratch_devices(remote
)
547 log
.info("roles %s", roles
)
550 'Test needs minimum of 3 devices, only found %s',
552 raise RuntimeError("Needs minimum of 3 devices ")
554 conf_path
= '{conf_dir}/ceph.conf'.format(conf_dir
=conf_dir
)
555 new_cmd
= 'new ' + nodename
556 execute_cdeploy(admin
, new_cmd
, path
)
557 if config
.get('conf') is not None:
558 confp
= config
.get('conf')
559 for section
, keys
in confp
.iteritems():
560 lines
= '[{section}]\n'.format(section
=section
)
561 teuthology
.append_lines_to_file(admin
, conf_path
, lines
,
563 for key
, value
in keys
.iteritems():
564 log
.info("[%s] %s = %s" % (section
, key
, value
))
565 lines
= '{key} = {value}\n'.format(key
=key
, value
=value
)
566 teuthology
.append_lines_to_file(admin
, conf_path
, lines
,
568 new_mon_install
= 'install {branch} --mon '.format(
569 branch
=test_branch
) + nodename
570 new_mgr_install
= 'install {branch} --mgr '.format(
571 branch
=test_branch
) + nodename
572 new_osd_install
= 'install {branch} --osd '.format(
573 branch
=test_branch
) + nodename
574 new_admin
= 'install {branch} --cli '.format(branch
=test_branch
) + nodename
575 create_initial
= 'mon create-initial '
576 # either use create-keys or push command
577 push_keys
= 'admin ' + nodename
578 execute_cdeploy(admin
, new_mon_install
, path
)
579 execute_cdeploy(admin
, new_mgr_install
, path
)
580 execute_cdeploy(admin
, new_osd_install
, path
)
581 execute_cdeploy(admin
, new_admin
, path
)
582 execute_cdeploy(admin
, create_initial
, path
)
583 execute_cdeploy(admin
, push_keys
, path
)
586 zap_disk
= 'disk zap ' + "{n}:{d}".format(n
=nodename
, d
=devs
[i
])
587 prepare
= 'osd prepare ' + "{n}:{d}".format(n
=nodename
, d
=devs
[i
])
588 execute_cdeploy(admin
, zap_disk
, path
)
589 execute_cdeploy(admin
, prepare
, path
)
591 log
.info("list files for debugging purpose to check file permissions")
592 admin
.run(args
=['ls', run
.Raw('-lt'), conf_dir
])
593 remote
.run(args
=['sudo', 'ceph', '-s'], check_status
=False)
594 r
= remote
.run(args
=['sudo', 'ceph', 'health'], stdout
=StringIO())
595 out
= r
.stdout
.getvalue()
596 log
.info('Ceph health: %s', out
.rstrip('\n'))
597 log
.info("Waiting for cluster to become healthy")
598 with contextutil
.safe_while(sleep
=10, tries
=6,
599 action
='check health') as proceed
:
601 r
= remote
.run(args
=['sudo', 'ceph', 'health'], stdout
=StringIO())
602 out
= r
.stdout
.getvalue()
603 if (out
.split(None,1)[0] == 'HEALTH_OK'):
605 rgw_install
= 'install {branch} --rgw {node}'.format(
609 rgw_create
= 'rgw create ' + nodename
610 execute_cdeploy(admin
, rgw_install
, path
)
611 execute_cdeploy(admin
, rgw_create
, path
)
612 log
.info('All ceph-deploy cli tests passed')
616 log
.info("cleaning up")
617 ctx
.cluster
.run(args
=['sudo', 'stop', 'ceph-all', run
.Raw('||'),
618 'sudo', 'service', 'ceph', 'stop', run
.Raw('||'),
619 'sudo', 'systemctl', 'stop', 'ceph.target'],
623 umount_dev
= "{d}1".format(d
=devs
[i
])
624 r
= remote
.run(args
=['sudo', 'umount', run
.Raw(umount_dev
)])
625 cmd
= 'purge ' + nodename
626 execute_cdeploy(admin
, cmd
, path
)
627 cmd
= 'purgedata ' + nodename
628 execute_cdeploy(admin
, cmd
, path
)
629 log
.info("Removing temporary dir")
636 if config
.get('rhbuild'):
637 admin
.run(args
=['sudo', 'yum', 'remove', 'ceph-deploy', '-y'])
640 @contextlib.contextmanager
641 def single_node_test(ctx
, config
):
643 - ceph-deploy.single_node_test: null
646 - ceph-deploy.single_node_test:
650 log
.info("Testing ceph-deploy on single node")
653 overrides
= ctx
.config
.get('overrides', {})
654 teuthology
.deep_merge(config
, overrides
.get('ceph-deploy', {}))
656 if config
.get('rhbuild'):
657 log
.info("RH Build, Skip Download")
658 with contextutil
.nested(
659 lambda: cli_test(ctx
=ctx
, config
=config
),
663 with contextutil
.nested(
664 lambda: install_fn
.ship_utilities(ctx
=ctx
, config
=None),
665 lambda: download_ceph_deploy(ctx
=ctx
, config
=config
),
666 lambda: cli_test(ctx
=ctx
, config
=config
),
671 @contextlib.contextmanager
672 def task(ctx
, config
):
674 Set up and tear down a Ceph cluster.
685 mon_initial_members: 1
708 separate_journal_disk: yes
714 assert isinstance(config
, dict), \
715 "task ceph-deploy only supports a dictionary for configuration"
717 overrides
= ctx
.config
.get('overrides', {})
718 teuthology
.deep_merge(config
, overrides
.get('ceph-deploy', {}))
720 if config
.get('branch') is not None:
722 config
['branch'], dict), 'branch must be a dictionary'
724 log
.info('task ceph-deploy with config ' + str(config
))
726 with contextutil
.nested(
727 lambda: install_fn
.ship_utilities(ctx
=ctx
, config
=None),
728 lambda: download_ceph_deploy(ctx
=ctx
, config
=config
),
729 lambda: build_ceph_cluster(ctx
=ctx
, config
=config
),