|
3 | 3 | import logging |
4 | 4 | import re |
5 | 5 |
|
6 | | -from teuthology import misc as teuthology |
7 | 6 | from teuthology.config import config as teuth_config |
8 | 7 | from teuthology.exceptions import ConfigError |
9 | 8 |
|
10 | 9 | log = logging.getLogger(__name__) |
11 | 10 |
|
12 | 11 |
|
13 | | -def subst_vip(ctx, cmd): |
14 | | - p = re.compile(r'({{VIP(\d+)}})') |
15 | | - for m in p.findall(cmd): |
16 | | - n = int(m[1]) |
17 | | - if n >= len(ctx.vip["vips"]): |
18 | | - log.warning(f'no VIP{n} (we have {len(ctx.vip["vips"])})') |
19 | | - else: |
20 | | - cmd = cmd.replace(m[0], str(ctx.vip["vips"][n])) |
21 | | - |
22 | | - if '{{VIPPREFIXLEN}}' in cmd: |
23 | | - cmd = cmd.replace('{{VIPPREFIXLEN}}', str(ctx.vip["vnet"].prefixlen)) |
24 | | - |
25 | | - if '{{VIPSUBNET}}' in cmd: |
26 | | - cmd = cmd.replace('{{VIPSUBNET}}', str(ctx.vip["vnet"].network_address)) |
27 | | - |
28 | | - return cmd |
29 | | - |
30 | | - |
31 | | -def echo(ctx, config): |
32 | | - """ |
33 | | - This is mostly for debugging |
34 | | - """ |
35 | | - for remote in ctx.cluster.remotes.keys(): |
36 | | - log.info(subst_vip(ctx, config)) |
37 | | - |
38 | | - |
39 | | -def exec(ctx, config): |
40 | | - """ |
41 | | - This is similar to the standard 'exec' task, but does the VIP substitutions. |
42 | | - """ |
43 | | - assert isinstance(config, dict), "task exec got invalid config" |
44 | | - |
45 | | - testdir = teuthology.get_testdir(ctx) |
46 | | - |
47 | | - if 'all-roles' in config and len(config) == 1: |
48 | | - a = config['all-roles'] |
49 | | - roles = teuthology.all_roles(ctx.cluster) |
50 | | - config = dict((id_, a) for id_ in roles if not id_.startswith('host.')) |
51 | | - elif 'all-hosts' in config and len(config) == 1: |
52 | | - a = config['all-hosts'] |
53 | | - roles = teuthology.all_roles(ctx.cluster) |
54 | | - config = dict((id_, a) for id_ in roles if id_.startswith('host.')) |
55 | | - |
56 | | - for role, ls in config.items(): |
57 | | - (remote,) = ctx.cluster.only(role).remotes.keys() |
58 | | - log.info('Running commands on role %s host %s', role, remote.name) |
59 | | - for c in ls: |
60 | | - c.replace('$TESTDIR', testdir) |
61 | | - remote.run( |
62 | | - args=[ |
63 | | - 'sudo', |
64 | | - 'TESTDIR={tdir}'.format(tdir=testdir), |
65 | | - 'bash', |
66 | | - '-ex', |
67 | | - '-c', |
68 | | - subst_vip(ctx, c)], |
69 | | - ) |
70 | | - |
71 | | - |
72 | 12 | def _map_vips(mip, count): |
73 | 13 | vip_entries = teuth_config.get('vip', []) |
74 | 14 | if not vip_entries: |
|
0 commit comments