Browse code

Fix wait_for with newer versions of psutil. (#26455)

* Add support for newer psutil versions.

(cherry picked from commit 895e6c5d063d02e1e55a860c9a083122aabdd4ac)

Matt Clay authored on 2017/07/06 11:00:13
Showing 1 changed files
... ...
@@ -232,14 +232,23 @@ class TCPConnectionInfo(object):
232 232
     def get_active_connections_count(self):
233 233
         active_connections = 0
234 234
         for p in psutil.process_iter():
235
-            connections = p.get_connections(kind='inet')
235
+            if hasattr(p, 'get_connections'):
236
+                connections = p.get_connections(kind='inet')
237
+            else:
238
+                connections = p.connections(kind='inet')
236 239
             for conn in connections:
237 240
                 if conn.status not in self.module.params['active_connection_states']:
238 241
                     continue
239
-                (local_ip, local_port) = conn.local_address
242
+                if hasattr(conn, 'local_address'):
243
+                    (local_ip, local_port) = conn.local_address
244
+                else:
245
+                    (local_ip, local_port) = conn.laddr
240 246
                 if self.port != local_port:
241 247
                     continue
242
-                (remote_ip, remote_port) = conn.remote_address
248
+                if hasattr(conn, 'remote_address'):
249
+                    (remote_ip, remote_port) = conn.remote_address
250
+                else:
251
+                    (remote_ip, remote_port) = conn.raddr
243 252
                 if (conn.family, remote_ip) in self.exclude_ips:
244 253
                     continue
245 254
                 if any((