From cc01b3bafb38bc32a2002d367a14047ce6314c96 Mon Sep 17 00:00:00 2001 From: Prabhat Ranjan Date: Wed, 19 Apr 2017 13:53:42 +0530 Subject: [PATCH] spawn is not checking if volume is a FC volume On instance spawn we only indirectly check if the requested volume is a FC volume via [1]. This will either fail with an "KeyError" or a "NoneType Error" depending on how the block_device_info object looks like for non FC volumes. [1] https://github.com/openstack/nova-dpm/blob/1.0.0/nova_dpm/virt/dpm/driver.py#L374 Closes-Bug: #1668343 Change-Id: I6eefda4127402d43ad9407190626220722ddee58 Signed-off-by: Prabhat Ranjan --- nova_dpm/tests/unit/virt/dpm/test_driver.py | 25 +++++++++++++++++++++ nova_dpm/virt/dpm/driver.py | 9 ++++++++ nova_dpm/virt/dpm/exceptions.py | 5 +++++ 3 files changed, 39 insertions(+) diff --git a/nova_dpm/tests/unit/virt/dpm/test_driver.py b/nova_dpm/tests/unit/virt/dpm/test_driver.py index 0984abe..2019a7e 100644 --- a/nova_dpm/tests/unit/virt/dpm/test_driver.py +++ b/nova_dpm/tests/unit/virt/dpm/test_driver.py @@ -95,6 +95,31 @@ class DPMdriverInitHostTestCase(TestCase): self.assertEqual(target_wwpn, '500507680B214AC1') self.assertEqual(lun, '0') + def test_validate_volume_type_unsupported(self): + + bdms = [ + {'connection_info': {'driver_volume_type': 'fake_vol_type'}}] + self.assertRaises(exceptions.UnsupportedVolumeTypeException, + self.dpmdriver._validate_volume_type, bdms) + + bdms = [ + {'connection_info': {'driver_volume_type': 'fake_vol_type'}}, + {'connection_info': {'driver_volume_type': 'fake_vol_type'}}] + self.assertRaises(exceptions.UnsupportedVolumeTypeException, + self.dpmdriver._validate_volume_type, bdms) + + bdms = [ + {'connection_info': {'driver_volume_type': 'fibre_channel'}}, + {'connection_info': {'driver_volume_type': 'fake_vol_type'}}] + self.assertRaises(exceptions.UnsupportedVolumeTypeException, + self.dpmdriver._validate_volume_type, bdms) + + def test_validate_volume_type_supported(self): + bdms = [ + {'connection_info': {'driver_volume_type': 'fibre_channel'}}, + {'connection_info': {'driver_volume_type': 'fibre_channel'}}] + self.dpmdriver._validate_volume_type(bdms) + @mock.patch.object(vm.PartitionInstance, 'get_partition') @mock.patch.object(vm.PartitionInstance, 'get_partition_wwpns', return_value=[PARTITION_WWPN]) diff --git a/nova_dpm/virt/dpm/driver.py b/nova_dpm/virt/dpm/driver.py index 3c5890e..88701cc 100644 --- a/nova_dpm/virt/dpm/driver.py +++ b/nova_dpm/virt/dpm/driver.py @@ -359,6 +359,8 @@ class DPMDriver(driver.ComputeDriver): block_device_mapping = driver.block_device_info_get_mapping( block_device_info) + self._validate_volume_type(block_device_mapping) + LOG.debug("Block device mapping %s", str(block_device_mapping)) wwpns = inst.get_partition_wwpns() @@ -409,6 +411,13 @@ class DPMDriver(driver.ComputeDriver): LOG.debug("Returning valid target WWPN %s", target_wwpn) return target_wwpn + def _validate_volume_type(self, bdms): + for bdm in bdms: + vol_type = bdm['connection_info']['driver_volume_type'] + if vol_type != 'fibre_channel': + raise exceptions.UnsupportedVolumeTypeException( + vol_type=vol_type) + def destroy(self, context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None): inst = vm.PartitionInstance(instance, self._cpc) diff --git a/nova_dpm/virt/dpm/exceptions.py b/nova_dpm/virt/dpm/exceptions.py index c86b6e7..dd047d9 100644 --- a/nova_dpm/virt/dpm/exceptions.py +++ b/nova_dpm/virt/dpm/exceptions.py @@ -30,3 +30,8 @@ class BootOsSpecificParametersPropertyExceededError(NovaException): """The boot-os-specific-parameters property would exceed the allowed max""" msg_fmt = _("Exceeded the maximum len for the partitions " "'boot-os-specific-parameters' property.") + + +class UnsupportedVolumeTypeException(NovaException): + msg_fmt = _("Driver volume type" + " %(vol_type)s is not supported by nova-dpm.")