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
 
@@ -73,12 +73,17 @@ Breaking changes:
 
* ``wsgi_website`` role
 

	
 
  * Parameters ``gunicorn_version`` and ``futures_version`` have been
 
    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
 
    ciphers. This could introduce incompatibility with older
 
    clients/servers trying to connect to the XMPP server.
 

	
docs/rolereference.rst
Show inline comments
 
@@ -1897,12 +1897,19 @@ Parameters
 
  ``.wsgi_requirements.txt``.
 

	
 
  To create complete requirements list, it is recommended to use `pip-tools
 
  <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
 
~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
Role is compatible with the following distributions:
 

	
roles/wsgi_website/defaults/main.yml
Show inline comments
 
@@ -12,12 +12,15 @@ website_mail_recipients: "root"
 
environment_indicator: null
 
proxy_headers: {}
 
python_version: 2
 
wsgi_requirements:
 
  - futures==3.3.0
 
  - gunicorn==19.10.0
 
wsgi_requirements_in:
 
  - futures
 
  - gunicorn
 

	
 
# Internal parameters.
 
admin: "admin-{{ fqdn | replace('.', '_') }}"
 
user: "web-{{ fqdn | replace('.', '_') }}"
 
home: "/var/www/{{ fqdn }}"
 
python_interpreter: "/usr/bin/python{{ python_version }}"
roles/wsgi_website/molecule/default/playbook.yml
Show inline comments
 
@@ -60,12 +60,14 @@
 
        - wcwidth==0.1.7
 
      website_mail_recipients: user
 
      wsgi_application: testapp:application
 
      wsgi_requirements:
 
        - futures==3.1.1
 
        - gunicorn==20.0.4
 
      wsgi_requirements_in:
 
        - gunicorn
 
      python_version: 3
 

	
 
    - role: wsgi_website
 
      fqdn: parameters-paste-req
 
      use_paste: true
 
      virtualenv_packages:
roles/wsgi_website/molecule/default/tests/test_default.py
Show inline comments
 
@@ -538,18 +538,18 @@ 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"]),
 
@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).
 
    """
 

	
 
    with host.sudo():
 
@@ -561,25 +561,27 @@ def test_wsgi_requirements(host, fqdn, expected_packages):
 

	
 
        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"
 

	
 
        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
 
        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
 
        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
 
        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
 
        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)