diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 06a83de..078d341 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -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: diff --git a/roles/product_startup/handlers/main.yml b/roles/product_startup/handlers/main.yml index 6e9e1d8..57275c9 100644 --- a/roles/product_startup/handlers/main.yml +++ b/roles/product_startup/handlers/main.yml @@ -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 diff --git a/roles/product_startup/molecule/default/converge.yml b/roles/product_startup/molecule/default/converge.yml index 5cff089..9a232fc 100644 --- a/roles/product_startup/molecule/default/converge.yml +++ b/roles/product_startup/molecule/default/converge.yml @@ -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 diff --git a/roles/product_startup/molecule/default/tests/test_default.py b/roles/product_startup/molecule/default/tests/test_default.py index d3b1994..b02bda9 100644 --- a/roles/product_startup/molecule/default/tests/test_default.py +++ b/roles/product_startup/molecule/default/tests/test_default.py @@ -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$') diff --git a/roles/product_startup/molecule/startup_restart_false/Dockerfile.j2 b/roles/product_startup/molecule/startup_restart_false/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/product_startup/molecule/startup_restart_false/Dockerfile.j2 @@ -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 diff --git a/roles/product_startup/molecule/startup_restart_false/converge.yml b/roles/product_startup/molecule/startup_restart_false/converge.yml new file mode 100644 index 0000000..1943cb3 --- /dev/null +++ b/roles/product_startup/molecule/startup_restart_false/converge.yml @@ -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 diff --git a/roles/product_startup/molecule/startup_restart_false/molecule.yml b/roles/product_startup/molecule/startup_restart_false/molecule.yml new file mode 100644 index 0000000..85b7cb3 --- /dev/null +++ b/roles/product_startup/molecule/startup_restart_false/molecule.yml @@ -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 diff --git a/roles/product_startup/molecule/startup_restart_false/tests/test_default.py b/roles/product_startup/molecule/startup_restart_false/tests/test_default.py new file mode 100644 index 0000000..a70d8d7 --- /dev/null +++ b/roles/product_startup/molecule/startup_restart_false/tests/test_default.py @@ -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$')