add tests to ensure expression for atl_startup_restart var in defaults is evaluated to boolean

This commit is contained in:
Lee Goolsbee
2021-02-05 15:44:15 -06:00
parent 1278cc6cf5
commit 520a881310
8 changed files with 121 additions and 5 deletions

View File

@@ -18,7 +18,7 @@ pipelines:
- step:
name: Pre Parallelization stage
script:
- echo "Running tests in 37 batches"
- echo "Running tests in 38 batches"
- step:
name: Check if the template is up-to-date
@@ -97,6 +97,14 @@ pipelines:
- ./bin/install-ansible --dev
- cd roles/product_startup
- pipenv run molecule test -s bitbucket
- step:
name: product_startup/startup_restart_false
services:
- docker
script:
- ./bin/install-ansible --dev
- cd roles/product_startup
- pipenv run molecule test -s startup_restart_false
- step:
name: product_common/default
services:

View File

@@ -4,12 +4,16 @@
service:
name: "{{ atl_systemd_service_name }}"
state: restarted
when: atl_startup_restart
when:
- atl_startup_restart
- molecule_yml is not defined
no_log: true
- name: Enable Product
service:
name: "{{ atl_systemd_service_name }}"
enabled: true
when: atl_startup_enable
when:
- atl_startup_enable
- molecule_yml is not defined
no_log: true

View File

@@ -6,8 +6,7 @@
atl_product_family: "jira"
atl_product_edition: "jira-software"
atl_startup_enable: false
atl_startup_restart: false
ansible_vars_dump_location: "/tmp/ansible-vars.yml"
pre_tasks:
- name: Create systemd dir if necessary
@@ -20,3 +19,20 @@
roles:
- role: product_startup
post_tasks:
- include_vars: ../../defaults/main.yml
# workaround Molecule idempotence check
# normal pattern of setting changed_when allows file to be written twice, which takes extra time
- name: Check if vars have already been dumped
stat:
path: "{{ ansible_vars_dump_location }}"
register: ansible_vars_stat_result
- name: Dump vars to file for inspection
copy:
content: |
{{ vars | to_nice_yaml }}
dest: "{{ ansible_vars_dump_location }}"
when: not ansible_vars_stat_result.stat.exists

View File

@@ -13,3 +13,9 @@ def test_service_file(host):
assert f.user == 'root'
assert f.group == 'root'
assert f.mode == 0o0640
def test_atl_startup_restart(host):
f = host.file('/tmp/ansible-vars.yml')
# value should appear as YAML boolean true (i.e., string 'true' will fail)
assert f.contains(r'^\s*atl_startup_restart: true$')

View File

@@ -0,0 +1,14 @@
# Molecule managed
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi

View File

@@ -0,0 +1,27 @@
---
- name: Converge
hosts: all
vars:
atl_product_user: "jira"
atl_product_family: "jira"
atl_product_edition: "jira-software"
atl_startup_enable: false
ansible_vars_dump_location: "/tmp/ansible-vars.yml"
tasks:
- include_vars: ../../defaults/main.yml
# workaround Molecule idempotence check
# normal pattern of setting changed_when allows file to be written twice, which takes extra time
- name: Check if vars have already been dumped
stat:
path: "{{ ansible_vars_dump_location }}"
register: ansible_vars_stat_result
- name: Dump vars to file for inspection
copy:
content: |
{{ vars | to_nice_yaml }}
dest: "{{ ansible_vars_dump_location }}"
when: not ansible_vars_stat_result.stat.exists

View File

@@ -0,0 +1,29 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: amazon_linux2
image: amazonlinux:2
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
- name: ubuntu_lts
image: ubuntu:bionic
groups:
- aws_node_local
ulimits:
- nofile:262144:262144
provisioner:
name: ansible
env:
ATL_STARTUP_RESTART: "false"
options:
skip-tags: runtime_pkg
inventory:
links:
group_vars: ../../../../group_vars/
verifier:
name: testinfra

View File

@@ -0,0 +1,12 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_atl_startup_restart(host):
f = host.file('/tmp/ansible-vars.yml')
# value should appear as YAML boolean false (i.e., boolean true or string 'false' will fail)
assert f.contains(r'^\s*atl_startup_restart: false$')