diff --git a/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hnas_nfs.py b/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hnas_nfs.py index 7ca98678a9f..5953a2473cb 100644 --- a/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hnas_nfs.py +++ b/cinder/tests/unit/volume/drivers/hitachi/test_hitachi_hnas_nfs.py @@ -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', diff --git a/cinder/volume/drivers/hitachi/hnas_nfs.py b/cinder/volume/drivers/hitachi/hnas_nfs.py index 889ce1142ec..13186defc5f 100644 --- a/cinder/volume/drivers/hitachi/hnas_nfs.py +++ b/cinder/volume/drivers/hitachi/hnas_nfs.py @@ -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 diff --git a/releasenotes/notes/fix-hnas-clone-with-different-volume-type-b969897cba2610cc.yaml b/releasenotes/notes/fix-hnas-clone-with-different-volume-type-b969897cba2610cc.yaml new file mode 100644 index 00000000000..40dab28d620 --- /dev/null +++ b/releasenotes/notes/fix-hnas-clone-with-different-volume-type-b969897cba2610cc.yaml @@ -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. \ No newline at end of file