]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
openstack: nuke must use ID and not name 763/head
authorLoic Dachary <ldachary@redhat.com>
Tue, 5 Jan 2016 19:24:48 +0000 (20:24 +0100)
committerLoic Dachary <ldachary@redhat.com>
Tue, 5 Jan 2016 19:43:43 +0000 (20:43 +0100)
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 <loic@dachary.org>
teuthology/nuke.py
teuthology/test/test_nuke.py

index cd9d2f8a180f594758c658b80571115cac8369c2..3452c96c4e9b8b92974b19c40323f49c461a33e9 100644 (file)
@@ -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}"
index a4e75f0ab0fe67b4f343490434eee5734443d98d..a77e2b54b9405bdedbd709c1bd37020d317d5277 100644 (file)
@@ -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): {},
             })