Wrapped the instance_types comparison with an int and added a test case for it. Removed the inadvertently added newline

This commit is contained in:
Nirmal Ranganathan 2011-02-28 18:59:34 +00:00 committed by Tarmac
commit 78bd53a44a
3 changed files with 10 additions and 1 deletions

View File

@ -47,6 +47,7 @@ MORITA Kazutaka <morita.kazutaka@gmail.com>
Muneyuki Noguchi <noguchimn@nttdata.co.jp>
Nachi Ueno <ueno.nachi@lab.ntt.co.jp>
Naveed Massjouni <naveed.massjouni@rackspace.com>
Nirmal Ranganathan <nirmal.ranganathan@rackspace.com>
Paul Voccio <paul@openstack.org>
Ricardo Carrillo Cruz <emaildericky@gmail.com>
Rick Clark <rick@openstack.org>

View File

@ -45,6 +45,6 @@ def get_by_type(instance_type):
def get_by_flavor_id(flavor_id):
for instance_type, details in INSTANCE_TYPES.iteritems():
if details['flavorid'] == flavor_id:
if details['flavorid'] == int(flavor_id):
return instance_type
return FLAGS.default_instance_type

View File

@ -30,6 +30,7 @@ from nova import log as logging
from nova import test
from nova import utils
from nova.auth import manager
from nova.compute import instance_types
LOG = logging.getLogger('nova.tests.compute')
@ -266,3 +267,10 @@ class ComputeTestCase(test.TestCase):
self.assertEqual(ret_val, None)
self.compute.terminate_instance(self.context, instance_id)
def test_get_by_flavor_id(self):
type = instance_types.get_by_flavor_id(1)
self.assertEqual(type, 'm1.tiny')
type = instance_types.get_by_flavor_id("1")
self.assertEqual(type, 'm1.tiny')