From 71d97836f87ae9c445bb7229828ebffe54798ed2 Mon Sep 17 00:00:00 2001 From: Stuart McLaren Date: Fri, 17 Apr 2015 12:48:39 +0000 Subject: [PATCH] Create functional test base This will allow adding 'check-glanceclient-dsvm-functional' tests in the gate, similar to: * check-novaclient-dsvm-functional * check-keystoneclient-dsvm-functional * check-neutronclient-dsvm-functional * etc Change-Id: Id970db52695db7dc53206aa05fe573995b57aa78 --- glanceclient/tests/functional/README.rst | 35 +++++++++++++ glanceclient/tests/functional/__init__.py | 0 glanceclient/tests/functional/base.py | 44 ++++++++++++++++ .../tests/functional/hooks/post_test_hook.sh | 50 +++++++++++++++++++ .../tests/functional/test_readonly_glance.py | 25 ++++++++++ test-requirements.txt | 1 + tox.ini | 4 ++ 7 files changed, 159 insertions(+) create mode 100644 glanceclient/tests/functional/README.rst create mode 100644 glanceclient/tests/functional/__init__.py create mode 100644 glanceclient/tests/functional/base.py create mode 100755 glanceclient/tests/functional/hooks/post_test_hook.sh create mode 100644 glanceclient/tests/functional/test_readonly_glance.py diff --git a/glanceclient/tests/functional/README.rst b/glanceclient/tests/functional/README.rst new file mode 100644 index 00000000..01b732f3 --- /dev/null +++ b/glanceclient/tests/functional/README.rst @@ -0,0 +1,35 @@ +===================================== +python-glanceclient functional testing +===================================== + +Idea +------ + +Run real client/server requests in the gate to catch issues which +are difficult to catch with a purely unit test approach. + +Many projects (nova, keystone...) already have this form of testing in +the gate. + + +Testing Theory +---------------- + +Since python-glanceclient has two uses, CLI and python API, we should +have two sets of functional tests. CLI and python API. The python API +tests should never use the CLI. But the CLI tests can use the python API +where adding native support to the CLI for the required functionality +would involve a non trivial amount of work. + + +Functional Test Guidelines +--------------------------- + +* Consume credentials via standard client environmental variables:: + + OS_USERNAME + OS_PASSWORD + OS_TENANT_NAME + OS_AUTH_URL + +* Try not to require an additional configuration file diff --git a/glanceclient/tests/functional/__init__.py b/glanceclient/tests/functional/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/glanceclient/tests/functional/base.py b/glanceclient/tests/functional/base.py new file mode 100644 index 00000000..89b9092a --- /dev/null +++ b/glanceclient/tests/functional/base.py @@ -0,0 +1,44 @@ +# 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 tempest_lib.cli import base + + +class ClientTestBase(base.ClientTestBase): + """ + This is a first pass at a simple read only python-glanceclient test. This + only exercises client commands that are read only. + + This should test commands: + * as a regular user + * as an admin user + * with and without optional parameters + * initially just check return codes, and later test command outputs + + """ + def _get_clients(self): + cli_dir = os.environ.get( + 'OS_GLANCECLIENT_EXEC_DIR', + os.path.join(os.path.abspath('.'), '.tox/functional/bin')) + + return base.CLIClient( + username=os.environ.get('OS_USERNAME'), + password=os.environ.get('OS_PASSWORD'), + tenant_name=os.environ.get('OS_TENANT_NAME'), + uri=os.environ.get('OS_AUTH_URL'), + cli_dir=cli_dir) + + def glance(self, *args, **kwargs): + return self.clients.glance(*args, + **kwargs) diff --git a/glanceclient/tests/functional/hooks/post_test_hook.sh b/glanceclient/tests/functional/hooks/post_test_hook.sh new file mode 100755 index 00000000..34498f34 --- /dev/null +++ b/glanceclient/tests/functional/hooks/post_test_hook.sh @@ -0,0 +1,50 @@ +#!/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. + +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 .tox/functional/bin/python /usr/local/jenkins/slave_scripts/subunit2html.py $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 GLANCECLIENT_DIR="$BASE/new/python-glanceclient" + +# Get admin credentials +cd $BASE/new/devstack +source openrc admin admin + +# Go to the glanceclient dir +cd $GLANCECLIENT_DIR + +sudo chown -R jenkins:stack $GLANCECLIENT_DIR + +# Run tests +echo "Running glanceclient 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 diff --git a/glanceclient/tests/functional/test_readonly_glance.py b/glanceclient/tests/functional/test_readonly_glance.py new file mode 100644 index 00000000..773d52db --- /dev/null +++ b/glanceclient/tests/functional/test_readonly_glance.py @@ -0,0 +1,25 @@ +# 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. + +from glanceclient.tests.functional import base + + +class SimpleReadOnlyGlanceClientTest(base.ClientTestBase): + + """ + read only functional python-glanceclient tests. + + This only exercises client commands that are read only. + """ + + def test_list(self): + self.glance('image-list') diff --git a/test-requirements.txt b/test-requirements.txt index b0e7f678..c2c4b424 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -12,3 +12,4 @@ testrepository>=0.0.18 testtools>=0.9.36,!=1.2.0 fixtures>=0.3.14 requests-mock>=0.6.0 # Apache-2.0 +tempest-lib>=0.4.0 diff --git a/tox.ini b/tox.ini index 7331edd4..f3a29009 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,10 @@ commands = flake8 [testenv:venv] commands = {posargs} +[testenv:functional] +setenv = + OS_TEST_PATH = ./glanceclient/tests/functional + [testenv:cover] commands = python setup.py testr --coverage --testr-args='{posargs}'