2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Admin Socket task -- used in rados, powercycle, and smoke testing
|
|
|
|
"""
|
2012-01-27 19:26:42 +00:00
|
|
|
from cStringIO import StringIO
|
|
|
|
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import os
|
2013-08-27 22:58:14 +00:00
|
|
|
import time
|
2012-01-27 19:26:42 +00:00
|
|
|
|
2014-08-07 14:24:59 +00:00
|
|
|
from teuthology.orchestra import run
|
2012-01-27 19:26:42 +00:00
|
|
|
from teuthology import misc as teuthology
|
|
|
|
from teuthology.parallel import parallel
|
2016-12-15 18:35:02 +00:00
|
|
|
from teuthology.config import config as teuth_config
|
2012-01-27 19:26:42 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-10-12 08:28:27 +00:00
|
|
|
|
2012-01-27 19:26:42 +00:00
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Run an admin socket command, make sure the output is json, and run
|
|
|
|
a test program on it. The test program should read json from
|
|
|
|
stdin. This task succeeds if the test program exits with status 0.
|
|
|
|
|
|
|
|
To run the same test on all clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rados:
|
|
|
|
- admin_socket:
|
|
|
|
all:
|
|
|
|
dump_requests:
|
|
|
|
test: http://example.com/script
|
|
|
|
|
|
|
|
To restrict it to certain clients::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rados: [client.1]
|
|
|
|
- admin_socket:
|
|
|
|
client.1:
|
|
|
|
dump_requests:
|
|
|
|
test: http://example.com/script
|
|
|
|
|
|
|
|
If an admin socket command has arguments, they can be specified as
|
|
|
|
a list::
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- ceph:
|
|
|
|
- rados: [client.0]
|
|
|
|
- admin_socket:
|
|
|
|
client.0:
|
|
|
|
dump_requests:
|
|
|
|
test: http://example.com/script
|
|
|
|
help:
|
|
|
|
test: http://example.com/test_help_version
|
|
|
|
args: [version]
|
|
|
|
|
|
|
|
Note that there must be a ceph client with an admin socket running
|
|
|
|
before this task is run. The tests are parallelized at the client
|
|
|
|
level. Tests for a single client are run serially.
|
2013-10-12 08:28:27 +00:00
|
|
|
|
|
|
|
:param ctx: Context
|
|
|
|
:param config: Configuration
|
2012-01-27 19:26:42 +00:00
|
|
|
"""
|
|
|
|
assert isinstance(config, dict), \
|
|
|
|
'admin_socket task requires a dict for configuration'
|
|
|
|
teuthology.replace_all_with_clients(ctx.cluster, config)
|
|
|
|
|
2013-10-12 08:28:27 +00:00
|
|
|
with parallel() as ptask:
|
2012-01-27 19:26:42 +00:00
|
|
|
for client, tests in config.iteritems():
|
2013-10-12 08:28:27 +00:00
|
|
|
ptask.spawn(_run_tests, ctx, client, tests)
|
|
|
|
|
2012-01-27 19:26:42 +00:00
|
|
|
|
2013-01-23 20:37:39 +00:00
|
|
|
def _socket_command(ctx, remote, socket_path, command, args):
|
2012-01-27 19:26:42 +00:00
|
|
|
"""
|
|
|
|
Run an admin socket command and return the result as a string.
|
2013-10-12 08:28:27 +00:00
|
|
|
|
|
|
|
:param ctx: Context
|
|
|
|
:param remote: Remote site
|
|
|
|
:param socket_path: path to socket
|
|
|
|
:param command: command to be run remotely
|
|
|
|
:param args: command arguments
|
|
|
|
|
|
|
|
:returns: output of command in json format
|
2012-01-27 19:26:42 +00:00
|
|
|
"""
|
|
|
|
json_fp = StringIO()
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2015-10-12 08:41:21 +00:00
|
|
|
max_tries = 120
|
2013-07-19 22:10:43 +00:00
|
|
|
while True:
|
|
|
|
proc = remote.run(
|
|
|
|
args=[
|
|
|
|
'sudo',
|
2013-09-06 20:08:01 +00:00
|
|
|
'adjust-ulimits',
|
2013-07-19 22:10:43 +00:00
|
|
|
'ceph-coverage',
|
|
|
|
'{tdir}/archive/coverage'.format(tdir=testdir),
|
|
|
|
'ceph',
|
|
|
|
'--admin-daemon', socket_path,
|
2013-08-09 16:04:25 +00:00
|
|
|
] + command.split(' ') + args,
|
2013-07-19 22:10:43 +00:00
|
|
|
stdout=json_fp,
|
2013-08-27 01:14:37 +00:00
|
|
|
check_status=False,
|
2013-07-19 22:10:43 +00:00
|
|
|
)
|
|
|
|
if proc.exitstatus == 0:
|
|
|
|
break
|
|
|
|
assert max_tries > 0
|
|
|
|
max_tries -= 1
|
2013-10-12 08:28:27 +00:00
|
|
|
log.info('ceph cli returned an error, command not registered yet?')
|
|
|
|
log.info('sleeping and retrying ...')
|
2013-07-19 22:10:43 +00:00
|
|
|
time.sleep(1)
|
2012-01-27 19:26:42 +00:00
|
|
|
out = json_fp.getvalue()
|
|
|
|
json_fp.close()
|
|
|
|
log.debug('admin socket command %s returned %s', command, out)
|
|
|
|
return json.loads(out)
|
|
|
|
|
|
|
|
def _run_tests(ctx, client, tests):
|
2013-10-12 08:28:27 +00:00
|
|
|
"""
|
|
|
|
Create a temp directory and wait for a client socket to be created.
|
|
|
|
For each test, copy the executable locally and run the test.
|
|
|
|
Remove temp directory when finished.
|
|
|
|
|
|
|
|
:param ctx: Context
|
|
|
|
:param client: client machine to run the test
|
|
|
|
:param tests: list of tests to run
|
|
|
|
"""
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir = teuthology.get_testdir(ctx)
|
2012-01-27 19:26:42 +00:00
|
|
|
log.debug('Running admin socket tests on %s', client)
|
2014-03-27 16:35:28 +00:00
|
|
|
(remote,) = ctx.cluster.only(client).remotes.iterkeys()
|
2013-02-21 19:35:36 +00:00
|
|
|
socket_path = '/var/run/ceph/ceph-{name}.asok'.format(name=client)
|
2013-06-19 17:36:49 +00:00
|
|
|
overrides = ctx.config.get('overrides', {}).get('admin_socket', {})
|
2012-01-27 19:26:42 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
tmp_dir = os.path.join(
|
2013-01-23 20:37:39 +00:00
|
|
|
testdir,
|
2012-01-27 19:26:42 +00:00
|
|
|
'admin_socket_{client}'.format(client=client),
|
|
|
|
)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'mkdir',
|
|
|
|
'--',
|
|
|
|
tmp_dir,
|
|
|
|
run.Raw('&&'),
|
|
|
|
# wait for client process to create the socket
|
|
|
|
'while', 'test', '!', '-e', socket_path, run.Raw(';'),
|
|
|
|
'do', 'sleep', '1', run.Raw(';'), 'done',
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
for command, config in tests.iteritems():
|
2012-07-24 22:25:56 +00:00
|
|
|
if config is None:
|
|
|
|
config = {}
|
2013-06-19 17:36:49 +00:00
|
|
|
teuthology.deep_merge(config, overrides)
|
2012-01-27 19:26:42 +00:00
|
|
|
log.debug('Testing %s with config %s', command, str(config))
|
|
|
|
|
2012-07-24 22:25:56 +00:00
|
|
|
test_path = None
|
|
|
|
if 'test' in config:
|
2016-12-15 18:35:02 +00:00
|
|
|
# hack: the git_url is always ceph-ci or ceph
|
|
|
|
git_url = teuth_config.get_ceph_git_url()
|
|
|
|
repo_name = 'ceph.git'
|
|
|
|
if git_url.count('ceph-ci'):
|
|
|
|
repo_name = 'ceph-ci.git'
|
2013-06-19 17:36:49 +00:00
|
|
|
url = config['test'].format(
|
2016-12-15 18:35:02 +00:00
|
|
|
branch=config.get('branch', 'master'),
|
|
|
|
repo=repo_name,
|
2013-06-19 17:36:49 +00:00
|
|
|
)
|
2012-07-24 22:25:56 +00:00
|
|
|
test_path = os.path.join(tmp_dir, command)
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'wget',
|
|
|
|
'-q',
|
|
|
|
'-O',
|
|
|
|
test_path,
|
|
|
|
'--',
|
2013-06-19 17:36:49 +00:00
|
|
|
url,
|
2012-07-24 22:25:56 +00:00
|
|
|
run.Raw('&&'),
|
|
|
|
'chmod',
|
|
|
|
'u=rx',
|
|
|
|
'--',
|
|
|
|
test_path,
|
|
|
|
],
|
|
|
|
)
|
2012-01-27 19:26:42 +00:00
|
|
|
|
|
|
|
args = config.get('args', [])
|
|
|
|
assert isinstance(args, list), \
|
|
|
|
'admin socket command args must be a list'
|
2013-01-23 20:37:39 +00:00
|
|
|
sock_out = _socket_command(ctx, remote, socket_path, command, args)
|
2013-01-29 11:45:45 +00:00
|
|
|
if test_path is not None:
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
test_path,
|
|
|
|
],
|
|
|
|
stdin=json.dumps(sock_out),
|
|
|
|
)
|
2012-01-27 19:26:42 +00:00
|
|
|
|
|
|
|
finally:
|
|
|
|
remote.run(
|
|
|
|
args=[
|
|
|
|
'rm', '-rf', '--', tmp_dir,
|
|
|
|
],
|
|
|
|
)
|