def shell(ctx, config): """ Execute (shell) commands """ cluster_name = config.get('cluster', 'ceph') env = [] if 'env' in config: for k in config['env']: env.extend(['-e', k + '=' + ctx.config.get(k, '')]) del config['env'] if 'all-roles' in config and len(config) == 1: a = config['all-roles'] roles = teuthology.all_roles(ctx.cluster) config = dict((id_, a) for id_ in roles if not id_.startswith('host.')) elif 'all-hosts' in config and len(config) == 1: a = config['all-hosts'] roles = teuthology.all_roles(ctx.cluster) config = dict((id_, a) for id_ in roles if id_.startswith('host.')) for role, cmd in config.items(): (remote,) = ctx.cluster.only(role).remotes.keys() log.info('Running commands on role %s host %s', role, remote.name) if isinstance(cmd, list): for c in cmd: _shell(ctx, cluster_name, remote, ['bash', '-c', subst_vip(ctx, c)], extra_cephadm_args=env) else: assert isinstance(cmd, str) _shell(ctx, cluster_name, remote, ['bash', '-ex', '-c', subst_vip(ctx, cmd)], extra_cephadm_args=env)
def apply(ctx, config): """ Apply spec tasks: - cephadm.apply: specs: - service_type: rgw service_id: foo spec: rgw_frontend_port: 8000 - service_type: rgw service_id: bar spec: rgw_frontend_port: 9000 zone: bar realm: asdf """ cluster_name = config.get('cluster', 'ceph') specs = config.get('specs', []) y = subst_vip(ctx, yaml.dump_all(specs)) log.info(f'Applying spec(s):\n{y}') _shell( ctx, cluster_name, ctx.ceph[cluster_name].bootstrap_remote, ['ceph', 'orch', 'apply', '-i', '-'], stdin=y, )
def task(ctx, config): """ Execute some python code. tasks: - python: host.a: | import boto3 c = boto3.resource(...) The provided dict is normally indexed by role. You can also include a 'sudo: false' key to run the code without sudo. tasks: - python: sudo: false host.b: | import boto3 c = boto3.resource(...) """ assert isinstance(config, dict), "task python got invalid config" testdir = teuthology.get_testdir(ctx) sudo = config.pop('sudo', True) for role, code in config.items(): (remote,) = ctx.cluster.only(role).remotes.keys() log.info('Running python on role %s host %s', role, remote.name) log.info(code) args=[ 'TESTDIR={tdir}'.format(tdir=testdir), 'python3', ] if sudo: args = ['sudo'] + args remote.run(args=args, stdin=subst_vip(ctx, code))