Merge "Add services list"

This commit is contained in:
Jenkins 2017-06-27 07:20:18 +00:00 committed by Gerrit Code Review
commit 87d645761d
6 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,43 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from senlinclient.tests.unit.v1 import fakes
from senlinclient.v1 import service as osc_service
class TestServiceList(fakes.TestClusteringv1):
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)
fake_service = mock.Mock(
Binary='senlin-engine',
Host='Host1',
Status='enabled',
State='up',
Updated_at=None,
Disabled_Reason=None,
)
fake_service.name = 'test_service'
fake_service.to_dict = mock.Mock(return_value={})
self.mock_client.get_service = 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.assertEqual(self.columns, columns)

View File

@ -1740,3 +1740,16 @@ class ShellTest(testtools.TestCase):
service, args)
msg = _('Action not found: fake_id')
self.assertEqual(msg, six.text_type(ex))
@mock.patch.object(utils, 'print_list')
def test_do_service_list(self, mock_print):
service = mock.Mock()
fields = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
'Disabled Reason']
result = mock.Mock()
service.services.return_value = result
formatters = {}
sh.do_service_list(service)
mock_print.assert_called_once_with(result, fields,
formatters=formatters)

View File

@ -448,3 +448,11 @@ class Client(object):
https://developer.openstack.org/api-ref/clustering/#show-action-details
"""
return self.service.get_action(action)
def get_service(self, **queries):
"""List service
Doc link:
http://developer.openstack.org/api-ref-clustering-v1.html#showAction
"""
return self.service.services(**queries)

View File

@ -0,0 +1,39 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from osc_lib.command import command
from osc_lib import utils
class Service(command.ShowOne):
"""Retrieve build information."""
log = logging.getLogger(__name__ + ".Service")
def get_parser(self, prog_name):
parser = super(Service, 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
queries = {}
result = senlin_client.get_service(**queries)
formatters = {}
columns = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
'Disabled Reason']
return columns, utils.get_dict_properties(result, columns,
formatters=formatters)

View File

@ -1710,3 +1710,16 @@ def do_action_show(service, args):
}
utils.print_dict(action.to_dict(), formatters=formatters)
def do_service_list(service, args=None):
"""Show a list of all running services."""
show_deprecated('senlin service-list',
'openstack cluster service list')
fields = ['Binary', 'Host', 'Status', 'State', 'Updated_at',
'Disabled Reason']
queries = {}
result = service.services(**queries)
formatters = {}
utils.print_list(result, fields, formatters=formatters)

View File

@ -84,6 +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.cluster.service.Service
[global]
setup-hooks =