From 6df06f4200786253493e3e51be05c62bb6386be5 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Mon, 27 Mar 2017 14:32:20 +0100 Subject: [PATCH] vagrant: Add openSUSE Leap 42.1 Add support for testing ansible roles against openSUSE Leap 42.1. This also improves the run_tests.sh script and also adds support for openSUSE bindep dependencies. Finally, it adds a new BINDEP_FILE variable which can be used to set an alternative bindep.txt dependency file. Change-Id: I57357b119eb1d8eb7726401b8feb48d1ae08c470 --- Vagrantfile | 30 ++++++++++++++----- bindep.txt | 20 ++++++------- run_tests.sh | 83 +++++++++++++++++++++++++++++++++++----------------- 3 files changed, 89 insertions(+), 44 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index ec1f163b..81f3afeb 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,9 +1,25 @@ Vagrant.configure(2) do |config| - config.vm.box = "ubuntu/xenial64" - config.vm.provision "shell", inline: <<-SHELL - sudo su - - cd /vagrant - apt-get update - ./run_tests.sh - SHELL + config.vm.provider "virtualbox" do |v| + v.memory = 2048 + v.cpus = 2 + end + + config.vm.define "ubuntu1604" do |xenial| + xenial.vm.box = "ubuntu/xenial64" + xenial.vm.provision "shell", inline: <<-SHELL + sudo su - + cd /vagrant + ./run_tests.sh + SHELL + end + + config.vm.define "opensuse421" do |leap421| + leap421.vm.box = "opensuse/openSUSE-42.1-x86_64" + leap421.vm.provision "shell", inline: <<-SHELL + sudo su - + cd /vagrant + ./run_tests.sh + SHELL + end + end diff --git a/bindep.txt b/bindep.txt index f93f28d4..cbf53b81 100644 --- a/bindep.txt +++ b/bindep.txt @@ -18,26 +18,26 @@ libffi-dev [platform:dpkg] python2.7 [platform:dpkg] python-dev [platform:dpkg] -# Base requirements for CentOS +# Base requirements for RPM distros gcc [platform:rpm] gcc-c++ [platform:rpm] git [platform:rpm] -python-devel [platform:rpm] libffi-devel [platform:rpm] openssl-devel [platform:rpm] +python-devel [platform:rpm] # For SELinux -libselinux-python [platform:rpm] +libselinux-python [platform:centos] +libsemanage-python [platform:centos] # For SSL SNI support -python-pyasn1 [platform:dpkg] -python-openssl [platform:dpkg] +python-pyasn1 [platform:dpkg platform:suselinux] +python-openssl [platform:dpkg platform:suselinux] python-ndg-httpsclient [platform:ubuntu] -python2-pyasn1 [platform:rpm] -python2-pyOpenSSL [platform:rpm] -python-ndg_httpsclient [platform:rpm] - - +python2-pyasn1 [platform:centos] +python2-pyOpenSSL [platform:centos] +python-pyOpenSSL [platform:suselinux] +python-ndg_httpsclient [platform:centos] # Required for compressing collected log files in CI gzip diff --git a/run_tests.sh b/run_tests.sh index 0482518e..1f92169e 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -13,23 +13,37 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o pipefail set -euov -FUNCTIONAL_TEST=${FUNCTIONAL_TEST:-true} +BINDEP_FILE=${BINDEP_FILE:-bindep.txt} -# Install python2 for Ubuntu 16.04 and CentOS 7 -if which apt-get; then - sudo apt-get update && sudo apt-get install -y python -fi +# Start fresh +rm -rf .tox -if which yum; then - sudo yum install -y python -fi +source /etc/os-release || source /usr/lib/os-release + +case "${ID,,}" in + *suse*) + # Need to pull libffi and python-pyOpenSSL early + # because we install ndg-httpsclient from pip + sudo zypper -n in python-devel lsb-release libffi-devel python-pyOpenSSL + ;; + centos) + sudo yum install -y python-devel redhat-lsb-core + ;; + ubuntu|debian) + sudo apt-get update && sudo apt-get install -y python-dev lsb-release + ;; + *) + echo "Unsupported distribution: ${ID,,}" + exit 1 +esac # Install pip -if [ ! "$(which pip)" ]; then - curl --silent --show-error --retry 5 \ - https://bootstrap.pypa.io/get-pip.py | sudo python2.7 +if ! which pip &>/dev/null; then + curl --silent --show-error --retry 5 \ + https://bootstrap.pypa.io/get-pip.py | sudo python2.7 fi # Install bindep and tox @@ -38,25 +52,40 @@ sudo pip install bindep tox # CentOS 7 requires two additional packages: # redhat-lsb-core - for bindep profile support # epel-release - required to install python-ndg_httpsclient/python2-pyasn1 -if [ "$(which yum)" ]; then +if [[ ${ID,,} == "centos" ]]; then sudo yum -y install redhat-lsb-core epel-release +# openSUSE 42.1 does not have python-ndg-httpsclient +elif [[ ${ID,,} == *suse* ]]; then + pip install ndg-httpsclient fi +# 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) +echo "Packages to install: ${BINDEP_PKGS}" + # Install OS packages using bindep -if apt-get -v >/dev/null 2>&1 ; then - sudo apt-get update - DEBIAN_FRONTEND=noninteractive \ - sudo apt-get -q --option "Dpkg::Options::=--force-confold" \ - --assume-yes install `bindep -b -f bindep.txt test` -else - sudo yum install -y `bindep -b -f bindep.txt test` +if [[ ${#BINDEP_PKGS} > 0 ]]; then + case "${ID,,}" in + *suse*) + sudo zypper -n in $BINDEP_PKGS + ;; + centos) + sudo yum install -y $BINDEP_PKGS + ;; + ubuntu|debian) + sudo apt-get update + DEBIAN_FRONTEND=noninteractive \ + sudo apt-get -q --option "Dpkg::Options::=--force-confold" \ + --assume-yes install $BINDEP_PKGS + ;; + esac fi -# run through each tox env and execute the test -for tox_env in $(awk -F= '/envlist/ {print $2}' tox.ini | sed 's/,/ /g'); do - if [ "${tox_env}" != "functional" ]; then - tox -e ${tox_env} - elif [ "${tox_env}" == "functional" ] && [ "${FUNCTIONAL_TEST}" == "true" ]; then - tox -e ${tox_env} - fi -done +# Get envlist in a $env1,$env2,...,$envn format +toxenvs="$(tox -l | tr '\n' ',' | sed 's/,$//')" + +# Execute all $toxenvs or only a specific one +tox -e "${1:-$toxenvs}" + +# vim: set ts=4 sw=4 expandtab: