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
This commit is contained in:
parent
f2a8a520e7
commit
71d97836f8
35
glanceclient/tests/functional/README.rst
Normal file
35
glanceclient/tests/functional/README.rst
Normal file
@ -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
|
0
glanceclient/tests/functional/__init__.py
Normal file
0
glanceclient/tests/functional/__init__.py
Normal file
44
glanceclient/tests/functional/base.py
Normal file
44
glanceclient/tests/functional/base.py
Normal file
@ -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)
|
50
glanceclient/tests/functional/hooks/post_test_hook.sh
Executable file
50
glanceclient/tests/functional/hooks/post_test_hook.sh
Executable file
@ -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
|
25
glanceclient/tests/functional/test_readonly_glance.py
Normal file
25
glanceclient/tests/functional/test_readonly_glance.py
Normal file
@ -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')
|
@ -12,3 +12,4 @@ testrepository>=0.0.18
|
|||||||
testtools>=0.9.36,!=1.2.0
|
testtools>=0.9.36,!=1.2.0
|
||||||
fixtures>=0.3.14
|
fixtures>=0.3.14
|
||||||
requests-mock>=0.6.0 # Apache-2.0
|
requests-mock>=0.6.0 # Apache-2.0
|
||||||
|
tempest-lib>=0.4.0
|
||||||
|
4
tox.ini
4
tox.ini
@ -21,6 +21,10 @@ commands = flake8
|
|||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
commands = {posargs}
|
commands = {posargs}
|
||||||
|
|
||||||
|
[testenv:functional]
|
||||||
|
setenv =
|
||||||
|
OS_TEST_PATH = ./glanceclient/tests/functional
|
||||||
|
|
||||||
[testenv:cover]
|
[testenv:cover]
|
||||||
commands = python setup.py testr --coverage --testr-args='{posargs}'
|
commands = python setup.py testr --coverage --testr-args='{posargs}'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user