Skip to content

Commit

Permalink
test: deduplicate qdevice tests code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjelinek committed Oct 11, 2023
1 parent e89d857 commit afbc87c
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 211 deletions.
68 changes: 68 additions & 0 deletions tests/template_qdevice.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SPDX-License-Identifier: MIT
---
- name: Run test
vars:
ha_cluster_cluster_name: test-cluster
block:
- name: Set up test environment
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_setup.yml

- name: Clean up test environment for qnetd
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_cleanup_qnetd.yml

- name: Set up test environment for qnetd
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_setup_qnetd.yml
run_once: true # noqa: run_once[task]

- name: Back up qnetd
include_tasks: tasks/qnetd_backup_restore.yml
vars:
operation: backup
run_once: true # noqa: run_once[task]

- name: Run HA Cluster role
include_role:
name: linux-system-roles.ha_cluster
# variables for the role are supposed to be defined in a playbook which
# includes this task file

# The role removed qnetd configuration
- name: Restore qnetd
include_tasks: tasks/qnetd_backup_restore.yml
vars:
operation: restore
run_once: true # noqa: run_once[task]

- name: Get services status
service_facts:

- name: Check qdevice status
assert:
that:
- ansible_facts.services["corosync-qdevice.service"].status
== "enabled"
- ansible_facts.services["corosync-qdevice.service"].state
== "running"

- name: Check corosync
include_tasks: tasks/assert_corosync_config.yml
# __test_expected_lines is supposed to be defined in a playbook which
# includes this task file

- name: Check cluster status
include_tasks: tasks/assert_cluster_running.yml

- name: Check qdevice status
include_tasks: tasks/assert_qdevice_in_cluster.yml

always:
- name: Clean up test environment for qnetd
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_cleanup_qnetd.yml
167 changes: 59 additions & 108 deletions tests/tests_qdevice_all_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,114 +3,65 @@
- name: Test qdevice - all options
hosts: all
vars_files: vars/main.yml
vars:
ha_cluster_cluster_name: test-cluster

tasks:
- name: Set qnetd address
set_fact:
__test_qnetd_address: "{{
(ansible_play_hosts_all | length == 1)
| ternary('localhost', ansible_play_hosts[0]) }}"

- name: Run test
tags: tests::verify
block:
- name: Set up test environment
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_setup.yml

- name: Set up test environment for qnetd / qdevice
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_setup_qnetd.yml
run_once: true # noqa: run_once[task]

- name: Back up qnetd
include_tasks: tasks/qnetd_backup_restore.yml
vars:
operation: backup
run_once: true # noqa: run_once[task]

- name: Set qnetd address
set_fact:
__test_qnetd_address: "{{
(ansible_play_hosts_all | length == 1)
| ternary('localhost', ansible_play_hosts[0]) }}"

- name: Run HA Cluster role
include_role:
name: linux-system-roles.ha_cluster
vars:
ha_cluster_quorum:
device:
model: net
model_options:
- name: host
value: "{{ __test_qnetd_address }}"
- name: algorithm
value: lms
generic_options:
- name: timeout
value: 1000
- name: sync_timeout
value: 3000
heuristics_options:
- name: mode
value: "on"
- name: exec_ping
value: /usr/bin/ping -c 1 127.0.0.1

# The role removed qnetd configuration
- name: Restore qnetd
include_tasks: tasks/qnetd_backup_restore.yml
vars:
operation: restore
run_once: true # noqa: run_once[task]

- name: Get services status
service_facts:

- name: Check qdevice status
assert:
that:
- ansible_facts.services["corosync-qdevice.service"].status
== "enabled"
- ansible_facts.services["corosync-qdevice.service"].state
== "running"

- name: Check corosync
include_tasks: tasks/assert_corosync_config.yml
vars:
__test_expected_lines:
- 'totem {'
- ' version: 2'
- ' cluster_name: {{ ha_cluster_cluster_name }}'
- ' transport: knet'
- ' crypto_cipher: aes256'
- ' crypto_hash: sha256'
- '}'
- 'nodelist {'
- '}'
- "quorum {"
- " provider: corosync_votequorum"
- " device {"
- " sync_timeout: 3000"
- " timeout: 1000"
- " model: net"
- " net {"
- " algorithm: lms"
- " host: {{ __test_qnetd_address }}"
- " }"
- " heuristics {"
- " exec_ping: /usr/bin/ping -c 1 127.0.0.1"
- " mode: on"
- " }"
- " }"
- "}"
- 'logging {'
- ' to_logfile: yes'
- ' logfile: /var/log/cluster/corosync.log'
- ' to_syslog: yes'
- ' timestamp: on'
- '}'

- name: Check cluster status
include_tasks: tasks/assert_cluster_running.yml

