Changeset - b7ca7da98606
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-09-15 20:51:00
branko@majic.rs
Noticket: Quick-fix for preseed role tests until MAR-155 (Do not use paths based on home directory and inventory directory with optional parameters) is implemented.
1 file changed with 6 insertions and 3 deletions:
0 comments (0 inline, 0 general)
roles/preseed/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
import os
 
import pwd
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory')
 
@@ -16,13 +17,14 @@ def test_preseed_directory(host):
 

	
 
        # Preseed directory created at same level as inventory.
 
        # @TODO: At this point, this path is getting uglier and
 
        #        uglier. It might be actually better to make the
 
        #        preseed_directory a mandatory parameter instead. Same
 
        #        goes for the ansible_key role parameter as well.
 
        preseed_directory = host.file(os.path.join('/tmp/molecule/preseed/default/inventory', 'preseed_files'))
 
        preseed_directory_path = "%s/.cache/molecule/preseed/default/inventory/preseed_files" % pwd.getpwuid(os.getuid()).pw_dir
 
        preseed_directory = host.file(preseed_directory_path)
 

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

	
 

	
 
def test_preseed_configuration_files(host):
 
@@ -30,13 +32,13 @@ def test_preseed_configuration_files(host):
 
    Tests presence and permissions on created preseed configuration files.
 
    """
 

	
 
    with host.sudo():
 

	
 
        # Preseed directory created at same level as inventory.
 
        preseed_directory_path = os.path.join('/tmp/molecule/preseed/default/inventory', 'preseed_files')
 
        preseed_directory_path = "%s/.cache/molecule/preseed/default/inventory/preseed_files" % pwd.getpwuid(os.getuid()).pw_dir
 

	
 
        # 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_path, "%s.cfg" % testinfra_host))
 

	
 
@@ -49,13 +51,14 @@ def test_preseed_configuration_file_content(host):
 
    Tests content of generated preseed configuration file.
 
    """
 

	
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    with host.sudo():
 
        preseed_file = host.file(os.path.join("/tmp/molecule/preseed/default/inventory", "preseed_files", "%s.cfg" % hostname))
 
        preseed_directory_path = "%s/.cache/molecule/preseed/default/inventory/preseed_files" % pwd.getpwuid(os.getuid()).pw_dir
 
        preseed_file = host.file(os.path.join(preseed_directory_path, "%s.cfg" % hostname))
 
        preseed_file_content = preseed_file.content_string
 
        ssh_public_key = open(os.path.join(os.path.expanduser("~"), ".ssh", "id_rsa.pub")).read().strip()
 

	
 
    assert "d-i debian-installer/language string en" in preseed_file_content
 
    assert "d-i debian-installer/country string SE" in preseed_file_content
 
    assert "d-i debian-installer/locale string en_US.UTF-8" in preseed_file_content
0 comments (0 inline, 0 general)