]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
make get_flavor_id to work if input is flavor id
authorVijendar Komalla <vijendar.komalla@RACKSPACE.COM>
Wed, 18 Sep 2013 17:27:33 +0000 (12:27 -0500)
committerVijendar Komalla <vijendar.komalla@RACKSPACE.COM>
Wed, 18 Sep 2013 17:27:37 +0000 (12:27 -0500)
Current implementation of get_flavor_id throws exception if input
value is a flavor id. This method is used in couple of resources
where input flavor could be flavor id. This change is to avoid
throwing exception if the input is flavor id.

Fixes bug #1227255

Change-Id: I11054d5f3a34a7e2afea140f8f37a21cb8eba419

heat/engine/resources/nova_utils.py
heat/tests/test_nova_utils.py

index 09578325d91560dc9ae7f2a5232f1e00d99ad0f6..740db39c1a2516153c03072b4d82708fe13f484e 100644 (file)
@@ -86,6 +86,7 @@ def get_image_id(nova_client, image_identifier):
 def get_flavor_id(nova_client, flavor):
     '''
     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 flavor: the name of the flavor to find
@@ -98,6 +99,9 @@ def get_flavor_id(nova_client, flavor):
         if o.name == flavor:
             flavor_id = o.id
             break
+        if o.id == flavor:
+            flavor_id = o.id
+            break
     if flavor_id is None:
         raise exception.FlavorMissing(flavor_id=flavor)
     return flavor_id
index 6c9f04c01549b0070c614701c211f1949f82f22b..ca3f5559e8249be6b625965583e8d18dfe8e8b0d 100644 (file)
@@ -62,6 +62,8 @@ class NovaUtilsTests(HeatTestCase):
         self.m.ReplayAll()
         self.assertEqual(flav_id, nova_utils.get_flavor_id(self.nova_client,
                                                            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.nova_client, 'noflavor')
         self.m.VerifyAll()