Merge "move sheepdog exception"

This commit is contained in:
Zuul 2019-05-20 21:33:34 +00:00 committed by Gerrit Code Review
commit b8a41b8d42
3 changed files with 78 additions and 79 deletions

View File

@ -1174,19 +1174,6 @@ class DotHillDriverNotSupported(VolumeDriverException):
message = _("The Dot Hill driver is no longer supported.") message = _("The Dot Hill driver is no longer supported.")
# Sheepdog
class SheepdogError(VolumeBackendAPIException):
message = _("An error has occurred in SheepdogDriver. "
"(Reason: %(reason)s)")
class SheepdogCmdError(SheepdogError):
message = _("(Command: %(cmd)s) "
"(Return Code: %(exit_code)s) "
"(Stdout: %(stdout)s) "
"(Stderr: %(stderr)s)")
class MetadataAbsent(CinderException): class MetadataAbsent(CinderException):
message = _("There is no metadata in DB object.") message = _("There is no metadata in DB object.")

View File

@ -445,7 +445,7 @@ class SheepdogClientTestCase(test.TestCase):
{'addr': SHEEP_ADDR, 'port': SHEEP_PORT}) {'addr': SHEEP_ADDR, 'port': SHEEP_PORT})
fake_execute.side_effect = processutils.ProcessExecutionError( fake_execute.side_effect = processutils.ProcessExecutionError(
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
ex = self.assertRaises(exception.SheepdogError, ex = self.assertRaises(sheepdog.SheepdogError,
self.client._run_dog, *args) self.client._run_dog, *args)
self.assertEqual(expected_reason, ex.kwargs['reason']) self.assertEqual(expected_reason, ex.kwargs['reason'])
@ -461,7 +461,7 @@ class SheepdogClientTestCase(test.TestCase):
'addr: %(addr)s, port: %(port)s'), 'addr: %(addr)s, port: %(port)s'),
{'addr': SHEEP_ADDR, 'port': SHEEP_PORT}) {'addr': SHEEP_ADDR, 'port': SHEEP_PORT})
fake_execute.return_value = (stdout, stderr) fake_execute.return_value = (stdout, stderr)
ex = self.assertRaises(exception.SheepdogError, ex = self.assertRaises(sheepdog.SheepdogError,
self.client._run_dog, *args) self.client._run_dog, *args)
self.assertEqual(expected_reason, ex.kwargs['reason']) self.assertEqual(expected_reason, ex.kwargs['reason'])
@ -477,7 +477,7 @@ class SheepdogClientTestCase(test.TestCase):
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
fake_execute.side_effect = processutils.ProcessExecutionError( fake_execute.side_effect = processutils.ProcessExecutionError(
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client._run_dog, *args) self.client._run_dog, *args)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -529,7 +529,7 @@ class SheepdogClientTestCase(test.TestCase):
{'addr': SHEEP_ADDR, 'port': SHEEP_PORT}) {'addr': SHEEP_ADDR, 'port': SHEEP_PORT})
fake_execute.side_effect = processutils.ProcessExecutionError( fake_execute.side_effect = processutils.ProcessExecutionError(
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
ex = self.assertRaises(exception.SheepdogError, ex = self.assertRaises(sheepdog.SheepdogError,
self.client._run_qemu_img, *args) self.client._run_qemu_img, *args)
self.assertEqual(expected_reason, ex.kwargs['reason']) self.assertEqual(expected_reason, ex.kwargs['reason'])
@ -546,7 +546,7 @@ class SheepdogClientTestCase(test.TestCase):
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
fake_execute.side_effect = processutils.ProcessExecutionError( fake_execute.side_effect = processutils.ProcessExecutionError(
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client._run_qemu_img, *args) self.client._run_qemu_img, *args)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -585,7 +585,7 @@ class SheepdogClientTestCase(test.TestCase):
'You should probably perform ' 'You should probably perform '
'"dog cluster format".') '"dog cluster format".')
fake_execute.return_value = (stdout, stderr) fake_execute.return_value = (stdout, stderr)
ex = self.assertRaises(exception.SheepdogError, ex = self.assertRaises(sheepdog.SheepdogError,
self.client.check_cluster_status) self.client.check_cluster_status)
self.assertEqual(expected_reason, ex.kwargs['reason']) self.assertEqual(expected_reason, ex.kwargs['reason'])
@ -598,7 +598,7 @@ class SheepdogClientTestCase(test.TestCase):
expected_reason = _('Waiting for all nodes to join cluster. ' expected_reason = _('Waiting for all nodes to join cluster. '
'Ensure all sheep daemons are running.') 'Ensure all sheep daemons are running.')
fake_execute.return_value = (stdout, stderr) fake_execute.return_value = (stdout, stderr)
ex = self.assertRaises(exception.SheepdogError, ex = self.assertRaises(sheepdog.SheepdogError,
self.client.check_cluster_status) self.client.check_cluster_status)
self.assertEqual(expected_reason, ex.kwargs['reason']) self.assertEqual(expected_reason, ex.kwargs['reason'])
@ -610,7 +610,7 @@ class SheepdogClientTestCase(test.TestCase):
stderr = '' stderr = ''
expected_reason = _('Invalid sheepdog cluster status.') expected_reason = _('Invalid sheepdog cluster status.')
fake_execute.return_value = (stdout, stderr) fake_execute.return_value = (stdout, stderr)
ex = self.assertRaises(exception.SheepdogError, ex = self.assertRaises(sheepdog.SheepdogError,
self.client.check_cluster_status) self.client.check_cluster_status)
self.assertEqual(expected_reason, ex.kwargs['reason']) self.assertEqual(expected_reason, ex.kwargs['reason'])
@ -626,9 +626,9 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.check_cluster_status) self.client.check_cluster_status)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -649,10 +649,10 @@ class SheepdogClientTestCase(test.TestCase):
{'vdiname': self._vdiname}) {'vdiname': self._vdiname})
expected_msg = self.test_data.sheepdog_cmd_error( expected_msg = self.test_data.sheepdog_cmd_error(
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, self.client.create, ex = self.assertRaises(sheepdog.SheepdogCmdError, self.client.create,
self._vdiname, self._vdisize) self._vdiname, self._vdisize)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -666,10 +666,10 @@ class SheepdogClientTestCase(test.TestCase):
stderr = 'stderr_dummy' stderr = 'stderr_dummy'
expected_msg = self.test_data.sheepdog_cmd_error( expected_msg = self.test_data.sheepdog_cmd_error(
cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr) cmd=cmd, exit_code=exit_code, stdout=stdout, stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, self.client.create, ex = self.assertRaises(sheepdog.SheepdogCmdError, self.client.create,
self._vdiname, self._vdisize) self._vdiname, self._vdisize)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -702,10 +702,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.delete, self._vdiname) self.client.delete, self._vdiname)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -731,10 +731,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.create_snapshot, *args) self.client.create_snapshot, *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -752,10 +752,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.create_snapshot, *args) self.client.create_snapshot, *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -772,10 +772,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.create_snapshot, *args) self.client.create_snapshot, *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -822,10 +822,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.delete_snapshot, *args) self.client.delete_snapshot, *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -856,10 +856,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, self.client.clone, ex = self.assertRaises(sheepdog.SheepdogCmdError, self.client.clone,
*args) *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -877,10 +877,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, self.client.clone, ex = self.assertRaises(sheepdog.SheepdogCmdError, self.client.clone,
*args) *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -898,10 +898,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, self.client.clone, ex = self.assertRaises(sheepdog.SheepdogCmdError, self.client.clone,
*args) *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -919,10 +919,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, self.client.clone, ex = self.assertRaises(sheepdog.SheepdogCmdError, self.client.clone,
*args) *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -940,10 +940,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, self.client.clone, ex = self.assertRaises(sheepdog.SheepdogCmdError, self.client.clone,
*args) *args)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -967,10 +967,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.resize, self._vdiname, 1) self.client.resize, self._vdiname, 1)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -986,10 +986,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.resize, self._vdiname, 1) self.client.resize, self._vdiname, 1)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -1005,10 +1005,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.resize, self._vdiname, 5120) self.client.resize, self._vdiname, 5120)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -1024,10 +1024,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.resize, self._vdiname, 10) self.client.resize, self._vdiname, 10)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -1050,10 +1050,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.get_volume_stats) self.client.get_volume_stats)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -1077,10 +1077,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.get_vdi_info, self._vdiname) self.client.get_vdi_info, self._vdiname)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -1103,10 +1103,10 @@ class SheepdogClientTestCase(test.TestCase):
exit_code=exit_code, exit_code=exit_code,
stdout=stdout, stdout=stdout,
stderr=stderr) stderr=stderr)
fake_execute.side_effect = exception.SheepdogCmdError( fake_execute.side_effect = sheepdog.SheepdogCmdError(
cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'), cmd=cmd, exit_code=exit_code, stdout=stdout.replace('\n', '\\n'),
stderr=stderr.replace('\n', '\\n')) stderr=stderr.replace('\n', '\\n'))
ex = self.assertRaises(exception.SheepdogCmdError, ex = self.assertRaises(sheepdog.SheepdogCmdError,
self.client.update_node_list) self.client.update_node_list)
self.assertTrue(fake_logger.error.called) self.assertTrue(fake_logger.error.called)
self.assertEqual(expected_msg, ex.msg) self.assertEqual(expected_msg, ex.msg)
@ -1283,9 +1283,9 @@ class SheepdogDriverTestCase(test.TestCase):
cloned_vol = self.test_data.TEST_CLONED_VOLUME cloned_vol = self.test_data.TEST_CLONED_VOLUME
snapshot_name = 'tmp-snap-%s-%s' % (src_vol.name, cloned_vol.id) snapshot_name = 'tmp-snap-%s-%s' % (src_vol.name, cloned_vol.id)
fake_clone.side_effect = exception.SheepdogCmdError( fake_clone.side_effect = sheepdog.SheepdogCmdError(
cmd='dummy', exit_code=1, stdout='dummy', stderr='dummy') cmd='dummy', exit_code=1, stdout='dummy', stderr='dummy')
self.assertRaises(exception.SheepdogCmdError, self.assertRaises(sheepdog.SheepdogCmdError,
self.driver.create_cloned_volume, self.driver.create_cloned_volume,
cloned_vol, src_vol) cloned_vol, src_vol)
fake_delete_snapshot.assert_called_once_with(src_vol.name, fake_delete_snapshot.assert_called_once_with(src_vol.name,

View File

@ -56,6 +56,18 @@ CONF.import_opt("image_conversion_dir", "cinder.image.image_utils")
CONF.register_opts(sheepdog_opts, group=configuration.SHARED_CONF_GROUP) CONF.register_opts(sheepdog_opts, group=configuration.SHARED_CONF_GROUP)
class SheepdogError(exception.VolumeBackendAPIException):
message = _("An error has occurred in SheepdogDriver. "
"(Reason: %(reason)s)")
class SheepdogCmdError(SheepdogError):
message = _("(Command: %(cmd)s) "
"(Return Code: %(exit_code)s) "
"(Stdout: %(stdout)s) "
"(Stderr: %(stderr)s)")
class SheepdogClient(object): class SheepdogClient(object):
"""Sheepdog command executor.""" """Sheepdog command executor."""
@ -113,7 +125,7 @@ class SheepdogClient(object):
reason = (_('Failed to connect to sheep daemon. ' reason = (_('Failed to connect to sheep daemon. '
'addr: %(addr)s, port: %(port)s'), 'addr: %(addr)s, port: %(port)s'),
{'addr': addr, 'port': self.port}) {'addr': addr, 'port': self.port})
raise exception.SheepdogError(reason=reason) raise SheepdogError(reason=reason)
return (_stdout, _stderr) return (_stdout, _stderr)
except OSError as e: except OSError as e:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
@ -128,8 +140,8 @@ class SheepdogClient(object):
reason = (_('Failed to connect to sheep daemon. ' reason = (_('Failed to connect to sheep daemon. '
'addr: %(addr)s, port: %(port)s'), 'addr: %(addr)s, port: %(port)s'),
{'addr': addr, 'port': self.port}) {'addr': addr, 'port': self.port})
raise exception.SheepdogError(reason=reason) raise SheepdogError(reason=reason)
raise exception.SheepdogCmdError( raise SheepdogCmdError(
cmd=e.cmd, cmd=e.cmd,
exit_code=e.exit_code, exit_code=e.exit_code,
stdout=e.stdout.replace('\n', '\\n'), stdout=e.stdout.replace('\n', '\\n'),
@ -165,8 +177,8 @@ class SheepdogClient(object):
reason = (_('Failed to connect to sheep daemon. ' reason = (_('Failed to connect to sheep daemon. '
'addr: %(addr)s, port: %(port)s'), 'addr: %(addr)s, port: %(port)s'),
{'addr': addr, 'port': self.port}) {'addr': addr, 'port': self.port})
raise exception.SheepdogError(reason=reason) raise SheepdogError(reason=reason)
raise exception.SheepdogCmdError( raise SheepdogCmdError(
cmd=e.cmd, cmd=e.cmd,
exit_code=e.exit_code, exit_code=e.exit_code,
stdout=e.stdout.replace('\n', '\\n'), stdout=e.stdout.replace('\n', '\\n'),
@ -175,7 +187,7 @@ class SheepdogClient(object):
def check_cluster_status(self): def check_cluster_status(self):
try: try:
(_stdout, _stderr) = self._run_dog('cluster', 'info') (_stdout, _stderr) = self._run_dog('cluster', 'info')
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
cmd = e.kwargs['cmd'] cmd = e.kwargs['cmd']
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error('Failed to check cluster status.' LOG.error('Failed to check cluster status.'
@ -192,12 +204,12 @@ class SheepdogClient(object):
elif _stdout.startswith(self.DOG_RESP_CLUSTER_WAITING): elif _stdout.startswith(self.DOG_RESP_CLUSTER_WAITING):
reason = _('Waiting for all nodes to join cluster. ' reason = _('Waiting for all nodes to join cluster. '
'Ensure all sheep daemons are running.') 'Ensure all sheep daemons are running.')
raise exception.SheepdogError(reason=reason) raise SheepdogError(reason=reason)
def create(self, vdiname, size): def create(self, vdiname, size):
try: try:
self._run_dog('vdi', 'create', vdiname, '%sG' % size) self._run_dog('vdi', 'create', vdiname, '%sG' % size)
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
_stderr = e.kwargs['stderr'] _stderr = e.kwargs['stderr']
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
if _stderr.rstrip('\\n').endswith( if _stderr.rstrip('\\n').endswith(
@ -211,7 +223,7 @@ class SheepdogClient(object):
(_stdout, _stderr) = self._run_dog('vdi', 'delete', vdiname) (_stdout, _stderr) = self._run_dog('vdi', 'delete', vdiname)
if _stderr.rstrip().endswith(self.DOG_RESP_VDI_NOT_FOUND): if _stderr.rstrip().endswith(self.DOG_RESP_VDI_NOT_FOUND):
LOG.warning('Volume not found. %s', vdiname) LOG.warning('Volume not found. %s', vdiname)
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
_stderr = e.kwargs['stderr'] _stderr = e.kwargs['stderr']
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error('Failed to delete volume. %s', vdiname) LOG.error('Failed to delete volume. %s', vdiname)
@ -219,7 +231,7 @@ class SheepdogClient(object):
def create_snapshot(self, vdiname, snapname): def create_snapshot(self, vdiname, snapname):
try: try:
self._run_dog('vdi', 'snapshot', '-s', snapname, vdiname) self._run_dog('vdi', 'snapshot', '-s', snapname, vdiname)
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
cmd = e.kwargs['cmd'] cmd = e.kwargs['cmd']
_stderr = e.kwargs['stderr'] _stderr = e.kwargs['stderr']
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
@ -244,7 +256,7 @@ class SheepdogClient(object):
LOG.warning('Snapshot "%s" not found.', snapname) LOG.warning('Snapshot "%s" not found.', snapname)
elif _stderr.rstrip().endswith(self.DOG_RESP_VDI_NOT_FOUND): elif _stderr.rstrip().endswith(self.DOG_RESP_VDI_NOT_FOUND):
LOG.warning('Volume "%s" not found.', vdiname) LOG.warning('Volume "%s" not found.', vdiname)
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
cmd = e.kwargs['cmd'] cmd = e.kwargs['cmd']
_stderr = e.kwargs['stderr'] _stderr = e.kwargs['stderr']
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
@ -258,7 +270,7 @@ class SheepdogClient(object):
{'src_vdiname': src_vdiname, {'src_vdiname': src_vdiname,
'src_snapname': src_snapname}, 'src_snapname': src_snapname},
'sheepdog:%s' % dst_vdiname, '%sG' % size) 'sheepdog:%s' % dst_vdiname, '%sG' % size)
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
cmd = e.kwargs['cmd'] cmd = e.kwargs['cmd']
_stderr = e.kwargs['stderr'] _stderr = e.kwargs['stderr']
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
@ -283,7 +295,7 @@ class SheepdogClient(object):
size = int(size) * units.Gi size = int(size) * units.Gi
try: try:
(_stdout, _stderr) = self._run_dog('vdi', 'resize', vdiname, size) (_stdout, _stderr) = self._run_dog('vdi', 'resize', vdiname, size)
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
_stderr = e.kwargs['stderr'] _stderr = e.kwargs['stderr']
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
if _stderr.rstrip('\\n').endswith( if _stderr.rstrip('\\n').endswith(
@ -308,7 +320,7 @@ class SheepdogClient(object):
def get_volume_stats(self): def get_volume_stats(self):
try: try:
(_stdout, _stderr) = self._run_dog('node', 'info', '-r') (_stdout, _stderr) = self._run_dog('node', 'info', '-r')
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error('Failed to get volume status. %s', e) LOG.error('Failed to get volume status. %s', e)
return _stdout return _stdout
@ -317,7 +329,7 @@ class SheepdogClient(object):
# Get info of the specified vdi. # Get info of the specified vdi.
try: try:
(_stdout, _stderr) = self._run_dog('vdi', 'list', vdiname, '-r') (_stdout, _stderr) = self._run_dog('vdi', 'list', vdiname, '-r')
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error('Failed to get vdi info. %s', e) LOG.error('Failed to get vdi info. %s', e)
return _stdout return _stdout
@ -325,7 +337,7 @@ class SheepdogClient(object):
def update_node_list(self): def update_node_list(self):
try: try:
(_stdout, _stderr) = self._run_dog('node', 'list', '-r') (_stdout, _stderr) = self._run_dog('node', 'list', '-r')
except exception.SheepdogCmdError as e: except SheepdogCmdError as e:
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
LOG.error('Failed to get node list. %s', e) LOG.error('Failed to get node list. %s', e)
node_list = [] node_list = []