DCD-802: Fix test and implementation for setting shared home owner and

group to application user
This commit is contained in:
Ben Partridge
2019-11-18 16:37:26 +11:00
parent 41cd616a60
commit 4827ae8423
4 changed files with 101 additions and 34 deletions

View File

@@ -4,7 +4,58 @@
vars:
atl_backup_manifest_url: 's3://dcd-slingshot-test/dummy_manifest.json'
atl_product_user: 'jira'
atl_product_user_uid: '2001'
atl_backup_home_restore_canary_path: '/tmp/canary.tmp'
atl_product_home_shared: '/media/atl/jira/shared'
atl_backup_id: 'test-backup'
atl_backup_home_dest: "{{ test_archive }}"
roles:
- restore_backups
test_archive_source: '/tmp/hello'
test_archive_file: 'hello.txt'
test_archive: '/tmp/hello.tar.gz'
test_pre_step_prefix: '[PRE-TEST]'
pre_tasks:
- name: "{{ test_pre_step_prefix }} Install tar"
package:
state: present
name: tar
- name: "{{ test_pre_step_prefix }} Install useradd and groupadd binaries"
package:
state: present
name: shadow-utils
- name: "{{ test_pre_step_prefix }} Create application group"
group:
name: "{{ atl_product_user }}"
gid: "{{ atl_product_user_uid }}"
- name: "{{ test_pre_step_prefix }} Create application user"
user:
name: "{{ atl_product_user }}"
uid: "{{ atl_product_user_uid }}"
group: "{{ atl_product_user }}"
- block:
- name: "{{ test_pre_step_prefix }} Create a directory for the shared home archive"
file:
path: "{{ test_archive_source }}"
state: directory
- name: "{{ test_pre_step_prefix }} Create a file in the shared home"
lineinfile:
create: yes
line: 'Hello, world!'
path: "{{ test_archive_source }}/{{ test_archive_file }}"
- name: "{{ test_pre_step_prefix }} Archive the shared home"
archive:
path: "{{ test_archive_source }}"
dest: "{{ test_archive }}"
owner: "{{ atl_product_user }}"
tasks:
- name: Install distro-specific restore support packages
include_tasks: "../../tasks/{{ ansible_distribution|lower }}.yml"
- name: Restore shared home
include_tasks: "../../tasks/home_restore.yml"

View File

@@ -19,8 +19,12 @@ def test_postgresql_version(host):
pg_dump_version_output = host.check_output('pg_dump --version')
assert '(PostgreSQL) 9.6' in pg_dump_version_output
def test_shared_home_owner(host):
for root, dirs, files in os.walk('/media/atl/jira/shared'):
for fileName in files + dirs:
assert host.file(fileName).user == 'jira'
assert host.file(fileName).group == 'jira'
@pytest.mark.parametrize('file', [
'/media/atl/jira/shared',
'/media/atl/jira/shared/hello',
'/media/atl/jira/shared/hello/hello.txt'
])
def test_shared_home_owner(host, file):
assert host.file(file).exists
assert host.file(file).user == 'jira'
assert host.file(file).group == 'jira'

View File

@@ -0,0 +1,37 @@
---
- name: Check for the restore canary file
stat:
path: "{{ atl_backup_home_restore_canary_path }}"
register: restore_canary
- block:
- name: Create shared home if necessary
file:
path: "{{ atl_product_home_shared }}"
state: directory
mode: 0750
owner: "{{ atl_product_user }}"
group: "{{ atl_product_user }}"
- name: Restore the shared-home backup
unarchive:
src: "{{ atl_backup_home_dest }}"
remote_src: yes
dest: "{{ atl_product_home_shared }}"
mode: 0640
- name: Set shared home file owner to application user
file:
path: "{{ atl_product_home_shared }}"
recurse: yes
group: "{{ atl_product_user }}"
state: directory
mode: 0640
owner: "{{ atl_product_user }}"
- name: Create restore-canary if necessary
copy:
dest: "{{ atl_backup_home_restore_canary_path }}"
content: "{{ atl_backup_id }}"
when: not restore_canary.stat.exists

View File

@@ -108,33 +108,8 @@
when: db_created.changed and atl_backup_db_dest is defined
- name: Check for the restore canary file
stat:
path: "{{ atl_backup_home_restore_canary_path }}"
register: restore_canary
- block:
- name: Create shared home if necessary
file:
path: "{{ atl_product_home_shared }}"
state: directory
mode: 0750
owner: "{{ atl_product_user }}"
group: "{{ atl_product_user }}"
- name: Restore the shared-home backup
unarchive:
src: "{{ atl_backup_home_dest }}"
dest: "{{ atl_product_home_shared }}"
become: "{{ atl_product_user }}"
- name: Create restore-canary if necessary
copy:
dest: "{{ atl_backup_home_restore_canary_path }}"
content: "{{ atl_backup_id }}"
when: not restore_canary.stat.exists
- name: Restore shared home
include_tasks: "{{ home_restore.yml }}"
when: atl_restore_required