Merge "make get_flavor_id to work if input is flavor id"

This commit is contained in:
Jenkins 2013-09-19 09:42:11 +00:00 committed by Gerrit Code Review
commit 0bde10c663
2 changed files with 6 additions and 0 deletions

View File

@ -86,6 +86,7 @@ def get_image_id(nova_client, image_identifier):
def get_flavor_id(nova_client, flavor): def get_flavor_id(nova_client, flavor):
''' '''
Get the id for the specified flavor name. Get the id for the specified flavor name.
If the specified value is flavor id, just return it.
:param nova_client: the nova client to use :param nova_client: the nova client to use
:param flavor: the name of the flavor to find :param flavor: the name of the flavor to find
@ -98,6 +99,9 @@ def get_flavor_id(nova_client, flavor):
if o.name == flavor: if o.name == flavor:
flavor_id = o.id flavor_id = o.id
break break
if o.id == flavor:
flavor_id = o.id
break
if flavor_id is None: if flavor_id is None:
raise exception.FlavorMissing(flavor_id=flavor) raise exception.FlavorMissing(flavor_id=flavor)
return flavor_id return flavor_id

View File

@ -62,6 +62,8 @@ class NovaUtilsTests(HeatTestCase):
self.m.ReplayAll() self.m.ReplayAll()
self.assertEqual(flav_id, nova_utils.get_flavor_id(self.nova_client, self.assertEqual(flav_id, nova_utils.get_flavor_id(self.nova_client,
flav_name)) flav_name))
self.assertEqual(flav_id, nova_utils.get_flavor_id(self.nova_client,
flav_id))
self.assertRaises(exception.FlavorMissing, nova_utils.get_flavor_id, self.assertRaises(exception.FlavorMissing, nova_utils.get_flavor_id,
self.nova_client, 'noflavor') self.nova_client, 'noflavor')
self.m.VerifyAll() self.m.VerifyAll()