From 67391f1f0f30172190882e7d3f4a4ddc271dfa00 Mon Sep 17 00:00:00 2001 From: Luiz Gavioli Date: Tue, 23 Jan 2018 15:50:06 -0200 Subject: [PATCH] NetApp: Add use-exact-size parameter when creating a LUN on ONTAP iSCSI When a cinder volume is created the ontap backend fits the LUN to the best geometry. It makes the image uploaded from a volume larger than expected and a volume of larger size must be created from that image. Using the use-exact-size parameter the backend does not fit to best geometry, the image uploaded from that volume has the same size and a volume of the same size may be created from that image. Nevertheless this parameter is available only in Data ONTAP 9.1 (ontapi version 1.110) and later. Closes-Bug: #1731474 Change-Id: I0e21cbcb6effa1e72999580564099976511ca4a9 --- .../dataontap/client/test_client_base.py | 24 ++++++++++++++++++- .../netapp/dataontap/client/client_base.py | 10 +++++--- ...ontap-use_exact_size-d03c90efbb8a30ac.yaml | 6 +++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/netapp-ontap-use_exact_size-d03c90efbb8a30ac.yaml diff --git a/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_base.py b/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_base.py index c46d5375b3e..60c72c2e51c 100644 --- a/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_base.py +++ b/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_base.py @@ -46,6 +46,7 @@ class NetAppBaseClientTestCase(test.TestCase): self.mock_object(client_base.Client, '_init_ssh_client') self.client = client_base.Client(**CONNECTION_INFO) self.client.connection = mock.MagicMock() + self.client.connection.get_api_version.return_value = (1, 100) self.client.ssh_client = mock.MagicMock() self.connection = self.client.connection self.fake_volume = six.text_type(uuid.uuid4()) @@ -86,7 +87,6 @@ class NetAppBaseClientTestCase(test.TestCase): def test_create_lun(self): expected_path = '/vol/%s/%s' % (self.fake_volume, self.fake_lun) - with mock.patch.object(netapp_api.NaElement, 'create_node_with_children', ) as mock_create_node: @@ -105,6 +105,28 @@ class NetAppBaseClientTestCase(test.TestCase): self.connection.invoke_successfully.assert_called_once_with( mock.ANY, True) + def test_create_lun_exact_size(self): + expected_path = '/vol/%s/%s' % (self.fake_volume, self.fake_lun) + self.connection.get_api_version.return_value = (1, 110) + with mock.patch.object(netapp_api.NaElement, + 'create_node_with_children', + ) as mock_create_node: + self.client.create_lun(self.fake_volume, + self.fake_lun, + self.fake_size, + self.fake_metadata) + + mock_create_node.assert_called_once_with( + 'lun-create-by-size', + **{'path': expected_path, + 'size': self.fake_size, + 'ostype': self.fake_metadata['OsType'], + 'use-exact-size': 'true', + 'space-reservation-enabled': + self.fake_metadata['SpaceReserved']}) + self.connection.invoke_successfully.assert_called_once_with( + mock.ANY, True) + def test_create_lun_with_qos_policy_group_name(self): expected_path = '/vol/%s/%s' % (self.fake_volume, self.fake_lun) expected_qos_group_name = 'qos_1' diff --git a/cinder/volume/drivers/netapp/dataontap/client/client_base.py b/cinder/volume/drivers/netapp/dataontap/client/client_base.py index 1d24c6d1a11..24c4bc9ba1f 100644 --- a/cinder/volume/drivers/netapp/dataontap/client/client_base.py +++ b/cinder/volume/drivers/netapp/dataontap/client/client_base.py @@ -94,11 +94,15 @@ class Client(object): """Issues API request for creating LUN on volume.""" path = '/vol/%s/%s' % (volume_name, lun_name) + params = {'path': path, 'size': six.text_type(size), + 'ostype': metadata['OsType'], + 'space-reservation-enabled': metadata['SpaceReserved']} + version = self.get_ontapi_version() + if version >= (1, 110): + params['use-exact-size'] = 'true' lun_create = netapp_api.NaElement.create_node_with_children( 'lun-create-by-size', - **{'path': path, 'size': six.text_type(size), - 'ostype': metadata['OsType'], - 'space-reservation-enabled': metadata['SpaceReserved']}) + **params) if qos_policy_group_name: lun_create.add_new_child('qos-policy-group', qos_policy_group_name) diff --git a/releasenotes/notes/netapp-ontap-use_exact_size-d03c90efbb8a30ac.yaml b/releasenotes/notes/netapp-ontap-use_exact_size-d03c90efbb8a30ac.yaml new file mode 100644 index 00000000000..dc4cf7ebf3e --- /dev/null +++ b/releasenotes/notes/netapp-ontap-use_exact_size-d03c90efbb8a30ac.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixed bug #1731474 on NetApp Data ONTAP driver that was causing LUNs to be created + with larger size than requested. This fix requires version 9.1 of ONTAP + or later. \ No newline at end of file