From: Zack Cerza Date: Thu, 22 Oct 2015 21:05:22 +0000 (-0600) Subject: ProvisionOpenStack: Cache server info in destroy() X-Git-Tag: 1.1.0~782^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c041ef9f850a76a5a4862ab6af2c46effada37d1;p=teuthology.git ProvisionOpenStack: Cache server info in destroy() So we don't have to call "openstack server show" twice Signed-off-by: Zack Cerza --- diff --git a/teuthology/provision.py b/teuthology/provision.py index f1621f6ed..45beb0437 100644 --- a/teuthology/provision.py +++ b/teuthology/provision.py @@ -269,16 +269,20 @@ class ProvisionOpenStack(OpenStack): misc.sh("openstack server add volume " + name + " " + volume_name) - def list_volumes(self, name_or_id): + def list_volumes(self, name_or_id, server_info=None): """ Return the uuid of the volumes attached to the name_or_id OpenStack instance. + + :param name_or_id: The name or ID of the server to query + :param server_info: Optionally, use already-retrieved results of + self.show() """ - instance = misc.sh("openstack server show -f json " + - name_or_id) - volumes = self.get_value(json.loads(instance), + if not server_info: + server_info = self.show(name_or_id) + volumes = self.get_value(server_info, 'os-extended-volumes:volumes_attached') - return [ volume['id'] for volume in volumes ] + return [volume['id'] for volume in volumes ] @staticmethod def ip2name(prefix, ip): @@ -355,9 +359,10 @@ class ProvisionOpenStack(OpenStack): Delete the name_or_id OpenStack instance. """ log.debug('ProvisionOpenStack:destroy ' + name_or_id) - if not self.exists(name_or_id): + server_info = self.show(name_or_id) + if not self.exists(name_or_id, server_info=server_info): return True - volumes = self.list_volumes(name_or_id) + volumes = self.list_volumes(name_or_id, server_info=server_info) for volume in volumes: misc.sh("openstack server remove volume %s %s" % (name_or_id, volume))