Changeset - 00a669691076
[Not reviewed]
0 2 0
Branko Majic (branko) - 2 months ago 2024-03-03 13:57:08
branko@majic.rs
MAR-192: Fix incorrect prompt for pipreqcheck virtual environment:

- Ensure that the virtualenv indicator string ends with a
whitespace.
- The virtualenv prompt parameter behaves slightly different between
the versions of Debian 11 Bullseye and Debian 12 Bookworm - the former
being a bit more user-friendly.
- Recreate virtual environment if the prompt does not match-up.
2 files changed with 36 insertions and 3 deletions:
0 comments (0 inline, 0 general)
roles/common/molecule/default/tests/test_default.py
Show inline comments
 
@@ -250,6 +250,25 @@ def test_pipreqcheck_virtualenv(host):
 
        assert virtualenv_activate.mode == 0o644
 

	
 

	
 
def test_pipreqcheck_virtualenv_prompt(host):
 
    """
 
    Tests if Python virtual environment prompt has been set-up
 
    correctly.
 
    """
 

	
 
    with host.sudo("pipreqcheck"):
 
        prompt = host.run('bash -c "source /var/lib/pipreqcheck/virtualenv/bin/activate; printenv PS1"')
 

	
 
        # Chop off trailing newline if present (this is from the
 
        # host.run itself).
 
        if prompt.stdout.endswith("\n"):
 
            prompt_stdout = prompt.stdout[:-1]
 
        else:
 
            prompt_stdout = prompt.stdout
 

	
 
        assert prompt_stdout == "(pipreqcheck) "
 

	
 

	
 
def test_pipreqcheck_directories(host):
 
    """
 
    Tests creation of directories used for storing configuration used by script
roles/common/tasks/main.yml
Show inline comments
 
@@ -369,11 +369,24 @@
 
  changed_when: false
 
  register: virtualenv_python_version
 

	
 
- name: Remove virtual environment if Python version does not match
 
- name: Retrieve virtual environment prompt
 
  command:
 
    argv:
 
      - "bash"
 
      - "-c"
 
      - "source '/var/lib/pipreqcheck/virtualenv/bin/activate'; printenv PS1"
 
  failed_when: false
 
  changed_when: false
 
  register: current_virtualenv_prompt
 

	
 
- name: Remove virtual environment in case of mismatches
 
  file:
 
    path: "/var/lib/pipreqcheck/virtualenv"
 
    state: absent
 
  when: "virtualenv_python_version.rc != 0 or virtualenv_python_version.stdout.strip() != python_interpreter_version.stdout.strip()"
 
  when: |
 
    virtualenv_python_version.rc != 0 or
 
    virtualenv_python_version.stdout.strip() != python_interpreter_version.stdout.strip() or
 
    current_virtualenv_prompt.stdout != "(pipreqcheck) "
 

	
 
- name: Create directory for Python virtual environment used for installing/running pip-tools
 
  file:
 
@@ -387,7 +400,7 @@
 
    - "/var/lib/pipreqcheck/virtualenv"
 

	
 
- name: Create Python virtual environment used for installing/running pip-tools
 
  command: "/usr/bin/virtualenv --python '{{ item.python_path }}' --prompt '({{ item.name }})' '{{ item.virtualenv_path }}'"
 
  command: "/usr/bin/virtualenv --python '{{ item.python_path }}' --prompt '{{ item.virtualenv_prompt }}' '{{ item.virtualenv_path }}'"
 
  args:
 
    creates: "{{ item.creates }}"
 
  become: true
 
@@ -395,6 +408,7 @@
 
  with_items:
 
    - name: pipreqcheck
 
      virtualenv_path: "/var/lib/pipreqcheck/virtualenv"
 
      virtualenv_prompt: "{% if ansible_distribution_release == 'bullseye' %}(pipreqcheck) {% else %}pipreqcheck{% endif %}"
 
      python_path: "/usr/bin/python3"
 
      creates: "/var/lib/pipreqcheck/virtualenv/bin/python3"
 

	
0 comments (0 inline, 0 general)