Changeset - 23bc0fa0d5c7
[Not reviewed]
0 6 0
Branko Majic (branko) - 4 years ago 2020-10-03 13:40:56
branko@majic.rs
MAR-159: Added wsgi_requirements_in parameter to wsgi_website role:

- Added the parameter as optional.
- Updated role reference documentation.
- Updated release notes.
- Updated tests.
6 files changed with 32 insertions and 12 deletions:
0 comments (0 inline, 0 general)
docs/releasenotes.rst
Show inline comments
 
@@ -76,6 +76,11 @@ Breaking changes:
 
    deprecated and removed. Existing roles should be updated to
 
    utilise the ``wsgi_requirements`` parameter instead.
 

	
 
  * Added parameter ``wsgi_requirements_in`` for listing top-level
 
    packages for performing pip requirements upgrade checks for
 
    Gunicorn requirements (listed via existing ``wsgi_requirements``
 
    parameter).
 

	
 
* ``xmpp_server`` role
 

	
 
  * Use 2048-bit Diffie-Hellman parameters for relevant TLS
docs/rolereference.rst
Show inline comments
 
@@ -1900,6 +1900,13 @@ Parameters
 
  <https://github.com/jazzband/pip-tools>`_ (the ``pip-compile`` utility) with
 
  ``gunicorn`` and ``futures`` in the ``.in.`` file.
 

	
 
**wsgi_requirements_in** (list, optional, ``[ futures, gunicorn ]``)
 
  List of top level packages to use when performing the pip
 
  requirements upgrade checks for the Gunicorn requirements (listed
 
  via ``wsgi_requirements`` parameter). For Python 3-based websites,
 
  it should be sufficient to list only ``gunicorn`` (``futures`` is
 
  required for Python 2).
 

	
 

	
 
Distribution compatibility
 
~~~~~~~~~~~~~~~~~~~~~~~~~~
roles/wsgi_website/defaults/main.yml
Show inline comments
 
@@ -15,6 +15,9 @@ python_version: 2
 
wsgi_requirements:
 
  - futures==3.3.0
 
  - gunicorn==19.10.0
 
wsgi_requirements_in:
 
  - futures
 
  - gunicorn
 

	
 
# Internal parameters.
 
admin: "admin-{{ fqdn | replace('.', '_') }}"
roles/wsgi_website/molecule/default/playbook.yml
Show inline comments
 
@@ -63,6 +63,8 @@
 
      wsgi_requirements:
 
        - futures==3.1.1
 
        - gunicorn==20.0.4
 
      wsgi_requirements_in:
 
        - gunicorn
 
      python_version: 3
 

	
 
    - role: wsgi_website
roles/wsgi_website/molecule/default/tests/test_default.py
Show inline comments
 
@@ -541,12 +541,12 @@ def test_python_version_in_virtualenv(host, python_path, expected_version):
 
        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"]),
 
@pytest.mark.parametrize("fqdn, expected_requirements_in, expected_requirements", [
 
    ("parameters-mandatory", ["futures", "gunicorn"], ["futures==3.3.0", "gunicorn==19.10.0"]),
 
    ("parameters-optional.local", ["gunicorn"], ["futures==3.1.1", "gunicorn==20.0.4"]),
 
    ("parameters-paste-req", ["futures", "gunicorn"], ["futures==3.1.1", "gunicorn==19.8.1"]),
 
])
 
def test_wsgi_requirements(host, fqdn, expected_packages):
 
def test_wsgi_requirements(host, fqdn, expected_requirements_in, expected_requirements):
 
    """
 
    Tests if Python requirements files are set-up correctly (for both
 
    installation and upgrade checks).
 
@@ -564,7 +564,9 @@ def test_wsgi_requirements(host, fqdn, expected_packages):
 
        assert config.user == 'root'
 
        assert config.group == 'pipreqcheck'
 
        assert config.mode == 0o640
 
        assert config.content_string == "futures\ngunicorn\n"
 

	
 
        check_requirements_in = config.content_string.strip().split("\n")
 
        assert check_requirements_in == expected_requirements_in
 

	
 
        config = host.file('/etc/pip_check_requirements_upgrades/%s/wsgi_requirements.txt' % fqdn)
 
        assert config.is_file
 
@@ -572,8 +574,8 @@ def test_wsgi_requirements(host, fqdn, expected_packages):
 
        assert config.group == 'pipreqcheck'
 
        assert config.mode == 0o640
 

	
 
        check_packages = config.content_string.strip().split("\n")
 
        assert check_packages == expected_packages
 
        check_requirements = config.content_string.strip().split("\n")
 
        assert check_requirements == expected_requirements
 

	
 
        requirements = host.file('/var/www/%s/.wsgi_requirements.txt' % fqdn)
 
        assert requirements.is_file
 
@@ -581,5 +583,5 @@ def test_wsgi_requirements(host, fqdn, expected_packages):
 
        assert requirements.group == 'web-%s' % fqdn.replace(".", "_")
 
        assert requirements.mode == 0o640
 

	
 
        install_packages = requirements.content_string.strip().split("\n")
 
        assert install_packages == expected_packages
 
        install_requirements = requirements.content_string.strip().split("\n")
 
        assert install_requirements == expected_requirements
roles/wsgi_website/templates/wsgi_requirements.in.j2
Show inline comments
 
futures
 
gunicorn
 
{% for requirement in wsgi_requirements_in %}
 
{{ requirement }}
 
{% endfor %}
0 comments (0 inline, 0 general)