]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move network MTU from core REST API to extension API
authorTim Swanson <tiswanso@cisco.com>
Tue, 31 Mar 2015 16:13:16 +0000 (12:13 -0400)
committerTim Swanson <tiswanso@cisco.com>
Thu, 2 Apr 2015 16:48:56 +0000 (12:48 -0400)
The network MTU was added to the core REST API via
https://review.openstack.org/#/c/154921.  This commit
reverts that change and adds the network MTU to the
extension API.

Change-Id: I7a7d679f471ced3230f230684d5ae9789bcca305
Closes-bug: 1434671

neutron/api/v2/attributes.py
neutron/db/netmtu_db.py [new file with mode: 0644]
neutron/extensions/netmtu.py [new file with mode: 0644]
neutron/plugins/ml2/plugin.py
neutron/tests/unit/test_db_plugin.py
neutron/tests/unit/test_extension_netmtu.py [new file with mode: 0644]

index d94a0a9723be3ff7321d6798e69328c0d0428e2e..c85f4afca9007c4870a2d5f192c5bbf98126b668 100644 (file)
@@ -703,8 +703,6 @@ RESOURCE_ATTRIBUTE_MAP = {
                            'is_visible': True},
         'status': {'allow_post': False, 'allow_put': False,
                    'is_visible': True},
-        'mtu': {'allow_post': False, 'allow_put': False,
-                'is_visible': True},
         'tenant_id': {'allow_post': True, 'allow_put': False,
                       'validate': {'type:string': TENANT_ID_MAX_LEN},
                       'required_by_policy': True,
diff --git a/neutron/db/netmtu_db.py b/neutron/db/netmtu_db.py
new file mode 100644 (file)
index 0000000..7d6acf7
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright (c) 2015 OpenStack Foundation.
+# All Rights Reserved.
+#
+#    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.
+
+from neutron.api.v2 import attributes
+from neutron.db import db_base_plugin_v2
+from neutron.extensions import netmtu
+
+
+class Netmtu_db_mixin(object):
+    """Mixin class to add network MTU methods to db_base_plugin_v2."""
+
+    def _extend_network_dict_mtu(self, network_res, network_db):
+        network_res[netmtu.MTU] = network_db.mtu
+        return network_res
+
+    db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
+        attributes.NETWORKS, ['_extend_network_dict_mtu'])
diff --git a/neutron/extensions/netmtu.py b/neutron/extensions/netmtu.py
new file mode 100644 (file)
index 0000000..55245fd
--- /dev/null
@@ -0,0 +1,54 @@
+# Copyright 2015 Openstack Foundation.
+#
+#    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.
+
+from neutron.api import extensions
+
+
+MTU = 'mtu'
+EXTENDED_ATTRIBUTES_2_0 = {
+    'networks': {
+        MTU: {'allow_post': False, 'allow_put': False,
+              'is_visible': True},
+    },
+}
+
+
+class Netmtu(extensions.ExtensionDescriptor):
+    """Extension class supporting network MTU."""
+
+    @classmethod
+    def get_name(cls):
+        return "Network MTU"
+
+    @classmethod
+    def get_alias(cls):
+        return "net-mtu"
+
+    @classmethod
+    def get_description(cls):
+        return "Provides MTU attribute for a network resource."
+
+    @classmethod
+    def get_namespace(cls):
+        return "http://docs.openstack.org/ext/net_mtu/api/v1.0"
+
+    @classmethod
+    def get_updated(cls):
+        return "2015-03-25T10:00:00-00:00"
+
+    def get_extended_resources(self, version):
+        if version == "2.0":
+            return EXTENDED_ATTRIBUTES_2_0
+        else:
+            return {}
index 01089ca8f9ad481187528e4adf1cbdfb1a3a2afd..7866103ef58e9eb7c8b69602cd7dc3899616802f 100644 (file)
@@ -53,6 +53,7 @@ from neutron.db import dvr_mac_db
 from neutron.db import external_net_db
 from neutron.db import extradhcpopt_db
 from neutron.db import models_v2
+from neutron.db import netmtu_db
 from neutron.db import quota_db  # noqa
 from neutron.db import securitygroups_rpc_base as sg_db_rpc
 from neutron.extensions import allowedaddresspairs as addr_pair
