mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-26 21:33:05 +00:00
tests/user/test_users*.yml: Use extended dynamic users.json
test_users_absent.yml was using users_absent.json. It has been adapted to use users.json instead with an additional json_query to get only the names from users_present.json. create_users_json.yml has been added to create users.json if it is missing containing 500 users. It is included by test_users_present.yml and test_users_absent.yml. users_present.sh has been renamed to users.sh and modified to create by default users.json with 1000 users and additional with password and passwordexpiration in two years. jmespath has been added to pip install list in tests/azure/templates/playbook_tests.yml to emable the use of json_query. The requirement for jmespath has been added to tests/README.md.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## Before starting
|
||||
|
||||
In order to run ansible-freeipa tests you will need to have `ansible` and `pytest` installed on your machine. We'll call this local machine `controller`.
|
||||
In order to run ansible-freeipa tests you will need to have `ansible`, `pytest` and `jmespath` installed on your machine. We'll call this local machine `controller`. `jmespath` is needed for the `json_query` filter.
|
||||
|
||||
You will also need to have a remote host with freeipa server installed and configured. We'll call this remote host `ipaserver`.
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ jobs:
|
||||
pip install \
|
||||
"molecule[docker]>=3" \
|
||||
"ansible${{ parameters.ansible_version }}" \
|
||||
jmespath \
|
||||
pytest \
|
||||
pytest-split-tests
|
||||
displayName: Install dependencies
|
||||
|
||||
13
tests/user/create_users_json.yml
Normal file
13
tests/user/create_users_json.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: Create users.json
|
||||
hosts: localhost
|
||||
|
||||
tasks:
|
||||
- name: Check if users.json exists
|
||||
stat:
|
||||
path: users.json
|
||||
register: register_stat_users
|
||||
|
||||
- name: Create users.json
|
||||
command: /bin/bash users.sh 500
|
||||
when: not register_stat_users.stat.exists
|
||||
@@ -1,16 +1,19 @@
|
||||
---
|
||||
- name: Include create_users_json.yml
|
||||
import_playbook: create_users_json.yml
|
||||
|
||||
- name: Test users absent
|
||||
hosts: ipaserver
|
||||
become: true
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Include users_absent.json
|
||||
- name: Include users.json
|
||||
include_vars:
|
||||
file: users_absent.json
|
||||
file: users.json
|
||||
|
||||
- name: Users absent
|
||||
- name: Users absent len:{{ users | length }}
|
||||
ipauser:
|
||||
ipaadmin_password: SomeADMINpassword
|
||||
users: "{{ users }}"
|
||||
users: "{{ users | json_query('[*].{name: name}') }}"
|
||||
state: absent
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
---
|
||||
- name: Include create_users_json.yml
|
||||
import_playbook: create_users_json.yml
|
||||
|
||||
- name: Test users present
|
||||
hosts: ipaserver
|
||||
become: true
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Include users_present.json
|
||||
- name: Include users.json
|
||||
include_vars:
|
||||
file: users_present.json
|
||||
file: users.json
|
||||
|
||||
- name: Users present
|
||||
- name: Users present len:{{ users | length }}
|
||||
ipauser:
|
||||
ipaadmin_password: SomeADMINpassword
|
||||
users: "{{ users }}"
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
vars:
|
||||
slice_size: 500
|
||||
tasks:
|
||||
- name: Include users_present.json
|
||||
- name: Include users.json
|
||||
include_vars:
|
||||
file: users_present.json
|
||||
file: users.json
|
||||
- debug:
|
||||
msg: "{{ users | length }}"
|
||||
- name: Users present
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
NUM=1000
|
||||
FILE="users_present.json"
|
||||
NUM=${1-1000}
|
||||
FILE="users.json"
|
||||
date=$(date --date='+2 years' "+%Y-%m-%d %H:%M:%S")
|
||||
|
||||
echo "{" > $FILE
|
||||
|
||||
@@ -11,7 +12,9 @@ for i in $(seq 1 $NUM); do
|
||||
echo " {" >> $FILE
|
||||
echo " \"name\": \"user$i\"," >> $FILE
|
||||
echo " \"first\": \"First $i\"," >> $FILE
|
||||
echo " \"last\": \"Last $i\"" >> $FILE
|
||||
echo " \"last\": \"Last $i\"," >> $FILE
|
||||
echo " \"password\": \"user${i}PW\"," >> $FILE
|
||||
echo " \"passwordexpiration\": \"$date\"" >> $FILE
|
||||
if [ $i -lt $NUM ]; then
|
||||
echo " }," >> $FILE
|
||||
else
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user