summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2011-06-29 15:22:56 -0700
committerChris Behrens <cbehrens@codestud.com>2011-06-29 15:22:56 -0700
commit7555aca28a5ab1ba4dd1be04a91bf6347eaac84f (patch)
treef21bb20974027103bd694e2ebb4d4ec425914047
parent097e25f69a3ce4fe29addf93e4f92fa861aa54dc (diff)
downloadnova-7555aca28a5ab1ba4dd1be04a91bf6347eaac84f.tar.gz
nova-7555aca28a5ab1ba4dd1be04a91bf6347eaac84f.tar.xz
nova-7555aca28a5ab1ba4dd1be04a91bf6347eaac84f.zip
fix issue of recurse_zones not being converted to bool properly
add bool_from_str util call add test for bool_from_str slight rework of min/max_count check
-rw-r--r--nova/api/openstack/create_instance_helper.py10
-rw-r--r--nova/api/openstack/servers.py3
-rw-r--r--nova/tests/test_utils.py13
-rw-r--r--nova/utils.py11
4 files changed, 27 insertions, 10 deletions
diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py
index 2cc38911a..1066713a3 100644
--- a/nova/api/openstack/create_instance_helper.py
+++ b/nova/api/openstack/create_instance_helper.py
@@ -119,14 +119,8 @@ class CreateInstanceHelper(object):
# min_count and max_count are optional. If they exist, they come
# in as strings. We want to default 'min_count' to 1, and default
# 'max_count' to be 'min_count'.
- if not min_count:
- min_count = 1
- else:
- min_count = int(min_count)
- if not max_count:
- max_count = min_count
- else:
- max_count = int(max_count)
+ min_count = int(min_count) if min_count else 1
+ max_count = int(max_count) if max_count else min_count
if min_count > max_count:
min_count = max_count
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 66ef97af0..fc1ab8d46 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -80,8 +80,7 @@ class Controller(object):
reservation_id = query_str.get('reservation_id')
project_id = query_str.get('project_id')
fixed_ip = query_str.get('fixed_ip')
- recurse_zones = query_str.get('recurse_zones')
- recurse_zones = recurse_zones and True or False
+ recurse_zones = utils.bool_from_str(query_str.get('recurse_zones'))
instance_list = self.compute_api.get_all(
req.environ['nova.context'],
reservation_id=reservation_id,
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py
index 3a3f914e4..0c359e981 100644
--- a/nova/tests/test_utils.py
+++ b/nova/tests/test_utils.py
@@ -276,6 +276,19 @@ class GenericUtilsTestCase(test.TestCase):
result = utils.parse_server_string('www.exa:mple.com:8443')
self.assertEqual(('', ''), result)
+ def test_bool_from_str(self):
+ self.assertTrue(utils.bool_from_str('1'))
+ self.assertTrue(utils.bool_from_str('2'))
+ self.assertTrue(utils.bool_from_str('-1'))
+ self.assertTrue(utils.bool_from_str('true'))
+ self.assertTrue(utils.bool_from_str('True'))
+ self.assertTrue(utils.bool_from_str('tRuE'))
+ self.assertFalse(utils.bool_from_str('False'))
+ self.assertFalse(utils.bool_from_str('false'))
+ self.assertFalse(utils.bool_from_str('0'))
+ self.assertFalse(utils.bool_from_str(None))
+ self.assertFalse(utils.bool_from_str('junk'))
+
class IsUUIDLikeTestCase(test.TestCase):
def assertUUIDLike(self, val, expected):
diff --git a/nova/utils.py b/nova/utils.py
index 510cdd9f6..be26899ca 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -772,6 +772,17 @@ def is_uuid_like(val):
return (len(val) == 36) and (val.count('-') == 4)
+def bool_from_str(val):
+ """Convert a string representation of a bool into a bool value"""
+
+ if not val:
+ return False
+ try:
+ return True if int(val) else False
+ except ValueError:
+ return val.lower() == 'true'
+
+
class Bootstrapper(object):
"""Provides environment bootstrapping capabilities for entry points."""