def stale_openstack(ctx):
- targets = dict(map(lambda i: (i['Name'], i),
+ targets = dict(map(lambda i: (i['ID'], i),
OpenStack.list_instances()))
nodes = list_locks(keyed_by_name=True, locked=True)
stale_openstack_instances(ctx, targets, nodes)
def stale_openstack_instances(ctx, instances, locked_nodes):
- for (name, instance) in instances.iteritems():
- i = OpenStackInstance(name)
+ for (instance_id, instance) in instances.iteritems():
+ i = OpenStackInstance(instance_id)
if not i.exists():
log.debug("stale-openstack: {instance} disappeared, ignored"
- .format(instance=name))
+ .format(instance=instance_id))
continue
if (i.get_created() >
config['max_job_time'] + OPENSTACK_DELAY):
def stale_openstack_nodes(ctx, instances, locked_nodes):
+ names = set([ i['Name'] for i in instances.values() ])
for (name, node) in locked_nodes.iteritems():
name = decanonicalize_hostname(name)
if node['machine_type'] != 'openstack':
continue
- if (name not in instances and
+ if (name not in names and
locked_since_seconds(node) > OPENSTACK_DELAY):
log.info("stale-openstack: unlocking node {name} unlocked"
" because it was created {created}"
ctx.teuthology_config = config
ctx.dry_run = False
name = 'target1'
+ uuid = 'UUID1'
now = datetime.datetime.strftime(datetime.datetime.now(),
"%Y-%m-%d %H:%M:%S.%f")
#
unlock_one=DEFAULT,
) as m:
nuke.stale_openstack_nodes(ctx, {
- name: { 'name': name, },
+ uuid: {
+ 'ID': uuid,
+ 'Name': name,
+ },
}, {
name: { 'locked_since': ancient,
'machine_type': 'openstack', },
ctx.teuthology_config = config
ctx.dry_run = False
name = 'target1'
+ uuid = 'UUID1'
#
# An instance created a second ago is left untouched,
# even when it is not locked.
destroy=DEFAULT,
) as m:
nuke.stale_openstack_instances(ctx, {
- name: { 'id': 'UUID', },
+ uuid: { 'Name': name, },
}, {
})
m['destroy'].assert_not_called()
destroy=DEFAULT,
) as m:
nuke.stale_openstack_instances(ctx, {
- name: { 'id': 'UUID', },
+ uuid: { 'Name': name, },
}, {
misc.canonicalize_hostname(name, user=None): {},
})
destroy=DEFAULT,
) as m:
nuke.stale_openstack_instances(ctx, {
- name: { 'id': 'UUID', },
+ uuid: { 'Name': name, },
}, {
misc.canonicalize_hostname(name, user=None): {},
})
destroy=DEFAULT,
) as m:
nuke.stale_openstack_instances(ctx, {
- name: { 'id': 'UUID', },
+ uuid: { 'Name': name, },
}, {
})
m['destroy'].assert_called_with()
destroy=DEFAULT,
) as m:
nuke.stale_openstack_instances(ctx, {
- name: { 'id': 'UUID', },
+ uuid: { 'Name': name, },
}, {
misc.canonicalize_hostname(name, user=None): {},
})