From b0b35a874fdbe14c232cfd617f4c258cc9d1f638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Oliveira?= Date: Fri, 6 May 2022 21:12:58 +0000 Subject: [PATCH] NetApp ONTAP: Add revert to snapshot functions on REST client This patch adds the function rename_file and its unit test, other functions used in the 'revert to snapshot' operation were migrated in a previous patch. Change-Id: I36076414de9d1d31429ffd63817631fedd5df7cc partially-implements: blueprint netapp-ontap-rest-api-client --- .../client/test_client_cmode_rest.py | 19 ++++++++++++++++ .../dataontap/client/client_cmode_rest.py | 22 +++++++++++++++++++ ...ntap-rest-api-client-d889cfa895f01249.yaml | 17 ++++++++++---- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_cmode_rest.py b/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_cmode_rest.py index 1f2c440cfe8..66578c79a7e 100644 --- a/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_cmode_rest.py +++ b/cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_cmode_rest.py @@ -3688,3 +3688,22 @@ class NetAppRestCmodeClientTestCase(test.TestCase): f'/cluster/jobs/{job_uuid}', 'get', query=query, enable_tunneling=False) self.assertEqual(expected_result, result) + + def test_rename_file(self): + volume = fake_client.VOLUME_ITEM_SIMPLE_RESPONSE_REST + orig_file_name = f'/vol/{fake_client.VOLUME_NAMES[0]}/cinder-vol' + new_file_name = f'/vol/{fake_client.VOLUME_NAMES[0]}/new-cinder-vol' + body = {'path': new_file_name.split('/')[3]} + + self.mock_object(self.client, 'send_request') + self.mock_object(self.client, '_get_volume_by_args', + return_value=volume) + + self.client.rename_file(orig_file_name, new_file_name) + + orig_file_name = orig_file_name.split('/')[3] + self.client.send_request.assert_called_once_with( + f'/storage/volumes/{volume["uuid"]}/files/{orig_file_name}', + 'patch', body=body) + self.client._get_volume_by_args.assert_called_once_with( + vol_name=fake_client.VOLUME_NAMES[0]) diff --git a/cinder/volume/drivers/netapp/dataontap/client/client_cmode_rest.py b/cinder/volume/drivers/netapp/dataontap/client/client_cmode_rest.py index 05fa18494b2..4a3154d6c86 100644 --- a/cinder/volume/drivers/netapp/dataontap/client/client_cmode_rest.py +++ b/cinder/volume/drivers/netapp/dataontap/client/client_cmode_rest.py @@ -2497,3 +2497,25 @@ class RestClient(object): } return copy_status + + def rename_file(self, orig_file_name, new_file_name): + """Rename a volume file.""" + LOG.debug("Renaming the file %(original)s to %(new)s.", + {'original': orig_file_name, 'new': new_file_name}) + + unique_volume = self._get_volume_by_args( + vol_name=orig_file_name.split('/')[2]) + + # Get the relative path + orig_file_name = '/'.join(orig_file_name.split('/')[3:]) + new_file_name = '/'.join(new_file_name.split('/')[3:]) + + # Path requires "%2E" to represent "." and "%2F" to represent "/". + orig_file_name = orig_file_name.replace('.', '%2E').replace('/', '%2F') + new_file_name = new_file_name.replace('.', '%2E').replace('/', '%2F') + + body = {'path': new_file_name} + + self.send_request( + f'/storage/volumes/{unique_volume["uuid"]}/files/{orig_file_name}', + 'patch', body=body) diff --git a/releasenotes/notes/netapp-ontap-rest-api-client-d889cfa895f01249.yaml b/releasenotes/notes/netapp-ontap-rest-api-client-d889cfa895f01249.yaml index 5f490a4f76c..c218b598a6b 100644 --- a/releasenotes/notes/netapp-ontap-rest-api-client-d889cfa895f01249.yaml +++ b/releasenotes/notes/netapp-ontap-rest-api-client-d889cfa895f01249.yaml @@ -3,8 +3,17 @@ features: - | NetApp drivers: NFS, iSCSI and FCP drivers have now the option to request ONTAP operations through REST API. The new option `netapp_use_legacy_client` - switch between the old ZAPI client approach and new REST client. It is + switches between the old ZAPI client approach and new REST client. It is default to `True`, meaning that the drivers will keep working as before - using ZAPI operations. If desired, this option can be set to `False` connecting - with new REST client that performs REST API operations if it is available, - otherwise falls back to ZAPI. + using ZAPI operations. If desired, this option can be set to `False` interacting + with the storage using the new REST client. However, this new client still + relies on ZAPI calls for consistency group snapshot operation. + + The drivers can only be configured with REST client when using ONTAP storage + 9.11.1 or newer. + + NOTE: Enabling ONTAP REST client changes the behavior of QoS specs. Earlier, + QoS values could be represented in BPS (bytes per second), but now REST client + only supports integer values represented in MBPS (Megabytes per second). + It means that though the user specifies the value in BPS, it will be converted + to MBPS and rounded up.