diff --git a/magnumclient/osc/v1/mservices.py b/magnumclient/osc/v1/mservices.py new file mode 100644 index 00000000..b074ffc9 --- /dev/null +++ b/magnumclient/osc/v1/mservices.py @@ -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)) diff --git a/magnumclient/tests/osc/unit/v1/fakes.py b/magnumclient/tests/osc/unit/v1/fakes.py index cf8220eb..98de4272 100644 --- a/magnumclient/tests/osc/unit/v1/fakes.py +++ b/magnumclient/tests/osc/unit/v1/fakes.py @@ -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): diff --git a/magnumclient/tests/osc/unit/v1/test_mservices.py b/magnumclient/tests/osc/unit/v1/test_mservices.py new file mode 100644 index 00000000..8039a502 --- /dev/null +++ b/magnumclient/tests/osc/unit/v1/test_mservices.py @@ -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) diff --git a/setup.cfg b/setup.cfg index db2d07f1..b72baa4c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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