Add magnum services call to shade

Change-Id: I7a50be5464b4962ece8e2f13e3e93f8939e26655
This commit is contained in:
Yolanda Robla 2016-05-06 16:42:11 +02:00 committed by Yolanda Robla
parent eb4ed45cf4
commit cb2e59c06a
5 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,3 @@
---
features:
- Add support for listing Magnum services.

View File

@ -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)

View File

@ -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())

View File

@ -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)

View File

@ -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)