- name: Check qdevice status
include_tasks: tasks/assert_qdevice_in_cluster.yml
include_tasks: template_qdevice.yml
vars:
ha_cluster_quorum:
device:
model: net
model_options:
- name: host
value: "{{ __test_qnetd_address }}"
- name: algorithm
value: lms
generic_options:
- name: timeout
value: 1000
- name: sync_timeout
value: 3000
heuristics_options:
- name: mode
value: "on"
- name: exec_ping
value: /usr/bin/ping -c 1 127.0.0.1
__test_expected_lines:
- "totem {"
- " version: 2"
- " cluster_name: {{ ha_cluster_cluster_name }}"
- " transport: knet"
- " crypto_cipher: aes256"
- " crypto_hash: sha256"
- "}"
- "nodelist {"
- "}"
- "quorum {"
- " provider: corosync_votequorum"
- " device {"
- " sync_timeout: 3000"
- " timeout: 1000"
- " model: net"
- " net {"
- " algorithm: lms"
- " host: {{ __test_qnetd_address }}"
- " }"
- " heuristics {"
- " exec_ping: /usr/bin/ping -c 1 127.0.0.1"
- " mode: on"
- " }"
- " }"
- "}"
- "logging {"
- " to_logfile: yes"
- " logfile: /var/log/cluster/corosync.log"
- " to_syslog: yes"
- " timestamp: on"
- "}"
145 changes: 42 additions & 103 deletions tests/tests_qdevice_minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,110 +3,49 @@
- name: Test qdevice - minimal configuration
hosts: all
vars_files: vars/main.yml
vars:
ha_cluster_cluster_name: test-cluster

tasks:
- name: Set qnetd address
set_fact:
__test_qnetd_address: "{{
(ansible_play_hosts_all | length == 1)
| ternary('localhost', ansible_play_hosts[0]) }}"

- name: Run test
tags: tests::verify
block:
- name: Set up test environment
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_setup.yml

- name: Clean up test environment for qnetd
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_cleanup_qnetd.yml

- name: Set up test environment for qnetd
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_setup_qnetd.yml
run_once: true # noqa: run_once[task]

- name: Back up qnetd
include_tasks: tasks/qnetd_backup_restore.yml
vars:
operation: backup
run_once: true # noqa: run_once[task]

- name: Set qnetd address
set_fact:
__test_qnetd_address: "{{
(ansible_play_hosts_all | length == 1)
| ternary('localhost', ansible_play_hosts[0]) }}"

- name: Run HA Cluster role
include_role:
name: linux-system-roles.ha_cluster
vars:
ha_cluster_quorum:
device:
model: net
model_options:
- name: host
value: "{{ __test_qnetd_address }}"
- name: algorithm
value: lms

# The role removed qnetd configuration
- name: Restore qnetd
include_tasks: tasks/qnetd_backup_restore.yml
vars:
operation: restore
run_once: true # noqa: run_once[task]

- name: Get services status
service_facts:

- name: Check qdevice status
assert:
that:
- ansible_facts.services["corosync-qdevice.service"].status
== "enabled"
- ansible_facts.services["corosync-qdevice.service"].state
== "running"

- name: Check corosync
include_tasks: tasks/assert_corosync_config.yml
vars:
__test_expected_lines:
- 'totem {'
- ' version: 2'
- ' cluster_name: {{ ha_cluster_cluster_name }}'
- ' transport: knet'
- ' crypto_cipher: aes256'
- ' crypto_hash: sha256'
- '}'
- 'nodelist {'
- '}'
- "quorum {"
- " provider: corosync_votequorum"
- " device {"
- " model: net"
- " net {"
- " algorithm: lms"
- " host: {{ __test_qnetd_address }}"
- " }"
- " }"
- "}"
- 'logging {'
- ' to_logfile: yes'
- ' logfile: /var/log/cluster/corosync.log'
- ' to_syslog: yes'
- ' timestamp: on'
- '}'

- name: Check cluster status
include_tasks: tasks/assert_cluster_running.yml

- name: Check qdevice status
include_tasks: tasks/assert_qdevice_in_cluster.yml

always:
- name: Clean up test environment for qnetd
include_role:
name: linux-system-roles.ha_cluster
tasks_from: test_cleanup_qnetd.yml
include_tasks: template_qdevice.yml
vars:
ha_cluster_quorum:
device:
model: net
model_options:
- name: host
value: "{{ __test_qnetd_address }}"
- name: algorithm
value: lms
__test_expected_lines:
- "totem {"
- " version: 2"
- " cluster_name: {{ ha_cluster_cluster_name }}"
- " transport: knet"
- " crypto_cipher: aes256"
- " crypto_hash: sha256"
- "}"
- "nodelist {"
- "}"
- "quorum {"
- " provider: corosync_votequorum"
- " device {"
- " model: net"
- " net {"
- " algorithm: lms"
- " host: {{ __test_qnetd_address }}"
- " }"
- " }"
- "}"
- "logging {"
- " to_logfile: yes"
- " logfile: /var/log/cluster/corosync.log"
- " to_syslog: yes"
- " timestamp: on"
- "}"

0 comments on commit afbc87c

Please sign in to comment.