if 'targets' not in ctx.config:
return
total_unnuked = {}
- targets = dict(ctx.config['targets'])
- if ctx.name:
- log.info('Checking targets against current locks')
- locks = list_locks()
- # Remove targets who's description doesn't match archive name.
- for lock in locks:
- for target in targets:
- if target == lock['name']:
- if ctx.name not in lock['description']:
- del ctx.config['targets'][lock['name']]
- log.info(
- "Not nuking %s because description doesn't match",
- lock['name'])
- elif lock.get('up') is False:
- del ctx.config['targets'][lock['name']]
- log.info(
- "Not nuking %s because it is down",
- lock['name'])
+ log.info('Checking targets against current locks')
with parallel() as p:
for target, hostkey in ctx.config['targets'].items():
+ status = get_status(target)
+ if ctx.name and ctx.name not in status['description']:
+ total_unnuked[target] = hostkey
+ log.info(
+ f"Not nuking {target} because description doesn't match: "
+ f"{ctx.name} != {status['description']}"
+ )
+ continue
+ elif status.get('up') is False:
+ total_unnuked[target] = hostkey
+ log.info(f"Not nuking {target} because it is down")
+ continue
p.spawn(
nuke_one,
ctx,
os_version='8.3',
name='test_name',
)
- locks = [{'name': target, 'description': job_config['name']} for target
- in job_config['targets'].keys()]
+ statuses = {
+ target: {'name': target, 'description': job_config['name']}
+ for target in job_config['targets'].keys()
+ }
ctx = create_fake_context(job_config)
# minimal call using defaults
with patch.multiple(
nuke,
nuke_helper=DEFAULT,
- list_locks=lambda: locks,
unlock_one=DEFAULT,
+ get_status=lambda i: statuses[i],
) as m:
nuke.nuke(ctx, True)
m['nuke_helper'].assert_called_with(ANY, True, False, True)
with patch.multiple(
nuke,
nuke_helper=DEFAULT,
- list_locks=lambda: locks,
unlock_one=DEFAULT,
+ get_status=lambda i: statuses[i],
) as m:
nuke.nuke(ctx, False)
m['nuke_helper'].assert_called_with(ANY, False, False, True)
with patch.multiple(
nuke,
nuke_helper=DEFAULT,
- list_locks=lambda: locks,
unlock_one=DEFAULT,
+ get_status=lambda i: statuses[i],
) as m:
nuke.nuke(ctx, False, True, False, True, False)
m['nuke_helper'].assert_called_with(ANY, False, True, False)
nuke,
nuke_helper=DEFAULT,
unlock_one=DEFAULT,
+ get_status=lambda i: statuses[i],
) as m:
nuke.nuke(ctx, True)
m['nuke_helper'].assert_not_called()