summaryrefslogtreecommitdiff
path: root/osprofiler/tests
diff options
context:
space:
mode:
authorVipin Balachandran <vbala@vmware.com>2016-11-24 14:35:34 +0530
committerVipin Balachandran <vbala@vmware.com>2016-12-02 15:55:51 +0530
commit221bb4f6b0a4c094f62fe4a6178d7c95e0365502 (patch)
treecc42e357561559b45e43dffe6c2b0ccd9817fc11 /osprofiler/tests
parent0ac59b8db9f27e8791e3c77bf7f90829f5c6a05c (diff)
downloadosprofiler-221bb4f6b0a4c094f62fe4a6178d7c95e0365502.tar.gz
Error out for invalid trace ID
There is no error message printed if the trace ID input to the 'trace show' command is invalid. Fixing this by checking for empty child nodes at the root of the trace result from driver. Change-Id: I8fc40356cffa98f5e9b9f6048b8fe422271f41f0 Closes-bug: #1644448
Diffstat (limited to 'osprofiler/tests')
-rw-r--r--osprofiler/tests/cmd/test_shell.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/osprofiler/tests/cmd/test_shell.py b/osprofiler/tests/cmd/test_shell.py
index f6316eb..c97c406 100644
--- a/osprofiler/tests/cmd/test_shell.py
+++ b/osprofiler/tests/cmd/test_shell.py
@@ -17,6 +17,7 @@ import json
import os
import sys
+import ddt
import mock
import six
@@ -25,6 +26,7 @@ from osprofiler import exc
from osprofiler.tests import test
+@ddt.ddt
class ShellTestCase(test.TestCase):
def setUp(self):
super(ShellTestCase, self).setUp()
@@ -145,14 +147,16 @@ class ShellTestCase(test.TestCase):
@mock.patch("osprofiler.drivers.ceilometer.Ceilometer.get_report")
def test_trace_show_no_selected_format(self, mock_get):
- mock_get.return_value = "some_notificatios"
+ mock_get.return_value = self._create_mock_notifications()
msg = ("You should choose one of the following output formats: "
"json, html or dot.")
self._test_with_command_error("trace show fake_id", msg)
@mock.patch("osprofiler.drivers.ceilometer.Ceilometer.get_report")
- def test_trace_show_trace_id_not_found(self, mock_get):
- mock_get.return_value = None
+ @ddt.data(None, {"info": {"started": 0, "finished": 1, "name": "total"},
+ "children": []})
+ def test_trace_show_trace_id_not_found(self, notifications, mock_get):
+ mock_get.return_value = notifications
fake_trace_id = "fake_id"
msg = ("Trace with UUID %s not found. There are 3 possible reasons: \n"
@@ -164,13 +168,28 @@ class ShellTestCase(test.TestCase):
self._test_with_command_error("trace show %s" % fake_trace_id, msg)
- @mock.patch("sys.stdout", six.StringIO())
- @mock.patch("osprofiler.drivers.ceilometer.Ceilometer.get_report")
- def test_trace_show_in_json(self, mock_get):
+ def _create_mock_notifications(self):
notifications = {
"info": {
- "started": 0, "finished": 0, "name": "total"}, "children": []}
+ "started": 0,
+ "finished": 1,
+ "name": "total"
+ },
+ "children": [{
+ "info": {
+ "started": 0,
+ "finished": 1,
+ "name": "total"
+ },
+ "children": []
+ }]
+ }
+ return notifications
+ @mock.patch("sys.stdout", six.StringIO())
+ @mock.patch("osprofiler.drivers.ceilometer.Ceilometer.get_report")
+ def test_trace_show_in_json(self, mock_get):
+ notifications = self._create_mock_notifications()
mock_get.return_value = notifications
self.run_command("trace show fake_id --json")
@@ -180,10 +199,7 @@ class ShellTestCase(test.TestCase):
@mock.patch("sys.stdout", six.StringIO())
@mock.patch("osprofiler.drivers.ceilometer.Ceilometer.get_report")
def test_trace_show_in_html(self, mock_get):
- notifications = {
- "info": {
- "started": 0, "finished": 0, "name": "total"}, "children": []}
-
+ notifications = self._create_mock_notifications()
mock_get.return_value = notifications
# NOTE(akurilin): to simplify assert statement, html-template should be
@@ -211,10 +227,7 @@ class ShellTestCase(test.TestCase):
@mock.patch("sys.stdout", six.StringIO())
@mock.patch("osprofiler.drivers.ceilometer.Ceilometer.get_report")
def test_trace_show_write_to_file(self, mock_get):
- notifications = {
- "info": {
- "started": 0, "finished": 0, "name": "total"}, "children": []}
-
+ notifications = self._create_mock_notifications()
mock_get.return_value = notifications
with mock.patch("osprofiler.cmd.commands.open",