Changeset - d47bd45e61b3
[Not reviewed]
0 3 1
Branko Majic (branko) - 3 years ago 2021-01-12 23:35:58
branko@majic.rs
MAR-163: Deduplicate tests for the preseed directory in preseed role:

- Run a single test on all three servers.
- Explicitly specify the preseed directory path (instead of using
constant).
4 files changed with 25 insertions and 50 deletions:
0 comments (0 inline, 0 general)
roles/preseed/molecule/default/tests/test_default.py
Show inline comments
 
new file 100644
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-*')
 

	
 

	
 
def test_preseed_directory(host):
 
    """
 
    Tests presence and permissions on created preseed directory.
 
    """
 

	
 
    with host.sudo():
 

	
 
        preseed_directory_path = "/tmp/preseed_files"
 
        preseed_directory = host.file(preseed_directory_path)
 

	
 
        assert preseed_directory.is_directory
 
        assert preseed_directory.mode == 0o750
roles/preseed/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
@@ -7,20 +7,6 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory')
 

	
 

	
 
def test_preseed_directory(host):
 
    """
 
    Tests presence and permissions on created preseed directory.
 
    """
 

	
 
    with host.sudo():
 

	
 
        preseed_directory_path = "/tmp/preseed_files"
 
        preseed_directory = host.file(preseed_directory_path)
 

	
 
        assert preseed_directory.is_directory
 
        assert preseed_directory.mode == 0o750
 

	
 

	
 
def test_preseed_configuration_files(host):
 
    """
 
    Tests presence and permissions on created preseed configuration files.
roles/preseed/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
@@ -7,22 +7,6 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional')
 

	
 

	
 
PRESEED_DIRECTORY = '/tmp/preseed_files'
 

	
 

	
 
def test_preseed_directory(host):
 
    """
 
    Test presence and permissions of preseed directory.
 
    """
 

	
 
    with host.sudo():
 

	
 
        preseed_directory = host.file(PRESEED_DIRECTORY)
 

	
 
        assert preseed_directory.is_directory
 
        assert preseed_directory.mode == 0o750
 

	
 

	
 
def test_preseed_configuration_files(host):
 
    """
 
    Tests presence and permissions on created preseed configuration files.
 
@@ -33,7 +17,7 @@ def test_preseed_configuration_files(host):
 
        # Verify that preseed configuration files are created for all hosts.
 
        for testinfra_host in testinfra_hosts:
 

	
 
            preseed_file = host.file(os.path.join(PRESEED_DIRECTORY, "%s.cfg" % testinfra_host))
 
            preseed_file = host.file(os.path.join("/tmp/preseed_files", "%s.cfg" % testinfra_host))
 

	
 
            assert preseed_file.is_file
 
            assert preseed_file.mode == 0o640
 
@@ -47,7 +31,7 @@ def test_preseed_configuration_file_content(host):
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    with host.sudo():
 
        preseed_file = host.file(os.path.join(PRESEED_DIRECTORY, "%s.cfg" % hostname))
 
        preseed_file = host.file(os.path.join("/tmp/preseed_files", "%s.cfg" % hostname))
 
        preseed_file_content = preseed_file.content_string
 
        ssh_public_key = "MY_ANSIBLE_KEY"
 

	
roles/preseed/molecule/default/tests/test_parameters_optional_with_overrides.py
Show inline comments
 
@@ -7,22 +7,6 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional-with-overrides')
 

	
 

	
 
PRESEED_DIRECTORY = '/tmp/preseed_files'
 

	
 

	
 
def test_preseed_directory(host):
 
    """
 
    Test presence and permissions of preseed directory.
 
    """
 

	
 
    with host.sudo():
 

	
 
        preseed_directory = host.file(PRESEED_DIRECTORY)
 

	
 
        assert preseed_directory.is_directory
 
        assert preseed_directory.mode == 0o750
 

	
 

	
 
def test_preseed_configuration_file_content_host_without_overrides(host):
 
    """
 
    Tests content of generated preseed configuration file.
 
@@ -31,7 +15,7 @@ def test_preseed_configuration_file_content_host_without_overrides(host):
 
    hostname = 'parameters-mandatory-stretch64'
 

	
 
    with host.sudo():
 
        preseed_file = host.file(os.path.join(PRESEED_DIRECTORY, "%s.cfg" % hostname))
 
        preseed_file = host.file(os.path.join("/tmp/preseed_files", "%s.cfg" % hostname))
 
        preseed_file_content = preseed_file.content_string
 
        ssh_public_key = "MY_ANSIBLE_KEY"
 

	
 
@@ -63,7 +47,7 @@ def test_preseed_configuration_file_content_host_with_overrides(host):
 
    hostname = 'parameters-optional-with-overrides-stretch64'
 

	
 
    with host.sudo():
 
        preseed_file = host.file(os.path.join(PRESEED_DIRECTORY, "%s.cfg" % hostname))
 
        preseed_file = host.file(os.path.join("/tmp/preseed_files", "%s.cfg" % hostname))
 
        preseed_file_content = preseed_file.content_string
 
        ssh_public_key = "MY_ANSIBLE_KEY"
 

	
0 comments (0 inline, 0 general)