From 8862ea83858db56367f0fdea18faabc3c0841f90 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Fri, 7 Jun 2019 14:42:58 -0500 Subject: [PATCH] Add bindep support to tox This change will allow a developer to run bindep via tox to install all of the required system packages needed to run general tests. > Integration `tox -e bindep` This will also allow CI to using the bindep file to install basic required packages as needed. Change-Id: I83e5e4f8dd5bb9acd4e6b21bf86f729bfc5447d4 Signed-off-by: Kevin Carter --- bindep.txt | 35 +++++++++++++++ .../notes/bindep-tox-606dbe4ddf68f7a6.yaml | 12 +++++ scripts/bindep-install | 45 +++++++++++++++++++ tox.ini | 4 ++ 4 files changed, 96 insertions(+) create mode 100644 bindep.txt create mode 100644 releasenotes/notes/bindep-tox-606dbe4ddf68f7a6.yaml create mode 100755 scripts/bindep-install diff --git a/bindep.txt b/bindep.txt new file mode 100644 index 000000000..5291d2060 --- /dev/null +++ b/bindep.txt @@ -0,0 +1,35 @@ +# This file facilitates OpenStack-CI package installation +# before the execution of any tests. +# +# See the following for details: +# - https://docs.openstack.org/infra/bindep/ +# - https://opendev.org/opendev/bindep/ +# +# Even if the role does not make use of this facility, it +# is better to have this file empty, otherwise OpenStack-CI +# will fall back to installing its default packages which +# will potentially be detrimental to the tests executed. + +# The gcc compiler +gcc + +# Base requirements for RPM distros +gcc-c++ [platform:rpm] +git [platform:rpm] +libffi-devel [platform:rpm] +openssl-devel [platform:rpm] +python-devel [platform:rpm] +python2-dnf [platform:fedora] + +# For SELinux +libselinux-python [platform:rpm] +libsemanage-python [platform:redhat] + +# Required for compressing collected log files in CI +gzip + +# Required to build language docs +gettext + +# Required for molecule testing +docker diff --git a/releasenotes/notes/bindep-tox-606dbe4ddf68f7a6.yaml b/releasenotes/notes/bindep-tox-606dbe4ddf68f7a6.yaml new file mode 100644 index 000000000..c1fb8d409 --- /dev/null +++ b/releasenotes/notes/bindep-tox-606dbe4ddf68f7a6.yaml @@ -0,0 +1,12 @@ +--- + +features: + - The `bindep.txt` file located in the project root contains all of the + basic required packages needed when running local tests. + - Developers can now use bindep to list system requirements. The bindep + command will load the list of packages for the given platform using + the `bindep.txt` file. + - Bindep can now be leveraged via tox using the environment **bindep**. + This tox environment will use bindep via the `bindep-install` script + to install any missing packages on the local system which are required + for development purposes. diff --git a/scripts/bindep-install b/scripts/bindep-install new file mode 100755 index 000000000..6451da028 --- /dev/null +++ b/scripts/bindep-install @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +## Shell Opts ---------------------------------------------------------------- + +set -o pipefail +set -xeuo + + +## Vars ---------------------------------------------------------------------- + +export BINDEP_FILE="${BINDEP_FILE:-$(dirname $(readlink -f ${BASH_SOURCE[0]}))/../bindep.txt}" + + +## Main ---------------------------------------------------------------------- + +# Source distribution information +source /etc/os-release || source /usr/lib/os-release +which dnf &>/dev/null && RHT_PKG_MGR='dnf' || RHT_PKG_MGR='yum' + +# NOTE(cloudnull): Get a list of packages to install with bindep. If packages +# need to be installed, bindep exits with an exit code of 1. +BINDEP_PKGS=$(bindep -b -f "${BINDEP_FILE}" test || true) + +if [[ ${#BINDEP_PKGS} > 0 ]]; then + case "${ID,,}" in + amzn|rhel|centos|fedora) + sudo "${RHT_PKG_MGR}" install -y ${BINDEP_PKGS} + ;; + esac +fi diff --git a/tox.ini b/tox.ini index 953073c9d..4e4d6517e 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,10 @@ deps = commands = stestr run {posargs} whitelist_externals = bash +[testenv:bindep] +deps = bindep +commands = bash -c "{toxinidir}/scripts/bindep-install" + [testenv:pep8] basepython = python3 commands = flake8