Skip to content

Commit

Permalink
Merge pull request #33 from YiHuangIX/febcr
Browse files Browse the repository at this point in the history
Fix for #24 #32
  • Loading branch information
william-gr authored Feb 27, 2023
2 parents cc6e388 + 902b8a3 commit 526e9d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
20 changes: 17 additions & 3 deletions driver/ixsystems/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,14 @@ def _delete_volume(self, name):
fullvolume, snapname = clone.split('@')
temp, snapvol = fullvolume.rsplit('/', 1)
self._delete_snapshot(snapname, snapvol)
if ret['status'] != FreeNASServer.STATUS_OK:

# When deleting volume with dependent snapsnot clone, 422 error triggered. Throw VolumeIsBusy exception ensures
# upper stream cinder manager mark volume status available instead of error-deleting.
if ret['status'] == 'error' and ret['code'] == 422:
errorexception = exception.VolumeIsBusy(
_("Cannot delete volume when clone child volume or snapshot exists!"), volume_name=name)
raise errorexception
elif ret['status'] != FreeNASServer.STATUS_OK:
msg = ('Error while deleting volume: %s' % ret['response'])
raise FreeNASApiError('Unexpected error', msg)

Expand Down Expand Up @@ -378,11 +385,18 @@ def _delete_snapshot(self, name, volume_name):
ret = self.handle.invoke_command(FreeNASServer.DELETE_COMMAND,
request_urn, None)
LOG.debug('_delete_snapshot response : %s', json.dumps(ret))
if ret['status'] != FreeNASServer.STATUS_OK:
# When deleting volume with dependent snapsnot clone, 422 error triggered. Throw VolumeIsBusy exception ensures
# upper stream cinder manager mark volume status available instead of error-deleting.
if ret['status'] == 'error' and ret['code'] == 422:
errorexception = exception.VolumeIsBusy(
_("Cannot delete volume when clone child volume or snapshot exists!"), volume_name=name)
raise errorexception
elif ret['status'] != FreeNASServer.STATUS_OK:
msg = ('Error while deleting snapshot: %s' % ret['response'])
raise FreeNASApiError('Unexpected error', msg)
except Exception as e:
raise FreeNASApiError('Unexpected error', e)
if not isinstance(e, exception.VolumeIsBusy):
raise FreeNASApiError('Unexpected error', e)

def _create_volume_from_snapshot(self, name, snapshot_name,
snap_zvol_name):
Expand Down
4 changes: 3 additions & 1 deletion driver/ixsystems/freenasapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class FreeNASServer(object):
CLONE = "clone"
# Command response format
COMMAND_RESPONSE = {'status': '%s',
'response': '%s'}
'response': '%s',
'code': -1}

# Command status
STATUS_OK = 'ok'
Expand Down Expand Up @@ -181,6 +182,7 @@ def _get_error_info(self, err):
self.COMMAND_RESPONSE['status'] = self.STATUS_ERROR
if isinstance(err, urllib.error.HTTPError):
self.COMMAND_RESPONSE['response'] = '%d:%s' % (err.code, err.msg)
self.COMMAND_RESPONSE['code'] = err.code
elif isinstance(err, urllib.error.URLError):
self.COMMAND_RESPONSE['response'] = '%s:%s' % \
(str(err.reason.errno),
Expand Down
4 changes: 2 additions & 2 deletions driver/ixsystems/iscsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ def get_volume_stats(self, refresh=False):
def create_cloned_volume(self, volume, src_vref):
"""Creates a volume from source volume."""
LOG.info('iXsystems Create Cloned Volume')
LOG.info('create_cloned_volume: %s', src_vref['id'])
LOG.info('create_cloned_volume: %s', volume['id'])

temp_snapshot = {'volume_name': src_vref['name'],
'name': 'name-c%s' % src_vref['id']}
'name': 'name-%s' % volume['id']}

self.create_snapshot(temp_snapshot)
self.create_volume_from_snapshot(volume, temp_snapshot)
Expand Down

0 comments on commit 526e9d7

Please sign in to comment.