The first functional test

Just implementing a single functional test to start things off.

This test introduces a new test dependency on os-client-config.
os-client-config is used to configure the SDK to run its functional test
on a particular cloud.

To run the functional tests do a

    tox -e functional

Unit tests continue to be run the same way as always.

Change-Id: Id1e8233c5e366e6ec864fb435f7f3cbf290ffae0
This commit is contained in:
Everett Toews 2015-04-02 22:43:48 -05:00
parent d8d4400be5
commit 22bc68ebfb
12 changed files with 217 additions and 29 deletions

3
.gitignore vendored
View File

@ -28,6 +28,9 @@ pip-log.txt
nosetests.xml
.testrepository
# os-client-config
clouds.yaml
# Translations
*.mo

View File

@ -2,6 +2,6 @@
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:-./openstack/tests/unit} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -45,6 +45,18 @@ documented in our `setup <setup.html>`_ section.
setup
Testing
-------
The project contains two test packages, one for unit tests and one for
functional tests. The ``openstack.tests.unit`` package tests the SDK's
features in isolation. The ``openstack.tests.functional`` package tests
the SDK's features against an OpenStack cloud.
.. toctree::
testing
Project Layout
--------------

View File

@ -0,0 +1,55 @@
[[local|localrc]]
# Configure passwords and the Swift Hash
MYSQL_PASSWORD=DEVSTACK_PASSWORD
RABBIT_PASSWORD=DEVSTACK_PASSWORD
SERVICE_TOKEN=DEVSTACK_PASSWORD
ADMIN_PASSWORD=DEVSTACK_PASSWORD
SERVICE_PASSWORD=DEVSTACK_PASSWORD
SWIFT_HASH=DEVSTACK_PASSWORD
# Configure the stable OpenStack branches used by DevStack
# For stable branches see
# http://git.openstack.org/cgit/openstack-dev/devstack/refs/
CINDER_BRANCH=stable/OPENSTACK_VERSION
CEILOMETER_BRANCH=stable/OPENSTACK_VERSION
GLANCE_BRANCH=stable/OPENSTACK_VERSION
HEAT_BRANCH=stable/OPENSTACK_VERSION
HORIZON_BRANCH=stable/OPENSTACK_VERSION
KEYSTONE_BRANCH=stable/OPENSTACK_VERSION
NEUTRON_BRANCH=stable/OPENSTACK_VERSION
NOVA_BRANCH=stable/OPENSTACK_VERSION
SWIFT_BRANCH=stable/OPENSTACK_VERSION
# Enable Swift
enable_service s-proxy
enable_service s-object
enable_service s-container
enable_service s-account
# Disable Nova Network and enable Neutron
disable_service n-net
enable_service q-svc
enable_service q-agt
enable_service q-dhcp
enable_service q-l3
enable_service q-meta
enable_service q-metering
# Enable Ceilometer
enable_service ceilometer-acompute
enable_service ceilometer-acentral
enable_service ceilometer-anotification
enable_service ceilometer-collector
enable_service ceilometer-alarm-evaluator
enable_service ceilometer-alarm-notifier
enable_service ceilometer-api
# Automatically download and register a VM image that Heat can launch
# For more information on Heat and DevStack see
# http://docs.openstack.org/developer/heat/getting_started/on_devstack.html
IMAGE_URLS+=",http://cloud.fedoraproject.org/fedora-20.x86_64.qcow2"
# Logging
LOGDAYS=1
LOGFILE=/opt/stack/logs/stack.sh.log
LOGDIR=/opt/stack/logs

View File

@ -122,33 +122,6 @@ environment to use the SDK in. This step installs the following dependencies.
* `stevedore <https://pypi.python.org/pypi/stevedore>`_, which we use for
working with plugins. stevedore builds on setuptools ``entry_points``.
Running the Tests
-----------------
In order to run the entire test suite, simply run the ``tox`` command inside
of your source checkout. This will attempt to run every test command listed
inside of ``tox.ini``, which includes Python 2.6, 2.7, 3.3, 3.4, PyPy, and
a PEP 8 check. You should run the full test suite on all versions before
submitting changes for review in order to avoid unexpected failures in
the continuous integration system.::
(sdk3)$ tox
...
py33: commands succeeded
py34: commands succeeded
py26: commands succeeded
py27: commands succeeded
pypy: commands succeeded
pep8: commands succeeded
congratulations :)
During development, it may be more convenient to run a subset of the tests
to keep test time to a minimum. You can choose to run the tests only on one
version. A step further is to run only the tests you are working on.::
(sdk3)$ tox -e py34 # Run run the tests on Python 3.4
(sdk3)$ tox -e py34 TestContainer # Run only the TestContainer tests on 3.4
Building the Documentation
--------------------------

View File

