Move network MTU from core REST API to extension API

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
This commit is contained in:
Tim Swanson 2015-03-31 12:13:16 -04:00
parent 0549c31b03
commit 692de8fa52
6 changed files with 162 additions and 10 deletions

View 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,

29
neutron/db/netmtu_db.py Normal file
View File

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

View File

@ -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 {}

View 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):

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

View File

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