Merge "Set TCP keepalive options"

This commit is contained in:
Jenkins 2016-03-11 18:43:44 +00:00 committed by Gerrit Code Review
commit 334a0c09b0
2 changed files with 37 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import ddt
import eventlet
import mock
from oslo_config import cfg
from oslo_utils import netutils
import six
from six.moves import urllib
import testtools
@ -115,6 +116,32 @@ class TestWSGIServer(test.TestCase):
server.stop()
server.wait()
def test_start_with_default_tcp_options(self):
server = manila.wsgi.Server("test_tcp_options",
None,
host="127.0.0.1")
self.mock_object(
netutils, 'set_tcp_keepalive')
server.start()
netutils.set_tcp_keepalive.assert_called_once_with(
mock.ANY, tcp_keepalive=True, tcp_keepalive_count=None,
tcp_keepalive_interval=None, tcp_keepidle=600)
def test_start_with_custom_tcp_options(self):
CONF.set_default("tcp_keepalive", False)
CONF.set_default("tcp_keepalive_count", 33)
CONF.set_default("tcp_keepalive_interval", 22)
CONF.set_default("tcp_keepidle", 11)
server = manila.wsgi.Server("test_tcp_options",
None,
host="127.0.0.1")
self.mock_object(
netutils, 'set_tcp_keepalive')
server.start()
netutils.set_tcp_keepalive.assert_called_once_with(
mock.ANY, tcp_keepalive=False, tcp_keepalive_count=33,
tcp_keepalive_interval=22, tcp_keepidle=11)
def test_app(self):
self.mock_object(
eventlet, 'spawn', mock.Mock(side_effect=eventlet.spawn))

View File

@ -33,6 +33,7 @@ from oslo_config import cfg
from oslo_log import log
from oslo_service import service
from oslo_utils import excutils
from oslo_utils import netutils
from paste import deploy
import routes.middleware
import webob.dec
@ -201,6 +202,15 @@ class Server(service.ServiceBase):
config.set_middleware_defaults()
dup_socket = self._socket.dup()
netutils.set_tcp_keepalive(
dup_socket,
tcp_keepalive=CONF.tcp_keepalive,
tcp_keepidle=CONF.tcp_keepidle,
tcp_keepalive_interval=CONF.tcp_keepalive_interval,
tcp_keepalive_count=CONF.tcp_keepalive_count
)
if self._use_ssl:
try:
ssl_kwargs = {
@ -220,10 +230,6 @@ class Server(service.ServiceBase):
dup_socket.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, 1)
# sockets can hang around forever without keepalive
dup_socket.setsockopt(socket.SOL_SOCKET,
socket.SO_KEEPALIVE, 1)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(