Use keystoneclient's TCPKeepAliveAdapter

When novaclient isn't using a session from keystoneclient, it needs to
set reasonable TCP Keep-Alive values otherwise the operating system
defaults may cause the client to hang for hours before a connection will
time out. Using keystoneclient's adpater (which sets good defaults) will
allow us to not have to maintain this adapter here and to benefit from
their defaults.

Closes-bug: 1477275
Related-bug: 1323862
Depends-On: Ibd53ae2d4d2455db0ebc9951e5c764befc57850f
Change-Id: I1924bd96eb1a4bac5d57a5cc5d5461acb3f7f5ac
This commit is contained in:
Ian Cordasco 2015-07-22 15:13:01 -05:00
parent 9efeb79660
commit c69c38c58f
2 changed files with 3 additions and 33 deletions
novaclient

@ -30,14 +30,13 @@ import logging
import os
import pkgutil
import re
import socket
from keystoneclient import adapter
from keystoneclient import session
from oslo_utils import importutils
from oslo_utils import netutils
import pkg_resources
import requests
from requests import adapters
try:
import json
@ -54,16 +53,6 @@ from novaclient import service_catalog
from novaclient import utils
class TCPKeepAliveAdapter(adapters.HTTPAdapter):
"""The custom adapter used to set TCP Keep-Alive on all connections."""
def init_poolmanager(self, *args, **kwargs):
kwargs.setdefault('socket_options', [
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
])
super(TCPKeepAliveAdapter, self).init_poolmanager(*args, **kwargs)
class _ClientConnectionPool(object):
def __init__(self):
@ -74,7 +63,7 @@ class _ClientConnectionPool(object):
Store and reuse HTTP adapters per Service URL.
"""
if url not in self._adapters:
self._adapters[url] = TCPKeepAliveAdapter()
self._adapters[url] = session.TCPKeepAliveAdapter()
return self._adapters[url]

@ -16,7 +16,6 @@
import json
import logging
import socket
import fixtures
from keystoneclient import adapter
@ -29,27 +28,9 @@ from novaclient.tests.unit import utils
import novaclient.v2.client
class TCPKeepAliveAdapterTest(utils.TestCase):
@mock.patch.object(requests.adapters.HTTPAdapter, 'init_poolmanager')
def test_init_poolmanager(self, mock_init_poolmgr):
adapter = novaclient.client.TCPKeepAliveAdapter()
kwargs = {}
adapter.init_poolmanager(**kwargs)
if requests.__version__ >= '2.4.1':
kwargs.setdefault('socket_options', [
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
])
# NOTE(melwitt): This is called twice because
# HTTPAdapter.__init__ calls it first.
self.assertEqual(2, mock_init_poolmgr.call_count)
mock_init_poolmgr.assert_called_with(**kwargs)
class ClientConnectionPoolTest(utils.TestCase):
@mock.patch("novaclient.client.TCPKeepAliveAdapter")
@mock.patch("keystoneclient.session.TCPKeepAliveAdapter")
def test_get(self, mock_http_adapter):
mock_http_adapter.side_effect = lambda: mock.Mock()
pool = novaclient.client._ClientConnectionPool()