mongodb_parameter module integration tests (#61644)
* Add final commits * End of day check in * Initial commit * Remove file * Remove module from pr * Run tests
This commit is contained in:
parent
fa66813696
commit
559de7ee1e
6 changed files with 253 additions and 0 deletions
6
test/integration/targets/mongodb_parameter/aliases
Normal file
6
test/integration/targets/mongodb_parameter/aliases
Normal file
|
@ -0,0 +1,6 @@
|
|||
destructive
|
||||
shippable/posix/group1
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
skip/rhel
|
||||
needs/root
|
21
test/integration/targets/mongodb_parameter/defaults/main.yml
Normal file
21
test/integration/targets/mongodb_parameter/defaults/main.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
# defaults file for test_mongodb_user
|
||||
mongodb_admin_user: test_root
|
||||
mongodb_admin_password: saE_Rr9!gE6gh#e~R#nZ
|
||||
mongod_auth: false
|
||||
kill_signal: SIGTERM
|
||||
# Should be one of
|
||||
# --storageEngine wiredTiger --wiredTigerEngineConfigString="cache_size=200M"
|
||||
# --storageEngine mmapv1 --nojournal
|
||||
mongod_storage_engine_opts: "--storageEngine wiredTiger --wiredTigerEngineConfigString='cache_size=200M'"
|
||||
mongodb_user: mongodb
|
||||
mongodb_user_list:
|
||||
- { "name": "user1", "password": "password1", "roles": "read", "database": "test" }
|
||||
- { "name": "user2", "password": "password2", "roles": "readWrite", "database": "test" }
|
||||
- { "name": "user3", "password": "password3", "roles": "dbAdmin", "database": "test" }
|
||||
- { "name": "user4", "password": "password4", "roles": "userAdmin", "database": "test" }
|
||||
- { "name": "user5", "password": "password5", "roles": "clusterAdmin", "database": "admin" }
|
||||
- { "name": "user6", "password": "password6", "roles": "readAnyDatabase", "database": "admin" }
|
||||
- { "name": "user7", "password": "password7", "roles": "readWriteAnyDatabase", "database": "admin" }
|
||||
- { "name": "user8", "password": "password8", "roles": "userAdminAnyDatabase", "database": "admin" }
|
||||
- { "name": "user9", "password": "password9", "roles": "dbAdminAnyDatabase", "database": "admin" }
|
3
test/integration/targets/mongodb_parameter/meta/main.yml
Normal file
3
test/integration/targets/mongodb_parameter/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
dependencies:
|
||||
- setup_mongodb
|
||||
- setup_remote_tmp_dir
|
143
test/integration/targets/mongodb_parameter/tasks/main.yml
Normal file
143
test/integration/targets/mongodb_parameter/tasks/main.yml
Normal file
|
@ -0,0 +1,143 @@
|
|||
# test code for the mongodb_parameter module
|
||||
# (c) 2019, Rhys Campbell <rhys.james.campbell@googlemail.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# 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 tests home exists
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/tests"
|
||||
state: directory
|
||||
|
||||
- include_tasks: mongod_teardown.yml
|
||||
|
||||
- include_tasks: mongod_singlenode.yml
|
||||
|
||||
- name: Set syncdelay to 99
|
||||
mongodb_parameter:
|
||||
login_port: 3001
|
||||
param: syncdelay
|
||||
value: 99
|
||||
param_type: int
|
||||
register: sd_change
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- sd_change.before | int == 60
|
||||
- sd_change.after | int == 99
|
||||
- sd_change.changed == True
|
||||
|
||||
- name: Set syncdelay to 99 (again)
|
||||
mongodb_parameter:
|
||||
login_port: 3001
|
||||
param: syncdelay
|
||||
value: 99
|
||||
param_type: int
|
||||
register: sd_change
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- sd_change.before | int == 99
|
||||
- sd_change.after | int == 99
|
||||
- sd_change.changed == False
|
||||
|
||||
- name: Create admin user with module
|
||||
mongodb_user:
|
||||
login_port: 3001
|
||||
database: admin
|
||||
name: "{{ mongodb_admin_user }}"
|
||||
password: "{{ mongodb_admin_password }}"
|
||||
roles: root
|
||||
state: present
|
||||
register: mongodb_admin_user_created
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- mongodb_admin_user_created.changed == True
|
||||
|
||||
- name: Kill all mongod processes
|
||||
command: pkill -{{ kill_signal }} mongod
|
||||
ignore_errors: true
|
||||
|
||||
- name: Getting pids for mongod
|
||||
pids:
|
||||
name: mongod
|
||||
register: pids_of_mongod
|
||||
|
||||
- name: Wait for all mongod processes to exit
|
||||
wait_for:
|
||||
path: "/proc/{{ item }}/status"
|
||||
state: absent
|
||||
delay: 3
|
||||
with_items: "{{ pids_of_mongod }}"
|
||||
|
||||
- set_fact:
|
||||
mongod_auth: true
|
||||
|
||||
- include_tasks: mongod_singlenode.yml
|
||||
# Tests with auth enabled
|
||||
|
||||
- name: Set syncdelay to 59 with auth
|
||||
mongodb_parameter:
|
||||
login_port: 3001
|
||||
login_user: "{{ mongodb_admin_user }}"
|
||||
login_password: "{{ mongodb_admin_password }}"
|
||||
param: syncdelay
|
||||
value: 59
|
||||
param_type: int
|
||||
register: sd_change
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- sd_change.before | int == 60
|
||||
- sd_change.after | int == 59
|
||||
- sd_change.changed == True
|
||||
|
||||
- name: Set syncdelay to 59 (again) with auth
|
||||
mongodb_parameter:
|
||||
login_port: 3001
|
||||
login_user: "{{ mongodb_admin_user }}"
|
||||
login_password: "{{ mongodb_admin_password }}"
|
||||
param: syncdelay
|
||||
value: 59
|
||||
param_type: int
|
||||
register: sd_change
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- sd_change.before | int == 59
|
||||
- sd_change.after | int == 59
|
||||
- sd_change.changed == False
|
||||
|
||||
- name: Set authenticationMechanisms to MONGODB-X509 with auth (will fail)
|
||||
mongodb_parameter:
|
||||
login_port: 3001
|
||||
login_user: "{{ mongodb_admin_user }}"
|
||||
login_password: "{{ mongodb_admin_password }}"
|
||||
param: authenticationMechanisms
|
||||
value: "MONGODB-X509"
|
||||
param_type: str
|
||||
register: diag_change
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- '"unable to change parameter" in diag_change.msg'
|
||||
- diag_change.failed == True
|
||||
|
||||
# Clean up
|
||||
- include_tasks: mongod_teardown.yml
|
|
@ -0,0 +1,55 @@
|
|||
- name: Set mongodb_user user for redhat
|
||||
set_fact:
|
||||
mongodb_user: "mongod"
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
- set_fact:
|
||||
mongodb_nodes:
|
||||
- 3001
|
||||
|
||||
- name: Create directories for mongod processes
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/mongod{{ item }}"
|
||||
state: directory
|
||||
owner: "{{ mongodb_user }}"
|
||||
group: "{{ mongodb_user }}"
|
||||
mode: 0755
|
||||
recurse: yes
|
||||
with_items: "{{ mongodb_nodes }}"
|
||||
|
||||
- name: Ensure {{ remote_tmp_dir }}/config dir exists
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/config"
|
||||
state: directory
|
||||
owner: "{{ mongodb_user }}"
|
||||
group: "{{ mongodb_user }}"
|
||||
mode: 0755
|
||||
|
||||
- name: Create keyfile
|
||||
copy:
|
||||
dest: "{{ remote_tmp_dir }}/my.key"
|
||||
content: |
|
||||
fd2CUrbXBJpB4rt74A6F
|
||||
owner: "{{ mongodb_user }}"
|
||||
group: "{{ mongodb_user }}"
|
||||
mode: 0600
|
||||
when: mongod_auth == True
|
||||
|
||||
- name: Spawn mongod process without auth
|
||||
command: mongod --shardsvr --smallfiles {{ mongod_storage_engine_opts }} --dbpath mongod{{ item }} --port {{ item }} --logpath mongod{{ item }}/log.log --fork
|
||||
args:
|
||||
chdir: "{{ remote_tmp_dir }}"
|
||||
with_items: "{{ mongodb_nodes | sort }}"
|
||||
when: mongod_auth == False
|
||||
|
||||
- name: Spawn mongod process with auth
|
||||
command: mongod --shardsvr --smallfiles {{ mongod_storage_engine_opts }} --dbpath mongod{{ item }} --port {{ item }} --logpath mongod{{ item }}/log.log --fork --auth --keyFile my.key
|
||||
args:
|
||||
chdir: "{{ remote_tmp_dir }}"
|
||||
with_items: "{{ mongodb_nodes | sort }}"
|
||||
when: mongod_auth == True
|
||||
|
||||
- name: Wait for mongod to start responding
|
||||
wait_for:
|
||||
port: "{{ item }}"
|
||||
with_items: "{{ mongodb_nodes }}"
|
|
@ -0,0 +1,25 @@
|
|||
- name: Kill all mongod processes
|
||||
command: pkill -{{ kill_signal }} mongod
|
||||
ignore_errors: true
|
||||
|
||||
- name: Getting pids for mongod
|
||||
pids:
|
||||
name: mongod
|
||||
register: pids_of_mongod
|
||||
|
||||
- name: Wait for all mongod processes to exit
|
||||
wait_for:
|
||||
path: "/proc/{{ item }}/status"
|
||||
state: absent
|
||||
delay: 1
|
||||
with_items: "{{ pids_of_mongod }}"
|
||||
|
||||
- name: Remove all mongod folders
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- mongod3001
|
||||
|
||||
- name: Remove all mongod sock files
|
||||
shell: rm -Rf /tmp/mongodb*.sock
|
Loading…
Reference in a new issue