2014-10-17 02:20:42 +00:00
|
|
|
"""
|
|
|
|
Calamari setup task
|
|
|
|
"""
|
|
|
|
import contextlib
|
2014-11-04 22:07:07 +00:00
|
|
|
import logging
|
2014-10-17 02:20:42 +00:00
|
|
|
import os
|
2014-11-04 22:07:07 +00:00
|
|
|
import requests
|
|
|
|
import shutil
|
2014-10-17 02:20:42 +00:00
|
|
|
import webbrowser
|
2014-11-04 22:07:07 +00:00
|
|
|
|
2014-10-17 02:20:42 +00:00
|
|
|
from cStringIO import StringIO
|
|
|
|
from teuthology.orchestra import run
|
|
|
|
from teuthology import contextutil
|
|
|
|
from teuthology import misc
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2014-11-04 22:07:07 +00:00
|
|
|
|
2015-03-26 23:46:35 +00:00
|
|
|
DEFAULTS = {
|
|
|
|
'version': 'v0.80.9',
|
|
|
|
'test_image': None,
|
|
|
|
'start_browser': False,
|
|
|
|
'email': 'x@y.com',
|
|
|
|
'no_epel': True,
|
|
|
|
'calamari_user': 'admin',
|
|
|
|
'calamari_password': 'admin',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-04 22:07:07 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Do the setup of a calamari server.
|
|
|
|
|
|
|
|
- calamari_setup:
|
|
|
|
version: 'v80.1'
|
2015-03-26 22:29:37 +00:00
|
|
|
test_image: <path to tarball or iso>
|
2014-11-04 22:07:07 +00:00
|
|
|
|
2015-03-26 23:46:35 +00:00
|
|
|
Options are (see DEFAULTS above):
|
2014-11-04 22:07:07 +00:00
|
|
|
|
2015-03-26 23:46:35 +00:00
|
|
|
version -- ceph version we are testing against
|
2015-03-26 22:29:37 +00:00
|
|
|
test_image -- Can be an HTTP URL, in which case fetch from this
|
|
|
|
http path; can also be local path
|
2014-11-04 22:07:07 +00:00
|
|
|
start_browser -- If True, start a browser. To be used by runs that will
|
|
|
|
bring up a browser quickly for human use. Set to False
|
|
|
|
for overnight suites that are testing for problems in
|
2015-03-26 23:46:35 +00:00
|
|
|
the installation itself
|
|
|
|
email -- email address for the user
|
2014-11-04 22:07:07 +00:00
|
|
|
no_epel -- indicates if we should remove epel files prior to yum
|
2015-03-26 23:46:35 +00:00
|
|
|
installations.
|
|
|
|
calamari_user -- user name to log into gui
|
|
|
|
calamari_password -- calamari user password
|
2014-11-04 22:07:07 +00:00
|
|
|
"""
|
2015-03-26 23:46:35 +00:00
|
|
|
config = DEFAULTS.update(config)
|
2014-11-04 22:07:07 +00:00
|
|
|
cal_svr = None
|
|
|
|
for remote_, roles in ctx.cluster.remotes.items():
|
|
|
|
if 'client.0' in roles:
|
|
|
|
cal_svr = remote_
|
|
|
|
break
|
|
|
|
if not cal_svr:
|
|
|
|
raise RuntimeError('client.0 not found in roles')
|
|
|
|
with contextutil.nested(
|
2015-03-26 23:46:35 +00:00
|
|
|
lambda: adjust_yum_repos(ctx, cal_svr, config['no_epel']),
|
2014-11-04 22:07:07 +00:00
|
|
|
lambda: calamari_install(config, cal_svr),
|
|
|
|
lambda: ceph_install(ctx, cal_svr),
|
|
|
|
lambda: calamari_connect(ctx, cal_svr),
|
2015-03-26 23:46:35 +00:00
|
|
|
lambda: browser(config['start_browser'], cal_svr.hostname),
|
2014-11-04 22:07:07 +00:00
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def adjust_yum_repos(ctx, cal_svr, no_epel):
|
|
|
|
"""
|
|
|
|
For each remote machine, fix the repos if yum is used.
|
|
|
|
"""
|
|
|
|
ice_distro = str(cal_svr.os)
|
|
|
|
if ice_distro.startswith('rhel') or ice_distro.startswith('centos'):
|
|
|
|
if no_epel:
|
|
|
|
for remote in ctx.cluster.remotes:
|
|
|
|
fix_yum_repos(remote, ice_distro)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
if ice_distro.startswith('rhel') or ice_distro.startswith('centos'):
|
|
|
|
if no_epel:
|
|
|
|
for remote in ctx.cluster.remotes:
|
|
|
|
restore_yum_repos(remote)
|
|
|
|
|
|
|
|
|
|
|
|
def restore_yum_repos(remote):
|
|
|
|
"""
|
|
|
|
Copy the old saved repo back in.
|
|
|
|
"""
|
|
|
|
if remote.run(args=['sudo', 'rm', '-rf', '/etc/yum.repos.d']).exitstatus:
|
|
|
|
return False
|
|
|
|
if remote.run(args=['sudo', 'mv', '/etc/yum.repos.d.old',
|
|
|
|
'/etc/yum.repos.d']).exitstatus:
|
|
|
|
return False
|
|
|
|
|
2014-10-17 02:20:42 +00:00
|
|
|
|
|
|
|
def fix_yum_repos(remote, distro):
|
|
|
|
"""
|
|
|
|
For yum calamari installations, the repos.d directory should only
|
|
|
|
contain a repo file named rhel<version-number>.repo
|
|
|
|
"""
|
|
|
|
if distro.startswith('centos'):
|
|
|
|
cmds = [
|
|
|
|
'sudo mkdir /etc/yum.repos.d.old'.split(),
|
|
|
|
['sudo', 'cp', run.Raw('/etc/yum.repos.d/*'),
|
|
|
|
'/etc/yum.repos.d.old'],
|
|
|
|
['sudo', 'rm', run.Raw('/etc/yum.repos.d/epel*')],
|
|
|
|
]
|
|
|
|
for cmd in cmds:
|
|
|
|
if remote.run(args=cmd).exitstatus:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
cmds = [
|
|
|
|
'sudo mv /etc/yum.repos.d /etc/yum.repos.d.old'.split(),
|
|
|
|
'sudo mkdir /etc/yum.repos.d'.split(),
|
|
|
|
]
|
|
|
|
for cmd in cmds:
|
|
|
|
if remote.run(args=cmd).exitstatus:
|
|
|
|
return False
|
|
|
|
|
2014-11-04 22:07:07 +00:00
|
|
|
# map "distroversion" from Remote.os to a tuple of
|
|
|
|
# (repo title, repo name descriptor, apt-mirror repo path chunk)
|
2014-10-17 02:20:42 +00:00
|
|
|
yum_repo_params = {
|
|
|
|
'rhel 6.4': ('rhel6-server', 'RHEL', 'rhel6repo-server'),
|
|
|
|
'rhel 6.5': ('rhel6-server', 'RHEL', 'rhel6repo-server'),
|
|
|
|
'rhel 7.0': ('rhel7-server', 'RHEL', 'rhel7repo/server'),
|
|
|
|
}
|
|
|
|
repotitle, reponame, path = yum_repo_params[distro]
|
|
|
|
repopath = '/etc/yum.repos.d/%s.repo' % repotitle
|
|
|
|
# TO DO: Make this data configurable too
|
|
|
|
repo_contents = '\n'.join(
|
|
|
|
('[%s]' % repotitle,
|
|
|
|
'name=%s $releasever - $basearch' % reponame,
|
|
|
|
'baseurl=http://apt-mirror.front.sepia.ceph.com/' + path,
|
|
|
|
'gpgcheck=0',
|
|
|
|
'enabled=1')
|
|
|
|
)
|
|
|
|
misc.sudo_write_file(remote, repopath, repo_contents)
|
|
|
|
cmds = [
|
|
|
|
'sudo yum clean all'.split(),
|
|
|
|
'sudo yum makecache'.split(),
|
|
|
|
]
|
|
|
|
for cmd in cmds:
|
|
|
|
if remote.run(args=cmd).exitstatus:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2015-03-26 22:29:37 +00:00
|
|
|
def get_iceball_with_http(url, destdir):
|
2014-11-04 22:07:07 +00:00
|
|
|
'''
|
2015-03-19 00:03:17 +00:00
|
|
|
Copy iceball with http to destdir. Try both .tar.gz and .iso.
|
2014-11-04 22:07:07 +00:00
|
|
|
'''
|
|
|
|
# stream=True means we don't download until copyfileobj below,
|
|
|
|
# and don't need a temp file
|
2015-03-26 22:29:37 +00:00
|
|
|
r = requests.get(url, stream=True)
|
|
|
|
if not r.ok:
|
|
|
|
raise RuntimeError("Failed to download %s", str(url))
|
|
|
|
filename = os.path.join(destdir, url.split('/')[-1])
|
|
|
|
with open(filename, 'w') as f:
|
|
|
|
shutil.copyfileobj(r.raw, f)
|
|
|
|
log.info('saved %s as %s' % (url, filename))
|
|
|
|
return filename
|
2015-03-19 00:16:41 +00:00
|
|
|
|
|
|
|
|
2014-10-17 02:20:42 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def calamari_install(config, cal_svr):
|
|
|
|
"""
|
|
|
|
Install calamari
|
|
|
|
|
|
|
|
The steps here are:
|
2015-03-26 22:29:37 +00:00
|
|
|
-- Get the iceball, locally or from http
|
2015-03-19 00:05:02 +00:00
|
|
|
-- Copy the iceball to the calamari server, and untar/mount it.
|
|
|
|
-- Run ice-setup on the calamari server.
|
|
|
|
-- Run calamari-ctl initialize.
|
2014-10-17 02:20:42 +00:00
|
|
|
"""
|
|
|
|
client_id = str(cal_svr)
|
|
|
|
at_loc = client_id.find('@')
|
|
|
|
if at_loc > 0:
|
|
|
|
client_id = client_id[at_loc + 1:]
|
2015-03-19 00:16:41 +00:00
|
|
|
|
2015-03-26 23:46:35 +00:00
|
|
|
test_image = config['test_image']
|
2015-03-19 00:16:41 +00:00
|
|
|
|
2015-03-26 22:29:37 +00:00
|
|
|
log.info('calamari test image: %s' % test_image)
|
2015-01-13 00:36:53 +00:00
|
|
|
delete_iceball = False
|
2015-03-19 00:16:41 +00:00
|
|
|
|
2015-03-26 22:29:37 +00:00
|
|
|
if test_image.startswith('http'):
|
|
|
|
iceball_file = get_iceball_with_http(test_image, '/tmp')
|
2015-03-19 00:16:41 +00:00
|
|
|
delete_iceball = True
|
2015-03-19 00:06:14 +00:00
|
|
|
else:
|
2015-03-26 22:29:37 +00:00
|
|
|
iceball_file = test_image
|
2015-03-19 00:06:14 +00:00
|
|
|
|
|
|
|
remote_iceball_file = os.path.join('/tmp', os.path.split(iceball_file)[1])
|
|
|
|
cal_svr.put_file(iceball_file, remote_iceball_file)
|
|
|
|
if iceball_file.endswith('.tar.gz'): # XXX specify tar/iso in config?
|
|
|
|
icetype = 'tarball'
|
|
|
|
elif iceball_file.endswith('.iso'):
|
|
|
|
icetype = 'iso'
|
|
|
|
else:
|
|
|
|
raise RuntimeError('Can''t handle iceball {0}'.format(iceball_file))
|
|
|
|
|
|
|
|
if icetype == 'tarball':
|
|
|
|
ret = cal_svr.run(args=['gunzip', run.Raw('<'), remote_iceball_file,
|
|
|
|
run.Raw('|'), 'tar', 'xvf', run.Raw('-')])
|
|
|
|
if ret.exitstatus:
|
|
|
|
raise RuntimeError('remote iceball untar failed')
|
|
|
|
elif icetype == 'iso':
|
|
|
|
mountpoint = '/mnt/' # XXX create?
|
|
|
|
ret = cal_svr.run(
|
2015-03-26 22:31:05 +00:00
|
|
|
args=['sudo', 'mount', '-o', 'loop', '-r',
|
|
|
|
remote_iceball_file, mountpoint]
|
2015-03-19 00:06:14 +00:00
|
|
|
)
|
2015-01-13 03:42:19 +00:00
|
|
|
|
2015-03-19 00:06:14 +00:00
|
|
|
# install ice_setup package
|
|
|
|
args = {
|
2015-03-19 20:14:52 +00:00
|
|
|
'deb': 'sudo dpkg -i /mnt/ice-setup*deb',
|
|
|
|
'rpm': 'sudo yum -y localinstall /mnt/ice_setup*rpm'
|
2015-03-19 00:06:14 +00:00
|
|
|
}.get(cal_svr.system_type, None)
|
|
|
|
if not args:
|
|
|
|
raise RuntimeError('{0}: unknown system type'.format(cal_svr))
|
|
|
|
ret = cal_svr.run(args=args)
|
2014-10-17 02:20:42 +00:00
|
|
|
if ret.exitstatus:
|
2015-03-19 00:06:14 +00:00
|
|
|
raise RuntimeError('ice_setup package install failed')
|
|
|
|
|
|
|
|
# Run ice_setup
|
2015-02-06 01:23:58 +00:00
|
|
|
icesetdata = 'yes\n\n%s\nhttp\n' % client_id
|
2014-10-17 02:20:42 +00:00
|
|
|
ice_in = StringIO(icesetdata)
|
2015-03-19 00:06:14 +00:00
|
|
|
ice_out = StringIO()
|
|
|
|
args = 'sudo ice_setup'
|
|
|
|
if icetype == 'iso':
|
|
|
|
args += ' -d /mnt'
|
|
|
|
ret = cal_svr.run(args=args, stdin=ice_in, stdout=ice_out)
|
|
|
|
log.debug(ice_out.getvalue())
|
2014-10-17 02:20:42 +00:00
|
|
|
if ret.exitstatus:
|
|
|
|
raise RuntimeError('ice_setup.py failed')
|
2015-03-19 00:06:14 +00:00
|
|
|
|
|
|
|
# Run calamari-ctl initialize.
|
2015-03-26 23:46:35 +00:00
|
|
|
icesetdata = '%s\n%s\n%s\n%s\n' % (
|
|
|
|
config['calamari_user'],
|
|
|
|
config['email'],
|
|
|
|
config['calamari_password'],
|
|
|
|
config['calamari_password'],
|
|
|
|
)
|
2014-10-17 02:20:42 +00:00
|
|
|
ice_in = StringIO(icesetdata)
|
|
|
|
ret = cal_svr.run(args=['sudo', 'calamari-ctl', 'initialize'],
|
2015-03-19 00:06:14 +00:00
|
|
|
stdin=ice_in, stdout=ice_out)
|
|
|
|
log.debug(ice_out.getvalue())
|
2014-10-17 02:20:42 +00:00
|
|
|
if ret.exitstatus:
|
|
|
|
raise RuntimeError('calamari-ctl initialize failed')
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
log.info('Cleaning up after Calamari installation')
|
2015-01-13 00:36:53 +00:00
|
|
|
if delete_iceball:
|
2015-03-19 00:06:14 +00:00
|
|
|
os.unlink(iceball_file)
|
2014-10-17 02:20:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def ceph_install(ctx, cal_svr):
|
|
|
|
"""
|
|
|
|
Install ceph if ceph was not previously installed by teuthology. This
|
|
|
|
code tests the case where calamari is installed on a brand new system.
|
|
|
|
"""
|
|
|
|
loc_inst = False
|
|
|
|
if 'install' not in [x.keys()[0] for x in ctx.config['tasks']]:
|
|
|
|
loc_inst = True
|
|
|
|
ret = deploy_ceph(ctx, cal_svr)
|
|
|
|
if ret:
|
|
|
|
raise RuntimeError('ceph installs failed')
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
if loc_inst:
|
|
|
|
if not undeploy_ceph(ctx, cal_svr):
|
|
|
|
log.error('Cleanup of Ceph installed by Calamari-setup failed')
|
|
|
|
|
|
|
|
|
2014-11-04 22:07:07 +00:00
|
|
|
def deploy_ceph(ctx, cal_svr):
|
|
|
|
"""
|
|
|
|
Perform the ceph-deploy actions needed to bring up a Ceph cluster. This
|
|
|
|
test is needed to check the ceph-deploy that comes with the calamari
|
|
|
|
package.
|
|
|
|
"""
|
|
|
|
osd_to_name = {}
|
|
|
|
all_machines = set()
|
2015-01-10 00:10:11 +00:00
|
|
|
all_mons = set()
|
2014-11-04 22:07:07 +00:00
|
|
|
for remote in ctx.cluster.remotes:
|
|
|
|
all_machines.add(remote.shortname)
|
|
|
|
roles = ctx.cluster.remotes[remote]
|
|
|
|
for role in roles:
|
|
|
|
daemon_type, number = role.split('.')
|
|
|
|
if daemon_type == 'osd':
|
|
|
|
osd_to_name[number] = remote.shortname
|
2015-01-10 00:10:11 +00:00
|
|
|
if daemon_type == 'mon':
|
|
|
|
all_mons.add(remote.shortname)
|
|
|
|
first_cmds = [['new'] + list(all_mons), ['install'] + list(all_machines),
|
2015-03-19 00:16:41 +00:00
|
|
|
['mon', 'create-initial']]
|
2014-11-04 22:07:07 +00:00
|
|
|
ret = True
|
|
|
|
for entry in first_cmds:
|
|
|
|
arg_list = ['ceph-deploy'] + entry
|
|
|
|
log.info('Running: %s' % ' '.join(arg_list))
|
|
|
|
ret &= cal_svr.run(args=arg_list).exitstatus
|
|
|
|
disk_labels = '_dcba'
|
|
|
|
# NEEDS WORK assumes disks start with vd (need to check this somewhere)
|
|
|
|
for cmd_pts in [['disk', 'zap'], ['osd', 'prepare'], ['osd', 'activate']]:
|
|
|
|
mach_osd_cnt = {}
|
|
|
|
for osdn in osd_to_name:
|
|
|
|
osd_mac = osd_to_name[osdn]
|
|
|
|
mach_osd_cnt[osd_mac] = mach_osd_cnt.get(osd_mac, 0) + 1
|
|
|
|
arg_list = ['ceph-deploy']
|
|
|
|
arg_list.extend(cmd_pts)
|
|
|
|
disk_id = '%s:vd%s' % (osd_to_name[osdn],
|
|
|
|
disk_labels[mach_osd_cnt[osd_mac]])
|
|
|
|
if 'activate' in cmd_pts:
|
|
|
|
disk_id += '1'
|
|
|
|
arg_list.append(disk_id)
|
|
|
|
log.info('Running: %s' % ' '.join(arg_list))
|
|
|
|
ret &= cal_svr.run(args=arg_list).exitstatus
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def undeploy_ceph(ctx, cal_svr):
|
|
|
|
"""
|
|
|
|
Cleanup deployment of ceph.
|
|
|
|
"""
|
|
|
|
all_machines = []
|
|
|
|
ret = True
|
|
|
|
for remote in ctx.cluster.remotes:
|
|
|
|
ret &= remote.run(args=['sudo', 'stop', 'ceph-all', run.Raw('||'),
|
|
|
|
'sudo', 'service', 'ceph', 'stop']
|
2015-03-19 20:14:52 +00:00
|
|
|
).exitstatus
|
2014-11-04 22:07:07 +00:00
|
|
|
all_machines.append(remote.shortname)
|
|
|
|
all_machines = set(all_machines)
|
|
|
|
cmd1 = ['ceph-deploy', 'uninstall']
|
|
|
|
cmd1.extend(all_machines)
|
|
|
|
ret &= cal_svr.run(args=cmd1).exitstatus
|
|
|
|
cmd2 = ['ceph-deploy', 'purge']
|
|
|
|
cmd2.extend(all_machines)
|
|
|
|
ret &= cal_svr.run(args=cmd2).exitstatus
|
|
|
|
for remote in ctx.cluster.remotes:
|
|
|
|
ret &= remote.run(args=['sudo', 'rm', '-rf',
|
|
|
|
'.ssh/known_hosts']).exitstatus
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2014-10-17 02:20:42 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def calamari_connect(ctx, cal_svr):
|
|
|
|
"""
|
|
|
|
Connect calamari to the ceph nodes.
|
|
|
|
"""
|
|
|
|
connects = ['ceph-deploy', 'calamari', 'connect']
|
|
|
|
for machine_info in ctx.cluster.remotes:
|
|
|
|
if 'client.0' not in ctx.cluster.remotes[machine_info]:
|
|
|
|
connects.append(machine_info.shortname)
|
|
|
|
ret = cal_svr.run(args=connects)
|
|
|
|
if ret.exitstatus:
|
|
|
|
raise RuntimeError('calamari connect failed')
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
log.info('Calamari test terminating')
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def browser(start_browser, web_page):
|
|
|
|
"""
|
|
|
|
Bring up a browser, if wanted.
|
|
|
|
"""
|
|
|
|
if start_browser:
|
|
|
|
webbrowser.open('http://%s' % web_page)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
if start_browser:
|
|
|
|
log.info('Web browser support terminating')
|