wait_for - ignore psutil related errors (#72401)

When enumerating connections with psutil, catch and ignore errors to avoid returning a stack trace.

Co-authored-by:  Matt Martz <matt@sivel.net>
pull/72408/head
Sam Doran 4 years ago committed by GitHub
parent e73a0b2460
commit fb09fd2a23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- wait_for - catch and ignore errors when getting active connections with psutil (https://github.com/ansible/ansible/issues/72322)

@ -289,10 +289,14 @@ class TCPConnectionInfo(object):
def get_active_connections_count(self): def get_active_connections_count(self):
active_connections = 0 active_connections = 0
for p in psutil.process_iter(): for p in psutil.process_iter():
if hasattr(p, 'get_connections'): try:
connections = p.get_connections(kind='inet') if hasattr(p, 'get_connections'):
else: connections = p.get_connections(kind='inet')
connections = p.connections(kind='inet') else:
connections = p.connections(kind='inet')
except psutil.Error:
# Process is Zombie or other error state
continue
for conn in connections: for conn in connections:
if conn.status not in self.module.params['active_connection_states']: if conn.status not in self.module.params['active_connection_states']:
continue continue

@ -0,0 +1,13 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os
import sys
import time
child_pid = os.fork()
if child_pid > 0:
time.sleep(60)
else:
sys.exit()

@ -153,6 +153,16 @@
name: psutil name: psutil
when: ansible_system != 'Linux' when: ansible_system != 'Linux'
- name: Copy zombie.py
copy:
src: zombie.py
dest: "{{ output_dir }}"
- name: Create zombie process
shell: "{{ ansible_python.executable }} {{ output_dir }}/zombie"
async: 90
poll: 0
- name: test wait for port drained - name: test wait for port drained
wait_for: wait_for:
port: "{{ http_port }}" port: "{{ http_port }}"

Loading…
Cancel
Save