From c0132acb527b8751bc1cb96feab3b01c6037071d Mon Sep 17 00:00:00 2001 From: LIU Yulong Date: Sun, 17 Mar 2019 22:54:59 +0800 Subject: [PATCH] Explicitly set neutron service ports for fullstack Fullstack neutron-server seems do not accept any connection during the running period sometimes. This patch explicitly set listening port range for neutron-server API and ovs agent openflow. And make sure other client side connection port does not seize the server side listening. Change-Id: If2a7977a3ac795db0bc7f726c0b26c5de638ea47 --- neutron/tests/common/net_helpers.py | 12 ++++++++++++ neutron/tests/fullstack/resources/config.py | 21 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/neutron/tests/common/net_helpers.py b/neutron/tests/common/net_helpers.py index 5c383d98f1b..5a4c9110bb5 100644 --- a/neutron/tests/common/net_helpers.py +++ b/neutron/tests/common/net_helpers.py @@ -228,6 +228,18 @@ def get_free_namespace_port(protocol, namespace=None, start=1024, end=None): return get_unused_port(used_ports, start, end) +def set_local_port_range(start, end): + utils.execute( + ['sysctl', '-w', 'net.ipv4.ip_local_port_range=%d %d' % (start, end)], + run_as_root=True) + utils.execute(['sysctl', '-p'], run_as_root=True) + # verify + port_range = utils.execute( + ['sysctl', '-n', 'net.ipv4.ip_local_port_range'], run_as_root=True) + assert int(port_range.split()[0]) == start + assert int(port_range.split()[1]) == end + + def create_patch_ports(source, destination): """Hook up two OVS bridges. diff --git a/neutron/tests/fullstack/resources/config.py b/neutron/tests/fullstack/resources/config.py index 1118e9d359c..fbddb931c4d 100644 --- a/neutron/tests/fullstack/resources/config.py +++ b/neutron/tests/fullstack/resources/config.py @@ -25,12 +25,22 @@ from neutron.tests import base from neutron.tests.common import config_fixtures from neutron.tests.common.exclusive_resources import port from neutron.tests.common import helpers as c_helpers +from neutron.tests.common import net_helpers from neutron.tests.fullstack import base as fullstack_base PHYSICAL_NETWORK_NAME = "physnet1" MINIMUM_BANDWIDTH_INGRESS_KBPS = 1000 MINIMUM_BANDWIDTH_EGRESS_KBPS = 1000 +NEUTRON_SERVER_PORT_START = 10000 +NEUTRON_SERVER_PORT_END = 20000 + +OVS_OF_PORT_LISTEN_START = 20001 +OVS_OF_PORT_LISTEN_END = 30000 + +CLIENT_CONN_PORT_START = 30001 +CLIENT_CONN_PORT_END = 65000 + class ConfigFixture(config_fixtures.ConfigFileFixture): """A fixture that holds an actual Neutron configuration. @@ -101,10 +111,15 @@ class NeutronConfigFixture(ConfigFixture): self.config['DEFAULT']['router_scheduler_driver'] = ( env_desc.router_scheduler) + net_helpers.set_local_port_range(CLIENT_CONN_PORT_START, + CLIENT_CONN_PORT_END) + def _setUp(self): self.config['DEFAULT'].update({ 'bind_port': self.useFixture( - port.ExclusivePort(constants.PROTO_NAME_TCP)).port + port.ExclusivePort(constants.PROTO_NAME_TCP, + start=NEUTRON_SERVER_PORT_START, + end=NEUTRON_SERVER_PORT_END)).port }) super(NeutronConfigFixture, self)._setUp() @@ -213,7 +228,9 @@ class OVSConfigFixture(ConfigFixture): if self.config['ovs']['of_interface'] == 'native': self.config['ovs'].update({ 'of_listen_port': self.useFixture( - port.ExclusivePort(constants.PROTO_NAME_TCP)).port + port.ExclusivePort(constants.PROTO_NAME_TCP, + start=OVS_OF_PORT_LISTEN_START, + end=OVS_OF_PORT_LISTEN_END)).port }) super(OVSConfigFixture, self)._setUp()