Changeset - 6e57b636d3a7
[Not reviewed]
0 4 0
Branko Majic (branko) - 6 years ago 2018-05-27 19:23:56
branko@majic.rs
MAR-129: Updated backup_client role tests:

- Update how the hosts are being referenced in tests (for limiting the
test runs).
- Use "state: present" for package presence/installation.
- Break-up long lines in tasks so they are under 160 characters
length.
- Fixed YAML linting issues.
4 files changed with 19 insertions and 12 deletions:
0 comments (0 inline, 0 general)
roles/backup_client/molecule/default/tests/test_default.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('all')
 
testinfra_hosts.remove('backup-server')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory', 'parameters-optional'])
 

	
 

	
 
def test_installed_packages(host):
roles/backup_client/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('parameters-mandatory')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory'])
 

	
 

	
 
def test_gnupg_private_keys_file_content(host):
roles/backup_client/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('parameters-optional')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-optional'])
 

	
 

	
 
def test_gnupg_private_keys_file_content(host):
roles/backup_client/tasks/main.yml
Show inline comments
 
@@ -3,12 +3,12 @@
 
- name: Install pexpect for pexpect+sftp Duplicity backend (mainly needed on Stretch)
 
  apt:
 
    name: "python-pexpect"
 
    state: installed
 
    state: present
 

	
 
- name: Install backup software
 
  apt:
 
    name: "{{ item }}"
 
    state: installed
 
    state: present
 
  with_items:
 
    - duplicity
 
    - duply
 
@@ -54,16 +54,18 @@
 
    - Import public keys
 

	
 
- name: Extract encryption key identifier (Duplicty requires key ID in hexadecimal format)
 
  shell: "{{ gnupg_binary }} --list-packets /etc/duply/main/private_keys.asc | grep keyid: | head -n1 | sed -e 's/.*: //' | sed -re 's/^.{{ '{' + gnupg_key_cutoff + '}' }}//'"
 
  shell: "{{ gnupg_binary }} --list-packets /etc/duply/main/private_keys.asc | grep keyid: |
 
    head -n1 | sed -e 's/.*: //' | sed -re 's/^.{{ '{' + gnupg_key_cutoff + '}' }}//'"
 
  register: backup_encryption_key_id
 
  changed_when: False
 
  changed_when: false
 
  failed_when: backup_encryption_key_id.stdout == ""
 

	
 
- name: Extract additional encryption keys identifiers (Duplicty requires key ID in hexadecimal format)
 
  shell: "{{ gnupg_binary }} --list-packets /etc/duply/main/public_keys.asc | grep keyid: | sed -e 's/.*: //' | sort -u | sed -re 's/^.{{ '{' + gnupg_key_cutoff + '}' }}//' | tr '\n' ',' | sed -e 's/,$//'"
 
  shell: "{{ gnupg_binary }} --list-packets /etc/duply/main/public_keys.asc | grep keyid: |
 
    sed -e 's/.*: //' | sort -u | sed -re 's/^.{{ '{' + gnupg_key_cutoff + '}' }}//' | tr '\n' ',' | sed -e 's/,$//'"
 
  when: backup_additional_encryption_keys
 
  register: backup_additional_encryption_keys_ids
 
  changed_when: False
 
  changed_when: false
 
  failed_when: backup_additional_encryption_keys_ids.stdout == ""
 

	
 
- name: Deploy private SSH key for logging-in into backup server
 
@@ -73,7 +75,7 @@
 
    owner: root
 
    group: root
 
    mode: 0600
 
  no_log: True
 
  no_log: true
 

	
 
- name: Deploy custom known_hosts for backup purposes
 
  template:
 
@@ -129,7 +131,7 @@
 
  copy:
 
    content: ""
 
    dest: /etc/duply/main/include
 
    force: no
 
    force: false
 
    group: root
 
    owner: root
 
    mode: 0600
0 comments (0 inline, 0 general)