Browse Source

Merge "Disables TCP_KEEPCNT when using Windows Subsystem for Linux"

Jenkins 2 years ago
parent
commit
5f34cb14d4

+ 8
- 0
keystoneauth1/_utils.py View File

@@ -73,3 +73,11 @@ def before_utcnow(**timedelta_kwargs):
73 73
     now = datetime.datetime.utcnow()
74 74
     delta = datetime.timedelta(**timedelta_kwargs)
75 75
     return now - delta
76
+
77
+
78
+# Detect if running on the Windows Subsystem for Linux
79
+try:
80
+    with open('/proc/version', 'r') as f:
81
+        is_windows_linux_subsystem = 'microsoft' in f.read().lower()
82
+except IOError:
83
+    is_windows_linux_subsystem = False

+ 3
- 1
keystoneauth1/session.py View File

@@ -893,7 +893,9 @@ class TCPKeepAliveAdapter(requests.adapters.HTTPAdapter):
893 893
                     (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60)
894 894
                 ]
895 895
 
896
-            if hasattr(socket, 'TCP_KEEPCNT'):
896
+            # Windows subsystem for Linux does not support this feature
897
+            if (hasattr(socket, 'TCP_KEEPCNT') and
898
+                    not utils.is_windows_linux_subsystem):
897 899
                 socket_options += [
898 900
                     # Set the maximum number of keep-alive probes
899 901
                     (socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4),

+ 18
- 0
keystoneauth1/tests/unit/test_session.py View File

@@ -1060,6 +1060,7 @@ class TCPKeepAliveAdapterTest(utils.TestCase):
1060 1060
 
1061 1061
     def test_init_poolmanager_with_tcp_keepcnt(self):
1062 1062
         self.patch(client_session, 'REQUESTS_VERSION', (2, 4, 1))
1063
+        self.patch(client_session.utils, 'is_windows_linux_subsystem', False)
1063 1064
         socket = self.patch_socket_with_options(
1064 1065
             ['IPPROTO_TCP', 'TCP_NODELAY', 'SOL_SOCKET', 'SO_KEEPALIVE',
1065 1066
              'TCP_KEEPCNT'])
@@ -1075,6 +1076,23 @@ class TCPKeepAliveAdapterTest(utils.TestCase):
1075 1076
                 (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
1076 1077
                 (socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4)])
1077 1078
 
1079
+    def test_init_poolmanager_with_tcp_keepcnt_on_windows(self):
1080
+        self.patch(client_session, 'REQUESTS_VERSION', (2, 4, 1))
1081
+        self.patch(client_session.utils, 'is_windows_linux_subsystem', True)
1082
+        socket = self.patch_socket_with_options(
1083
+            ['IPPROTO_TCP', 'TCP_NODELAY', 'SOL_SOCKET', 'SO_KEEPALIVE',
1084
+             'TCP_KEEPCNT'])
1085
+        given_adapter = client_session.TCPKeepAliveAdapter()
1086
+
1087
+        # when pool manager is initialized
1088
+        given_adapter.init_poolmanager(1, 2, 3)
1089
+
1090
+        # then socket_options are given
1091
+        self.init_poolmanager.assert_called_once_with(
1092
+            1, 2, 3, socket_options=[
1093
+                (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
1094
+                (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)])
1095
+
1078 1096
     def test_init_poolmanager_with_tcp_keepintvl(self):
1079 1097
         self.patch(client_session, 'REQUESTS_VERSION', (2, 4, 1))
1080 1098
         socket = self.patch_socket_with_options(

+ 9
- 0
releasenotes/notes/bug-1614688-c4a1bd54f4ba5644.yaml View File

@@ -0,0 +1,9 @@
1
+---
2
+prelude: >
3
+    HTTP connections work under Windows Subsystem for Linux
4
+fixes:
5
+  - >
6
+    [`bug 1614688 <https://bugs.launchpad.net/keystoneauth/+bug/1614688>`_]
7
+    HTTP connections were failing under Windows subsystem for Linux because
8
+    TCP_KEEPCNT was being set and that environment does not support such
9
+    override yet.

Loading…
Cancel
Save