Boot from image fails without a clear error message

Booting an instance form image fails somewhere with
a magic error message.But as we do not support the boot
from image case. We should check that at first
when the spawn method is entered or even the
pre_for_spawn method is entered and abort with
an appropriate error message!

Closes-Bug: #1663550

Change-Id: I577b28d034322b109b81c978cb50a299be140510
Signed-off-by: Prabhat Ranjan <pranjank@in.ibm.com>
This commit is contained in:
Prabhat Ranjan 2017-04-19 18:20:40 +05:30
parent fc57d88e5e
commit ff1e8ed060
3 changed files with 37 additions and 4 deletions

View File

@ -142,13 +142,38 @@ class DPMdriverInitHostTestCase(TestCase):
@mock.patch.object(vm.PartitionInstance, 'attach_hbas')
@mock.patch.object(vm.PartitionInstance, 'get_partition')
@mock.patch.object(vm.PartitionInstance, 'properties')
def test_prep_for_spawn(self, mock_properties,
mock_partition, mock_attac_hbas,
mock_create, mock_context, mock_flavor):
self.dpmdriver.prep_for_spawn(mock.Mock, mock.Mock())
def test_prep_for_spawn_volume(self, mock_properties,
mock_partition,
mock_attac_hbas,
mock_create,
mock_context,
mock_flavor):
instance = mock.Mock()
instance.image_ref = ''
self.dpmdriver.prep_for_spawn(mock.Mock, instance)
mock_create.assert_called_once()
mock_attac_hbas.assert_called_once()
@mock.patch.object(flavor_object.Flavor, 'get_by_id')
@mock.patch.object(context_object, 'get_admin_context')
@mock.patch.object(vm.PartitionInstance, 'create')
@mock.patch.object(vm.PartitionInstance, 'attach_hbas')
@mock.patch.object(vm.PartitionInstance, 'get_partition')
@mock.patch.object(vm.PartitionInstance, 'properties')
def test_prep_for_spawn_image(self, mock_properties,
mock_partition,
mock_attac_hbas,
mock_create,
mock_context,
mock_flavor):
instance = mock.Mock()
instance.image_ref = '6c77503d-4bff-4205-9e90-d75373c3c689'
self.assertRaises(
exceptions.BootFromImageNotSupported,
self.dpmdriver.prep_for_spawn,
mock.Mock(), instance)
@mock.patch.object(vm.PartitionInstance, 'get_partition')
def test_get_volume_connector(self, mock_get_partition):
self.dpmdriver.get_volume_connector(mock.Mock())

View File

@ -300,6 +300,10 @@ class DPMDriver(driver.ComputeDriver):
def prep_for_spawn(self, context, instance,
flavor=None):
if instance.image_ref != '':
raise exceptions.BootFromImageNotSupported()
if not flavor:
context = context_object.get_admin_context(read_deleted='yes')
flavor = (

View File

@ -32,6 +32,10 @@ class BootOsSpecificParametersPropertyExceededError(NovaException):
"'boot-os-specific-parameters' property.")
class BootFromImageNotSupported(NovaException):
msg_fmt = _("Boot from image is not supported in nova-dpm.")
class UnsupportedVolumeTypeException(NovaException):
msg_fmt = _("Driver volume type"
" %(vol_type)s is not supported by nova-dpm.")