Merge "HDS-HNAS: fixed exception when export not found"
This commit is contained in:
commit
45ebe720e6
|
@ -315,23 +315,25 @@ class HNASSSHBackend(object):
|
|||
def _get_share_export(self, share_id):
|
||||
share_id = '/shares/' + share_id
|
||||
command = ['nfs-export', 'list ', share_id]
|
||||
output, err = self._execute(command)
|
||||
export_list = []
|
||||
try:
|
||||
output, err = self._execute(command)
|
||||
except processutils.ProcessExecutionError as e:
|
||||
if 'does not exist' in e.stderr:
|
||||
msg = _("Export %(share)s was not found in EVS "
|
||||
"%(evs_id)s") % {'share': share_id,
|
||||
'evs_id': self.evs_id}
|
||||
raise exception.HNASItemNotFoundException(msg=msg)
|
||||
else:
|
||||
raise
|
||||
items = output.split('Export name')
|
||||
|
||||
if 'No exports are currently configured' in output:
|
||||
msg = _("Export %(share)s was not found in EVS "
|
||||
"%(evs_id)s") % {'share': share_id,
|
||||
'evs_id': self.evs_id}
|
||||
raise exception.HNASItemNotFoundException(msg=msg)
|
||||
else:
|
||||
items = output.split('Export name')
|
||||
if items[0][0] == '\n':
|
||||
items.pop(0)
|
||||
|
||||
if items[0][0] == '\n':
|
||||
items.pop(0)
|
||||
|
||||
for i in range(0, len(items)):
|
||||
export_list.append(Export(items[i]))
|
||||
return export_list
|
||||
for i in range(0, len(items)):
|
||||
export_list.append(Export(items[i]))
|
||||
return export_list
|
||||
|
||||
def _get_filesystem_list(self):
|
||||
command = ['filesystem-list', self.fs_name]
|
||||
|
|
|
@ -834,15 +834,25 @@ class HNASSSHTestCase(test.TestCase):
|
|||
self.assertEqual('fake_fs', export_list[0].file_system_label)
|
||||
self.assertEqual('Yes', export_list[0].mounted)
|
||||
|
||||
def test__get_share_export_exception(self):
|
||||
output_msg = 'No exports are currently configured'
|
||||
def test__get_share_export_exception_not_found(self):
|
||||
|
||||
self.mock_object(ssh.HNASSSHBackend, '_execute',
|
||||
mock.Mock(return_value=[output_msg, '']))
|
||||
self.mock_object(ssh.HNASSSHBackend, "_execute", mock.Mock(
|
||||
side_effect=putils.ProcessExecutionError(
|
||||
stderr="NFS Export List: Export 'id' does not exist.")
|
||||
))
|
||||
|
||||
self.assertRaises(exception.HNASItemNotFoundException,
|
||||
self._driver_ssh._get_share_export, 'fake_id')
|
||||
|
||||
def test__get_share_export_exception_error(self):
|
||||
|
||||
self.mock_object(ssh.HNASSSHBackend, "_execute", mock.Mock(
|
||||
side_effect=putils.ProcessExecutionError(stderr="Some error.")
|
||||
))
|
||||
|
||||
self.assertRaises(putils.ProcessExecutionError,
|
||||
self._driver_ssh._get_share_export, 'fake_id')
|
||||
|
||||
def test__get_filesystem_list(self):
|
||||
self.mock_object(ssh.HNASSSHBackend, '_execute',
|
||||
mock.Mock(return_value=[HNAS_RESULT_fs, '']))
|
||||
|
|
Loading…
Reference in New Issue