Skip to content

Commit 7b4ec99

Browse files
authored
Add file_exists check to file_clone (#271)
Add file_exists check to file_clone Safeguard clone operation, that failed due to overwrite flag was set, but no file exists. The api fails if the file does not exists and the overwrite flag is set. The fix is checking the dest directory if the file exists, it sets the flag, but if not, that omits setting it. Change-Id: I87c21c6b3962b590af1e636f54988d990994dec0
1 parent 51723ef commit 7b4ec99

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cinder/tests/unit/volume/drivers/netapp/dataontap/client/test_client_cmode_rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,8 @@ def test_clone_file_snapshot(self, overwrite_dest):
23452345
return_value=fake_volume)
23462346
self.mock_object(self.client.connection, 'get_api_version',
23472347
return_value=api_version)
2348+
self.mock_object(self.client, 'file_exists',
2349+
return_vaule=True)
23482350

23492351
self.client.clone_file(
23502352
fake_volume['name'], fake_name, fake_new_name, fake.VSERVER_NAME,

cinder/volume/drivers/netapp/dataontap/client/client_cmode_rest.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,25 @@ def move_lun(self, path, new_path):
16901690
}
16911691
self.send_request('/storage/luns/', 'patch', query=query, body=body)
16921692

1693+
def file_exists(self, netapp_vol, file_path):
1694+
1695+
file_found = False
1696+
info_fields = {'type': 'file'}
1697+
file_elements = file_path.split('/')
1698+
if len(file_elements) == 1:
1699+
dir_path = ''
1700+
else:
1701+
dir_path = '/'.join(file_elements[:-1])
1702+
dir_path.replace('.', '%2E').replace('/', '%2F')
1703+
file_name = file_elements[-1]
1704+
query = f'/storage/volumes/{netapp_vol["uuid"]}/files/{dir_path}'
1705+
file_info = self.send_request(query, 'get', body=info_fields)
1706+
for file in file_info['records']:
1707+
if file['name'] == file_name:
1708+
file_found = True
1709+
1710+
return file_found
1711+
16931712
def clone_file(self, flex_vol, src_path, dest_path, vserver,
16941713
dest_exists=False, source_snapshot=None, is_snapshot=False):
16951714
"""Clones file on vserver."""
@@ -1716,7 +1735,7 @@ def clone_file(self, flex_vol, src_path, dest_path, vserver,
17161735
if is_snapshot and self.features.BACKUP_CLONE_PARAM:
17171736
body['is_backup'] = True
17181737

1719-
if dest_exists:
1738+
if dest_exists and self.file_exists(volume, dest_path):
17201739
body['overwrite_destination'] = True
17211740

17221741
self.send_request('/storage/file/clone', 'post', body=body)

0 commit comments

Comments
 (0)