Merge "Add "event trait list" command"

changes/41/465141/1
Jenkins 6 years ago committed by Gerrit Code Review
commit 10a6c83e11

@ -19,6 +19,7 @@ import copy
import json
from osc_lib.command import command
from osc_lib import utils
class EventList(command.Lister):
@ -104,3 +105,29 @@ class EventTypeList(command.Lister):
ac = self.app.client_manager.event
event_types = ac.event_type.list()
return ('Event Type',), ((t,)for t in event_types)
class EventTraitList(command.Lister):
"""List event traits of a specified event type and trait name"""
def get_parser(self, prog_name):
parser = super(EventTraitList, self).get_parser(prog_name)
parser.add_argument(
'type_name',
metavar='<EVENT_TYPE>',
help='Type of the event for which traits will listed.'
)
parser.add_argument(
'trait_name',
metavar='<TRAIT_NAME>',
help='The name of the trait to list.'
)
return parser
def take_action(self, parsed_args):
ac = self.app.client_manager.event
event_traits = ac.event_trait.list(
parsed_args.type_name, parsed_args.trait_name)
columns = ('name', 'value', 'type')
return (columns,
(utils.get_item_properties(t, columns) for t in event_traits))

@ -58,6 +58,7 @@ class FakeTestEventV2Client(object):
self.capabilities = capabilities.CapabilitiesManager(
self.fake_http_client)
self.event_type = events.EventTypeManager(self.fake_http_client)
self.event_trait = events.EventTraitsManager(self.fake_http_client)
class FakeHTTPClient(object):

@ -32,3 +32,25 @@ class TestEventTypeList(test_base.TestEventV2):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
mock_list.assert_called_once_with('/v2/event_types/')
@mock.patch.object(events_mgr.EventTraitsManager, '_list')
class TestEventTraitsList(test_base.TestEventV2):
def setUp(self):
super(TestEventTraitsList, self).setUp()
self.cmd = events.EventTraitList(self.app, None)
def test_event_traits_list(self, mock_list):
arglist = [
'event_type1',
'trait_name1'
]
verifylist = [
('type_name', 'event_type1'),
('trait_name', 'trait_name1'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
expected_url = '/v2/event_types/%s/traits/%s' % (
parsed_args.type_name, parsed_args.trait_name)
mock_list.assert_called_once_with(expected_url)

@ -27,3 +27,4 @@ class Client(object):
self.capabilities = capabilities.CapabilitiesManager(self.http_client)
self.event = events.EventManager(self.http_client)
self.event_type = events.EventTypeManager(self.http_client)
self.event_trait = events.EventTraitsManager(self.http_client)

@ -23,6 +23,10 @@ class EventType(base.Resource):
pass
class EventTrait(base.Resource):
pass
class EventManager(base.ManagerWithFind):
resource_class = Event
@ -63,3 +67,11 @@ class EventTypeManager(base.ManagerWithFind):
def list(self):
url = '/v2/event_types/'
return self._list(url)
class EventTraitsManager(base.ManagerWithFind):
resource_class = EventTrait
def list(self, event_type, trait_name):
url = '/v2/event_types/%s/traits/%s' % (event_type, trait_name)
return self._list(url)

@ -34,6 +34,7 @@ openstack.event.v2 =
event list = pankoclient.osc.v2.events:EventList
event show = pankoclient.osc.v2.events:EventShow
event type list = pankoclient.osc.v2.events:EventTypeList
event trait list = pankoclient.osc.v2.events:EventTraitList
[build_sphinx]
source-dir = doc/source

Loading…
Cancel
Save