From 545b5aae28c9ab513f543ced35fa41c16dd6f732 Mon Sep 17 00:00:00 2001 From: Toure Dunnon Date: Thu, 28 Jun 2018 11:51:03 -0400 Subject: [PATCH] python-shade expose MTU setting. The networking API v2 specification, which is implemented by openstack neutron, features an optional MTU parameter - when creating a network, this allows operators to specify the value for the maximum transmission unit value. Change-Id: I288f02551555fff3e8b350fc6d7c6ae8f60c405c --- .../notes/mtu-settings-8ce8b54d096580a2.yaml | 6 ++++ shade/openstackcloud.py | 20 +++++++++-- shade/tests/unit/test_network.py | 35 +++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/mtu-settings-8ce8b54d096580a2.yaml diff --git a/releasenotes/notes/mtu-settings-8ce8b54d096580a2.yaml b/releasenotes/notes/mtu-settings-8ce8b54d096580a2.yaml new file mode 100644 index 000000000..4de74d662 --- /dev/null +++ b/releasenotes/notes/mtu-settings-8ce8b54d096580a2.yaml @@ -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. diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 59fcd50cf..88e452e1d 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -3462,7 +3462,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. @@ -3476,6 +3477,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. @@ -3524,6 +3527,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}) @@ -11239,7 +11252,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. @@ -11260,7 +11273,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 @@ -11333,6 +11346,7 @@ class OpenStackCloud( :returns: Munch object with the usage """ + def parse_date(date): try: return iso8601.parse_date(date) diff --git a/shade/tests/unit/test_network.py b/shade/tests/unit/test_network.py index 31714be55..b59034764 100644 --- a/shade/tests/unit/test_network.py +++ b/shade/tests/unit/test_network.py @@ -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"