summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-11-24 08:58:37 +0000
committerGerrit Code Review <review@openstack.org>2017-11-24 08:58:37 +0000
commit57db907ad931c29ee89d55600cdf728c7b81c7d1 (patch)
tree13a18799ac49241af990ced4ae2b2e3309f6881c
parentc035f9299ffcb474021732429d1277ed844abab2 (diff)
parentfe51e61cdc7b948c6ac5c897fe3e835221304a33 (diff)
Merge "OSC: Add magnum service-list command"
-rw-r--r--magnumclient/osc/v1/mservices.py39
-rw-r--r--magnumclient/tests/osc/unit/v1/fakes.py1
-rw-r--r--magnumclient/tests/osc/unit/v1/test_mservices.py45
-rw-r--r--setup.cfg2
4 files changed, 87 insertions, 0 deletions
diff --git a/magnumclient/osc/v1/mservices.py b/magnumclient/osc/v1/mservices.py
new file mode 100644
index 0000000..b074ffc
--- /dev/null
+++ b/magnumclient/osc/v1/mservices.py
@@ -0,0 +1,39 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import logging
14
15from osc_lib.command import command
16from osc_lib import utils
17
18
19def _get_client(obj, parsed_args):
20 obj.log.debug("take_action(%s)" % parsed_args)
21 return obj.app.client_manager.container_infra
22
23
24class ListService(command.Lister):
25 """Print a list of Magnum services."""
26
27 log = logging.getLogger(__name__ + ".ListService")
28
29 def get_parser(self, prog_name):
30 parser = super(ListService, self).get_parser(prog_name)
31 return parser
32
33 def take_action(self, parsed_args):
34 client = _get_client(self, parsed_args)
35 services = client.mservices.list()
36 columns = ('id', 'host', 'binary', 'state', 'disabled',
37 'disabled_reason', 'created_at', 'updated_at')
38 return (columns, (utils.get_item_properties(service, columns)
39 for service in services))
diff --git a/magnumclient/tests/osc/unit/v1/fakes.py b/magnumclient/tests/osc/unit/v1/fakes.py
index 076aaac..034dfe7 100644
--- a/magnumclient/tests/osc/unit/v1/fakes.py
+++ b/magnumclient/tests/osc/unit/v1/fakes.py
@@ -47,6 +47,7 @@ class MagnumFakeContainerInfra(object):
47 def __init__(self): 47 def __init__(self):
48 self.cluster_templates = FakeBaseModelManager() 48 self.cluster_templates = FakeBaseModelManager()
49 self.clusters = FakeBaseModelManager() 49 self.clusters = FakeBaseModelManager()
50 self.mservices = FakeBaseModelManager()
50 51
51 52
52class MagnumFakeClientManager(osc_fakes.FakeClientManager): 53class 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 0000000..8039a50
--- /dev/null
+++ b/magnumclient/tests/osc/unit/v1/test_mservices.py
@@ -0,0 +1,45 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12import mock
13
14from magnumclient.osc.v1 import mservices
15from magnumclient.tests.osc.unit.v1 import fakes
16
17
18class TestServiceList(fakes.TestMagnumClientOSCV1):
19 columns = ('id', 'host', 'binary', 'state', 'disabled',
20 'disabled_reason', 'created_at', 'updated_at')
21
22 def setUp(self):
23 super(TestServiceList, self).setUp()
24 self.mservices_mock = self.app.client_manager.container_infra.mservices
25 self.mservices_mock.list = mock.Mock()
26 fake_service = mock.Mock(
27 Binary='magnum-conductor',
28 Host='Host1',
29 Status='enabled',
30 State='up',
31 Updated_at=None,
32 Disabled_Reason=None,
33 )
34 fake_service.name = 'test_service'
35 self.mservices_mock.list.return_value = [fake_service]
36
37 # Get the command object to test
38 self.cmd = mservices.ListService(self.app, None)
39
40 def test_service_list(self):
41 arglist = []
42 parsed_args = self.check_parser(self.cmd, arglist, [])
43 columns, data = self.cmd.take_action(parsed_args)
44 self.mservices_mock.list.assert_called_with()
45 self.assertEqual(self.columns, columns)
diff --git a/setup.cfg b/setup.cfg
index db2d07f..b72baa4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -43,6 +43,8 @@ openstack.container_infra.v1 =
43 coe_cluster_update = magnumclient.osc.v1.clusters:UpdateCluster 43 coe_cluster_update = magnumclient.osc.v1.clusters:UpdateCluster
44 coe_cluster_config = magnumclient.osc.v1.clusters:ConfigCluster 44 coe_cluster_config = magnumclient.osc.v1.clusters:ConfigCluster
45 45
46 coe_service_list = magnumclient.osc.v1.mservices:ListService
47
46[build_sphinx] 48[build_sphinx]
47source-dir = doc/source 49source-dir = doc/source
48build-dir = doc/build 50build-dir = doc/build