Fix openstack cluster service

1 Better to use command.Lister;
2 Revise to `openstack cluster service list`
3 Indeed, this command can't work now, implement it.

Closes-Bug: #1705321
Change-Id: I5986751ba6d8a0b33c3c3d53e1efd93f7003d028
This commit is contained in:
jonnary 2017-07-19 23:47:29 +08:00
parent 7f05b87af8
commit 8682e2fc5e
4 changed files with 19 additions and 15 deletions

View File

@ -16,13 +16,13 @@ from senlinclient.v1 import service as osc_service
class TestServiceList(fakes.TestClusteringv1): class TestServiceList(fakes.TestClusteringv1):
columns = ['Binary', 'Host', 'Status', 'State', 'Updated_at', columns = ['binary', 'host', 'status', 'state', 'updated_at',
'Disabled Reason'] 'disabled_reason']
def setUp(self): def setUp(self):
super(TestServiceList, self).setUp() super(TestServiceList, self).setUp()
self.mock_client = self.app.client_manager.clustering self.mock_client = self.app.client_manager.clustering
self.cmd = osc_service.Service(self.app, None) self.cmd = osc_service.ListService(self.app, None)
fake_service = mock.Mock( fake_service = mock.Mock(
Binary='senlin-engine', Binary='senlin-engine',
Host='Host1', Host='Host1',
@ -33,11 +33,11 @@ class TestServiceList(fakes.TestClusteringv1):
) )
fake_service.name = 'test_service' fake_service.name = 'test_service'
fake_service.to_dict = mock.Mock(return_value={}) fake_service.to_dict = mock.Mock(return_value={})
self.mock_client.get_service = mock.Mock(return_value=[fake_service]) self.mock_client.services = mock.Mock(return_value=[fake_service])
def test_service(self): def test_service(self):
arglist = [] arglist = []
parsed_args = self.check_parser(self.cmd, arglist, []) parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.mock_client.get_service.assert_called_with() self.mock_client.services.assert_called_with()
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)

View File

@ -469,7 +469,7 @@ class Client(object):
""" """
return self.service.get_action(action) return self.service.get_action(action)
def get_service(self, **queries): def services(self, **queries):
"""List services """List services
Doc link: Doc link:

View File

@ -16,24 +16,28 @@ from osc_lib.command import command
from osc_lib import utils from osc_lib import utils
class Service(command.ShowOne): class ListService(command.Lister):
"""Show a list of all running services.""" """Show a list of all running services."""
log = logging.getLogger(__name__ + ".Service") log = logging.getLogger(__name__ + ".ListService")
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(Service, self).get_parser(prog_name) parser = super(ListService, self).get_parser(prog_name)
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args) self.log.debug("take_action(%s)", parsed_args)
senlin_client = self.app.client_manager.clustering senlin_client = self.app.client_manager.clustering
columns = ['binary', 'host', 'status', 'state', 'updated_at',
'disabled_reason']
queries = {} queries = {}
result = senlin_client.get_service(**queries) result = senlin_client.services(**queries)
formatters = {} formatters = {}
columns = ['Binary', 'Host', 'Status', 'State', 'Updated_at', return (
'Disabled Reason'] columns,
return columns, utils.get_dict_properties(result, columns, (utils.get_item_properties(s, columns, formatters=formatters)
formatters=formatters) for s in result)
)

View File

@ -84,7 +84,7 @@ openstack.clustering.v1 =
cluster_update = senlinclient.v1.cluster:UpdateCluster cluster_update = senlinclient.v1.cluster:UpdateCluster
cluster_collect = senlinclient.v1.cluster:ClusterCollect cluster_collect = senlinclient.v1.cluster:ClusterCollect
cluster_run = senlinclient.v1.cluster:ClusterRun cluster_run = senlinclient.v1.cluster:ClusterRun
cluster_service = senlinclient.v1.service:Service cluster_service_list = senlinclient.v1.service:ListService
[global] [global]
setup-hooks = setup-hooks =