diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index e258e0e..892cc36 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -30,7 +30,7 @@ pipelines: - step: name: Pre Parallelization stage script: - - echo "Running tests in 38 batches" + - echo "Running tests in 39 batches" - step: name: Check if the template is up-to-date @@ -38,7 +38,7 @@ pipelines: - | actual_scenario_count=$(find ./roles -type f -name "molecule.yml" -exec dirname {} ';' | wc -l | sed -e 's/^[[:space:]]*//') if ! grep -q "Running tests in ${actual_scenario_count} batches" bitbucket-pipelines.yml; then - echo "Mismatch between expected (38) and actual number (${actual_scenario_count}) of scenarios. Please look at https://bitbucket.org/atlassian/dc-deployments-automation/src/master/DEVELOPMENT.md for instructions on how to fix this error." + echo "Mismatch between expected (39) and actual number (${actual_scenario_count}) of scenarios. Please look at https://bitbucket.org/atlassian/dc-deployments-automation/src/master/DEVELOPMENT.md for instructions on how to fix this error." exit 1 fi @@ -295,6 +295,20 @@ pipelines: - ./bin/install-ansible --dev - cd roles/product_install - pipenv run molecule test -s bitbucket_latest + - step: + name: product_install/confluence_cached_with_upgrade + caches: + - ansible-collections + - docker + - pip + services: + - docker + script: + - apt-get update && apt-get install -y rsync + - export ANSIBLE_CONFIG=./ansible.cfg + - ./bin/install-ansible --dev + - cd roles/product_install + - pipenv run molecule test -s confluence_cached_with_upgrade - step: name: product_install/confluence_latest caches: diff --git a/roles/product_install/molecule/confluence_cached_with_upgrade/Dockerfile.j2 b/roles/product_install/molecule/confluence_cached_with_upgrade/Dockerfile.j2 new file mode 100644 index 0000000..fbd7b34 --- /dev/null +++ b/roles/product_install/molecule/confluence_cached_with_upgrade/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 python3 sudo bash ca-certificates file && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python3.11 sudo python3.11-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_install/molecule/confluence_cached_with_upgrade/converge.yml b/roles/product_install/molecule/confluence_cached_with_upgrade/converge.yml new file mode 100644 index 0000000..7dbbec7 --- /dev/null +++ b/roles/product_install/molecule/confluence_cached_with_upgrade/converge.yml @@ -0,0 +1,46 @@ +--- +# Regression test for ITSD-611934: upgrading from a cached milestone that has +# an uppercase qualifier (e.g. 11.0.0-CONFDCDEV-4353-m02) to the matching GA +# release. Before the fix, LooseVersion sorted the uppercase qualifier above +# the GA '-z' marker, so the cached milestone won and the GA was never +# installed. +- name: Converge + hosts: all + vars: + atl_product_family: "confluence" + atl_product_edition: "confluence" + atl_product_user: "confluence" + # NOTE: This should be honoured as it is the GA of the cached milestone. + atl_product_version: "7.20.0" + + pre_tasks: + - name: Create cache dir + ansible.builtin.file: + path: '/media/atl/confluence/shared-home/' + state: directory + - name: Seed cached uppercase milestone version + ansible.builtin.copy: + dest: '/media/atl/confluence/shared-home/confluence.version' + content: "7.20.0-CONFSERVER-63193-m01" + force: false # For idempotency check + + roles: + - role: linux_common + - role: product_common + - role: product_install + +# Then the inverse: supplying the uppercase milestone while its GA is cached +# must not downgrade. Before the case-insensitive comparison, it did. The +# existing tests (cache still 7.20.0, milestone not installed) cover this. +- name: Converge (no downgrade to uppercase milestone) + hosts: all + vars: + atl_product_family: "confluence" + atl_product_edition: "confluence" + atl_product_user: "confluence" + atl_product_version: "7.20.0-CONFSERVER-63193-m01" + + roles: + - role: linux_common + - role: product_common + - role: product_install diff --git a/roles/product_install/molecule/confluence_cached_with_upgrade/molecule.yml b/roles/product_install/molecule/confluence_cached_with_upgrade/molecule.yml new file mode 100644 index 0000000..1f8d749 --- /dev/null +++ b/roles/product_install/molecule/confluence_cached_with_upgrade/molecule.yml @@ -0,0 +1,25 @@ +--- +driver: + name: docker +platforms: + - name: amazon_linux2023 + image: amazonlinux:2023 + groups: + - aws_node_local + platform: linux/amd64 + - name: ubuntu_lts + image: ubuntu:jammy + groups: + - aws_node_local + platform: linux/amd64 +provisioner: + name: ansible + env: + ANSIBLE_COLLECTIONS_PATH: "../../../../" + options: + skip-tags: runtime_pkg + inventory: + links: + group_vars: ../../../../group_vars/ +verifier: + name: testinfra diff --git a/roles/product_install/molecule/confluence_cached_with_upgrade/tests/test_default.py b/roles/product_install/molecule/confluence_cached_with_upgrade/tests/test_default.py new file mode 100644 index 0000000..ec11931 --- /dev/null +++ b/roles/product_install/molecule/confluence_cached_with_upgrade/tests/test_default.py @@ -0,0 +1,28 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_version_cache_upgraded_to_ga(host): + verfile = host.file('/media/atl/confluence/shared-home/confluence.version') + assert verfile.exists + assert verfile.content.decode("UTF-8").strip() == "7.20.0" + + +def test_ga_is_unpacked(host): + installdir = host.file('/opt/atlassian/confluence/7.20.0') + assert installdir.exists + assert installdir.is_directory + + +def test_milestone_not_installed(host): + assert not host.file('/opt/atlassian/confluence/7.20.0-CONFSERVER-63193-m01').exists + + +def test_current_points_to_ga(host): + current = host.file('/opt/atlassian/confluence/current') + assert current.is_symlink + assert current.linked_to == '/opt/atlassian/confluence/7.20.0' diff --git a/roles/product_install/tasks/main.yml b/roles/product_install/tasks/main.yml index 8439b42..bdf134f 100644 --- a/roles/product_install/tasks/main.yml +++ b/roles/product_install/tasks/main.yml @@ -66,6 +66,13 @@ # there is some test logic hack to allow atlassian specfic versioning # requirements to work as expected ie - (7.2.0 to upgrade over 7.2.0-rc1) and # (7.2.0-beta1 to upgrade over 7.2.0-m01) in "version is not latest" +# +# The comparison values are lowercased first. LooseVersion only splits +# lowercase letters into their own components, so an uppercase qualifier +# (e.g. 11.0.0-CONFDCDEV-4353-m02) would otherwise become a single '-CONFDCDEV-' +# component that sorts *above* the GA '-z' marker, causing the cached +# milestone to win over the supplied GA release. Lowercasing only affects +# the comparison; the real version strings are left untouched. - name: "Case: Version is latest" block: @@ -91,8 +98,8 @@ - name: "create atlassian ordered versioning for comparison" ansible.builtin.set_fact: - atl_product_normalised_version: "{{ atl_z_product_version | replace('-m', '-am') }}" - atl_cached_normalised_version: "{{ atl_z_cached_version | replace('-m', '-am') }}" + atl_product_normalised_version: "{{ atl_z_product_version | lower | replace('-m', '-am') }}" + atl_cached_normalised_version: "{{ atl_z_cached_version | lower | replace('-m', '-am') }}" - name: "Case: No cached version, or supplied is higher; use supplied" ansible.builtin.set_fact: