Refactor structure of group module integration tests (#78652)

This to match the structure with the tests for the user module. When having the tests available as stand-alone tests, it will be easier to add more integration tests in the future.
pull/78172/head
Roy Lenferink 3 years ago committed by GitHub
parent 196084773b
commit a3531ac422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,23 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import grp
def main():
gids = [g.gr_gid for g in grp.getgrall()]
# Start the gid numbering with 1
# FreeBSD doesn't support the usage of gid 0, it doesn't fail (rc=0) but instead a number in the normal
# range is picked.
i = 1
while True:
if i not in gids:
print(i)
break
i += 1
if __name__ == '__main__':
main()

@ -0,0 +1,18 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import grp
import sys
def main():
group_name = None
if len(sys.argv) >= 2:
group_name = sys.argv[1]
print(grp.getgrnam(group_name).gr_gid)
if __name__ == '__main__':
main()

@ -1,15 +0,0 @@
#!/usr/bin/env python
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import grp
gids = [g.gr_gid for g in grp.getgrall()]
i = 0
while True:
if i not in gids:
print(i)
break
i += 1

@ -16,25 +16,4 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: ensure test groups are deleted before the test
group:
name: '{{ item }}'
state: absent
loop:
- ansibullgroup
- ansibullgroup2
- ansibullgroup3
- block:
- name: run tests
include_tasks: tests.yml
always:
- name: remove test groups after test
group:
name: '{{ item }}'
state: absent
loop:
- ansibullgroup
- ansibullgroup2
- ansibullgroup3
- import_tasks: tests.yml

@ -1,4 +1,14 @@
---
- name: ensure test groups are deleted before the test
group:
name: '{{ item }}'
state: absent
loop:
- ansibullgroup
- ansibullgroup2
- ansibullgroup3
- block:
##
## group add
##
@ -8,7 +18,7 @@
name: ansibullgroup
state: present
register: create_group_check
check_mode: True
check_mode: true
- name: get result of create group (check mode)
script: 'grouplist.sh "{{ ansible_distribution }}"'
@ -75,7 +85,7 @@
##
- name: get the next available gid
script: gidget.py
script: get_free_gid.py
args:
executable: '{{ ansible_python_interpreter }}'
register: gid
@ -86,7 +96,7 @@
gid: '{{ gid.stdout_lines[0] }}'
state: present
register: create_group_gid_check
check_mode: True
check_mode: true
- name: get result of create a group with a gid (check mode)
script: 'grouplist.sh "{{ ansible_distribution }}"'
@ -106,7 +116,9 @@
register: create_group_gid
- name: get gid of created group
command: "{{ ansible_python_interpreter | quote }} -c \"import grp; print(grp.getgrnam('ansibullgroup2').gr_gid)\""
script: "get_gid_for_group.py ansibullgroup2"
args:
executable: '{{ ansible_python_interpreter }}'
register: create_group_gid_actual
- name: assert create group with a gid
@ -162,10 +174,10 @@
name: ansibullgroup
state: absent
register: delete_group_check
check_mode: True
check_mode: true
- name: get result of delete group (check mode)
script: grouplist.sh "{{ ansible_distribution }}"
script: 'grouplist.sh "{{ ansible_distribution }}"'
register: delete_group_actual_check
- name: assert delete group (check mode)
@ -181,7 +193,7 @@
register: delete_group
- name: get result of delete group
script: grouplist.sh "{{ ansible_distribution }}"
script: 'grouplist.sh "{{ ansible_distribution }}"'
register: delete_group_actual
- name: assert delete group
@ -222,11 +234,11 @@
group:
name: "{{ item }}"
gid: 1337
local: yes
local: true
loop:
- group1_local_test
- group2_local_test
ignore_errors: yes
ignore_errors: true
register: local_duplicate_gid_result
- assert:
@ -247,12 +259,14 @@
group:
name: group1_local_test
gid: 1337
local: yes
local: true
state: present
register: create_local_group_gid
- name: get gid of created local group
command: "{{ ansible_python_interpreter | quote }} -c \"import grp; print(grp.getgrnam('group1_local_test').gr_gid)\""
script: "get_gid_for_group.py group1_local_test"
args:
executable: '{{ ansible_python_interpreter }}'
register: create_local_group_gid_actual
- name: assert create local group with a gid
@ -288,12 +302,14 @@
group:
name: group1_test
gid: 1337
local: no
local: false
state: present
register: create_group_gid
- name: get gid of created group
command: "{{ ansible_python_interpreter | quote }} -c \"import grp; print(grp.getgrnam('group1_test').gr_gid)\""
script: "get_gid_for_group.py group1_test"
args:
executable: '{{ ansible_python_interpreter }}'
register: create_group_gid_actual
- name: assert create group with a gid
@ -307,7 +323,7 @@
group:
name: group1_test
gid: 1337
local: yes
local: true
state: present
register: create_local_group_gid
@ -319,12 +335,12 @@
- name: Cleanup create group with a gid
group:
name: group1_test
local: no
local: false
state: absent
- name: Cleanup create local group with the same gid
group:
name: group1_test
local: yes
local: true
state: absent
# only applicable to Linux, limit further to CentOS where 'lgroupadd' is installed
when: ansible_distribution == 'CentOS'
@ -340,4 +356,14 @@
group:
name: ansibullgroup
state: present
system: yes
system: true
always:
- name: remove test groups after test
group:
name: '{{ item }}'
state: absent
loop:
- ansibullgroup
- ansibullgroup2
- ansibullgroup3

Loading…
Cancel
Save