Change TaskNotFound traceback info to user-friendly message

In some common cases (like detecting absense of requested object),
CLI shows exception traceback instead of just a simple message
that "<something> is not found".

This traceback is redundant and confusing users - they think that
rally went into trouble, but all that actually happened is wrong
uuid specified.

The traceback must be shown only with `--debug' option explicitly
specified.

The unit test and functional test are both provided.

Change-Id: I32811974d88f414c4508dfed19a7c5dc5e80fd98
Closes-Bug: #1392354
This commit is contained in:
Li Ma 2014-11-23 00:22:19 -08:00
parent 1d6d28abf8
commit 7dcf0e68df
3 changed files with 61 additions and 0 deletions

View File

@ -302,6 +302,11 @@ def run(argv, categories):
raise
print(e)
return 1
except exceptions.TaskNotFound as e:
if CONF.debug:
LOG.exception(e)
print(e)
return 1
except Exception:
print(_("Command failed, please check log for more info"))
raise

View File

@ -21,6 +21,9 @@ import mock
from tests.functional import utils
FAKE_TASK_UUID = '87ab639d-4968-4638-b9a1-07774c32484a'
class TaskTestCase(unittest.TestCase):
def _get_sample_task_config(self):
@ -61,6 +64,46 @@ class TaskTestCase(unittest.TestCase):
rally("task start --task %s" % config.filename)
self.assertIn("result", rally("task results"))
def test_results_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task results --uuid %s" % FAKE_TASK_UUID)
def test_abort_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task abort --uuid %s" % FAKE_TASK_UUID)
def test_delete_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task delete --uuid %s" % FAKE_TASK_UUID)
def test_detailed_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task detailed --uuid %s" % FAKE_TASK_UUID)
def test_plot2html_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task plot2html --uuid %s" % FAKE_TASK_UUID)
def test_report_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task report --uuid %s" % FAKE_TASK_UUID)
def test_sla_check_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task sla_check --uuid %s" % FAKE_TASK_UUID)
def test_status_with_wrong_task_id(self):
rally = utils.Rally()
self.assertRaises(utils.RallyCmdError,
rally, "task status --uuid %s" % FAKE_TASK_UUID)
def test_report(self):
rally = utils.Rally()
cfg = self._get_sample_task_config()
@ -71,6 +114,8 @@ class TaskTestCase(unittest.TestCase):
os.remove(html_file)
rally("task report --out %s" % html_file)
self.assertTrue(os.path.exists(html_file))
self.assertRaises(utils.RallyCmdError,
rally, "task report --uuid %s" % FAKE_TASK_UUID)
def test_delete(self):
rally = utils.Rally()

View File

@ -23,11 +23,14 @@ from rally.cmd.commands import show
from rally.cmd.commands import task
from rally.cmd.commands import use
from rally.cmd.commands import verify
from rally import exceptions
from rally.openstack.common import cliutils as common_cliutils
from tests.unit import test
CONF = cfg.CONF
FAKE_TASK_UUID = 'bb0f621c-29bd-495c-9d7a-d844335ed0fa'
class CliUtilsTestCase(test.TestCase):
@ -138,6 +141,14 @@ class CliUtilsTestCase(test.TestCase):
ret = cliutils.run(["rally", "show", "keypairs"], self.categories)
self.assertEqual(ret, 1)
@mock.patch("rally.db.task_get",
side_effect=exceptions.TaskNotFound(FAKE_TASK_UUID))
def test_run_task_not_found(self, mock_task_get):
ret = cliutils.run(["rally", "task", "status", "%s" % FAKE_TASK_UUID],
self.categories)
self.assertTrue(mock_task_get.called)
self.assertEqual(ret, 1)
@mock.patch("rally.openstack.common.cliutils.validate_args",
side_effect=common_cliutils.MissingArgs("missing"))
def test_run_show_fails(self, mock_validate_args):