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):
columns = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
'Disabled Reason']
columns = ['binary', 'host', 'status', 'state', 'updated_at',
'disabled_reason']
def setUp(self):
super(TestServiceList, self).setUp()
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(
Binary='senlin-engine',
Host='Host1',
@ -33,11 +33,11 @@ class TestServiceList(fakes.TestClusteringv1):
)
fake_service.name = 'test_service'
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):
arglist = []
parsed_args = self.check_parser(self.cmd, arglist, [])
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)

View File

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

View File

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

View File

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