Add OSC plugin for openstack cluster event show
This change implements the "openstack cluster event show" command Based on the existing senlin command: senlin event-show Change-Id: I405c55d6eadb2e6fa0535388604f114d04b17eec Blueprint: senlin-support-python-openstackclient
This commit is contained in:
@@ -13,8 +13,12 @@
|
||||
"""Clustering v1 event action implementations"""
|
||||
|
||||
import logging
|
||||
import six
|
||||
|
||||
from cliff import lister
|
||||
from cliff import show
|
||||
from openstack import exceptions as sdk_exc
|
||||
from openstackclient.common import exceptions as exc
|
||||
from openstackclient.common import utils
|
||||
|
||||
from senlinclient.common.i18n import _
|
||||
@@ -100,3 +104,30 @@ class ListEvent(lister.Lister):
|
||||
(utils.get_item_properties(e, columns, formatters=formatters)
|
||||
for e in events)
|
||||
)
|
||||
|
||||
|
||||
class ShowEvent(show.ShowOne):
|
||||
"""Describe the event."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".ShowEvent")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowEvent, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'event',
|
||||
metavar='<event>',
|
||||
help=_('ID of event to display details for')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
try:
|
||||
event = senlin_client.get_event(parsed_args.event)
|
||||
except sdk_exc.ResourceNotFound:
|
||||
raise exc.CommandError(_("Event not found: %s")
|
||||
% parsed_args.event)
|
||||
columns = list(six.iterkeys(event))
|
||||
return columns, utils.get_dict_properties(event.to_dict(), columns)
|
||||
|
||||
@@ -15,6 +15,7 @@ import mock
|
||||
|
||||
from openstack.cluster.v1 import event as sdk_event
|
||||
from openstack import exceptions as sdk_exc
|
||||
from openstackclient.common import exceptions as exc
|
||||
|
||||
from senlinclient.osc.v1 import event as osc_event
|
||||
from senlinclient.tests.unit.osc.v1 import fakes
|
||||
@@ -132,3 +133,40 @@ class TestEventList(TestEvent):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.mock_client.events.assert_called_with(**kwargs)
|
||||
self.assertEqual(self.columns, columns)
|
||||
|
||||
|
||||
class TestEventShow(TestEvent):
|
||||
get_response = {"event": {
|
||||
"action": "create",
|
||||
"cluster_id": 'null',
|
||||
"id": "2d255b9c-8f36-41a2-a137-c0175ccc29c3",
|
||||
"level": "20",
|
||||
"obj_id": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
|
||||
"obj_name": "node009",
|
||||
"obj_type": "NODE",
|
||||
"project": "6e18cc2bdbeb48a5b3cad2dc499f6804",
|
||||
"status": "CREATING",
|
||||
"status_reason": "Initializing",
|
||||
"timestamp": "2015-03-05T08:53:15",
|
||||
"user": "a21ded6060534d99840658a777c2af5a"
|
||||
}}
|
||||
|
||||
def setUp(self):
|
||||
super(TestEventShow, self).setUp()
|
||||
self.cmd = osc_event.ShowEvent(self.app, None)
|
||||
self.mock_client.get_event = mock.Mock(
|
||||
return_value=sdk_event.Event(None, self.get_response))
|
||||
|
||||
def test_event_show(self):
|
||||
arglist = ['my_event']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.get_event.assert_called_with('my_event')
|
||||
|
||||
def test_event_show_not_found(self):
|
||||
arglist = ['my_event']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.mock_client.get_event.side_effect = sdk_exc.ResourceNotFound()
|
||||
error = self.assertRaises(exc.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertEqual('Event not found: my_event', str(error))
|
||||
|
||||
@@ -33,6 +33,7 @@ openstack.clustering.v1 =
|
||||
cluster_create = senlinclient.osc.v1.cluster:CreateCluster
|
||||
cluster_delete = senlinclient.osc.v1.cluster:DeleteCluster
|
||||
cluster_event_list = senlinclient.osc.v1.event:ListEvent
|
||||
cluster_event_show = senlinclient.osc.v1.event:ShowEvent
|
||||
cluster_list = senlinclient.osc.v1.cluster:ListCluster
|
||||
cluster_resize = senlinclient.osc.v1.cluster:ResizeCluster
|
||||
cluster_scale_in = senlinclient.osc.v1.cluster:ScaleInCluster
|
||||
|
||||
Reference in New Issue
Block a user