@ -0,0 +1,96 @@
Testing
=======
The tests are run with `tox <https://tox.readthedocs.org/en/latest/>`_ and
configured in ``tox.ini``. The test results are tracked by
`testr <https://testrepository.readthedocs.org/en/latest/>`_ and configured
in ``.testr.conf``.
Unit Tests
----------
Run
***
In order to run the entire unit test suite, simply run the ``tox`` command
inside of your source checkout. This will attempt to run every test command
listed inside of ``tox.ini``, which includes Python 2.7, 3.3, 3.4, PyPy,
and a PEP 8 check. You should run the full test suite on all versions before
submitting changes for review in order to avoid unexpected failures in the
continuous integration system.::
(sdk3)$ tox
...
py33: commands succeeded
py34: commands succeeded
py27: commands succeeded
pypy: commands succeeded
pep8: commands succeeded
congratulations :)
During development, it may be more convenient to run a subset of the tests
to keep test time to a minimum. You can choose to run the tests only on one
version. A step further is to run only the tests you are working on.::
(sdk3)$ tox -e py34 # Run run the tests on Python 3.4
(sdk3)$ tox -e py34 TestContainer # Run only the TestContainer tests on 3.4
Functional Tests
----------------
The functional tests assume that you have a public or private OpenStack cloud
that you can run the tests against. The tests must be able to be run against
public clouds but first and foremost they must be run against OpenStack. In
practice, this means that the tests should initially be run against a stable
branch of `DevStack <http://docs.openstack.org/developer/devstack/>`_.
DevStack
********
There are many ways to run and configure DevStack. The link above will show
you how to run DevStack a number of ways. You'll need to choose a method
you're familiar with and can run in your environment. Wherever DevStack is
running, we need to make sure that python-openstacksdk contributors are
using the same configuration.
This is the ``local.conf`` file we use to configure DevStack.
.. literalinclude:: local.conf
Replace ``DEVSTACK_PASSWORD`` with a password of your choice.
Replace ``OPENSTACK_VERSION`` with a `stable branch <http://git.openstack.org/cgit/openstack-dev/devstack/refs/>`_
of OpenStack (without the ``stable/`` prefix on the branch name).
os-client-config
****************
To connect the functional tests to an OpenStack cloud we use
`os-client-config <http://git.openstack.org/cgit/openstack/os-client-config/tree/README.rst>`_.
To setup os-client-config create a ``clouds.yaml`` file in the root of your
source checkout.
This is an example of a minimal configuration for a ``clouds.yaml`` that
connects the functional tests to a DevStack instance. Note that one cloud
under ``clouds`` must be named ``test_cloud``.
.. literalinclude:: clouds.yaml
:language: yaml
Replace ``xxx.xxx.xxx.xxx`` with the IP address or FQDN of your DevStack instance.
Run
***
In order to run the entire functional test suite, simply run the
``tox -e functional`` command inside of your source checkout. This will
attempt to run every test command under ``/openstack/tests/functional/``
in the source tree. The functional tests are run with your system Python
interpreter. You should run the full functional test suite before submitting
changes for review in order to avoid unexpected failures in the continuous
integration system.::
(sdk3)$ tox -e functional
...
functional: commands succeeded
congratulations :)

View File

View File

@ -0,0 +1,46 @@
# 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 unittest
import os_client_config
import six
from openstack import connection
from openstack import user_preference
class TestFlavor(unittest.TestCase):
def setUp(self):
test_cloud = os_client_config.OpenStackConfig().get_one_cloud(
'test_cloud')
pref = user_preference.UserPreference()
pref.set_region(pref.ALL, test_cloud.region)
self.conn = connection.Connection(
preference=pref,
auth_url=test_cloud.config['auth']['auth_url'],
project_name=test_cloud.config['auth']['project_name'],
username=test_cloud.config['auth']['username'],
password=test_cloud.config['auth']['password'])
def test_flavors(self):
flavors = list(self.conn.compute.list_flavors())
self.assertGreater(len(flavors), 0)
for flavor in flavors:
self.assertIsInstance(flavor.id, six.string_types)
self.assertIsInstance(flavor.name, six.string_types)
self.assertIsInstance(flavor.disk, int)
self.assertIsInstance(flavor.ram, int)
self.assertIsInstance(flavor.vcpus, int)

View File

@ -12,7 +12,7 @@ python-subunit>=0.0.18
requests-mock>=0.6.0 # Apache-2.0
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
oslosphinx>=2.5.0,<2.6.0 # Apache-2.0
os_client_config
testrepository>=0.0.18
testscenarios>=0.4
testtools>=0.9.36,!=1.2.0

View File

@ -12,6 +12,9 @@ deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}'
[testenv:functional]
setenv = OS_TEST_PATH=./openstack/tests/functional
[testenv:pep8]
commands = flake8