Skip to content

Commit

Permalink
Merge pull request freeipa#1281 from t-woerner/multi_user_test_genera…
Browse files Browse the repository at this point in the history
…te_test_data

tests/user/test_users_present_*: Use new generate_test_data.yml
  • Loading branch information
rjeffman authored Nov 4, 2024
2 parents 3d5ff1f + 907650c commit 08a2ba1
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 98 deletions.
13 changes: 0 additions & 13 deletions tests/user/create_users_json.yml

This file was deleted.

48 changes: 48 additions & 0 deletions tests/user/generate_test_data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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 }}"
31 changes: 15 additions & 16 deletions tests/user/test_users_present_absent.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
---
- 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
31 changes: 13 additions & 18 deletions tests/user/test_users_present_absent_slice.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
---
- 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
Expand All @@ -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
29 changes: 0 additions & 29 deletions tests/user/users.sh

This file was deleted.

22 changes: 0 additions & 22 deletions tests/user/users_absent.sh

This file was deleted.

0 comments on commit 08a2ba1

Please sign in to comment.