Skip to content
Snippets Groups Projects
Commit 907650c7 authored by Thomas Woerner's avatar Thomas Woerner
Browse files

tests/user/test_users_present_*: Use new generate_test_data.yml

The new generate_test_data.yml is creating the test data with
ansible.builtin.shell and is not calling shell scripts any more. The
generation in the yml file and also the set_fact calls make sure that
the test data is used.
parent 220c4f00
No related branches found
No related tags found
No related merge requests found
---
- name: Create users.json
hosts: localhost
tasks:
- name: Check if users.json exists
ansible.builtin.stat:
path: users.json
register: register_stat_users
- name: Create users.json
ansible.builtin.command: /bin/bash users.sh 500
when: not register_stat_users.stat.exists
# Generate lists for users
---
- name: Create present services.json data
ansible.builtin.shell: |
date=$(date --date='+2 years' "+%Y-%m-%d %H:%M:%S")
echo "["
for i in $(seq -w 1 "{{ NUM }}"); do
echo " {"
echo " \"name\": \"testuser_${i}\","
echo " \"first\": \"First ${i}\","
echo " \"last\": \"Last ${i}\","
echo " \"password\": \"user${i}PW\","
echo " \"passwordexpiration\": \"${date}\""
if [ "$i" -lt "{{ NUM }}" ]; then
echo " },"
else
echo " }"
fi
done
echo "]"
vars:
NUM: 500
register: command
- name: Set user_list
ansible.builtin.set_fact:
user_list: "{{ command.stdout | from_json }}"
- name: Create absent user.json data
ansible.builtin.shell: |
echo "["
for i in $(seq -w 1 "{{ NUM }}"); do
echo " {"
echo " \"name\": \"testuser_${i}\""
if [ "$i" -lt "{{ NUM }}" ]; then
echo " },"
else
echo " }"
fi
done
echo "]"
vars:
NUM: 500
register: command
- name: Set user_absent_list
ansible.builtin.set_fact:
user_absent_list: "{{ command.stdout | from_json }}"
---
- name: Include create_users_json.yml
ansible.builtin.import_playbook: create_users_json.yml
- name: Test users present and absent
hosts: ipaserver
become: true
gather_facts: false
tasks:
- name: Include users.json
ansible.builtin.include_vars:
file: users.json # noqa missing-import
- name: Include generate_test_data.yml
ansible.builtin.include_tasks: generate_test_data.yml
- name: Size of user_list
ansible.builtin.debug:
msg: "{{ user_list | length }}"
- name: Create dict with user names
ansible.builtin.set_fact:
user_names: "{{ user_names | default([]) + [{'name': item.name}] }}"
loop: "{{ users }}"
- name: Size of user_absent_list
ansible.builtin.debug:
msg: "{{ user_absent_list | length }}"
- name: Cleanup test users len:{{ users | length }}
- name: Cleanup test users
ipauser:
ipaadmin_password: SomeADMINpassword
users: "{{ user_names }}"
users: "{{ user_absent_list }}"
state: absent
- name: Users present len:{{ users | length }}
- name: Users present
ipauser:
ipaadmin_password: SomeADMINpassword
users: "{{ users }}"
users: "{{ user_list }}"
register: result
failed_when: not result.changed or result.failed
- name: Users absent len:{{ users | length }}
- name: Users absent
ipauser:
ipaadmin_password: SomeADMINpassword
users: "{{ user_names }}"
users: "{{ user_absent_list }}"
state: absent
register: result
failed_when: not result.changed or result.failed
---
- name: Include create_users_json.yml
ansible.builtin.import_playbook: create_users_json.yml
- name: Test users present and absent with slice
hosts: ipaserver
become: true
......@@ -10,39 +7,37 @@
vars:
slice_size: 100
tasks:
- name: Include users.json
ansible.builtin.include_vars:
file: users.json # noqa missing-import
- name: Include generate_test_data.yml
ansible.builtin.include_tasks: generate_test_data.yml
- name: Create dict with user names
ansible.builtin.set_fact:
user_names: "{{ user_names | default([]) + [{'name': item.name}] }}"
loop: "{{ users }}"
- name: Size of user_list
ansible.builtin.debug:
msg: "{{ user_list | length }}"
- name: Size of users slice.
- name: Size of user_absent_list
ansible.builtin.debug:
msg: "{{ users | length }}"
msg: "{{ user_absent_list | length }}"
- name: Cleanup test users
ipauser:
ipaadmin_password: SomeADMINpassword
users: "{{ user_names[item : item + slice_size] }}"
users: "{{ user_absent_list[item : item + slice_size] }}"
state: absent
loop: "{{ range(0, user_names | length, slice_size) | list }}"
loop: "{{ range(0, user_absent_list | length, slice_size) | list }}"
- name: Users present
ipauser:
ipaadmin_password: SomeADMINpassword
users: "{{ users[item : item + slice_size] }}"
loop: "{{ range(0, users | length, slice_size) | list }}"
users: "{{ user_list[item : item + slice_size] }}"
loop: "{{ range(0, user_list | length, slice_size) | list }}"
register: result
failed_when: not result.changed or result.failed
- name: Users absent
ipauser:
ipaadmin_password: SomeADMINpassword
users: "{{ user_names[item : item + slice_size] }}"
users: "{{ user_absent_list[item : item + slice_size] }}"
state: absent
loop: "{{ range(0, user_names | length, slice_size) | list }}"
loop: "{{ range(0, user_absent_list | length, slice_size) | list }}"
register: result
failed_when: not result.changed or result.failed
#!/bin/bash -eu
NUM=${1-1000}
FILE="users.json"
date=$(date --date='+2 years' "+%Y-%m-%d %H:%M:%S")
echo "{" > "$FILE"
echo " \"users\": [" >> "$FILE"
for i in $(seq 1 "$NUM"); do
{
echo " {"
echo " \"name\": \"user$i\","
echo " \"first\": \"First $i\","
echo " \"last\": \"Last $i\","
echo " \"password\": \"user${i}PW\","
echo " \"passwordexpiration\": \"$date\""
} >> "$FILE"
if [ "$i" -lt "$NUM" ]; then
echo " }," >> "$FILE"
else
echo " }" >> "$FILE"
fi
done
echo " ]" >> "$FILE"
echo "}" >> "$FILE"
#!/bin/bash -eu
NUM=1000
FILE="users_absent.json"
echo "{" > "$FILE"
echo " \"users\": [" >> "$FILE"
for i in $(seq 1 "$NUM"); do
echo " {" >> "$FILE"
echo " \"name\": \"user$i\"," >> "$FILE"
if [ "$i" -lt "$NUM" ]; then
echo " }," >> "$FILE"
else
echo " }" >> "$FILE"
fi
done
echo " ]" >> "$FILE"
echo "}" >> "$FILE"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment