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
(ctx, config)
| 6 | |
| 7 | |
| 8 | def task(ctx, config): |
| 9 | """ |
| 10 | Execute some python code. |
| 11 | |
| 12 | tasks: |
| 13 | - python: |
| 14 | host.a: | |
| 15 | import boto3 |
| 16 | c = boto3.resource(...) |
| 17 | |
| 18 | The provided dict is normally indexed by role. You can also include a |
| 19 | 'sudo: false' key to run the code without sudo. |
| 20 | |
| 21 | tasks: |
| 22 | - python: |
| 23 | sudo: false |
| 24 | host.b: | |
| 25 | import boto3 |
| 26 | c = boto3.resource(...) |
| 27 | """ |
| 28 | assert isinstance(config, dict), "task python got invalid config" |
| 29 | |
| 30 | testdir = teuthology.get_testdir(ctx) |
| 31 | |
| 32 | sudo = config.pop('sudo', True) |
| 33 | |
| 34 | for role, code in config.items(): |
| 35 | (remote,) = ctx.cluster.only(role).remotes.keys() |
| 36 | log.info('Running python on role %s host %s', role, remote.name) |
| 37 | log.info(code) |
| 38 | args=[ |
| 39 | 'TESTDIR={tdir}'.format(tdir=testdir), |
| 40 | 'python3', |
| 41 | ] |
| 42 | if sudo: |
| 43 | args = ['sudo'] + args |
| 44 | code = template.transform(ctx, config, code) |
| 45 | remote.run(args=args, stdin=code) |
| 46 |