Merge "python-shade expose MTU setting."

This commit is contained in:
Zuul 2018-07-30 18:17:45 +00:00 committed by Gerrit Code Review
commit b274873695
3 changed files with 58 additions and 3 deletions

View File

@ -0,0 +1,6 @@
---
features:
- |
create_network now exposes the mtu api option in accordance to network
v2 api. This allows the operator to adjust the given MTU value which
is needed in various complex network deployments.

View File

@ -3153,7 +3153,8 @@ class OpenStackCloud(
def create_network(self, name, shared=False, admin_state_up=True,
external=False, provider=None, project_id=None,
availability_zone_hints=None,
port_security_enabled=None):
port_security_enabled=None,
mtu_size=None):
"""Create a network.
:param string name: Name of the network being created.
@ -3167,6 +3168,8 @@ class OpenStackCloud(
will be created on (admin-only).
:param list availability_zone_hints: A list of availability zone hints.
:param bool port_security_enabled: Enable / Disable port security
:param int mtu_size: maximum transmission unit value to address
fragmentation. Minimum value is 68 for IPv4, and 1280 for IPv6.
:returns: The network object.
:raises: OpenStackCloudException on operation error.
@ -3215,6 +3218,16 @@ class OpenStackCloud(
"Parameter 'port_security_enabled' must be a bool")
network['port_security_enabled'] = port_security_enabled
if mtu_size:
if not isinstance(mtu_size, int):
raise exc.OpenStackCloudException(
"Parameter 'mtu_size' must be an integer.")
if not mtu_size >= 68:
raise exc.OpenStackCloudException(
"Parameter 'mtu_size' must be greater than 67.")
network['mtu'] = mtu_size
data = self._network_client.post("/networks.json",
json={'network': network})
@ -10977,7 +10990,7 @@ class OpenStackCloud(
json=dict(addProjectAccess=payload),
error_message="Unable to authorize {project} "
"to use volume type {name}".format(
name=name_or_id, project=project_id))
name=name_or_id, project=project_id))
def remove_volume_type_access(self, name_or_id, project_id):
"""Revoke access on a volume_type to a project.
@ -10998,7 +11011,7 @@ class OpenStackCloud(
json=dict(removeProjectAccess=payload),
error_message="Unable to revoke {project} "
"to use volume type {name}".format(
name=name_or_id, project=project_id))
name=name_or_id, project=project_id))
def set_compute_quotas(self, name_or_id, **kwargs):
""" Set a quota in a project
@ -11071,6 +11084,7 @@ class OpenStackCloud(
:returns: Munch object with the usage
"""
def parse_date(date):
try:
return iso8601.parse_date(date)

View File

@ -250,6 +250,41 @@ class TestNetwork(base.RequestsMockTestCase):
self.assertEqual(mock_new_network_rep, network)
self.assert_calls()
def test_create_network_with_mtu(self):
mtu_size = 1500
mock_new_network_rep = copy.copy(self.mock_new_network_rep)
mock_new_network_rep['mtu'] = mtu_size
self.register_uris([
dict(method='POST',
uri=self.get_mock_url(
'network', 'public', append=['v2.0', 'networks.json']),
json={'network': mock_new_network_rep},
validate=dict(
json={'network': {
'admin_state_up': True,
'name': 'netname',
'mtu': mtu_size}}))
])
network = self.cloud.create_network("netname",
mtu_size=mtu_size
)
self.assertEqual(mock_new_network_rep, network)
self.assert_calls()
def test_create_network_with_wrong_mtu_size(self):
with testtools.ExpectedException(
shade.OpenStackCloudException,
"Parameter 'mtu_size' must be greater than 67."
):
self.cloud.create_network("netname", mtu_size=42)
def test_create_network_with_wrong_mtu_type(self):
with testtools.ExpectedException(
shade.OpenStackCloudException,
"Parameter 'mtu_size' must be an integer."
):
self.cloud.create_network("netname", mtu_size="fourty_two")
def test_delete_network(self):
network_id = "test-net-id"
network_name = "network"