Add cleanup to create from snap in Manila HNAS driver
Adding a cleanup to method create_from_snapshot in case
of a failure.
Also, raising the correct exception on backend layer in
case of a failure when exporting shares.
Conflicts:
manila/share/drivers/hitachi/hds_hnas.py
manila/share/drivers/hitachi/ssh.py
manila/tests/share/drivers/hitachi/hnas/test_driver.py
manila/tests/share/drivers/hitachi/test_ssh.py
Change-Id: I86d2c3c5ff5a790868f8362e065df1eb2be8a3ad
Closes-Bug: #1613721
(cherry picked from commit 9d6823b3ea
)
This commit is contained in:
parent
407c30bd94
commit
0531204971
|
@ -23,9 +23,7 @@ import six
|
|||
|
||||
from manila.common import constants
|
||||
from manila import exception
|
||||
from manila.i18n import _
|
||||
from manila.i18n import _LI
|
||||
from manila.i18n import _LW
|
||||
from manila.i18n import _, _LE, _LI, _LW
|
||||
from manila.share import driver
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
@ -671,5 +669,14 @@ class HDSHNASDriver(driver.ShareDriver):
|
|||
except exception.HNASNothingToCloneException:
|
||||
LOG.warning(_LW("Source directory is empty, exporting "
|
||||
"directory."))
|
||||
self.hnas.nfs_export_add(share['id'])
|
||||
|
||||
try:
|
||||
self.hnas.nfs_export_add(share['id'])
|
||||
except exception.HNASBackendException:
|
||||
with excutils.save_and_reraise_exception():
|
||||
msg = _LE('Failed to create share %(share_id)s from snapshot '
|
||||
'%(snap)s.')
|
||||
LOG.exception(msg, {'share_id': share['id'],
|
||||
'snap': snapshot['id']})
|
||||
self.hnas.vvol_delete(share['id'])
|
||||
return dest_path
|
||||
|
|
|
@ -67,7 +67,12 @@ class HNASSSHBackend(object):
|
|||
path = '/shares/' + share_id
|
||||
command = ['nfs-export', 'add', '-S', 'disable', '-c', '127.0.0.1',
|
||||
path, self.fs_name, path]
|
||||
self._execute(command)
|
||||
try:
|
||||
self._execute(command)
|
||||
except processutils.ProcessExecutionError:
|
||||
msg = _("Could not create NFS export %s.") % share_id
|
||||
LOG.exception(msg)
|
||||
raise exception.HNASBackendException(msg=msg)
|
||||
|
||||
def nfs_export_del(self, share_id):
|
||||
path = '/shares/' + share_id
|
||||
|
|
|
@ -501,6 +501,35 @@ class HDSHNASTestCase(test.TestCase):
|
|||
'/shares/' + share['id'])
|
||||
ssh.HNASSSHBackend.nfs_export_add.assert_called_once_with(share['id'])
|
||||
|
||||
def test_create_share_from_snapshot_cleanup(self):
|
||||
dest_path = '/snapshots/' + share['id'] + '/' + snapshot['id']
|
||||
src_path = '/shares/' + share['id']
|
||||
|
||||
self.mock_object(hds_hnas.HDSHNASDriver, "_check_fs_mounted",
|
||||
mock.Mock())
|
||||
self.mock_object(ssh.HNASSSHBackend, "vvol_create")
|
||||
self.mock_object(ssh.HNASSSHBackend, "quota_add")
|
||||
self.mock_object(ssh.HNASSSHBackend, "tree_clone")
|
||||
self.mock_object(ssh.HNASSSHBackend, "vvol_delete")
|
||||
self.mock_object(ssh.HNASSSHBackend, "nfs_export_add", mock.Mock(
|
||||
side_effect=exception.HNASBackendException(
|
||||
msg='Error adding nfs export.')))
|
||||
|
||||
self.assertRaises(exception.HNASBackendException,
|
||||
self._driver.create_share_from_snapshot,
|
||||
'context', share, snapshot)
|
||||
|
||||
ssh.HNASSSHBackend.vvol_create.assert_called_once_with(
|
||||
share['id'])
|
||||
ssh.HNASSSHBackend.quota_add.assert_called_once_with(
|
||||
share['id'], share['size'])
|
||||
ssh.HNASSSHBackend.tree_clone.assert_called_once_with(
|
||||
dest_path, src_path)
|
||||
ssh.HNASSSHBackend.nfs_export_add.assert_called_once_with(
|
||||
share['id'])
|
||||
ssh.HNASSSHBackend.vvol_delete.assert_called_once_with(
|
||||
share['id'])
|
||||
|
||||
def test__check_fs_mounted(self):
|
||||
self.mock_object(ssh.HNASSSHBackend, 'check_fs_mounted', mock.Mock(
|
||||
return_value=True))
|
||||
|
|
|
@ -470,6 +470,14 @@ class HNASSSHTestCase(test.TestCase):
|
|||
|
||||
self._driver_ssh._execute.assert_called_with(fake_nfs_command)
|
||||
|
||||
def test_nfs_export_add_error(self):
|
||||
self.mock_object(ssh.HNASSSHBackend, '_execute', mock.Mock(
|
||||
side_effect=[putils.ProcessExecutionError(stderr='')]))
|
||||
|
||||
self.assertRaises(exception.HNASBackendException,
|
||||
self._driver_ssh.nfs_export_add, 'vvol_test')
|
||||
self.assertTrue(self.mock_log.exception.called)
|
||||
|
||||
def test_nfs_export_del(self):
|
||||
fake_nfs_command = ['nfs-export', 'del', '/shares/vvol_test']
|
||||
self.mock_object(ssh.HNASSSHBackend, '_execute', mock.Mock())
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
fixes:
|
||||
- Fixed Hitachi HNAS driver not cleaning up data in backend when failing
|
||||
to create a share from snapshot.
|
Loading…
Reference in New Issue