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>
This commit is contained in:
parent
e73a0b2460
commit
fb09fd2a23
4 changed files with 33 additions and 4 deletions
2
changelogs/fragments/72322-wait-for-handle-errors.yml
Normal file
2
changelogs/fragments/72322-wait-for-handle-errors.yml
Normal file
|
@ -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():
|
||||||
|
try:
|
||||||
if hasattr(p, 'get_connections'):
|
if hasattr(p, 'get_connections'):
|
||||||
connections = p.get_connections(kind='inet')
|
connections = p.get_connections(kind='inet')
|
||||||
else:
|
else:
|
||||||
connections = p.connections(kind='inet')
|
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
|
||||||
|
|
13
test/integration/targets/wait_for/files/zombie.py
Normal file
13
test/integration/targets/wait_for/files/zombie.py
Normal file
|
@ -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…
Reference in a new issue