Changeset - 251942f9d332
[Not reviewed]
0 3 0
Branko Majic (branko) - 7 years ago 2018-12-15 14:29:22
branko@majic.rs
MAR-142: Fix wrong Python version use in pipreqcheck virtual environment for Python 3.
3 files changed with 70 insertions and 5 deletions:
0 comments (0 inline, 0 general)
docs/releasenotes.rst
Show inline comments
 
@@ -4,12 +4,22 @@ Release notes
 

	
 
NEXT RELEASE
 
------------
 

	
 
Minor improvements and fixes.
 

	
 
Bug fixes:
 

	
 
* ``common`` role
 

	
 
  * Use Python 3 in Python virtual environment used for checking if
 
    upgrades are available for Python requirements files. Fixes
 
    possibly incorrect package resolution due to wrong version of
 
    Python (for packages that have different dependencies based on
 
    Python version).
 

	
 
New features/improvements:
 

	
 
* ``common`` role
 

	
 
  * Changed how the packages are installed in Python virtual
 
    environments used for performing pip requirements upgrade checks,
roles/common/molecule/default/tests/test_default.py
Show inline comments
 
@@ -370,6 +370,38 @@ def test_pipreqcheck_crontab(host, crontab_path, virtualenv_path):
 
    assert crontab.is_file
 
    assert crontab.user == 'root'
 
    assert crontab.group == 'root'
 
    assert crontab.mode == 0o644
 
    assert "MAILTO=root" in crontab.content
 
    assert virtualenv_path in crontab.content.split(" ")
 

	
 

	
 
@pytest.mark.parametrize('python_path, expected_major_version', [
 
    ('/var/lib/pipreqcheck/virtualenv/bin/python', '2'),
 
    ('/var/lib/pipreqcheck/virtualenv-py3/bin/python', '3'),
 
])
 
def test_pipreqcheck_virtualenv_python_version(host, python_path, expected_major_version):
 
    """
 
    Tests if Python virtual environment for pipreqcheck has been
 
    set-up correctly.
 
    """
 

	
 
    with host.sudo('pipreqcheck'):
 
        major_version = host.run("%s -c %s", python_path, "import sys; print(sys.version_info.major)")
 

	
 
    assert major_version.rc == 0
 
    assert major_version.stdout == expected_major_version
 

	
 

	
 
@pytest.mark.parametrize('wrong_python_path', [
 
    '/var/lib/pipreqcheck/virtualenv/bin/python3',
 
    '/var/lib/pipreqcheck/virtualenv-py3/bin/python2',
 
])
 
def test_pipreqcheck_virtualenv_wrong_python_version_not_present(host, wrong_python_path):
 
    """
 
    Tests if wrong version of Python 2 is absent or not.
 
    """
 

	
 
    with host.sudo():
 
        wrong_python_path_file = host.file(wrong_python_path)
 

	
 
        assert not wrong_python_path_file.exists
roles/common/tasks/main.yml
Show inline comments
 
@@ -295,32 +295,55 @@
 
    name: "pipreqcheck"
 
    uid: "{{ pipreqcheck_uid | default(omit) }}"
 
    group: "pipreqcheck"
 
    home: "/var/lib/pipreqcheck"
 
    state: present
 

	
 
- name: Check for presence of wrong Python versions
 
  stat:
 
    path: "{{ item.offending_binary }}"
 
  with_items:
 
    - offending_binary: "/var/lib/pipreqcheck/virtualenv/bin/python3"
 
      virtualenv_directory: "/var/lib/pipreqcheck/virtualenv"
 
    - offending_binary: "/var/lib/pipreqcheck/virtualenv-py3/bin/python2"
 
      virtualenv_directory: "/var/lib/pipreqcheck/virtualenv-py3"
 
  register: "pipreqcheck_wrong_python_version_check"
 

	
 
- name: Drop Python virtual environment if wrong Python version has been detected within
 
  file:
 
    path: "{{ item.item.virtualenv_directory }}"
 
    state: absent
 
  when: "item.stat.exists"
 
  with_items: "{{ pipreqcheck_wrong_python_version_check.results }}"
 

	
 
- name: Create directory for Python virtual environment used for installing/running pip-tools
 
  file:
 
    path: "{{ item }}"
 
    state: directory
 
    owner: pipreqcheck
 
    group: pipreqcheck
 
    mode: 0750
 
  with_items:
 
    - "/var/lib/pipreqcheck/virtualenv"
 
    - "/var/lib/pipreqcheck/virtualenv-py3"
 

	
 
- name: Create Python virtual environment used for installing/running pip-tools
 
  command: "/usr/bin/virtualenv --prompt '({{ item.key }})' '{{ item.value }}'"
 
  command: "/usr/bin/virtualenv --python '{{ item.python_path }}' --prompt '({{ item.name }})' '{{ item.virtualenv_path }}'"
 
  args:
 
    creates: '/var/lib/pipreqcheck/virtualenv/bin/activate'
 
    creates: "{{ item.creates }}"
 
  become: true
 
  become_user: "pipreqcheck"
 
  with_dict:
 
    pipreqcheck: "/var/lib/pipreqcheck/virtualenv"
 
    pipreqcheck-py3: "/var/lib/pipreqcheck/virtualenv-py3"
 
  with_items:
 
    - name: pipreqcheck
 
      virtualenv_path: "/var/lib/pipreqcheck/virtualenv"
 
      python_path: "/usr/bin/python"
 
      creates: "/var/lib/pipreqcheck/virtualenv/bin/python2"
 
    - name: pipreqcheck-py3
 
      virtualenv_path: "/var/lib/pipreqcheck/virtualenv-py3"
 
      python_path: "/usr/bin/python3"
 
      creates: "/var/lib/pipreqcheck/virtualenv-py3/bin/python3"
 
  tags:
 
    # [ANSIBLE0012] Commands should not change things if nothing needs doing
 
    #   Command will not run if the virtualenv has already been created,
 
    #   therefore the warning is a false positive.
 
    - skip_ansible_lint
 

	
0 comments (0 inline, 0 general)