HNAS: Cloned volume with different volume type

HNAS NFS driver allows the creation of cloned volumes using volume
types that are not the same as the ones from the source volume. This
could make cinder information inconsistent with the real volume
location in the backend when we have multiple pools configured.
As the clones are always created in the same pool as the source
volumes, this patch makes the driver accept the creation of cloned
volumes only if they have the same volume type as the source volume.

Closes-Bug: #1660411

Change-Id: I1272a6d27d7f172e77f1260a2acc6fc7c02e2e73
This commit is contained in:
Adriano Rosso 2017-01-30 15:22:41 -02:00
parent 8c186565c3
commit d1f23f3634
3 changed files with 26 additions and 0 deletions

View File

@ -302,6 +302,17 @@ class HNASNFSDriverTest(test.TestCase):
self.assertEqual('hnas', out['provider_location'])
def test_create_cloned_volume_invalid_volume_type(self):
self.volume.volume_type_id = fake.VOLUME_TYPE_ID
self.clone.volume_type_id = fake.VOLUME_TYPE2_ID
self.mock_object(self.driver, 'extend_volume')
self.mock_object(backend.HNASSSHBackend, 'file_clone')
self.assertRaises(exception.InvalidVolumeType,
self.driver.create_cloned_volume, self.volume,
self.clone)
def test_get_volume_stats(self):
self.driver.pools = [{'pool_name': 'default',
'service_label': 'default',

View File

@ -284,6 +284,16 @@ class HNASNFSDriver(nfs.NfsDriver):
:param src_vref: reference to the source volume
:returns: the provider_location of the cloned volume
"""
# HNAS always creates cloned volumes in the same pool as the source
# volumes. So, it is not allowed to use different volume types for
# clone operations.
if volume.volume_type_id != src_vref.volume_type_id:
msg = _("Source and cloned volumes should have the same "
"volume type.")
LOG.error(msg)
raise exception.InvalidVolumeType(msg)
vol_size = volume.size
src_vol_size = src_vref.size

View File

@ -0,0 +1,5 @@
---
fixes:
- Fixed HNAS bug that placed a cloned volume in the same pool as its
source, even if the clone had a different pool specification. Driver will
not allow to make clones using a different volume type anymore.