diff --git a/shade/_utils.py b/shade/_utils.py index b7604bad4..6500556fd 100644 --- a/shade/_utils.py +++ b/shade/_utils.py @@ -379,6 +379,7 @@ def normalize_stacks(stacks): def normalize_cluster_templates(cluster_templates): """Normalize Magnum cluster_templates.""" for cluster_template in cluster_templates: + cluster_template.pop('model_name', None) cluster_template['id'] = cluster_template['uuid'] return cluster_templates diff --git a/shade/tests/unit/fixtures/catalog-v3.json b/shade/tests/unit/fixtures/catalog-v3.json index 66df0f5c1..bb74465c0 100644 --- a/shade/tests/unit/fixtures/catalog-v3.json +++ b/shade/tests/unit/fixtures/catalog-v3.json @@ -84,6 +84,19 @@ "name": "neutron", "type": "network" }, + { + "endpoints": [ + { + "id": "4deb4d0504a044a395d4480741ba628e", + "interface": "public", + "region": "RegionOne", + "url": "https://container-infra.example.com/v1" + } + ], + "endpoints_links": [], + "name": "magnum", + "type": "container-infra" + }, { "endpoints": [ { diff --git a/shade/tests/unit/test_cluster_templates.py b/shade/tests/unit/test_cluster_templates.py index ff52556b5..0ab8cdd60 100644 --- a/shade/tests/unit/test_cluster_templates.py +++ b/shade/tests/unit/test_cluster_templates.py @@ -15,6 +15,7 @@ import mock import munch import shade +from shade import _utils import testtools from shade.tests.unit import base @@ -63,28 +64,31 @@ cluster_template_detail_obj = munch.Munch( ) -class TestClusterTemplates(base.TestCase): +class TestClusterTemplates(base.RequestsMockTestCase): - def setUp(self): - super(TestClusterTemplates, self).setUp() - self.cloud = shade.openstack_cloud(validate=False) + def test_list_cluster_templates_without_detail(self): - @mock.patch.object(shade.OpenStackCloud, 'magnum_client') - def test_list_cluster_templates_without_detail(self, mock_magnum): - mock_magnum.baymodels.list.return_value = [ - cluster_template_obj] + self.register_uris([dict( + method='GET', + uri='https://container-infra.example.com/v1/baymodels', + json=dict(baymodels=[cluster_template_obj.toDict()]))]) cluster_templates_list = self.cloud.list_cluster_templates() - mock_magnum.baymodels.list.assert_called_with(detail=False) - self.assertEqual(cluster_templates_list[0], cluster_template_obj) - - @mock.patch.object(shade.OpenStackCloud, 'magnum_client') - def test_list_cluster_templates_with_detail(self, mock_magnum): - mock_magnum.baymodels.list.return_value = [ - cluster_template_detail_obj] - cluster_templates_list = self.cloud.list_cluster_templates(detail=True) - mock_magnum.baymodels.list.assert_called_with(detail=True) self.assertEqual( - cluster_templates_list[0], cluster_template_detail_obj) + cluster_templates_list[0], + _utils.normalize_cluster_templates([cluster_template_obj])[0]) + self.assert_calls() + + def test_list_cluster_templates_with_detail(self): + self.register_uris([dict( + method='GET', + uri='https://container-infra.example.com/v1/baymodels/detail', + json=dict(baymodels=[cluster_template_detail_obj.toDict()]))]) + cluster_templates_list = self.cloud.list_cluster_templates(detail=True) + self.assertEqual( + cluster_templates_list[0], + _utils.normalize_cluster_templates( + [cluster_template_detail_obj])[0]) + self.assert_calls() @mock.patch.object(shade.OpenStackCloud, 'magnum_client') def test_search_cluster_templates_by_name(self, mock_magnum):