diff --git a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py index f92a399bd3..d20b3449ce 100644 --- a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py +++ b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py @@ -723,6 +723,8 @@ class NetAppCmodeFileStorageLibrary(object): vserver_client.create_volume_clone(share_name, parent_share_name, parent_snapshot_name, **provisioning_options) + if share['size'] > snapshot['size']: + vserver_client.set_volume_size(share_name, share['size']) @na_utils.trace def _share_exists(self, share_name, vserver_client): @@ -1157,7 +1159,8 @@ class NetAppCmodeFileStorageLibrary(object): cgsnapshot_member['id']): clone_info['snapshot'] = { 'share_id': cgsnapshot_member['share_id'], - 'id': cgsnapshot_dict['id'] + 'id': cgsnapshot_dict['id'], + 'size': cgsnapshot_member['size'], } break diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py index d705dbea75..e3898c4151 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py @@ -1014,35 +1014,47 @@ class NetAppFileStorageLibraryTestCase(test.TestCase): fake.AGGREGATES[1], fake.EXTRA_SPEC) - @ddt.data(None, 'fake_location') - def test_allocate_container_from_snapshot(self, provider_location): + @ddt.data({'provider_location': None, 'size': 50}, + {'provider_location': 'fake_location', 'size': 30}, + {'provider_location': 'fake_location', 'size': 20}) + @ddt.unpack + def test_allocate_container_from_snapshot(self, provider_location, size): mock_get_provisioning_opts = self.mock_object( self.library, '_get_provisioning_options_for_share', mock.Mock(return_value=copy.deepcopy(fake.PROVISIONING_OPTIONS))) vserver = fake.VSERVER1 vserver_client = mock.Mock() + original_snapshot_size = 20 + fake_share = copy.deepcopy(fake.SHARE) + fake_share['size'] = size fake_snapshot = copy.deepcopy(fake.SNAPSHOT) fake_snapshot['provider_location'] = provider_location + fake_snapshot['size'] = original_snapshot_size - self.library._allocate_container_from_snapshot(fake.SHARE, + self.library._allocate_container_from_snapshot(fake_share, fake_snapshot, vserver, vserver_client) - share_name = self.library._get_backend_share_name(fake.SHARE['id']) + share_name = self.library._get_backend_share_name(fake_share['id']) parent_share_name = self.library._get_backend_share_name( - fake.SNAPSHOT['share_id']) + fake_snapshot['share_id']) parent_snapshot_name = self.library._get_backend_snapshot_name( - fake.SNAPSHOT['id']) if not provider_location else 'fake_location' + fake_snapshot['id']) if not provider_location else 'fake_location' mock_get_provisioning_opts.assert_called_once_with( - fake.SHARE, fake.VSERVER1) + fake_share, fake.VSERVER1) vserver_client.create_volume_clone.assert_called_once_with( share_name, parent_share_name, parent_snapshot_name, thin_provisioned=True, snapshot_policy='default', language='en-US', dedup_enabled=True, split=True, compression_enabled=False, max_files=5000) + if size > original_snapshot_size: + vserver_client.set_volume_size.assert_called_once_with( + share_name, size) + else: + vserver_client.set_volume_size.assert_not_called() def test_share_exists(self): diff --git a/manila/tests/share/drivers/netapp/dataontap/fakes.py b/manila/tests/share/drivers/netapp/dataontap/fakes.py index f77c41aefa..5bbdbe9f18 100644 --- a/manila/tests/share/drivers/netapp/dataontap/fakes.py +++ b/manila/tests/share/drivers/netapp/dataontap/fakes.py @@ -453,6 +453,7 @@ CG_SNAPSHOT_MEMBER_1 = { 'id': CG_SNAPSHOT_MEMBER_ID1, 'share_id': SHARE_ID, 'share_proto': 'NFS', + 'size': SHARE_SIZE, } CG_SNAPSHOT_MEMBER_2 = { @@ -460,6 +461,7 @@ CG_SNAPSHOT_MEMBER_2 = { 'id': CG_SNAPSHOT_MEMBER_ID2, 'share_id': SHARE_ID2, 'share_proto': 'NFS', + 'size': SHARE_SIZE, } CG_SNAPSHOT = { @@ -476,14 +478,16 @@ COLLATED_CGSNAPSHOT_INFO = [ 'share': SHARE_FOR_CG3, 'snapshot': { 'share_id': SHARE_ID, - 'id': CG_SNAPSHOT_ID + 'id': CG_SNAPSHOT_ID, + 'size': SHARE_SIZE, } }, { 'share': SHARE_FOR_CG4, 'snapshot': { 'share_id': SHARE_ID2, - 'id': CG_SNAPSHOT_ID + 'id': CG_SNAPSHOT_ID, + 'size': SHARE_SIZE, } }, ] diff --git a/releasenotes/notes/bug-1717263-netapp-ontap-fix-size-for-share-from-snapshot-02385baa7e085f39.yaml b/releasenotes/notes/bug-1717263-netapp-ontap-fix-size-for-share-from-snapshot-02385baa7e085f39.yaml new file mode 100644 index 0000000000..fc3407a66c --- /dev/null +++ b/releasenotes/notes/bug-1717263-netapp-ontap-fix-size-for-share-from-snapshot-02385baa7e085f39.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - The NetApp ONTAP driver has been fixed to honor the share size as + requested when creating shares from an existing snapshot.