From 22bc68ebfb6696b02be611a1dc6c552edf30c31e Mon Sep 17 00:00:00 2001 From: Everett Toews Date: Thu, 2 Apr 2015 22:43:48 -0500 Subject: [PATCH] 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 --- .gitignore | 3 + .testr.conf | 2 +- doc/source/contributors/index.rst | 12 +++ doc/source/contributors/local.conf | 55 +++++++++++ doc/source/contributors/setup.rst | 27 ------ doc/source/contributors/testing.rst | 96 +++++++++++++++++++ openstack/tests/functional/__init__.py | 0 .../tests/functional/compute/__init__.py | 0 .../tests/functional/compute/v2/__init__.py | 0 .../functional/compute/v2/test_flavor.py | 46 +++++++++ test-requirements.txt | 2 +- tox.ini | 3 + 12 files changed, 217 insertions(+), 29 deletions(-) create mode 100644 doc/source/contributors/local.conf create mode 100644 doc/source/contributors/testing.rst create mode 100644 openstack/tests/functional/__init__.py create mode 100644 openstack/tests/functional/compute/__init__.py create mode 100644 openstack/tests/functional/compute/v2/__init__.py create mode 100644 openstack/tests/functional/compute/v2/test_flavor.py diff --git a/.gitignore b/.gitignore index d75fc901c..0da147822 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,9 @@ pip-log.txt nosetests.xml .testrepository +# os-client-config +clouds.yaml + # Translations *.mo diff --git a/.testr.conf b/.testr.conf index fb622677a..4ae1e204a 100644 --- a/.testr.conf +++ b/.testr.conf @@ -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 \ No newline at end of file diff --git a/doc/source/contributors/index.rst b/doc/source/contributors/index.rst index 8f85b340d..2c41389a1 100644 --- a/doc/source/contributors/index.rst +++ b/doc/source/contributors/index.rst @@ -45,6 +45,18 @@ documented in our `setup `_ 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 -------------- diff --git a/doc/source/contributors/local.conf b/doc/source/contributors/local.conf new file mode 100644 index 000000000..862bea842 --- /dev/null +++ b/doc/source/contributors/local.conf @@ -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 diff --git a/doc/source/contributors/setup.rst b/doc/source/contributors/setup.rst index 36b828f05..1045b6b72 100644 --- a/doc/source/contributors/setup.rst +++ b/doc/source/contributors/setup.rst @@ -122,33 +122,6 @@ environment to use the SDK in. This step installs the following dependencies. * `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 -------------------------- diff --git a/doc/source/contributors/testing.rst b/doc/source/contributors/testing.rst new file mode 100644 index 000000000..dd1938803 --- /dev/null +++ b/doc/source/contributors/testing.rst @@ -0,0 +1,96 @@ +Testing +======= + +The tests are run with `tox `_ and +configured in ``tox.ini``. The test results are tracked by +`testr `_ 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 `_. + +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 `_ +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 `_. +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 :) diff --git a/openstack/tests/functional/__init__.py b/openstack/tests/functional/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/tests/functional/compute/__init__.py b/openstack/tests/functional/compute/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/tests/functional/compute/v2/__init__.py b/openstack/tests/functional/compute/v2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openstack/tests/functional/compute/v2/test_flavor.py b/openstack/tests/functional/compute/v2/test_flavor.py new file mode 100644 index 000000000..6a9b11e42 --- /dev/null +++ b/openstack/tests/functional/compute/v2/test_flavor.py @@ -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) diff --git a/test-requirements.txt b/test-requirements.txt index d253ec9b5..5b8e32688 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 - diff --git a/tox.ini b/tox.ini index f30525927..6c13da826 100644 --- a/tox.ini +++ b/tox.ini @@ -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