diff --git a/.testr.conf b/.testr.conf index 5ffe9b7..db26af9 100644 --- a/.testr.conf +++ b/.testr.conf @@ -1,4 +1,4 @@ [DEFAULT] -test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ./refstack_client/tests $LISTOPT $IDOPTION +test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ./refstack_client/tests/unit $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list diff --git a/README.rst b/README.rst index f340076..1141bf2 100644 --- a/README.rst +++ b/README.rst @@ -5,11 +5,11 @@ refstack-client is a command line utility that allows you to execute Tempest test runs based on configurations you specify. When finished running Tempest it sends the passed test data back to the Refstack API server. -**Usage (Ubuntu)** +**Usage** -We've created an "easy button" for Ubuntu. +We've created an "easy button" for Ubuntu, Centos, RHEL and openSuSe. -$ sh ./setup_ubuntu_env.sh +$ ./setup_env.sh **Start testing** @@ -19,11 +19,12 @@ $ sh ./setup_ubuntu_env.sh (i.e. cd ~/refstack-client). 3. Source to use the correct Python environment. - source test_runner/bin/activate + source .venv/bin/activate 4. Execute test by typing: - ./refstack-client -c "Path of the tempest configuration file to use" + ./refstack-client -c "Path of the tempest configuration file\ + to use" **Note:** @@ -34,4 +35,3 @@ $ sh ./setup_ubuntu_env.sh (i.e. -t "tempest.api.identity.admin.test_roles"). d. Adding --url option will upload the test results to a Refstack API server instead of the default Refstack API server. - e. Adding --offline option will not upload the test results. diff --git a/refstack_client/refstack_client.py b/refstack_client/refstack_client.py index 7fe9f7c..afc93e4 100755 --- a/refstack_client/refstack_client.py +++ b/refstack_client/refstack_client.py @@ -227,7 +227,7 @@ def parse_cli_args(args=None): action='store', required=False, dest='tempest_dir', - default='test_runner/src/tempest', + default='.venv/src/tempest', help='Path of the tempest project directory.') parser.add_argument('-c', '--conf-file', diff --git a/refstack_client/tests/smoke/__init__.py b/refstack_client/tests/smoke/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/refstack_client/tests/smoke/run_in_docker b/refstack_client/tests/smoke/run_in_docker new file mode 100755 index 0000000..0912e1d --- /dev/null +++ b/refstack_client/tests/smoke/run_in_docker @@ -0,0 +1,5 @@ +#!/bin/sh +cp -r /refstack-client /test +cd /test +./setup_env +/bin/bash -c ". .venv/bin/activate; exec ./refstack-client -vv -c tempest.conf -t tempest.api.identity.admin.test_users" diff --git a/refstack_client/tests/smoke/test_distros.py b/refstack_client/tests/smoke/test_distros.py new file mode 100644 index 0000000..324ec3e --- /dev/null +++ b/refstack_client/tests/smoke/test_distros.py @@ -0,0 +1,60 @@ +import os +import subprocess +import unittest + + +def get_project_path(): + path = os.path.dirname(os.path.realpath(__file__)) + while 'setup.py' not in os.listdir(path): + path = os.path.realpath(os.path.join(path, '..')) + return path + + +class TestSequenceFunctions(unittest.TestCase): + scp_command = ('scp %s:/opt/stack/tempest/etc/' + 'tempest.conf %s') + pull_command = ('docker pull %s') + test_command = ('docker run -t -v %s:/refstack-client -w /refstack-client/' + 'refstack_client/tests/smoke --rm %s ./run_in_docker') + + def run_test(self, distro): + subprocess.check_call(self.pull_command % distro, shell=True) + subprocess.check_call(self.test_command % (get_project_path(), distro), + shell=True) + + def setUp(self): + devstack_host = os.environ.get('DEVSTACK_HOST', None) + self.assertIsNotNone(devstack_host) + subprocess.check_call( + self.scp_command % (devstack_host, get_project_path()), + shell=True + ) + + def test_ubuntu_14(self): + distro_image = 'ubuntu:12.04' + self.run_test(distro_image) + + def test_ubuntu_12(self): + distro_image = 'ubuntu:14.04' + self.run_test(distro_image) + + def test_centos6(self): + distro_image = 'centos:centos6' + self.run_test(distro_image) + + def test_centos7(self): + distro_image = 'centos:centos7' + self.run_test(distro_image) + + def test_fedora_21(self): + distro_image = 'fedora:21' + self.run_test(distro_image) + + def test_opensuse_13(self): + # offcial opensuse image has outdated certificates + # we can't use it while this issue isn't fixed + distro_image = 'mmckeen/opensuse-13-1' + self.run_test(distro_image) + +if __name__ == '__main__': + unittest.main() diff --git a/setup_env b/setup_env new file mode 100755 index 0000000..edfb1f2 --- /dev/null +++ b/setup_env @@ -0,0 +1,74 @@ +#!/bin/sh +# Setup binary requirements +if [ -n "$(command -v apt-get)" ]; then +# For apt-get-based Linux distributions (Ubuntu, Debian) + # If we run script in container we need sudo + apt-get update + if [ ! -n "$(command -v sudo)" ]; then + apt-get -y install sudo + fi + # Workaroud for Ubuntu 10.04. + # There is no package 'git' in default ubuntu 10.04 repo's + sudo apt-get -s install git + if [ $? = 100 ]; then + sudo apt-get -y install python-software-properties + sudo add-apt-repository ppa:git-core/ppa + sudo apt-get update + fi + sudo apt-get -y install git curl wget tar unzip python-dev build-essential libssl-dev libxslt-dev libsasl2-dev libffi-dev libbz2-dev + + # Setup pip for python + curl https://bootstrap.pypa.io/get-pip.py | sudo -E python - +elif [ -n "$(command -v yum)" ]; then +# For yum-based distributions (RHEL, Centos) + # If we run script in container we need sudo + if [ ! -f sudo ]; then + yum -y install sudo + fi + sudo yum -y install git curl wget tar unzip make python-devel.x86_64 gcc gcc-c++ libffi-devel libxml2-devel bzip2-devel libxslt-devel openssl-devel + + # Setup pip for python + curl https://bootstrap.pypa.io/get-pip.py | sudo -E python - +elif [ -n "$(command) -v zypper" ]; then +# For zypper-based distributions (openSuSe, SELS) + # If we run script in container we need sudo + if [ ! -f sudo ]; then + zypper --no-gpg-checks --non-interactive install sudo + fi + sudo zypper --no-gpg-checks --non-interactive refresh + sudo zypper --non-interactive install git curl wget tar unzip make python-devel.x86_64 gcc gcc-c++ libffi-devel libxml2-devel zlib-devel libxslt-devel libopenssl-devel + + # Setup pip for python + sudo zypper --non-interactive install python-pip +else + echo "Neither apt-get nor yum nor zypper found" + exit 1 +fi + +if [ ! -n "$(command -v python2.7)" ]; then + echo "python2.7 not found. Building one..." + WORKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + mkdir ${WORKDIR}/.localpython + mkdir ${WORKDIR}/.python_src + cd ${WORKDIR}/.python_src + wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz + tar -zxvf Python-2.7.8.tgz + cd Python-2.7.8 + + ./configure --prefix=${WORKDIR}/.localpython + make && make install + cd ${WORKDIR} + PYPATH="${WORKDIR}/.localpython/bin/python" +else +echo "python2.7 found!" +PYPATH="python2.7" +fi + +# Setup python requirements +sudo pip install virtualenv +# Create virtual environment +if [ ! -d .venv ]; then + virtualenv .venv --python="$PYPATH" +fi +# Setup virtual environment +.venv/bin/pip install -r requirements.txt \ No newline at end of file diff --git a/setup_ubuntu_env.sh b/setup_ubuntu_env.sh deleted file mode 100755 index 13e898c..0000000 --- a/setup_ubuntu_env.sh +++ /dev/null @@ -1,14 +0,0 @@ -# insure base requirements are installed -sudo apt-get install -y git python-pip wget unzip -sudo apt-get install -y libxml2-dev libxslt-dev lib32z1-dev python2.7-dev libssl-dev -sudo apt-get install -y libsasl2-dev libffi-dev -sudo pip install virtualenv - -# If we've already created it, source it. If not, start and then source it. -if [ ! -d test_runner ]; then - virtualenv test_runner -fi - -source test_runner/bin/activate - -pip install -r requirements.txt