diff --git a/.gitignore b/.gitignore index 36f0400..5421f90 100644 --- a/.gitignore +++ b/.gitignore @@ -61,13 +61,11 @@ ChangeLog releasenotes/build # Test temp files -tests/plugins -tests/playbooks tests/common tests/*.retry # Vagrant artifacts .vagrant -# IDE created files -.idea/ +# Git clones +openstack-ansible-ops diff --git a/Vagrantfile b/Vagrantfile index ec1f163..7d8c27a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,9 +1,47 @@ -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 +# Note: +# This file is maintained in the openstack-ansible-tests repository. +# https://git.openstack.org/cgit/openstack/openstack-ansible-tests/tree/Vagrantfile +# +# If you need to perform any change on it, you should modify the central file, +# then, an OpenStack CI job will propagate your changes to every OSA repository +# since every repo uses the same Vagrantfile + +# Verify whether required plugins are installed. +required_plugins = [ "vagrant-disksize" ] +required_plugins.each do |plugin| + if not Vagrant.has_plugin?(plugin) + raise "The vagrant plugin #{plugin} is required. Please run `vagrant plugin install #{plugin}`" + end +end + +Vagrant.configure(2) do |config| + config.vm.provider "virtualbox" do |v| + v.memory = 4096 + v.cpus = 2 + end + + config.vm.provision "shell", + privileged: false, + inline: <<-SHELL + cd /vagrant + ./run_tests.sh + SHELL + + config.vm.define "ubuntu1604" do |xenial| + xenial.disksize.size = "40GB" + xenial.vm.box = "ubuntu/xenial64" + end + + config.vm.define "opensuse422" do |leap422| + leap422.vm.box = "opensuse/openSUSE-42.2-x86_64" + end + + config.vm.define "opensuse423" do |leap423| + leap423.vm.box = "opensuse/openSUSE-42.3-x86_64" + end + + config.vm.define "centos7" do |centos7| + centos7.vm.box = "centos/7" + end + end diff --git a/run_tests.sh b/run_tests.sh index 5bd6a64..e8f6f3a 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2016, Rackspace US, Inc. +# Copyright 2015, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,32 +12,61 @@ # 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. +# +# Note: +# This file is maintained in the openstack-ansible-tests repository. +# https://git.openstack.org/cgit/openstack/openstack-ansible-tests/tree/run_tests.sh +# If you need to modify this file, update the one in the openstack-ansible-tests +# repository and then update this file as well. The purpose of this file is to +# prepare the host and then execute all the tox tests. +# -set -euov +## Shell Opts ---------------------------------------------------------------- +set -xeu -FUNCTIONAL_TEST=${FUNCTIONAL_TEST:-true} +## Vars ---------------------------------------------------------------------- -# prep the host -if [ "$(which apt-get)" ]; then - apt-get install -y build-essential python2.7 python-dev git-core libssl-dev libffi-dev -fi +export WORKING_DIR=${WORKING_DIR:-$(pwd)} -# get pip, if necessary -if [ ! "$(which pip)" ]; then - curl --silent --show-error --retry 5 \ - https://bootstrap.pypa.io/get-pip.py | sudo python2.7 -fi +## Main ---------------------------------------------------------------------- -# install tox -pip install tox +source /etc/os-release || source /usr/lib/os-release -# 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" ]; then - if ${FUNCTIONAL_TEST}; then - tox -e ${tox_env} +install_pkg_deps() { + pkg_deps="git" + + # Prefer dnf over yum for CentOS. + which dnf &>/dev/null && RHT_PKG_MGR='dnf' || RHT_PKG_MGR='yum' + + case ${ID,,} in + *suse*) pkg_mgr_cmd="zypper -n in" ;; + centos|rhel) pkg_mgr_cmd="${RHT_PKG_MGR} install -y" ;; + fedora) pkg_mgr_cmd="dnf -y install" ;; + ubuntu|debian) pkg_mgr_cmd="apt-get install -y" ;; + *) echo "unsupported distribution: ${ID,,}"; exit 1 ;; + esac + + eval sudo $pkg_mgr_cmd $pkg_deps +} + +git_clone_repo() { + if [[ ! -d tests/common ]]; then + # The tests repo doesn't need a clone, we can just + # symlink it. + if [[ "$(basename ${WORKING_DIR})" == "openstack-ansible-tests" ]]; then + ln -s ${WORKING_DIR} ${WORKING_DIR}/tests/common + else + git clone \ + https://git.openstack.org/openstack/openstack-ansible-tests \ + tests/common + fi fi - fi -done +} + +install_pkg_deps + +git_clone_repo + +# start executing the main test script +source tests/common/run_tests_common.sh +