From 6b76d6bcfcf27c6a4edd237871e7ae2d6117d326 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Tue, 5 Jan 2016 20:24:48 +0100 Subject: [PATCH] openstack: nuke must use ID and not name Otherwise it will fail if there are multiple instances by the same name. http://tracker.ceph.com/issues/14238 Fixes: #14238 Signed-off-by: Loic Dachary --- teuthology/nuke.py | 11 ++++++----- teuthology/test/test_nuke.py | 17 +++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/teuthology/nuke.py b/teuthology/nuke.py index cd9d2f8a18..3452c96c4e 100644 --- a/teuthology/nuke.py +++ b/teuthology/nuke.py @@ -370,7 +370,7 @@ def synch_clocks(remotes): 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) @@ -387,11 +387,11 @@ OPENSTACK_DELAY = 30 * 60 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): @@ -457,11 +457,12 @@ def stale_openstack_volumes(ctx, volumes): 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}" diff --git a/teuthology/test/test_nuke.py b/teuthology/test/test_nuke.py index a4e75f0ab0..a77e2b54b9 100644 --- a/teuthology/test/test_nuke.py +++ b/teuthology/test/test_nuke.py @@ -88,6 +88,7 @@ class TestNuke(object): 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") # @@ -144,7 +145,10 @@ class TestNuke(object): 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', }, @@ -156,6 +160,7 @@ class TestNuke(object): 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. @@ -168,7 +173,7 @@ class TestNuke(object): destroy=DEFAULT, ) as m: nuke.stale_openstack_instances(ctx, { - name: { 'id': 'UUID', }, + uuid: { 'Name': name, }, }, { }) m['destroy'].assert_not_called() @@ -183,7 +188,7 @@ class TestNuke(object): destroy=DEFAULT, ) as m: nuke.stale_openstack_instances(ctx, { - name: { 'id': 'UUID', }, + uuid: { 'Name': name, }, }, { misc.canonicalize_hostname(name, user=None): {}, }) @@ -199,7 +204,7 @@ class TestNuke(object): destroy=DEFAULT, ) as m: nuke.stale_openstack_instances(ctx, { - name: { 'id': 'UUID', }, + uuid: { 'Name': name, }, }, { misc.canonicalize_hostname(name, user=None): {}, }) @@ -216,7 +221,7 @@ class TestNuke(object): destroy=DEFAULT, ) as m: nuke.stale_openstack_instances(ctx, { - name: { 'id': 'UUID', }, + uuid: { 'Name': name, }, }, { }) m['destroy'].assert_called_with() @@ -232,7 +237,7 @@ class TestNuke(object): destroy=DEFAULT, ) as m: nuke.stale_openstack_instances(ctx, { - name: { 'id': 'UUID', }, + uuid: { 'Name': name, }, }, { misc.canonicalize_hostname(name, user=None): {}, }) -- 2.39.5