From d1f23f3634f032ee0eae26eee2c3057f309c674a Mon Sep 17 00:00:00 2001 From: Adriano Rosso Date: Mon, 30 Jan 2017 15:22:41 -0200 Subject: [PATCH] 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 --- .../volume/drivers/hitachi/test_hitachi_hnas_nfs.py | 11 +++++++++++ cinder/volume/drivers/hitachi/hnas_nfs.py | 10 ++++++++++ ...e-with-different-volume-type-b969897cba2610cc.yaml | 5 +++++ 3 files changed, 26 insertions(+) create mode 100644 releasenotes/notes/fix-hnas-clone-with-different-volume-type-b969897cba2610cc.yaml 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