mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
f3e07723cd
(cherry picked from commit 6d960e9e10
)
Co-authored-by: Felix Fontein <felix@fontein.de>
69 lines
2.1 KiB
YAML
69 lines
2.1 KiB
YAML
####################################################################
|
|
# WARNING: These are designed specifically for Ansible tests #
|
|
# and should not be used as examples of how to write Ansible roles #
|
|
####################################################################
|
|
|
|
# Test code for the pids module
|
|
# Copyright: (c) 2019, Saranya Sridharan
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
- name: "Installing the psutil module"
|
|
pip:
|
|
name: psutil < 5.7.0
|
|
# Version 5.7.0 breaks on older pip versions. See https://github.com/ansible/ansible/pull/70667
|
|
|
|
- name: "Checking the empty result"
|
|
pids:
|
|
name: "blahblah"
|
|
register: emptypids
|
|
|
|
- name: "Verify that the list of Process IDs (PIDs) returned is empty"
|
|
assert:
|
|
that:
|
|
- emptypids is not changed
|
|
- emptypids.pids == []
|
|
|
|
- name: "Picking a random process name"
|
|
set_fact:
|
|
random_name: some-random-long-name-{{ 99999999 | random }}
|
|
|
|
- name: "finding the 'sleep' binary"
|
|
command: which sleep
|
|
register: find_sleep
|
|
|
|
- name: "Copying 'sleep' binary"
|
|
copy:
|
|
src: "{{ find_sleep.stdout }}"
|
|
dest: "{{ output_dir }}/{{ random_name }}"
|
|
mode: "0777"
|
|
|
|
- name: "Running the copy of 'sleep' binary"
|
|
command: "sh {{ role_path }}/files/obtainpid.sh '{{ output_dir }}/{{ random_name }}' '{{ output_dir }}/obtainpid.txt'"
|
|
|
|
async: 100
|
|
poll: 0
|
|
|
|
- name: "Wait for one second to make sure that the sleep copy has actually been started"
|
|
pause:
|
|
seconds: 1
|
|
|
|
- name: "Checking the process IDs (PIDs) of sleep binary"
|
|
pids:
|
|
name: "{{ random_name }}"
|
|
register: pids
|
|
|
|
- name: "Checking that exact non-substring matches are required"
|
|
pids:
|
|
name: "{{ random_name[0:5] }}"
|
|
register: exactpidmatch
|
|
|
|
- name: "Reading pid from the file"
|
|
slurp:
|
|
src: "{{ output_dir }}/obtainpid.txt"
|
|
register: newpid
|
|
|
|
- name: "Verify that the Process IDs (PIDs) returned is not empty and also equal to the PIDs obtained in console"
|
|
assert:
|
|
that:
|
|
- "pids.pids | join(' ') == newpid.content | b64decode | trim"
|
|
- "pids.pids | length > 0"
|
|
- "exactpidmatch.pids == []"
|