diff --git a/releasenotes/notes/add_magnum_services_support-3d95f9dcc60b5573.yaml b/releasenotes/notes/add_magnum_services_support-3d95f9dcc60b5573.yaml new file mode 100644 index 000000000..3a32e3dde --- /dev/null +++ b/releasenotes/notes/add_magnum_services_support-3d95f9dcc60b5573.yaml @@ -0,0 +1,3 @@ +--- +features: + - Add support for listing Magnum services. diff --git a/shade/_tasks.py b/shade/_tasks.py index 4783c04c0..e7f0667dd 100644 --- a/shade/_tasks.py +++ b/shade/_tasks.py @@ -928,3 +928,8 @@ class BaymodelUpdate(task_manager.Task): def main(self, client): return client.magnum_client.baymodels.update( self.args['id'], self.args['patch']) + + +class MagnumServicesList(task_manager.Task): + def main(self, client): + return client.magnum_client.mservices.list(detail=False) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 23f32c08b..7cf764dc4 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -5818,3 +5818,13 @@ class OpenStackCloud(object): new_baymodel = self.get_baymodel(name_or_id) return new_baymodel + + def list_magnum_services(self): + """List all Magnum services. + :returns: a list of dicts containing the service details. + + :raises: OpenStackCloudException on operation error. + """ + with _utils.shade_exceptions("Error fetching Magnum services list"): + return self.manager.submitTask( + _tasks.MagnumServicesList()) diff --git a/shade/tests/functional/test_magnum_services.py b/shade/tests/functional/test_magnum_services.py new file mode 100644 index 000000000..17c622c95 --- /dev/null +++ b/shade/tests/functional/test_magnum_services.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- + +# 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. + +""" +test_magnum_services +-------------------- + +Functional tests for `shade` services method. +""" + +from shade.tests.functional import base + + +class TestMagnumServices(base.BaseFunctionalTestCase): + + def setUp(self): + super(TestMagnumServices, self).setUp() + if not self.operator_cloud.has_service('container'): + self.skipTest('Container service not supported by cloud') + + def test_magnum_services(self): + '''Test magnum services functionality''' + + # Test that we can list services + services = self.operator_cloud.list_magnum_services() + + self.assertEqual(1, len(services)) + self.assertEqual(services[0]['id'], 1) + self.assertEqual('up', services[0]['state']) + self.assertEqual('magnum-conductor', services[0]['binary']) + self.assertGreater(services[0]['report_count'], 0) diff --git a/shade/tests/unit/test_magnum_services.py b/shade/tests/unit/test_magnum_services.py new file mode 100644 index 000000000..d63bb6694 --- /dev/null +++ b/shade/tests/unit/test_magnum_services.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +# 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 +import munch + +import shade +from shade.tests.unit import base + + +magnum_service_obj = munch.Munch( + binary='fake-service', + state='up', + report_count=1, + human_id=None, + host='fake-host', + id=1, + disabled_reason=None +) + + +class TestMagnumServices(base.TestCase): + + def setUp(self): + super(TestMagnumServices, self).setUp() + self.cloud = shade.openstack_cloud(validate=False) + + @mock.patch.object(shade.OpenStackCloud, 'magnum_client') + def test_list_magnum_services(self, mock_magnum): + mock_magnum.mservices.list.return_value = [magnum_service_obj, ] + mservices_list = self.cloud.list_magnum_services() + mock_magnum.mservices.list.assert_called_with(detail=False) + self.assertEqual(mservices_list[0], magnum_service_obj)