Xen: convert image auto_disk_config value to bool before compare
During rescue mode the auto_disk_config value is pulled from the rescue image if provided. The value is a string but it was being used as a boolean in an 'if' statement, leading it to be True when it shouldn't be. This converts it to a boolean value before comparison. Change-Id: Ib7ffcab235ead0e770800d33c4c7cff131ca99f5 Closes-bug: 1481078
This commit is contained in:
parent
db7fc595eb
commit
20847c25a8
|
@ -182,6 +182,37 @@ class VMOpsTestCase(VMOpsTestBase):
|
|||
hard_shutdown_vm.assert_called_once_with(self._vmops._session,
|
||||
self.instance, vm_ref)
|
||||
|
||||
@mock.patch.object(vm_utils, 'try_auto_configure_disk')
|
||||
@mock.patch.object(vm_utils, 'create_vbd',
|
||||
side_effect=test.TestingException)
|
||||
def test_attach_disks_rescue_auto_disk_config_false(self, create_vbd,
|
||||
try_auto_config):
|
||||
ctxt = context.RequestContext('user', 'project')
|
||||
instance = fake_instance.fake_instance_obj(ctxt)
|
||||
image_meta = {'properties': {'auto_disk_config': 'false'}}
|
||||
vdis = {'root': {'ref': 'fake-ref'}}
|
||||
self.assertRaises(test.TestingException, self._vmops._attach_disks,
|
||||
instance, image_meta=image_meta, vm_ref=None,
|
||||
name_label=None, vdis=vdis, disk_image_type='fake',
|
||||
network_info=[], rescue=True)
|
||||
self.assertFalse(try_auto_config.called)
|
||||
|
||||
@mock.patch.object(vm_utils, 'try_auto_configure_disk')
|
||||
@mock.patch.object(vm_utils, 'create_vbd',
|
||||
side_effect=test.TestingException)
|
||||
def test_attach_disks_rescue_auto_disk_config_true(self, create_vbd,
|
||||
try_auto_config):
|
||||
ctxt = context.RequestContext('user', 'project')
|
||||
instance = fake_instance.fake_instance_obj(ctxt)
|
||||
image_meta = {'properties': {'auto_disk_config': 'true'}}
|
||||
vdis = {'root': {'ref': 'fake-ref'}}
|
||||
self.assertRaises(test.TestingException, self._vmops._attach_disks,
|
||||
instance, image_meta=image_meta, vm_ref=None,
|
||||
name_label=None, vdis=vdis, disk_image_type='fake',
|
||||
network_info=[], rescue=True)
|
||||
try_auto_config.assert_called_once_with(self._vmops._session,
|
||||
'fake-ref', instance.flavor.root_gb)
|
||||
|
||||
|
||||
class InjectAutoDiskConfigTestCase(VMOpsTestBase):
|
||||
def test_inject_auto_disk_config_when_present(self):
|
||||
|
|
|
@ -713,7 +713,8 @@ class VMOps(object):
|
|||
"rescue image_properties. Setting value to %s",
|
||||
auto_disk_config, instance=instance)
|
||||
else:
|
||||
auto_disk_config = rescue_auto_disk_config
|
||||
auto_disk_config = strutils.bool_from_string(
|
||||
rescue_auto_disk_config)
|
||||
|
||||
if auto_disk_config:
|
||||
LOG.debug("Auto configuring disk, attempting to "
|
||||
|
|
Loading…
Reference in New Issue