From 2005446dc6a4664a14fd7ddb26224a9c3428de80 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Wed, 13 Mar 2024 09:32:44 +0100 Subject: [PATCH] Use upper-constraints in the Tobiko ansible roles In Tobiko we have roles to e.g. ensure that tox is installed. It uses pip but it didn't use upper-constraints.txt file from the OpenStack requirements and that could cause some issues, especially on e.g. older operating systems, see related bug for example. With this patch those ansible roles which uses pip to install some python packages will use upper-constraints file if it exists in the file system (in the u/s CI it will exist). This patch also lowers min tox version for stable/2023.1 and stable/zed branches are those should still use tox 3.28 Closes-Bug: #2057492 Change-Id: I147770a7949c59ba61b8dcca23d5c6fbbacb2606 --- roles/tobiko-bindep/tasks/ensure-bindep.yaml | 10 ++++++- roles/tobiko-common/defaults/main.yaml | 2 ++ .../tobiko-ensure-python3/tasks/install.yaml | 11 ++++++-- roles/tobiko-ensure-tox/tasks/tox.yaml | 26 +++++++++++++++++-- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/roles/tobiko-bindep/tasks/ensure-bindep.yaml b/roles/tobiko-bindep/tasks/ensure-bindep.yaml index bd96fb713..e87bc9ef9 100644 --- a/roles/tobiko-bindep/tasks/ensure-bindep.yaml +++ b/roles/tobiko-bindep/tasks/ensure-bindep.yaml @@ -1,8 +1,16 @@ --- +- name: "check if upper-constraints file exists" + stat: + path: "{{ openstack_requirements_dir }}/upper-constraints.txt" + register: upper_constraints_file + + - name: "ensure Bindep is installed" command: > - '{{ python_executable }}' -m pip install --user 'bindep>={{ bindep_min_version }}' + '{{ python_executable }}' -m pip install \ + {% if upper_constraints_file.stat.exists == true %}-c'{{ upper_constraints_file.stat.path }}'{% endif %} \ + --user bindep>='{{ bindep_min_version }}' register: install_bindep changed_when: "'Successfully installed' in install_bindep.stdout" diff --git a/roles/tobiko-common/defaults/main.yaml b/roles/tobiko-common/defaults/main.yaml index d52961dcb..6a6010ea3 100644 --- a/roles/tobiko-common/defaults/main.yaml +++ b/roles/tobiko-common/defaults/main.yaml @@ -18,6 +18,8 @@ test_project: test_git_repo: '{{ git_base }}/x/tobiko.git' test_src_dir: '' +openstack_requirements_dir: "/opt/stack/requirements" + # NOTE: if test_dir and tobiko_dir variables endup being the same actual # directory then test_src and test_git_* variables will be overriden diff --git a/roles/tobiko-ensure-python3/tasks/install.yaml b/roles/tobiko-ensure-python3/tasks/install.yaml index 035d66bb2..c02c70e49 100644 --- a/roles/tobiko-ensure-python3/tasks/install.yaml +++ b/roles/tobiko-ensure-python3/tasks/install.yaml @@ -57,10 +57,17 @@ failed_when: (python_info | length) == 0 +- name: "check if upper-constraints file exists" + stat: + path: "{{ openstack_requirements_dir }}/upper-constraints.txt" + register: upper_constraints_file + + - name: "upgrade '{{ python_command }}' packages to the latest versions" command: > - '{{ python_info[python_command].executable }}' -m pip install '{{ item }}' \ - --upgrade --user + '{{ python_info[python_command].executable }}' -m pip install \ + {% if upper_constraints_file.stat.exists == true %}-c'{{ upper_constraints_file.stat.path }}'{% endif %} + '{{ item }}' --upgrade --user register: upgrade_python_packages changed_when: "'Successfully installed' in upgrade_python_packages.stdout" diff --git a/roles/tobiko-ensure-tox/tasks/tox.yaml b/roles/tobiko-ensure-tox/tasks/tox.yaml index 8a079da11..5b2cdceb5 100644 --- a/roles/tobiko-ensure-tox/tasks/tox.yaml +++ b/roles/tobiko-ensure-tox/tasks/tox.yaml @@ -1,9 +1,31 @@ --- +- name: "check if upper-constraints file exists" + stat: + path: "{{ openstack_requirements_dir }}/upper-constraints.txt" + register: upper_constraints_file + + +- name: "Determine min tox version to be installed" + when: upper_constraints_file.stat.exists == true + block: + - name: "Check requirements repo branch" + ansible.builtin.command: + cmd: git rev-parse --abbrev-ref HEAD + chdir: "{{ openstack_requirements_dir }}" + register: requirements_branch + + - name: "Set min tox version for Ubuntu 20.04" + set_fact: + tox_min_version: "3.28" + when: requirements_branch.stdout == "stable/2023.1" or "stable/zed" + + - name: "ensure Tox is installed" command: > - {{ python_executable }} -m pip install --user - 'tox>={{ tox_min_version }}{% if tox_max_version is not none %},<={{ tox_max_version }}{% endif %}' + '{{ python_executable }}' -m pip install \ + {% if upper_constraints_file.stat.exists is true %}-c'{{ upper_constraints_file.stat.path }}'{% endif %} \ + --user 'tox>={{ tox_min_version }}{% if tox_max_version is not none %},<={{ tox_max_version }}{% endif %}' register: install_tox changed_when: "'Successfully installed' in install_tox.stdout"