From 19f5f9cab18921ccfea99a4f5c862043234de311 2020-10-02 22:00:41 From: Branko Majic Date: 2020-10-02 22:00:41 Subject: [PATCH] MAR-159: Set-up defaults for wsgi_requirements and update tests: - Set defaults for the wsgi_requirements parameter (for running using Python 2). - Drop the use of futures_version and gunicorn_version from the Molecule tests. - Updated and deduplicated tests related to testing of installed/requested futures and gunicorn package versions. --- diff --git a/roles/wsgi_website/defaults/main.yml b/roles/wsgi_website/defaults/main.yml index b62bfe8dc71a21cef8cbdd379307ca5c8dd87bd2..8d483359aa24f7405e737d057389201bb3d02720 100644 --- a/roles/wsgi_website/defaults/main.yml +++ b/roles/wsgi_website/defaults/main.yml @@ -14,7 +14,9 @@ website_mail_recipients: "root" environment_indicator: null proxy_headers: {} python_version: 2 -wsgi_requirements: [] +wsgi_requirements: + - futures==3.3.0 + - gunicorn==19.10.0 # Internal parameters. admin: "admin-{{ fqdn | replace('.', '_') }}" diff --git a/roles/wsgi_website/molecule/default/playbook.yml b/roles/wsgi_website/molecule/default/playbook.yml index 762c4a6f8006ea84cfd5da7952f74c554bf29ade..55238a7ac667c52396594f2dcf933d86221419c1 100644 --- a/roles/wsgi_website/molecule/default/playbook.yml +++ b/roles/wsgi_website/molecule/default/playbook.yml @@ -33,8 +33,6 @@ text: "parameters-optional" environment_variables: MY_ENV_VAR: "My environment variable" - futures_version: 3.1.0 - gunicorn_version: 19.7.0 packages: - "libmariadbclient-dev-compat" - global @@ -62,7 +60,9 @@ - wcwidth==0.1.7 website_mail_recipients: user wsgi_application: testapp:application - wsgi_requirements: [] + wsgi_requirements: + - futures==3.1.1 + - gunicorn==20.0.4 python_version: 3 - role: wsgi_website @@ -81,8 +81,8 @@ - Werkzeug==0.12.2 wsgi_application: config.ini wsgi_requirements: - - futures==3.1.0 - - gunicorn==19.7.0 + - futures==3.1.1 + - gunicorn==19.8.1 https_tls_certificate: "{{ lookup('file', 'tests/data/x509/server/parameters-paste-req_https.cert.pem') }}" https_tls_key: "{{ lookup('file', 'tests/data/x509/server/parameters-paste-req_https.key.pem') }}" diff --git a/roles/wsgi_website/molecule/default/tests/test_default.py b/roles/wsgi_website/molecule/default/tests/test_default.py index 9c1ba7e5f70b50c43d82263c05746d1093133680..9b9a20f4b76ae6d90a61435b7ca85f5a84fde247 100644 --- a/roles/wsgi_website/molecule/default/tests/test_default.py +++ b/roles/wsgi_website/molecule/default/tests/test_default.py @@ -297,15 +297,15 @@ def test_python_virtualenv_wrapper_script(host, wrapper_script, expected_owner, @pytest.mark.parametrize("admin_user, pip_path, expected_packages", [ ('admin-parameters-mandatory', '/var/www/parameters-mandatory/virtualenv/bin/pip', [ - "futures==3.2.0", - "gunicorn==19.9.0", + "futures==3.3.0", + "gunicorn==19.10.0", ]), ('admin-parameters-optional_local', '/var/www/parameters-optional.local/virtualenv/bin/pip', [ "Pygments==2.2.0", "dnspython==1.15.0", "docopt==0.6.2", - "futures==3.1.0", - "gunicorn==19.7.0", + "futures==3.1.1", + "gunicorn==20.0.4", "jedi==0.13.1", "parso==0.3.1", "prompt-toolkit==1.0.15", @@ -322,8 +322,8 @@ def test_python_virtualenv_wrapper_script(host, wrapper_script, expected_owner, "PasteScript==2.0.2", "Werkzeug==0.12.2", "click==6.7", - "futures==3.1.0", - "gunicorn==19.7.0", + "futures==3.1.1", + "gunicorn==19.8.1", "itsdangerous==0.24", "six==1.10.0", ]), @@ -342,21 +342,6 @@ def test_virtualenv_packages(host, admin_user, pip_path, expected_packages): assert actual_packages == expected_packages -@pytest.mark.parametrize('check_config_dir', [ - '/etc/pip_check_requirements_upgrades/parameters-mandatory', - '/etc/pip_check_requirements_upgrades/parameters-optional.local', -]) -def test_wsgi_requirements_upgrade_checks(host, check_config_dir): - """ - Tests if Python requirements files for upgrade checks are set-up - correctly (absent when not configured). - """ - - with host.sudo(): - directory = host.file(check_config_dir) - assert not directory.exists - - @pytest.mark.parametrize("config_file, expected_website_name, expected_socket_file_path", [ ('/etc/systemd/system/parameters-mandatory.socket', 'parameters-mandatory', '/run/wsgi/parameters-mandatory.sock'), ('/etc/systemd/system/parameters-optional.local.socket', 'parameters-optional.local', '/run/wsgi/parameters-optional.local.sock'), @@ -554,3 +539,47 @@ def test_python_version_in_virtualenv(host, python_path, expected_version): # Python 2 outputs version to stderr, Python 3 outputs it to # stdout. Go figure. assert expected_version in python_version.stdout or expected_version in python_version.stderr + + +@pytest.mark.parametrize("fqdn, expected_packages", [ + ("parameters-mandatory", ["futures==3.3.0", "gunicorn==19.10.0"]), + ("parameters-optional.local", ["futures==3.1.1", "gunicorn==20.0.4"]), + ("parameters-paste-req", ["futures==3.1.1", "gunicorn==19.8.1"]), +]) +def test_wsgi_requirements(host, fqdn, expected_packages): + """ + Tests if Python requirements files are set-up correctly (for both + installation and upgrade checks). + """ + + with host.sudo(): + directory = host.file('/etc/pip_check_requirements_upgrades/%s' % fqdn) + assert directory.is_directory + assert directory.user == 'root' + assert directory.group == 'pipreqcheck' + assert directory.mode == 0o750 + + config = host.file('/etc/pip_check_requirements_upgrades/%s/wsgi_requirements.in' % fqdn) + assert config.is_file + assert config.user == 'root' + assert config.group == 'pipreqcheck' + assert config.mode == 0o640 + assert config.content_string == "futures\ngunicorn\n" + + config = host.file('/etc/pip_check_requirements_upgrades/%s/wsgi_requirements.txt' % fqdn) + assert config.is_file + assert config.user == 'root' + assert config.group == 'pipreqcheck' + assert config.mode == 0o640 + + check_packages = config.content_string.strip().split("\n") + assert check_packages == expected_packages + + requirements = host.file('/var/www/%s/.wsgi_requirements.txt' % fqdn) + assert requirements.is_file + assert requirements.user == 'admin-%s' % fqdn.replace(".", "_") + assert requirements.group == 'web-%s' % fqdn.replace(".", "_") + assert requirements.mode == 0o640 + + install_packages = requirements.content_string.strip().split("\n") + assert install_packages == expected_packages diff --git a/roles/wsgi_website/molecule/default/tests/test_parameters_paste_req.py b/roles/wsgi_website/molecule/default/tests/test_parameters_paste_req.py index 0fbfce9d8c07ee93bdb0eb99569081e8511749bc..b6bf3065dacbe8ff2499296ea3e396c4ce6dbde1 100644 --- a/roles/wsgi_website/molecule/default/tests/test_parameters_paste_req.py +++ b/roles/wsgi_website/molecule/default/tests/test_parameters_paste_req.py @@ -7,49 +7,6 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') -def test_wsgi_requirements_upgrade_checks(host): - """ - Tests if Python requirements files for upgrade checks are set-up correctly. - """ - - with host.sudo(): - directory = host.file('/etc/pip_check_requirements_upgrades/parameters-paste-req') - assert directory.is_directory - assert directory.user == 'root' - assert directory.group == 'pipreqcheck' - assert directory.mode == 0o750 - - config = host.file('/etc/pip_check_requirements_upgrades/parameters-paste-req/wsgi_requirements.in') - assert config.is_file - assert config.user == 'root' - assert config.group == 'pipreqcheck' - assert config.mode == 0o640 - assert config.content_string == "gunicorn\nfutures\n" - - config = host.file('/etc/pip_check_requirements_upgrades/parameters-paste-req/wsgi_requirements.txt') - assert config.is_file - assert config.user == 'root' - assert config.group == 'pipreqcheck' - assert config.mode == 0o640 - assert config.content_string == "futures==3.1.0\ngunicorn==19.7.0\n" - - -def test_gunicorn_requirements_installation_file(host): - """ - Tests if requirements file for installing Gunicorn has been deployed - correctly. - """ - - with host.sudo(): - - requirements = host.file('/var/www/parameters-paste-req/.wsgi_requirements.txt') - assert requirements.is_file - assert requirements.user == 'admin-parameters-paste-req' - assert requirements.group == 'web-parameters-paste-req' - assert requirements.mode == 0o640 - assert requirements.content_string == "futures==3.1.0\ngunicorn==19.7.0\n" - - def test_index_page(host): """ Tests if index page is served correctly. This covers: diff --git a/roles/wsgi_website/templates/wsgi_requirements.in.j2 b/roles/wsgi_website/templates/wsgi_requirements.in.j2 index e2f4cc25f9fd87ce5b150670aad830b65a87c5ba..a1aba3a63a9245813ca7791e0047a7f5f8818988 100644 --- a/roles/wsgi_website/templates/wsgi_requirements.in.j2 +++ b/roles/wsgi_website/templates/wsgi_requirements.in.j2 @@ -1,2 +1,2 @@ -gunicorn futures +gunicorn