Merge "OSC: Add magnum service-list command"

This commit is contained in:
Zuul 2017-11-24 08:58:37 +00:00 committed by Gerrit Code Review
commit 57db907ad9
4 changed files with 87 additions and 0 deletions

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
def _get_client(obj, parsed_args):
obj.log.debug("take_action(%s)" % parsed_args)
return obj.app.client_manager.container_infra
class ListService(command.Lister):
"""Print a list of Magnum services."""
log = logging.getLogger(__name__ + ".ListService")
def get_parser(self, prog_name):
parser = super(ListService, self).get_parser(prog_name)
return parser
def take_action(self, parsed_args):
client = _get_client(self, parsed_args)
services = client.mservices.list()
columns = ('id', 'host', 'binary', 'state', 'disabled',
'disabled_reason', 'created_at', 'updated_at')
return (columns, (utils.get_item_properties(service, columns)
for service in services))

View File

@ -47,6 +47,7 @@ class MagnumFakeContainerInfra(object):
def __init__(self):
self.cluster_templates = FakeBaseModelManager()
self.clusters = FakeBaseModelManager()
self.mservices = FakeBaseModelManager()
class MagnumFakeClientManager(osc_fakes.FakeClientManager):

View File

@ -0,0 +1,45 @@
# 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 magnumclient.osc.v1 import mservices
from magnumclient.tests.osc.unit.v1 import fakes
class TestServiceList(fakes.TestMagnumClientOSCV1):
columns = ('id', 'host', 'binary', 'state', 'disabled',
'disabled_reason', 'created_at', 'updated_at')
def setUp(self):
super(TestServiceList, self).setUp()
self.mservices_mock = self.app.client_manager.container_infra.mservices
self.mservices_mock.list = mock.Mock()
fake_service = mock.Mock(
Binary='magnum-conductor',
Host='Host1',
Status='enabled',
State='up',
Updated_at=None,
Disabled_Reason=None,
)
fake_service.name = 'test_service'
self.mservices_mock.list.return_value = [fake_service]
# Get the command object to test
self.cmd = mservices.ListService(self.app, None)
def test_service_list(self):
arglist = []
parsed_args = self.check_parser(self.cmd, arglist, [])
columns, data = self.cmd.take_action(parsed_args)
self.mservices_mock.list.assert_called_with()
self.assertEqual(self.columns, columns)

View File

@ -43,6 +43,8 @@ openstack.container_infra.v1 =
coe_cluster_update = magnumclient.osc.v1.clusters:UpdateCluster
coe_cluster_config = magnumclient.osc.v1.clusters:ConfigCluster
coe_service_list = magnumclient.osc.v1.mservices:ListService
[build_sphinx]
source-dir = doc/source
build-dir = doc/build