mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix wait_for with newer versions of psutil. (#26455)
* Add support for newer psutil versions. * Fix psutil install in wait_for integration test. * Fix test requirements for wait_for elapsed.
This commit is contained in:
parent
2a041d10d2
commit
895e6c5d06
2 changed files with 23 additions and 16 deletions
|
@ -243,14 +243,23 @@ 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():
|
||||||
connections = p.get_connections(kind='inet')
|
if hasattr(p, 'get_connections'):
|
||||||
|
connections = p.get_connections(kind='inet')
|
||||||
|
else:
|
||||||
|
connections = p.connections(kind='inet')
|
||||||
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
|
||||||
(local_ip, local_port) = conn.local_address
|
if hasattr(conn, 'local_address'):
|
||||||
|
(local_ip, local_port) = conn.local_address
|
||||||
|
else:
|
||||||
|
(local_ip, local_port) = conn.laddr
|
||||||
if self.port != local_port:
|
if self.port != local_port:
|
||||||
continue
|
continue
|
||||||
(remote_ip, remote_port) = conn.remote_address
|
if hasattr(conn, 'remote_address'):
|
||||||
|
(remote_ip, remote_port) = conn.remote_address
|
||||||
|
else:
|
||||||
|
(remote_ip, remote_port) = conn.raddr
|
||||||
if (conn.family, remote_ip) in self.exclude_ips:
|
if (conn.family, remote_ip) in self.exclude_ips:
|
||||||
continue
|
continue
|
||||||
if any((
|
if any((
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
that:
|
that:
|
||||||
- waitfor|success
|
- waitfor|success
|
||||||
- "waitfor.path == '/tmp/wait_for_file'"
|
- "waitfor.path == '/tmp/wait_for_file'"
|
||||||
- waitfor.elapsed <= 10
|
- waitfor.elapsed >= 5
|
||||||
- waitfor.elapsed > 0
|
- waitfor.elapsed <= 15
|
||||||
|
|
||||||
- name: setup create a file after 10s
|
- name: setup create a file after 10s
|
||||||
shell: sleep 10 && touch /tmp/wait_for_file
|
shell: sleep 10 && touch /tmp/wait_for_file
|
||||||
|
@ -48,8 +48,8 @@
|
||||||
that:
|
that:
|
||||||
- waitfor|success
|
- waitfor|success
|
||||||
- "waitfor.path == '/tmp/wait_for_file'"
|
- "waitfor.path == '/tmp/wait_for_file'"
|
||||||
- waitfor.elapsed <= 10
|
- waitfor.elapsed >= 5
|
||||||
- waitfor.elapsed > 0
|
- waitfor.elapsed <= 15
|
||||||
|
|
||||||
- name: setup write keyword to file after 10s
|
- name: setup write keyword to file after 10s
|
||||||
shell: rm -f /tmp/wait_for_keyword && sleep 10 && echo completed > /tmp/wait_for_keyword
|
shell: rm -f /tmp/wait_for_keyword && sleep 10 && echo completed > /tmp/wait_for_keyword
|
||||||
|
@ -67,8 +67,8 @@
|
||||||
that:
|
that:
|
||||||
- waitfor|success
|
- waitfor|success
|
||||||
- "waitfor.search_regex == 'completed'"
|
- "waitfor.search_regex == 'completed'"
|
||||||
- waitfor.elapsed <= 10
|
- waitfor.elapsed >= 5
|
||||||
- waitfor.elapsed > 0
|
- waitfor.elapsed <= 15
|
||||||
|
|
||||||
- name: test wait for port timeout
|
- name: test wait for port timeout
|
||||||
wait_for:
|
wait_for:
|
||||||
|
@ -114,22 +114,20 @@
|
||||||
- not waitfor|changed
|
- not waitfor|changed
|
||||||
- "waitfor.port == {{ http_port }}"
|
- "waitfor.port == {{ http_port }}"
|
||||||
|
|
||||||
# TODO: fix drain test for freebsd and macOS, ubuntu-py3
|
- name: install psutil using pip (non-Linux only)
|
||||||
- name: setup install psutil
|
pip:
|
||||||
package:
|
name: psutil
|
||||||
name: python-psutil
|
when: ansible_system != 'Linux'
|
||||||
when: ansible_system == "Linux" and not (ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04")
|
|
||||||
|
|
||||||
- name: test wait for port drained
|
- name: test wait for port drained
|
||||||
wait_for:
|
wait_for:
|
||||||
port: "{{ http_port }}"
|
port: "{{ http_port }}"
|
||||||
state: drained
|
state: drained
|
||||||
register: waitfor
|
register: waitfor
|
||||||
when: ansible_system == "Linux" and not (ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04")
|
|
||||||
- name: verify test wait for port
|
- name: verify test wait for port
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- waitfor|success
|
- waitfor|success
|
||||||
- not waitfor|changed
|
- not waitfor|changed
|
||||||
- "waitfor.port == {{ http_port }}"
|
- "waitfor.port == {{ http_port }}"
|
||||||
when: ansible_system == "Linux" and not (ansible_distribution == "Ubuntu" and ansible_distribution_version == "16.04")
|
|
||||||
|
|
Loading…
Reference in a new issue