Changeset - e1dd478473a2
[Not reviewed]
0 2 2
Branko Majic (branko) - 7 years ago 2017-06-13 11:34:30
branko@majic.rs
MAR-109: Implemented tests for backup role.
4 files changed with 89 insertions and 6 deletions:
0 comments (0 inline, 0 general)
roles/backup/tasks/main.yml
Show inline comments
 
@@ -2,6 +2,6 @@
 

	
 
- name: Configure backup patterns
 
  template: src="backup_patterns.j2" dest="/etc/duply/main/patterns/{{ backup_patterns_filename }}"
 
            owner="root" group="root" mode=0700
 
            owner="root" group="root" mode=0600
 
  notify:
 
    - Assemble Duply include patterns
roles/backup/tests/test_default.py
Show inline comments
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory').get_hosts('all')
 

	
 

	
 
def test_hosts_file(File):
 
    f = File('/etc/hosts')
 
def test_backup_patterns_file(File, Sudo):
 
    """
 
    Tests if deployed file with backup patterns has correct permissions.
 
    """
 

	
 
    with Sudo():
 

	
 
        backup_pattern = File('/etc/duply/main/patterns/test')
 

	
 
        assert backup_pattern.is_file
 
        assert backup_pattern.user == 'root'
 
        assert backup_pattern.group == 'root'
 
        assert backup_pattern.mode == 0o600
 

	
 

	
 
def test_include_file(File, Sudo):
 
    """
 
    Tests if assembled include file has correct permissions.
 
    """
 

	
 
    with Sudo():
 

	
 
        include = File('/etc/duply/main/include')
 

	
 
    assert f.exists
 
    assert f.user == 'root'
 
    assert f.group == 'root'
 
        assert include.is_file
 
        assert include.user == 'root'
 
        assert include.group == 'root'
 
        assert include.mode == 0o600
roles/backup/tests/test_parameters_mandatory.py
Show inline comments
 
new file 100644
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory').get_hosts('parameters-mandatory')
 

	
 

	
 
def test_backup_patterns_content(File, Sudo):
 
    """
 
    Tests if content of file containing backup patterns is correct.
 
    """
 

	
 
    with Sudo():
 

	
 
        backup_pattern = File('/etc/duply/main/patterns/test')
 

	
 
        assert backup_pattern.content == ''
 

	
 

	
 
def test_include_content(File, Sudo):
 
    """
 
    Tests if content of assembled include file containing backup patterns is
 
    correct.
 
    """
 

	
 
    with Sudo():
 

	
 
        include = File('/etc/duply/main/include')
 

	
 
        assert include.content == ''
roles/backup/tests/test_parameters_optional.py
Show inline comments
 
new file 100644
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory').get_hosts('parameters-optional')
 

	
 

	
 
def test_backup_patterns_content(File, Sudo):
 
    """
 
    Tests if content of file containing backup patterns is correct.
 
    """
 

	
 
    with Sudo():
 

	
 
        backup_pattern = File('/etc/duply/main/patterns/test')
 

	
 
        assert backup_pattern.content == "/etc/hosts\n/etc/ethers\n/var/log"
 

	
 

	
 
def test_include_content(File, Sudo):
 
    """
 
    Tests if content of assembled include file containing backup patterns is
 
    correct.
 
    """
 

	
 
    with Sudo():
 

	
 
        include = File('/etc/duply/main/include')
 

	
 
        assert include.content == "/etc/hosts\n/etc/ethers\n/var/log"
0 comments (0 inline, 0 general)