Convert magnum service to requests_mock

Also add documentation and normalization, of which there was previously
not.

Change-Id: Ib4ba4fc748117ae4339683ae9fd4f9f958c3cc0e
This commit is contained in:
Monty Taylor 2017-03-20 10:15:12 -05:00
parent 360a87fe16
commit 7311bf0187
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
4 changed files with 68 additions and 18 deletions

View File

@ -433,3 +433,21 @@ A Cluster Template from magnum.
updated_at=str() or None,
volume_driver=str(),
properties=dict())
MagnumService
-------------
A Magnum Service from magnum
.. code-block:: python
MagnumService = dict(
location=Location(),
binary=str(),
created_at=str(),
disabled_reason=str() or None,
host=str(),
id=str(),
report_count=int(),
state=str(),
properties=dict())

View File

@ -905,3 +905,34 @@ class Normalizer(object):
ret['properties'] = cluster_template
return ret
def _normalize_magnum_services(self, magnum_services):
ret = []
for magnum_service in magnum_services:
ret.append(self._normalize_magnum_service(magnum_service))
return ret
def _normalize_magnum_service(self, magnum_service):
"""Normalize Magnum magnum_services."""
magnum_service = magnum_service.copy()
# Discard noise
magnum_service.pop('links', None)
magnum_service.pop('human_id', None)
# model_name is a magnumclient-ism
magnum_service.pop('model_name', None)
ret = munch.Munch(location=self._get_current_location())
for key in (
'binary',
'created_at',
'disabled_reason',
'host',
'id',
'report_count',
'state',
'updated_at'):
ret[key] = magnum_service.pop(key)
ret['properties'] = magnum_service
return ret

View File

@ -2251,5 +2251,5 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
:raises: OpenStackCloudException on operation error.
"""
with _utils.shade_exceptions("Error fetching Magnum services list"):
return self.manager.submit_task(
_tasks.MagnumServicesList())
return self._normalize_magnum_services(
self.manager.submit_task(_tasks.MagnumServicesList()))

View File

@ -10,30 +10,31 @@
# 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(
magnum_service_obj = dict(
binary='fake-service',
state='up',
report_count=1,
human_id=None,
created_at='2015-08-27T09:49:58-05:00',
disabled_reason=None,
host='fake-host',
human_id=None,
id=1,
disabled_reason=None
report_count=1,
state='up',
updated_at=None,
)
class TestMagnumServices(base.TestCase):
class TestMagnumServices(base.RequestsMockTestCase):
@mock.patch.object(shade.OpenStackCloud, 'magnum_client')
def test_list_magnum_services(self, mock_magnum):
mock_magnum.mservices.list.return_value = [magnum_service_obj, ]
def test_list_magnum_services(self):
self.register_uris([dict(
method='GET',
uri='https://container-infra.example.com/v1/mservices',
json=dict(mservices=[magnum_service_obj]))])
mservices_list = self.op_cloud.list_magnum_services()
mock_magnum.mservices.list.assert_called_with(detail=False)
self.assertEqual(mservices_list[0], magnum_service_obj)
self.assertEqual(
mservices_list[0],
self.cloud._normalize_magnum_service(magnum_service_obj))
self.assert_calls()