summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-02-05 14:56:17 +0000
committerGerrit Code Review <review@openstack.org>2015-02-05 14:56:17 +0000
commit6c9fed0eafb5ec82e0a98ed265857bce27dedc14 (patch)
treea66d59e21de78989b0f366dfc7d46366018a942a
parent57c582c354c4fcc1695e06a532b6312ec02e6cbf (diff)
parentf5fd6afbd102eb0b27a2d7b922d5862291248952 (diff)
downloadpython-ceilometerclient-6c9fed0eafb5ec82e0a98ed265857bce27dedc14.tar.gz
Merge "add --no-traits for event-list"
-rw-r--r--ceilometerclient/tests/v2/test_shell.py61
-rw-r--r--ceilometerclient/v2/shell.py5
2 files changed, 60 insertions, 6 deletions
diff --git a/ceilometerclient/tests/v2/test_shell.py b/ceilometerclient/tests/v2/test_shell.py
index fcd2d6a..2f13c12 100644
--- a/ceilometerclient/tests/v2/test_shell.py
+++ b/ceilometerclient/tests/v2/test_shell.py
@@ -1031,12 +1031,22 @@ class ShellEventListCommandTest(utils.BaseTestCase):
"generated": "2015-01-12T04:03:25.741471",
"message_id": "fb2bef58-88af-4380-8698-e0f18fcf452d",
"event_type": "compute.instance.create.start",
+ "traits": [{
+ "name": "state",
+ "type": "string",
+ "value": "building",
+ }],
},
{
"traits": [],
"generated": "2015-01-12T04:03:28.452495",
"message_id": "9b20509a-576b-4995-acfa-1a24ee5cf49f",
"event_type": "compute.instance.create.end",
+ "traits": [{
+ "name": "state",
+ "type": "string",
+ "value": "active",
+ }],
},
]
@@ -1045,6 +1055,7 @@ class ShellEventListCommandTest(utils.BaseTestCase):
self.cc = mock.Mock()
self.args = mock.Mock()
self.args.query = None
+ self.args.no_traits = None
@mock.patch('sys.stdout', new=six.StringIO())
def test_event_list(self):
@@ -1053,16 +1064,54 @@ class ShellEventListCommandTest(utils.BaseTestCase):
self.cc.events.list.return_value = ret_events
ceilometer_shell.do_event_list(self.cc, self.args)
self.assertEqual('''\
++--------------------------------------+-------------------------------+\
+----------------------------+-------------------------------+
+| Message ID | Event Type |\
+ Generated | Traits |
++--------------------------------------+-------------------------------+\
+----------------------------+-------------------------------+
+| fb2bef58-88af-4380-8698-e0f18fcf452d | compute.instance.create.start |\
+ 2015-01-12T04:03:25.741471 | +-------+--------+----------+ |
+| | |\
+ | | name | type | value | |
+| | |\
+ | +-------+--------+----------+ |
+| | |\
+ | | state | string | building | |
+| | |\
+ | +-------+--------+----------+ |
+| 9b20509a-576b-4995-acfa-1a24ee5cf49f | compute.instance.create.end |\
+ 2015-01-12T04:03:28.452495 | +-------+--------+--------+ |
+| | |\
+ | | name | type | value | |
+| | |\
+ | +-------+--------+--------+ |
+| | |\
+ | | state | string | active | |
+| | |\
+ | +-------+--------+--------+ |
++--------------------------------------+-------------------------------+\
+----------------------------+-------------------------------+
+''', sys.stdout.getvalue())
+
+ @mock.patch('sys.stdout', new=six.StringIO())
+ def test_event_list_no_traits(self):
+ self.args.no_traits = True
+ ret_events = [events.Event(mock.Mock(), event)
+ for event in self.EVENTS]
+ self.cc.events.list.return_value = ret_events
+ ceilometer_shell.do_event_list(self.cc, self.args)
+ self.assertEqual('''\
+--------------------------------------+-------------------------------\
-+----------------------------+--------+
++----------------------------+
| Message ID | Event Type \
-| Generated | Traits |
+| Generated |
+--------------------------------------+-------------------------------\
-+----------------------------+--------+
++----------------------------+
| fb2bef58-88af-4380-8698-e0f18fcf452d | compute.instance.create.start \
-| 2015-01-12T04:03:25.741471 | |
+| 2015-01-12T04:03:25.741471 |
| 9b20509a-576b-4995-acfa-1a24ee5cf49f | compute.instance.create.end \
-| 2015-01-12T04:03:28.452495 | |
+| 2015-01-12T04:03:28.452495 |
+--------------------------------------+-------------------------------\
-+----------------------------+--------+
++----------------------------+
''', sys.stdout.getvalue())
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
index 961ff47..ef91e8d 100644
--- a/ceilometerclient/v2/shell.py
+++ b/ceilometerclient/v2/shell.py
@@ -779,11 +779,16 @@ def do_resource_show(cc, args={}):
help='key[op]data_type::value; list. data_type is optional, '
'but if supplied must be string, integer, float'
'or datetime.')
+@utils.arg('--no-traits', dest='no_traits', action='store_true',
+ help='If specified, traits will not be printed.')
def do_event_list(cc, args={}):
"""List events."""
events = cc.events.list(q=options.cli_to_array(args.query))
field_labels = ['Message ID', 'Event Type', 'Generated', 'Traits']
fields = ['message_id', 'event_type', 'generated', 'traits']
+ if args.no_traits:
+ field_labels.pop()
+ fields.pop()
utils.print_list(events, fields, field_labels,
formatters={
'traits': utils.nested_list_of_dict_formatter(