NetApp ONTAP: Fix sub-clone zapi call

The ONTAP documentation states that the `clone-create` ZAPI call
fails with `block-ranges` and `space-reserve` parameters sent
together. The sub-clone uses the `block-ranges` and is failing
because of that restriction.

This patch fixes the `clone-create` operation by using exactly one
of `block-ranges` or `space-reserve`.

Change-Id: I05d83d73de69c57d885e0c417e8a376f7cfb1e4f
Closes-Bug: #1924643
This commit is contained in:
Felipe Rodrigues 2021-04-16 10:05:40 -03:00 committed by Nahim Alves de Souza
parent 91d0a6512f
commit dd0b1076df
3 changed files with 48 additions and 2 deletions

View File

@ -823,6 +823,42 @@ class NetAppCmodeClientTestCase(test.TestCase):
netapp_api.NaElement.create_node_with_children(
'clone-create', **clone_create_args), True)
@ddt.data(0, 1)
def test_clone_lun_is_sub_clone(self, block_count):
self.client.clone_lun(
'volume', 'fakeLUN', 'newFakeLUN', block_count=block_count)
clone_create_args = {
'volume': 'volume',
'source-path': 'fakeLUN',
'destination-path': 'newFakeLUN',
}
is_sub_clone = block_count > 0
if not is_sub_clone:
clone_create_args['space-reserve'] = 'true'
# build the expected request
expected_clone_create_request = \
netapp_api.NaElement.create_node_with_children(
'clone-create', **clone_create_args)
# add expected fields in the request if it's a sub-clone
if is_sub_clone:
block_ranges = netapp_api.NaElement("block-ranges")
block_range = \
netapp_api.NaElement.create_node_with_children(
'block-range',
**{'source-block-number': '0',
'destination-block-number': '0',
'block-count': '1'})
block_ranges.add_child_elem(block_range)
expected_clone_create_request.add_child_elem(block_ranges)
self.connection.invoke_successfully.assert_called_once_with(
expected_clone_create_request, True)
def test_clone_lun_multiple_zapi_calls(self):
"""Test for when lun clone requires more than one zapi call."""

View File

@ -635,12 +635,14 @@ class Client(client_base.Client):
else:
block_count = zbc
is_sub_clone = block_count > 0
zapi_args = {
'volume': volume,
'source-path': name,
'destination-path': new_name,
'space-reserve': space_reserved,
}
if not is_sub_clone:
zapi_args['space-reserve'] = space_reserved
if source_snapshot:
zapi_args['snapshot-name'] = source_snapshot
if is_snapshot and self.features.BACKUP_CLONE_PARAM:
@ -651,7 +653,8 @@ class Client(client_base.Client):
child_name = 'qos-%spolicy-group-name' % (
'adaptive-' if qos_policy_group_is_adaptive else '')
clone_create.add_new_child(child_name, qos_policy_group_name)
if block_count > 0:
if is_sub_clone:
block_ranges = netapp_api.NaElement("block-ranges")
segments = int(math.ceil(block_count / float(bc_limit)))
bc = block_count

View File

@ -0,0 +1,7 @@
---
fixes:
- |
`Bug #1924643 <https://bugs.launchpad.net/cinder/+bug/1924643>`_: Fixed
the NetApp cinder driver sub-clone operation that might be used
by extend operation in case the extended size is greater than the max
LUN geometry.