Skip to content

Commit

Permalink
Fix config drive code logical error.
Browse files Browse the repository at this point in the history
Image id has changed to uuid, so bool value can't be a image ID
any more, remove unnecessary test code.

fix bug #1181991

Change-Id: I420e4cdb848401375b347d43e06343efaa7bf5fc
(cherry picked from commit 4f44cd9)
  • Loading branch information
Yaguang Tang authored and russellb committed May 29, 2013
1 parent 34efd5d commit 94d87df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
10 changes: 3 additions & 7 deletions nova/compute/api.py
Expand Up @@ -479,19 +479,15 @@ def _apply_instance_name_template(self, context, instance, index):
return instance

def _check_config_drive(self, context, config_drive):
bool_like = True
try:
strutils.bool_from_string(config_drive, strict=True)
bool_like = strutils.bool_from_string(config_drive, strict=True)
except ValueError:
bool_like = False

if config_drive is None:
return None, None
elif bool_like and config_drive not in (0, 1, '0', '1'):
# NOTE(sirp): '0' and '1' could be a bool value or an ID. Since
# there are many other ways to specify bools (e.g. 't', 'f'), it's
# better to treat as an ID.
return None, config_drive
elif bool_like:
return None, bool_like
else:
cd_image_service, config_drive_id = \
glance.get_remote_image_service(context, config_drive)
Expand Down
16 changes: 4 additions & 12 deletions nova/tests/compute/test_compute.py
Expand Up @@ -8989,21 +8989,13 @@ def test_value_is_none(self):
self.assertCheck((None, None), None)
self.assertFalse(self.called['show'])

def test_value_is_bool_like_string(self):
self.assertCheck((None, 'True'), 'True')
self.assertCheck((None, 'yes'), 'yes')

def test_bool_string_or_id(self):
# NOTE(sirp): '0' and '1' could be a bool value or an ID. Since there
# are many other ways to specify bools (e.g. 't', 'f'), it's better to
# treat as an ID.
self.assertCheck((0, None), 0)
self.assertCheck((1, None), 1)
self.assertCheck(('0', None), '0')
self.assertCheck(('1', None), '1')
self.assertCheck((None, True), "true")
self.assertCheck((None, True), 1)
self.assertCheck((None, True), 't')

def test_value_is_image_id(self):
self.assertCheck((2, None), 2)
self.assertCheck(("fake-uuid", None), "fake-uuid")


class CheckRequestedImageTestCase(test.TestCase):
Expand Down

0 comments on commit 94d87df

Please sign in to comment.