@@ -89,7 +90,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
                 sg_db_rpc.SecurityGroupServerRpcMixin,
                 agentschedulers_db.DhcpAgentSchedulerDbMixin,
                 addr_pair_db.AllowedAddressPairsMixin,
-                extradhcpopt_db.ExtraDhcpOptMixin):
+                extradhcpopt_db.ExtraDhcpOptMixin,
+                netmtu_db.Netmtu_db_mixin):
 
     """Implement the Neutron L2 abstractions using modules.
 
@@ -112,7 +114,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
                                     "quotas", "security-group", "agent",
                                     "dhcp_agent_scheduler",
                                     "multi-provider", "allowed-address-pairs",
-                                    "extra_dhcp_opt", "subnet_allocation"]
+                                    "extra_dhcp_opt", "subnet_allocation",
+                                    "net-mtu"]
 
     @property
     def supported_extension_aliases(self):
index 4b87ef4527e9fcf813efcffc0ca1368712114279..87619a50afbc12f12d11a9a3e1f9db70d5fa1d01 100644 (file)
@@ -2223,12 +2223,6 @@ class TestNetworksV2(NeutronDbPluginV2TestCase):
         self.assertEqual(ctx_manager.exception.code,
                          webob.exc.HTTPForbidden.code)
 
-    def test_create_network_default_mtu(self):
-        name = 'net1'
-        with self.network(name=name) as net:
-            self.assertEqual(net['network']['mtu'],
-                             constants.DEFAULT_NETWORK_MTU)
-
     def test_create_network_vlan_transparent(self):
         name = "vlan_transparent"
         cfg.CONF.set_override('vlan_transparent', True)
diff --git a/neutron/tests/unit/test_extension_netmtu.py b/neutron/tests/unit/test_extension_netmtu.py
new file mode 100644 (file)
index 0000000..ca57d7a
--- /dev/null
@@ -0,0 +1,74 @@
+# Copyright 2015 Openstack Foundation.
+#
+#    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.
+
+from neutron.common import constants
+from neutron.db import db_base_plugin_v2
+from neutron.db import netmtu_db
+from neutron.extensions import netmtu
+from neutron.tests.unit import test_db_plugin
+
+
+class NetmtuExtensionManager(object):
+
+    def get_resources(self):
+        return []
+
+    def get_actions(self):
+        return []
+
+    def get_request_extensions(self):
+        return []
+
+    def get_extended_resources(self, version):
+        return netmtu.get_extended_resources(version)
+
+
+class NetmtuExtensionTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
+                                netmtu_db.Netmtu_db_mixin):
+    """Test plugin to mixin the network MTU extensions.
+    """
+
+    supported_extension_aliases = ["net-mtu"]
+
+
+class NetmtuExtensionTestCase(test_db_plugin.TestNetworksV2):
+    """Test API extension net-mtu attributes.
+    """
+
+    def setUp(self):
+        plugin = ('neutron.tests.unit.test_extension_netmtu.' +
+                  'NetmtuExtensionTestPlugin')
+        ext_mgr = NetmtuExtensionManager()
+        super(NetmtuExtensionTestCase, self).setUp(plugin=plugin,
+                                                   ext_mgr=ext_mgr)
+
+    def test_list_networks_with_fields_mtu(self):
+        with self.network(name='net1') as net1:
+            req = self.new_list_request('networks',
+                                        params='fields=name&fields=mtu')
+            res = self.deserialize(self.fmt, req.get_response(self.api))
+            self.assertEqual(1, len(res['networks']))
+            self.assertEqual(res['networks'][0]['name'],
+                             net1['network']['name'])
+            self.assertEqual(res['networks'][0].get('mtu'),
+                             constants.DEFAULT_NETWORK_MTU)
+
+    def test_show_network_mtu(self):
+        with self.network(name='net1') as net:
+            req = self.new_show_request('networks', net['network']['id'])
+            res = self.deserialize(self.fmt, req.get_response(self.api))
+            self.assertEqual(res['network']['name'],
+                             net['network']['name'])
+            self.assertEqual(res['network']['mtu'],
+                             constants.DEFAULT_NETWORK_MTU)