1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pids: re-enabled tests on Alpine Linux (#4405)

* [WIP] pids: re-enabled tests on Alpine Linux

* trying to compile a simple-faked sleep command

* make FreeBSD happy

* remove the block testing for Alpine Linux

* simpler version of sleeper.c

* simpler version of sleeper.c, part II

* Update tests/integration/targets/pids/tasks/main.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/integration/targets/pids/tasks/main.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* added license to sleeper.c file

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2022-04-02 19:18:19 +13:00 committed by GitHub
parent 24ca69aa05
commit 21ee4c84b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 91 deletions

View file

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
"$1" 100 & "$1" 100 &
echo "$!" > "$2" echo "$!" > "$2"

View file

@ -0,0 +1,12 @@
/*
* (c) 2022, Alexei Znamensky <russoz@gmail.com>
* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
*/
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
int delay = atoi(argv[1]);
sleep(delay);
}

View file

@ -7,112 +7,105 @@
# Copyright: (c) 2019, Saranya Sridharan # Copyright: (c) 2019, Saranya Sridharan
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- when: - name: Attempt installation of latest 'psutil' version
- not (ansible_os_family == 'Alpine') # TODO pip:
block: name: psutil
ignore_errors: true
register: psutil_latest_install
- name: Attempt installation of latest 'psutil' version - name: Install greatest 'psutil' version which will work with all pip versions
pip: pip:
name: psutil name: psutil < 5.7.0
ignore_errors: true when: psutil_latest_install is failed
register: psutil_latest_install
- name: Install greatest 'psutil' version which will work with all pip versions - name: "Checking the empty result"
pip: pids:
name: psutil < 5.7.0 name: "blahblah"
when: psutil_latest_install is failed register: emptypids
- name: "Checking the empty result" - name: "Verify that the list of Process IDs (PIDs) returned is empty"
pids: assert:
name: "blahblah" that:
register: emptypids - emptypids is not changed
- emptypids.pids == []
- name: "Verify that the list of Process IDs (PIDs) returned is empty" - name: "Picking a random process name"
assert: set_fact:
that: random_name: some-random-long-name-{{ 99999999 | random }}
- emptypids is not changed
- emptypids.pids == []
- name: "Picking a random process name" - name: Copy the fake 'sleep' source code
set_fact: copy:
random_name: some-random-long-name-{{ 99999999 | random }} src: sleeper.c
dest: "{{ remote_tmp_dir }}/sleeper.c"
mode: 0644
- name: "finding the 'sleep' binary" - name: Compile fake 'sleep' binary
command: which sleep command: cc {{ remote_tmp_dir }}/sleeper.c -o {{ remote_tmp_dir }}/{{ random_name }}
register: find_sleep
- name: "Copying 'sleep' binary" - name: Copy helper script
command: cp {{ find_sleep.stdout }} {{ remote_tmp_dir }}/{{ random_name }} copy:
# The following does not work on macOS 11.1 (it uses shutil.copystat, and that will die with a PermissionError): src: obtainpid.sh
# copy: dest: "{{ remote_tmp_dir }}/obtainpid.sh"
# src: "{{ find_sleep.stdout }}" mode: 0755
# dest: "{{ remote_tmp_dir }}/{{ random_name }}"
# mode: "0777"
# remote_src: true
- name: Copy helper script - name: "Run the fake 'sleep' binary"
copy: command: "sh {{ remote_tmp_dir }}/obtainpid.sh '{{ remote_tmp_dir }}/{{ random_name }}' '{{ remote_tmp_dir }}/obtainpid.txt'"
src: obtainpid.sh
dest: "{{ remote_tmp_dir }}/obtainpid.sh"
- name: "Running the copy of 'sleep' binary" async: 100
command: "sh {{ remote_tmp_dir }}/obtainpid.sh '{{ remote_tmp_dir }}/{{ random_name }}' '{{ remote_tmp_dir }}/obtainpid.txt'" poll: 0
async: 100 - name: "Wait for one second to make sure that the fake 'sleep' binary has actually been started"
poll: 0 pause:
seconds: 1
- name: "Wait for one second to make sure that the sleep copy has actually been started" - name: "Checking the process IDs (PIDs) of fake 'sleep' binary"
pause: pids:
seconds: 1 name: "{{ random_name }}"
register: pids
- name: "Checking the process IDs (PIDs) of sleep binary" - name: "Checking that exact non-substring matches are required"
pids: pids:
name: "{{ random_name }}" name: "{{ random_name[0:5] }}"
register: pids register: exactpidmatch
- name: "Checking that exact non-substring matches are required" - name: "Checking that patterns can be used with the pattern option"
pids: pids:
name: "{{ random_name[0:5] }}" pattern: "{{ random_name[0:5] }}"
register: exactpidmatch register: pattern_pid_match
- name: "Checking that patterns can be used with the pattern option" - name: "Checking that case-insensitive patterns can be used with the pattern option"
pids: pids:
pattern: "{{ random_name[0:5] }}" pattern: "{{ random_name[0:5] | upper }}"
register: pattern_pid_match ignore_case: true
register: caseinsensitive_pattern_pid_match
- name: "Checking that case-insensitive patterns can be used with the pattern option" - name: "Checking that .* includes test pid"
pids: pids:
pattern: "{{ random_name[0:5] | upper }}" pattern: .*
ignore_case: true register: match_all
register: caseinsensitive_pattern_pid_match
- name: "Checking that .* includes test pid" - name: "Reading pid from the file"
pids: slurp:
pattern: .* src: "{{ remote_tmp_dir }}/obtainpid.txt"
register: match_all register: newpid
- name: "Reading pid from the file" - name: "Verify that the Process IDs (PIDs) returned is not empty and also equal to the PIDs obtained in console"
slurp: assert:
src: "{{ remote_tmp_dir }}/obtainpid.txt" that:
register: newpid - "pids.pids | join(' ') == newpid.content | b64decode | trim"
- "pids.pids | length > 0"
- "exactpidmatch.pids == []"
- "pattern_pid_match.pids | join(' ') == newpid.content | b64decode | trim"
- "caseinsensitive_pattern_pid_match.pids | join(' ') == newpid.content | b64decode | trim"
- newpid.content | b64decode | trim | int in match_all.pids
- name: "Verify that the Process IDs (PIDs) returned is not empty and also equal to the PIDs obtained in console" - name: "Register output of bad input pattern"
assert: pids:
that: pattern: (unterminated
- "pids.pids | join(' ') == newpid.content | b64decode | trim" register: bad_pattern_result
- "pids.pids | length > 0" ignore_errors: true
- "exactpidmatch.pids == []"
- "pattern_pid_match.pids | join(' ') == newpid.content | b64decode | trim"
- "caseinsensitive_pattern_pid_match.pids | join(' ') == newpid.content | b64decode | trim"
- newpid.content | b64decode | trim | int in match_all.pids
- name: "Register output of bad input pattern" - name: "Verify that bad input pattern result is failed"
pids: assert:
pattern: (unterminated that:
register: bad_pattern_result - bad_pattern_result is failed
ignore_errors: true
- name: "Verify that bad input pattern result is failed"
assert:
that:
- bad_pattern_result is failed