diff --git a/quark/plugin_views.py b/quark/plugin_views.py index a7d9acb..383f4a6 100644 --- a/quark/plugin_views.py +++ b/quark/plugin_views.py @@ -35,6 +35,9 @@ quark_view_opts = [ default=True, help=_('Controls whether or not to calculate and display' 'allocation pools or not')), + cfg.BoolOpt('show_ipam_strategy', + default=False, + help=_('Controls whether or not to show ipam_strategy')), cfg.BoolOpt('show_subnet_ip_policy_id', default=True, help=_('Controls whether or not to show ip_policy_id for' @@ -54,9 +57,11 @@ def _make_network_dict(network, fields=None): "name": network.get("name"), "tenant_id": network.get("tenant_id"), "admin_state_up": None, - "ipam_strategy": network.get("ipam_strategy"), "status": "ACTIVE", "shared": shared_net} + if CONF.QUARK.show_ipam_strategy: + res['ipam_strategy'] = network.get("ipam_strategy") + if not shared_net: if fields and "all_subnets" in fields: res["subnets"] = [_make_subnet_dict(s) diff --git a/quark/tests/functional/plugin_modules/test_networks.py b/quark/tests/functional/plugin_modules/test_networks.py index e2c32c0..f6cc435 100644 --- a/quark/tests/functional/plugin_modules/test_networks.py +++ b/quark/tests/functional/plugin_modules/test_networks.py @@ -19,6 +19,7 @@ import mock import netaddr from neutron.common import exceptions from neutron.common import rpc +from oslo.config import cfg from quark.db import api as db_api import quark.ipam @@ -36,6 +37,29 @@ class QuarkNetworkFunctionalTest(BaseFunctionalTest): rpc.init(mock.MagicMock()) +class QuarkGetNetwork(QuarkNetworkFunctionalTest): + + def test_show_ipam_strategy(self): + plugin = quark.plugin.Plugin() + network = dict(name="public", tenant_id="fake", network_plugin="BASE") + network = dict(network=network) + original = cfg.CONF.QUARK.show_ipam_strategy + + cfg.CONF.set_override('show_ipam_strategy', True, "QUARK") + net = plugin.create_network(self.context, network) + self.assertTrue('ipam_strategy' in net) + net = plugin.get_network(self.context, net['id']) + self.assertTrue('ipam_strategy' in net) + + cfg.CONF.set_override('show_ipam_strategy', False, "QUARK") + net = plugin.create_network(self.context, network) + self.assertFalse('ipam_strategy' in net) + net = plugin.get_network(self.context, net['id']) + self.assertFalse('ipam_strategy' in net) + + cfg.CONF.set_override('show_ipam_strategy', original, "QUARK") + + class QuarkDeleteNetworKDeallocatedIPs(QuarkNetworkFunctionalTest): @contextlib.contextmanager def _stubs(self, network, subnet, dealloc=True): diff --git a/quark/tests/plugin_modules/test_networks.py b/quark/tests/plugin_modules/test_networks.py index 1a173d1..978954c 100644 --- a/quark/tests/plugin_modules/test_networks.py +++ b/quark/tests/plugin_modules/test_networks.py @@ -324,7 +324,7 @@ class TestQuarkCreateNetwork(test_quark_plugin.TestQuarkPlugin): with self._stubs(net=net) as net_create: net = self.plugin.create_network(self.context, dict(network=net)) self.assertTrue(net_create.called) - self.assertEqual(len(net.keys()), 8) + self.assertEqual(len(net.keys()), 7) self.assertIsNotNone(net["id"]) self.assertEqual(net["name"], "public") self.assertIsNone(net["admin_state_up"]) @@ -332,7 +332,6 @@ class TestQuarkCreateNetwork(test_quark_plugin.TestQuarkPlugin): self.assertEqual(net["subnets"], []) self.assertEqual(net["shared"], False) self.assertEqual(net["tenant_id"], 0) - self.assertEqual(net["ipam_strategy"], None) def test_create_network_with_subnets(self): subnet = dict(id=2, cidr="172.168.0.0/24", tenant_id=0) @@ -342,7 +341,7 @@ class TestQuarkCreateNetwork(test_quark_plugin.TestQuarkPlugin): net.update(dict(subnets=[dict(subnet=subnet)])) net = self.plugin.create_network(self.context, dict(network=net)) self.assertTrue(net_create.called) - self.assertEqual(len(net.keys()), 8) + self.assertEqual(len(net.keys()), 7) self.assertIsNotNone(net["id"]) self.assertEqual(net["name"], "public") self.assertIsNone(net["admin_state_up"]) @@ -350,7 +349,6 @@ class TestQuarkCreateNetwork(test_quark_plugin.TestQuarkPlugin): self.assertEqual(net["subnets"], [2]) self.assertEqual(net["shared"], False) self.assertEqual(net["tenant_id"], 0) - self.assertEqual(net["ipam_strategy"], None) def test_create_network_with_id(self): net = dict(id="abcdef", name="public", admin_state_up=True, @@ -381,9 +379,13 @@ class TestQuarkCreateNetwork(test_quark_plugin.TestQuarkPlugin): net = dict(id="abcdef", name="public", admin_state_up=True, tenant_id=0, ipam_strategy="BOTH") admin_context = self.context.elevated() + original = cfg.CONF.QUARK.show_ipam_strategy + + cfg.CONF.set_override('show_ipam_strategy', True, "QUARK") with self._stubs(net=net): res = self.plugin.create_network(admin_context, dict(network=net)) self.assertEqual(res["ipam_strategy"], net["ipam_strategy"]) + cfg.CONF.set_override('show_ipam_strategy', original, "QUARK") def test_create_network_with_bad_ipam_strategy_raises(self): net = dict(id="abcdef", name="public", admin_state_up=True,