From 6304b10cd453c4a4d380d05c60cda6ff3effe8fc Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Fri, 8 Nov 2019 12:29:21 +1100 Subject: [PATCH 1/8] DCD-727: Update for new manifest format. --- roles/restore_backups/tasks/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/restore_backups/tasks/main.yml b/roles/restore_backups/tasks/main.yml index 4d6865f..c1587bd 100644 --- a/roles/restore_backups/tasks/main.yml +++ b/roles/restore_backups/tasks/main.yml @@ -56,8 +56,8 @@ # FIXME: The manifest format is still undecided so the # following usages will need to be updated once it settles.. atl_backup_id: "{{ atl_backup_manifest.name }}" - atl_backup_db_dest: "{{ atl_installer_temp }}/{{ atl_backup_manifest.artifacts.db.location.value | basename }}" - atl_backup_home_dest: "{{ atl_installer_temp }}/{{ atl_backup_manifest.artifacts.sharedHome.location.value | basename }}" + atl_backup_db_dest: "{{ atl_installer_temp }}/{{ atl_backup_manifest.artifacts.db.location.location | basename }}" + atl_backup_home_dest: "{{ atl_installer_temp }}/{{ atl_backup_manifest.artifacts.sharedHome.location.location | basename }}" # FIXME: Here we fetch the backups. However we may wish to stream # these directly from S3 to the target DB/FS to avoid requiring @@ -66,16 +66,16 @@ aws_s3: mode: get overwrite: different - bucket: "{{ atl_backup_manifest.artifacts.db.location.value | urlsplit('hostname') }}" - object: "{{ atl_backup_manifest.artifacts.db.location.value | urlsplit('path') }}" + bucket: "{{ atl_backup_manifest.artifacts.db.location.location | urlsplit('hostname') }}" + object: "{{ atl_backup_manifest.artifacts.db.location.location | urlsplit('path') }}" dest: "{{ atl_backup_db_dest }}" - name: Fetch Home backup from S3 aws_s3: mode: get overwrite: different - bucket: "{{ atl_backup_manifest.artifacts.sharedHome.location.value | urlsplit('hostname') }}" - object: "{{ atl_backup_manifest.artifacts.sharedHome.location.value | urlsplit('path') }}" + bucket: "{{ atl_backup_manifest.artifacts.sharedHome.location.location | urlsplit('hostname') }}" + object: "{{ atl_backup_manifest.artifacts.sharedHome.location.location | urlsplit('path') }}" dest: "{{ atl_backup_home_dest }}" - name: Install distro-specific restore support packages From 96e006cbb31b798fa846c51c08ddf2d7844953dc Mon Sep 17 00:00:00 2001 From: Ben Partridge Date: Wed, 13 Nov 2019 11:55:56 +1100 Subject: [PATCH 2/8] Sets python environment for amazon-linux-extras to system python --- roles/restore_backups/tasks/amazon.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/restore_backups/tasks/amazon.yml b/roles/restore_backups/tasks/amazon.yml index bf32125..2444212 100644 --- a/roles/restore_backups/tasks/amazon.yml +++ b/roles/restore_backups/tasks/amazon.yml @@ -5,3 +5,5 @@ command: amazon-linux-extras install -y "postgresql{{ postgres_version }}" args: creates: /usr/bin/psql + environment: + PYTHON: /bin/python From f3ced1534a717debb25aeb482e43c2988188472d Mon Sep 17 00:00:00 2001 From: Ben Partridge Date: Wed, 13 Nov 2019 12:03:48 +1100 Subject: [PATCH 3/8] DCD-796: Adds test for amazon-linux-extras install postgres --- .../molecule/restore/Dockerfile.j2 | 14 +++++++++ .../molecule/restore/molecule.yml | 30 +++++++++++++++++++ .../molecule/restore/playbook.yml | 11 +++++++ .../molecule/restore/tests/test_default.py | 16 ++++++++++ 4 files changed, 71 insertions(+) create mode 100644 roles/restore_backups/molecule/restore/Dockerfile.j2 create mode 100644 roles/restore_backups/molecule/restore/molecule.yml create mode 100644 roles/restore_backups/molecule/restore/playbook.yml create mode 100644 roles/restore_backups/molecule/restore/tests/test_default.py diff --git a/roles/restore_backups/molecule/restore/Dockerfile.j2 b/roles/restore_backups/molecule/restore/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/restore_backups/molecule/restore/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/restore_backups/molecule/restore/molecule.yml b/roles/restore_backups/molecule/restore/molecule.yml new file mode 100644 index 0000000..04c0973 --- /dev/null +++ b/roles/restore_backups/molecule/restore/molecule.yml @@ -0,0 +1,30 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: amazon_linux2 + image: amazonlinux:2 + groups: + - aws_node_local + ulimits: + - nofile:262144:262144 +provisioner: + name: ansible + options: + skip-tags: runtime_pkg + lint: + name: ansible-lint + options: + x: ["701"] + inventory: + links: + group_vars: ../../../../group_vars/ +verifier: + name: testinfra + lint: + name: flake8 + enabled: false diff --git a/roles/restore_backups/molecule/restore/playbook.yml b/roles/restore_backups/molecule/restore/playbook.yml new file mode 100644 index 0000000..b3c60b0 --- /dev/null +++ b/roles/restore_backups/molecule/restore/playbook.yml @@ -0,0 +1,11 @@ +--- +- name: Converge + hosts: all + vars: + atl_backup_manifest_url: 's3://dcd-slingshot-test/dummy_manifest.json' + atl_product_user: 'jira' + atl_backup_home_restore_canary_path: '/tmp/canary.tmp' + + tasks: + - name: Install distro-specific restore support packages + include_tasks: "../../tasks/{{ ansible_distribution|lower }}.yml" diff --git a/roles/restore_backups/molecule/restore/tests/test_default.py b/roles/restore_backups/molecule/restore/tests/test_default.py new file mode 100644 index 0000000..018ae24 --- /dev/null +++ b/roles/restore_backups/molecule/restore/tests/test_default.py @@ -0,0 +1,16 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +@pytest.mark.parametrize('exe', [ + '/usr/bin/pg_dump', + '/usr/bin/pg_restore', + '/usr/bin/psql' +]) +def test_postgresql_amazon_linux_extras_exes(host, exe): + assert host.file(exe).exists From b2b18e2cff13c4042f642a7222fe52b0ad869c80 Mon Sep 17 00:00:00 2001 From: Ben Partridge Date: Wed, 13 Nov 2019 13:10:43 +1100 Subject: [PATCH 4/8] DCD-796: Fix incorrect number of pipelines batches --- bitbucket-pipelines.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 408b078..0df8a14 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -14,7 +14,7 @@ pipelines: - step: name: Pre Parallelization stage script: - - echo "Running tests in 30 batches" + - echo "Running tests in 31 batches" - step: name: Check if number of batches match actual number of scenarios script: @@ -267,4 +267,11 @@ pipelines: - apt-get update && ./bin/install-ansible --dev - ./bin/run-tests-in-batches --batch 30 - + - step: + name: Molecule Test Batch - 31 + services: + - docker + script: + - apt-get update && ./bin/install-ansible --dev + - ./bin/run-tests-in-batches --batch 31 + From f4badd4667d58654707c7aa55b0627660c8c1dae Mon Sep 17 00:00:00 2001 From: Adam Brokes Date: Wed, 13 Nov 2019 14:52:44 +1100 Subject: [PATCH 5/8] DCD-803: Ignore COMMENT ON EXTENSION errors when restoring to RDS --- roles/restore_backups/tasks/main.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/restore_backups/tasks/main.yml b/roles/restore_backups/tasks/main.yml index c1587bd..6b28bb1 100644 --- a/roles/restore_backups/tasks/main.yml +++ b/roles/restore_backups/tasks/main.yml @@ -97,6 +97,10 @@ # Depends on fetch_backup roles state: restore target: "{{ atl_backup_db_dest }}" + register: result + failed_when: + - result.rc != 0 + - "COMMENT ON EXTENSION" not in result.msg when: db_created.changed and atl_backup_db_dest is defined From a0496644d4c45b9c030e68a2bcb8a17826827f3f Mon Sep 17 00:00:00 2001 From: Adam Brokes Date: Wed, 13 Nov 2019 15:28:47 +1100 Subject: [PATCH 6/8] DCD-803: Quote the statement --- roles/restore_backups/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/restore_backups/tasks/main.yml b/roles/restore_backups/tasks/main.yml index 6b28bb1..5b752ff 100644 --- a/roles/restore_backups/tasks/main.yml +++ b/roles/restore_backups/tasks/main.yml @@ -100,7 +100,7 @@ register: result failed_when: - result.rc != 0 - - "COMMENT ON EXTENSION" not in result.msg + - '"COMMENT ON EXTENSION" not in result.msg' when: db_created.changed and atl_backup_db_dest is defined From 1e3208d49e854234261f6f11657c8ca8b0fecfbe Mon Sep 17 00:00:00 2001 From: Ben Partridge Date: Wed, 13 Nov 2019 15:42:51 +1100 Subject: [PATCH 7/8] DCD-796: Implement test that pg_dump is the correct version --- roles/restore_backups/molecule/restore/tests/test_default.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/restore_backups/molecule/restore/tests/test_default.py b/roles/restore_backups/molecule/restore/tests/test_default.py index 018ae24..6f88a4f 100644 --- a/roles/restore_backups/molecule/restore/tests/test_default.py +++ b/roles/restore_backups/molecule/restore/tests/test_default.py @@ -14,3 +14,7 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( ]) def test_postgresql_amazon_linux_extras_exes(host, exe): assert host.file(exe).exists + +def test_postgresql_version(host): + pg_dump_version_output = host.check_output('pg_dump --version') + assert '(PostgreSQL) 9.6' in pg_dump_version_output From c1486e14ecc9a13907a56c64f168027c159c04ed Mon Sep 17 00:00:00 2001 From: Adam Brokes Date: Wed, 13 Nov 2019 15:49:00 +1100 Subject: [PATCH 8/8] DCD-803: Add explaining comment --- roles/restore_backups/tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/restore_backups/tasks/main.yml b/roles/restore_backups/tasks/main.yml index 5b752ff..1f9ebdb 100644 --- a/roles/restore_backups/tasks/main.yml +++ b/roles/restore_backups/tasks/main.yml @@ -98,6 +98,7 @@ state: restore target: "{{ atl_backup_db_dest }}" register: result + # managed DBs in cloud providers are not allowing full root access to the DB engine, we can safely ignore the COMMENT ON EXTENSION error failed_when: - result.rc != 0 - '"COMMENT ON EXTENSION" not in result.msg'