Introduce functional tests for python-brick-cinderclient-ext

This patch adds new tox environment to run functional tests:
    $ tox -e functional

It also adds 'post_test_hook.sh' script to run functional tests on
gates.

All unit tests moved to 'unit' directory.

Change-Id: Iac2f4c6d9d77e96d2478aa00632aad33fa6a22d8
This commit is contained in:
Ivan Kolodyazhny 2016-01-11 14:57:50 +02:00
parent 32b30640de
commit 896f044d19
7 changed files with 144 additions and 9 deletions

View File

@ -2,6 +2,8 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
${PYTHON:-python} -m subunit.run discover \
-t ./ ${OS_TEST_PATH:-./brick_cinderclient_ext/tests/unit} \
$LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -0,0 +1,53 @@
#!/bin/bash -xe
# 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.
# This script is executed inside post_test_hook function in devstack gate.
# Default gate uses /opt/stack/new... but some of us may install differently
STACK_DIR=$BASE/new/devstack
function generate_testr_results {
if [ -f .testrepository/0 ]; then
sudo .tox/functional/bin/testr last --subunit > $WORKSPACE/testrepository.subunit
sudo mv $WORKSPACE/testrepository.subunit $BASE/logs/testrepository.subunit
sudo /usr/os-testr-env/bin/subunit2html $BASE/logs/testrepository.subunit $BASE/logs/testr_results.html
sudo gzip -9 $BASE/logs/testrepository.subunit
sudo gzip -9 $BASE/logs/testr_results.html
sudo chown jenkins:jenkins $BASE/logs/testrepository.subunit.gz $BASE/logs/testr_results.html.gz
sudo chmod a+r $BASE/logs/testrepository.subunit.gz $BASE/logs/testr_results.html.gz
fi
}
export BRICK_CINDERCLIENT_EXT_DIR="$BASE/new/python-brick-cinderclient-ext"
sudo chown -R jenkins:stack $BRICK_CINDERCLIENT_EXT_DIR
# Get admin credentials
cd $STACK_DIR
source openrc admin admin
# Go to the cinderclient dir
cd $BRICK_CINDERCLIENT_EXT_DIR
# Run tests
echo "Running cinderclient functional test suite"
set +e
# Preserve env for OS_ credentials
sudo -E -H -u jenkins tox -efunctional
EXIT_CODE=$?
set -e
# Collect and parse result
generate_testr_results
exit $EXIT_CODE

View File

@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
# 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.
import os
from cinderclient import client as c_client
from oslotest import base
import six
from brick_cinderclient_ext import client
_CREDS_FILE = 'functional_creds.conf'
def credentials():
"""Retrieves credentials to run functional tests
Credentials are either read from the environment or from a config file
('functional_creds.conf'). Environment variables override those from the
config file.
The 'functional_creds.conf' file is the clean and new way to use (by
default tox 2.0 does not pass environment variables).
"""
username = os.environ.get('OS_USERNAME')
password = os.environ.get('OS_PASSWORD')
tenant_name = os.environ.get('OS_TENANT_NAME')
auth_url = os.environ.get('OS_AUTH_URL')
config = six.moves.configparser.RawConfigParser()
if config.read(_CREDS_FILE):
username = username or config.get('admin', 'user')
password = password or config.get('admin', 'pass')
tenant_name = tenant_name or config.get('admin', 'tenant_name')
auth_url = auth_url or config.get('auth', 'uri')
return {
'username': username,
'password': password,
'tenant_name': tenant_name,
'uri': auth_url
}
class BrickClientTests(base.BaseTestCase):
def setUp(self):
super(BrickClientTests, self).setUp()
creds = credentials()
self.cinder_client = c_client.Client(2,
creds['username'],
creds['password'],
creds['tenant_name'],
creds['uri'])
self.client = client.Client(self.cinder_client)
def test_get_connector(self):
connector = self.client.get_connector()
for prop in ['ip', 'host', 'multipath', 'platform', 'os_type']:
self.assertIn(prop, connector)

23
tox.ini
View File

@ -4,14 +4,16 @@ envlist = py34-constraints,py27-constraints,pypy-constraints,pep8-constraints
skipsdist = True
[testenv]
usedevelop = True
install_command =
constraints: {[testenv:common-constraints]install_command}
pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/test-requirements.txt
commands = python setup.py test --slowest --testr-args='{posargs}'
install_command = pip install -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
passenv = *_proxy *_PROXY
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
find . -type f -name "*.pyc" -delete
python setup.py testr --testr-args='{posargs}'
whitelist_externals = find
[testenv:common-constraints]
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
@ -26,6 +28,11 @@ commands = flake8 {posargs}
[testenv:venv]
commands = {posargs}
[testenv:functional]
setenv =
OS_TEST_PATH=./brick_cinderclient_ext/tests/functional
passenv = OS_*
[testenv:venv-constraints]
install_command = {[testenv:common-constraints]install_command}
commands = {posargs}