Changeset - 71bc6c4991f8
[Not reviewed]
0 3 0
Branko Majic (branko) - 7 years ago 2018-08-05 14:13:04
branko@majic.rs
MAR-132: Fix virtual environment set-up in wsgi_website role:

- Install more up-to-date version of pip. This fixes some issues
related to pip freeze detecting argparse and wsgiref in virtualenv
as separate packages.
- Remove the pkg-resources package from virtualenv. Workaround for
Debian-specific behaviour. More details at:
- https://github.com/pypa/pip/issues/4022
- https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
- https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871790
- Deploy Gunicorn requirements file without switching to website admin
user (otherwise Ansible fails to template the file due to
permissions restrictions).
- Updated test for checking packages installed in the virtualenv.
3 files changed with 21 insertions and 6 deletions:
0 comments (0 inline, 0 general)
roles/wsgi_website/molecule/default/tests/test_default.py
Show inline comments
 
@@ -297,16 +297,14 @@ def test_python_virtualenv_wrapper_script(host, wrapper_script, expected_owner,
 
        command = host.run("sudo -u %s %s python -c 'import gunicorn'" % (expected_owner, wrapper_script))
 
        assert command.rc == 0
 

	
 

	
 
@pytest.mark.parametrize("admin_user, pip_path, expected_packages",  [
 
    ('admin-parameters-mandatory', '/var/www/parameters-mandatory/virtualenv/bin/pip', [
 
        "argparse==1.2.1",
 
        "futures==3.2.0",
 
        "gunicorn==19.9.0",
 
        "wsgiref==0.1.2"
 
    ]),
 
    ('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",
 
@@ -323,19 +321,17 @@ def test_python_virtualenv_wrapper_script(host, wrapper_script, expected_owner,
 
        "Jinja2==2.9.6",
 
        "MarkupSafe==1.0",
 
        "Paste==2.0.3",
 
        "PasteDeploy==1.5.2",
 
        "PasteScript==2.0.2",
 
        "Werkzeug==0.12.2",
 
        "argparse==1.2.1",
 
        "click==6.7",
 
        "futures==3.1.0",
 
        "gunicorn==19.7.0",
 
        "itsdangerous==0.24",
 
        "six==1.10.0",
 
        "wsgiref==0.1.2",
 
    ]),
 
])
 
def test_virtualenv_packages(host, admin_user, pip_path, expected_packages):
 
    """
 
    Tests if correct packages are installed in virtualenv.
 
    """
roles/wsgi_website/tasks/main.yml
Show inline comments
 
@@ -119,12 +119,33 @@
 
  tags:
 
    # [ANSIBLE0012] Commands should not change things if nothing needs doing
 
    #   This task will not fire if the virtual environment has already bene
 
    #   created (thanks to 'creates' parameter).
 
    - skip_ansible_lint
 

	
 
- name: Install latest pip in virtual environment
 
  pip:
 
    name:
 
      - "pip>=18.0.0,<19.0.0"
 
    virtualenv: "{{ home }}/virtualenv"
 
  become: true
 
  become_user: "{{ admin }}"
 

	
 
# Workaround for:
 
#
 
# - https://github.com/pypa/pip/issues/4022
 
# - https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
 
# - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871790
 
- name: Remove the pkg-resources package from virtual environment (see comments above for details)
 
  pip:
 
    name: pkg-resources
 
    virtualenv: "{{ home }}/virtualenv"
 
    state: absent
 
  become: true
 
  become_user: "{{ admin }}"
 

	
 
- name: Configure project directory for the Python virtual environment
 
  template:
 
    src: "venv_project.j2"
 
    dest: "{{ home }}/virtualenv/.project"
 
    owner: "{{ admin }}"
 
    group: "{{ user }}"
roles/wsgi_website/tasks/requirements.yml
Show inline comments
 
@@ -17,14 +17,12 @@
 
    mode: 0640
 
  with_items:
 
    - wsgi_requirements.in
 
    - wsgi_requirements.txt
 

	
 
- name: Deploy Gunicorn requirements file for installation purposes
 
  become: true
 
  become_user: "{{ admin }}"
 
  template:
 
    src: "wsgi_requirements.txt.j2"
 
    dest: "{{ home }}/.wsgi_requirements.txt"
 
    owner: "{{ admin }}"
 
    group: "{{ user }}"
 
    mode: 0640
0 comments (0 inline, 0 general)