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
This commit is contained in:
@@ -119,14 +119,8 @@ class CreateInstanceHelper(object):
|
|||||||
# min_count and max_count are optional. If they exist, they come
|
# 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
|
# in as strings. We want to default 'min_count' to 1, and default
|
||||||
# 'max_count' to be 'min_count'.
|
# 'max_count' to be 'min_count'.
|
||||||
if not min_count:
|
min_count = int(min_count) if min_count else 1
|
||||||
min_count = 1
|
max_count = int(max_count) if max_count else min_count
|
||||||
else:
|
|
||||||
min_count = int(min_count)
|
|
||||||
if not max_count:
|
|
||||||
max_count = min_count
|
|
||||||
else:
|
|
||||||
max_count = int(max_count)
|
|
||||||
if min_count > max_count:
|
if min_count > max_count:
|
||||||
min_count = max_count
|
min_count = max_count
|
||||||
|
|
||||||
|
|||||||
@@ -80,8 +80,7 @@ class Controller(object):
|
|||||||
reservation_id = query_str.get('reservation_id')
|
reservation_id = query_str.get('reservation_id')
|
||||||
project_id = query_str.get('project_id')
|
project_id = query_str.get('project_id')
|
||||||
fixed_ip = query_str.get('fixed_ip')
|
fixed_ip = query_str.get('fixed_ip')
|
||||||
recurse_zones = query_str.get('recurse_zones')
|
recurse_zones = utils.bool_from_str(query_str.get('recurse_zones'))
|
||||||
recurse_zones = recurse_zones and True or False
|
|
||||||
instance_list = self.compute_api.get_all(
|
instance_list = self.compute_api.get_all(
|
||||||
req.environ['nova.context'],
|
req.environ['nova.context'],
|
||||||
reservation_id=reservation_id,
|
reservation_id=reservation_id,
|
||||||
|
|||||||
@@ -276,6 +276,19 @@ class GenericUtilsTestCase(test.TestCase):
|
|||||||
result = utils.parse_server_string('www.exa:mple.com:8443')
|
result = utils.parse_server_string('www.exa:mple.com:8443')
|
||||||
self.assertEqual(('', ''), result)
|
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):
|
class IsUUIDLikeTestCase(test.TestCase):
|
||||||
def assertUUIDLike(self, val, expected):
|
def assertUUIDLike(self, val, expected):
|
||||||
|
|||||||
@@ -772,6 +772,17 @@ def is_uuid_like(val):
|
|||||||
return (len(val) == 36) and (val.count('-') == 4)
|
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):
|
class Bootstrapper(object):
|
||||||
"""Provides environment bootstrapping capabilities for entry points."""
|
"""Provides environment bootstrapping capabilities for entry points."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user