postgresql_set: improve CI tests (#59583)

This commit is contained in:
Andrey Klychkov 2019-07-26 20:53:34 +03:00 committed by Felix Fontein
parent 3b5a96fcb7
commit 5b1a4f959a

View file

@ -4,31 +4,76 @@
# #
# Notice: assertions are different for Ubuntu 16.04 and FreeBSD because they don't work # Notice: assertions are different for Ubuntu 16.04 and FreeBSD because they don't work
# correctly for these tests. There are some stranges exactly in Shippable CI. # correctly for these tests. There are some stranges exactly in Shippable CI.
# However I checked it manually for all points and it worked as expected. # However I checked it manually for all points (including Ubuntu 16.05 and FreeBSD)
# and it worked as expected.
- name: postgresql_set - preparation to the next step - vars:
become_user: "{{ pg_user }}" task_parameters: &task_parameters
become: yes become_user: '{{ pg_user }}'
postgresql_set: become: yes
db: postgres pg_parameters: &pg_parameters
login_user: "{{ pg_user }}" login_user: '{{ pg_user }}'
name: work_mem login_db: postgres
reset: yes
ignore_errors: yes
- name: postgresql_set - set work_mem (restart is not required) block:
become_user: "{{ pg_user }}" - name: postgresql_set - preparation to the next step
become: yes <<: *task_parameters
postgresql_set: become_user: "{{ pg_user }}"
db: postgres become: yes
login_user: "{{ pg_user }}" postgresql_set:
name: work_mem <<: *pg_parameters
value: 12MB name: work_mem
register: set_wm reset: yes
ignore_errors: yes
- assert: #####################
that: # Testing check_mode:
- name: postgresql_set - get work_mem initial value
<<: *task_parameters
postgresql_query:
<<: *pg_parameters
query: SHOW work_mem
register: before
- name: postgresql_set - set work_mem (restart is not required), check_mode
<<: *task_parameters
postgresql_set:
<<: *pg_parameters
name: work_mem
value: 12MB
register: set_wm
check_mode: yes
- assert:
that:
- set_wm.name == 'work_mem'
- set_wm.changed == true
- set_wm.prev_val_pretty == before.query_result[0].work_mem
- set_wm.value_pretty == '12MB'
- set_wm.restart_required == false
- name: postgresql_set - get work_mem value to check, must be the same as initial
<<: *task_parameters
postgresql_query:
<<: *pg_parameters
query: SHOW work_mem
register: after
- assert:
that:
- before.query_result[0].work_mem == after.query_result[0].work_mem
######
#
- name: postgresql_set - set work_mem (restart is not required)
<<: *task_parameters
postgresql_set:
<<: *pg_parameters
name: work_mem
value: 12MB
register: set_wm
- assert:
that:
- set_wm.name == 'work_mem' - set_wm.name == 'work_mem'
- set_wm.changed == true - set_wm.changed == true
- set_wm.value_pretty == '12MB' - set_wm.value_pretty == '12MB'
@ -36,196 +81,202 @@
- set_wm.restart_required == false - set_wm.restart_required == false
- set_wm.value.value == 12582912 - set_wm.value.value == 12582912
- set_wm.value.unit == 'b' - set_wm.value.unit == 'b'
when: ansible_distribution != "Ubuntu" and ansible_distribution_major_version != '16' and ansible_distribution != "FreeBSD" when:
- ansible_distribution != "Ubuntu"
- ansible_distribution_major_version != '16'
- ansible_distribution != "FreeBSD"
- assert: - assert:
that: that:
- set_wm.name == 'work_mem' - set_wm.name == 'work_mem'
- set_wm.changed == true - set_wm.changed == true
- set_wm.restart_required == false - set_wm.restart_required == false
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == '16' when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version == '16'
- name: postgresql_set - reset work_mem (restart is not required) - name: postgresql_set - reset work_mem (restart is not required)
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: work_mem
login_user: "{{ pg_user }}" reset: yes
name: work_mem register: reset_wm
reset: yes
register: reset_wm
ignore_errors: yes
- assert: - assert:
that: that:
- reset_wm.name == 'work_mem' - reset_wm.name == 'work_mem'
- reset_wm.changed == true - reset_wm.changed == true
- reset_wm.value_pretty != reset_wm.prev_val_pretty - reset_wm.value_pretty != reset_wm.prev_val_pretty
- reset_wm.restart_required == false - reset_wm.restart_required == false
- reset_wm.value.value != '12582912' - reset_wm.value.value != '12582912'
when: ansible_distribution != "Ubuntu" and ansible_distribution_major_version != '16' and ansible_distribution != "FreeBSD" when:
- ansible_distribution != "Ubuntu"
- ansible_distribution_major_version != '16'
- ansible_distribution != "FreeBSD"
- assert: - assert:
that: that:
- reset_wm.name == 'work_mem' - reset_wm.name == 'work_mem'
- reset_wm.changed == true - reset_wm.changed == true
- reset_wm.restart_required == false - reset_wm.restart_required == false
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == '16' when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version == '16'
- name: postgresql_set - reset work_mem again to check that nothing changed (restart is not required) - name: postgresql_set - reset work_mem again to check that nothing changed (restart is not required)
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: work_mem
login_user: "{{ pg_user }}" reset: yes
name: work_mem register: reset_wm2
reset: yes
register: reset_wm2
ignore_errors: yes
- assert: - assert:
that: that:
- reset_wm2.name == 'work_mem' - reset_wm2.name == 'work_mem'
- reset_wm2.changed == false - reset_wm2.changed == false
- reset_wm2.value_pretty == reset_wm2.prev_val_pretty - reset_wm2.value_pretty == reset_wm2.prev_val_pretty
- reset_wm2.restart_required == false - reset_wm2.restart_required == false
when: ansible_distribution != "Ubuntu" and ansible_distribution_major_version != '16' when:
- ansible_distribution != "Ubuntu"
- ansible_distribution_major_version != '16'
- assert: - assert:
that: that:
- reset_wm2.name == 'work_mem' - reset_wm2.name == 'work_mem'
- reset_wm2.changed == false - reset_wm2.changed == false
- reset_wm2.restart_required == false - reset_wm2.restart_required == false
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == '16' when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version == '16'
- name: postgresql_set - preparation to the next step - name: postgresql_set - preparation to the next step
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: work_mem
login_user: "{{ pg_user }}" value: 14MB
name: work_mem
value: 14MB
ignore_errors: yes
- name: postgresql_set - set work_mem to initial state (restart is not required) - name: postgresql_set - set work_mem to initial state (restart is not required)
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: work_mem
login_user: "{{ pg_user }}" value: default
name: work_mem register: def_wm
value: default
register: def_wm
ignore_errors: yes
- assert: - assert:
that: that:
- def_wm.name == 'work_mem' - def_wm.name == 'work_mem'
- def_wm.changed == true - def_wm.changed == true
- def_wm.value_pretty != def_wm.prev_val_pretty - def_wm.value_pretty != def_wm.prev_val_pretty
- def_wm.restart_required == false - def_wm.restart_required == false
- def_wm.value.value != '14680064' - def_wm.value.value != '14680064'
when: ansible_distribution != "Ubuntu" and ansible_distribution_major_version != '16' and ansible_distribution != 'FreeBSD' when:
- ansible_distribution != "Ubuntu"
- ansible_distribution_major_version != '16'
- ansible_distribution != 'FreeBSD'
- assert: - assert:
that: that:
- def_wm.name == 'work_mem' - def_wm.name == 'work_mem'
- def_wm.changed == true - def_wm.changed == true
- def_wm.restart_required == false - def_wm.restart_required == false
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == '16' and ansible_distribution != 'FreeBSD' when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version == '16'
- ansible_distribution != 'FreeBSD'
- name: postgresql_set - set shared_buffers (restart is required) - name: postgresql_set - set shared_buffers (restart is required)
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: shared_buffers
login_user: "{{ pg_user }}" value: 111MB
name: shared_buffers register: set_shb
value: 111MB
register: set_shb
ignore_errors: yes
- assert: - assert:
that: that:
- set_shb.name == 'shared_buffers' - set_shb.name == 'shared_buffers'
- set_shb.changed == true - set_shb.changed == true
- set_shb.restart_required == true - set_shb.restart_required == true
# We don't check value.utin because it is none # We don't check value.unit because it is none
- name: postgresql_set - set autovacuum (enabled by default, restart is not required) - name: postgresql_set - set autovacuum (enabled by default, restart is not required)
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: autovacuum
login_user: "{{ pg_user }}" value: off
name: autovacuum register: set_aut
value: off
register: set_aut
ignore_errors: yes
- assert: - assert:
that: that:
- set_aut.name == 'autovacuum' - set_aut.name == 'autovacuum'
- set_aut.changed == true - set_aut.changed == true
- set_aut.restart_required == false - set_aut.restart_required == false
- set_aut.value.value == 'off' - set_aut.value.value == 'off'
# Test check_mode, step 1. At the previous test we set autovacuum = 'off' # Test check_mode, step 1. At the previous test we set autovacuum = 'off'
- name: postgresql - try to change autovacuum again in check_mode - name: postgresql - try to change autovacuum again in check_mode
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: autovacuum
login_user: "{{ pg_user }}" value: on
name: autovacuum register: set_aut
value: on check_mode: yes
register: set_aut
ignore_errors: yes
check_mode: yes
- assert: - assert:
that: that:
- set_aut.name == 'autovacuum' - set_aut.name == 'autovacuum'
- set_aut.changed == true - set_aut.changed == true
- set_aut.restart_required == false - set_aut.restart_required == false
- set_aut.value.value == 'off' - set_aut.value.value == 'off'
# Test check_mode, step 2 # Test check_mode, step 2
- name: postgresql - check that autovacuum wasn't actually changed after change in check_mode - name: postgresql - check that autovacuum wasn't actually changed after change in check_mode
become_user: "{{ pg_user }}" <<: *task_parameters
become: yes postgresql_set:
postgresql_set: <<: *pg_parameters
db: postgres name: autovacuum
login_user: "{{ pg_user }}" value: off
name: autovacuum register: set_aut
value: off check_mode: yes
register: set_aut
ignore_errors: yes
check_mode: yes
- assert: - assert:
that: that:
- set_aut.name == 'autovacuum' - set_aut.name == 'autovacuum'
- set_aut.changed == false - set_aut.changed == false
- set_aut.restart_required == false - set_aut.restart_required == false
- set_aut.value.value == 'off' - set_aut.value.value == 'off'
# Test check_mode, step 3. It is different from the prev test - it runs without check_mode: yes # Additional check by SQL query:
# Before the check_mode tests autovacuum was off - name: postgresql_set - get autovacuum value to check, must be off
- name: postgresql - check that autovacuum wasn't actually changed after change in check_mode <<: *task_parameters
become_user: "{{ pg_user }}" postgresql_query:
become: yes <<: *pg_parameters
postgresql_set: query: SHOW autovacuum
db: postgres register: result
login_user: "{{ pg_user }}"
name: autovacuum
value: off
register: set_aut
ignore_errors: yes
- assert: - assert:
that: that:
- result.query_result[0].autovacuum == 'off'
# Test check_mode, step 3. It is different from
# the prev test - it runs without check_mode: yes.
# Before the check_mode tests autovacuum was off
- name: postgresql - check that autovacuum wasn't actually changed after change in check_mode
<<: *task_parameters
postgresql_set:
<<: *pg_parameters
name: autovacuum
value: off
register: set_aut
- assert:
that:
- set_aut.name == 'autovacuum' - set_aut.name == 'autovacuum'
- set_aut.changed == false - set_aut.changed == false
- set_aut.restart_required == false - set_aut.restart_required == false