Merge "Adds test_show_XX_fields cases to show some fields"
diff --git a/README.rst b/README.rst
index 4098e32..9daf873 100644
--- a/README.rst
+++ b/README.rst
@@ -63,13 +63,13 @@
used tool. After setting up your configuration file, you can execute
the set of Tempest tests by using ``testr`` ::
- $> testr run --parallel tempest
+ $> testr run --parallel
To run one single test ::
$> testr run --parallel tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON.test_reboot_non_existent_server
-Alternatively, you can use the run_tests.sh script which will create a venv
+Alternatively, you can use the run_tempest.sh script which will create a venv
and run the tests or use tox to do the same.
Configuration
@@ -101,3 +101,32 @@
For the moment, the best solution is to provide the same image uuid for
both image_ref and image_ref_alt. Tempest will skip tests as needed if it
detects that both images are the same.
+
+Unit Tests
+----------
+
+Tempest also has a set of unit tests which test the tempest code itself. These
+tests can be run by specifing the test discovery path::
+
+ $> OS_TEST_PATH=./tempest/tests testr run --parallel
+
+By setting OS_TEST_PATH to ./tempest/tests it specifies that test discover
+should only be run on the unit test directory. The default value of OS_TEST_PATH
+is OS_TEST_PATH=./tempest/test_discover which will only run test discover on the
+tempest suite.
+
+Alternatively, you can use the run_tests.sh script which will create a venv and
+run the unit tests. There are also the py26, py27, or py33 tox jobs which will
+run the unit tests with the corresponding version of python.
+
+Python 2.6
+----------
+
+Tempest can be run with Python 2.6 however the unit tests and the gate
+currently only run with Python 2.7, so there are no guarantees about the state
+of tempest when running with Python 2.6. Additionally, to enable testr to work
+with tempest using python 2.6 the discover module from the unittest-ext
+project has to be patched to switch the unittest.TestSuite to use
+unittest2.TestSuite instead. See::
+
+https://code.google.com/p/unittest-ext/issues/detail?id=79
diff --git a/doc/source/conf.py b/doc/source/conf.py
index e5444ae..bd4e553 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -30,7 +30,7 @@
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
- 'oslo.sphinx'
+ 'oslosphinx'
]
todo_include_todos = True
diff --git a/etc/schemas/compute/flavors/flavor_details.json b/etc/schemas/compute/flavors/flavor_details.json
new file mode 100644
index 0000000..c16075c
--- /dev/null
+++ b/etc/schemas/compute/flavors/flavor_details.json
@@ -0,0 +1,8 @@
+{
+ "name": "get-flavor-details",
+ "http-method": "GET",
+ "url": "flavors/%s",
+ "resources": [
+ {"name": "flavor", "expected_result": 404}
+ ]
+}
diff --git a/etc/schemas/compute/flavors/flavors_list.json b/etc/schemas/compute/flavors/flavors_list.json
new file mode 100644
index 0000000..eb8383b
--- /dev/null
+++ b/etc/schemas/compute/flavors/flavors_list.json
@@ -0,0 +1,24 @@
+{
+ "name": "list-flavors-with-detail",
+ "http-method": "GET",
+ "url": "flavors/detail",
+ "json-schema": {
+ "type": "object",
+ "properties": {
+ "minRam": {
+ "type": "integer",
+ "results": {
+ "gen_none": 400,
+ "gen_string": 400
+ }
+ },
+ "minDisk": {
+ "type": "integer",
+ "results": {
+ "gen_none": 400,
+ "gen_string": 400
+ }
+ }
+ }
+ }
+}
diff --git a/etc/schemas/compute/servers/get_console_output.json b/etc/schemas/compute/servers/get_console_output.json
new file mode 100644
index 0000000..8d974ba
--- /dev/null
+++ b/etc/schemas/compute/servers/get_console_output.json
@@ -0,0 +1,23 @@
+{
+ "name": "get-console-output",
+ "http-method": "POST",
+ "url": "servers/%s/action",
+ "resources": [
+ {"name":"server", "expected_result": 404}
+ ],
+ "json-schema": {
+ "type": "object",
+ "properties": {
+ "os-getConsoleOutput": {
+ "type": "object",
+ "properties": {
+ "length": {
+ "type": ["integer", "string"],
+ "minimum": 0
+ }
+ }
+ }
+ },
+ "additionalProperties": false
+ }
+}
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index f306d8e..fe4959b 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -95,6 +95,17 @@
#syslog_log_facility=LOG_USER
+[baremetal]
+
+#
+# Options defined in tempest.config
+#
+
+# Catalog type of the baremetal provisioning service. (string
+# value)
+#catalog_type=baremetal
+
+
[boto]
#
@@ -144,7 +155,7 @@
[cli]
#
-# Options defined in tempest.cli
+# Options defined in tempest.config
#
# enable cli tests (boolean value)
@@ -215,7 +226,7 @@
# Timeout in seconds to wait for ping to succeed. (integer
# value)
-#ping_timeout=60
+#ping_timeout=120
# Timeout in seconds to wait for authentication to succeed.
# (integer value)
@@ -386,6 +397,10 @@
# (string value)
#uri_v3=<None>
+# Identity API version to be used for authentication for API
+# tests. (string value)
+#auth_version=v2
+
# The identity region name to use. Also used as the other
# services' region name unless they are set explicitly. If no
# such region is found in the service catalog, the first found
@@ -416,7 +431,7 @@
# (string value)
#alt_password=<None>
-# Administrative Username to use forKeystone API requests.
+# Administrative Username to use for Keystone API requests.
# (string value)
#admin_username=admin
@@ -428,6 +443,17 @@
#admin_password=pass
+[identity-feature-enabled]
+
+#
+# Options defined in tempest.config
+#
+
+# Does the identity service have delegation and impersonation
+# enabled (boolean value)
+#trust=true
+
+
[image]
#
@@ -460,6 +486,29 @@
#api_v1=true
+[input-scenario]
+
+#
+# Options defined in tempest.config
+#
+
+# Matching images become parameters for scenario tests (string
+# value)
+#image_regex=^cirros-0.3.1-x86_64-uec$
+
+# Matching flavors become parameters for scenario tests
+# (string value)
+#flavor_regex=^m1.nano$
+
+# SSH verification in tests is skippedfor matching images
+# (string value)
+#non_ssh_image_regex=^.*[Ww]in.*$
+
+# List of user mapped to regex to matching image names.
+# (string value)
+#ssh_user_regex=[["^.*[Cc]irros.*$", "root"]]
+
+
[network]
#
@@ -529,11 +578,11 @@
# (string value)
#region=
-# Number of seconds to time on waiting for a containerto
+# Number of seconds to time on waiting for a container to
# container synchronization complete. (integer value)
#container_sync_timeout=120
-# Number of seconds to wait while looping to check thestatus
+# Number of seconds to wait while looping to check the status
# of a container to container synchronization (integer value)
#container_sync_interval=5
@@ -548,21 +597,10 @@
# Options defined in tempest.config
#
-# Set to True if the Container Quota middleware is enabled
-# (boolean value)
-#container_quotas=true
-
-# Set to True if the Account Quota middleware is enabled
-# (boolean value)
-#accounts_quotas=true
-
-# Set to True if the Crossdomain middleware is enabled
-# (boolean value)
-#crossdomain=true
-
-# Set to True if the TempURL middleware is enabled (boolean
-# value)
-#tempurl=true
+# A list of the enabled optional discoverable apis. A single
+# entry, all, indicates that all of these features are
+# expected to be enabled (list value)
+#discoverable_apis=all
[orchestration]
@@ -672,6 +710,10 @@
# value)
#savanna=false
+# Whether or not Ironic is expected to be available (boolean
+# value)
+#ironic=false
+
[stress]
@@ -710,6 +752,11 @@
# value)
#default_thread_number_per_action=4
+# Prevent the cleaning (tearDownClass()) between each stress
+# test run if an exception occurs during this run. (boolean
+# value)
+#leave_dirty_stack=false
+
[telemetry]
diff --git a/etc/whitelist.yaml b/etc/whitelist.yaml
index a8c5276..2d8b741 100644
--- a/etc/whitelist.yaml
+++ b/etc/whitelist.yaml
@@ -39,6 +39,8 @@
message: "Instance failed network setup after 1 attempt"
- module: "nova.compute.manager"
message: "Periodic sync_power_state task had an error"
+ - module: "nova.virt.driver"
+ message: "Info cache for instance .* could not be found"
g-api:
- module: "glance.store.sheepdog"
@@ -73,6 +75,12 @@
- module: "ceilometer.compute.pollsters.disk"
message: ".*"
+ceilometer-acentral:
+ - module: "ceilometer.central.manager"
+ message: "403 Forbidden"
+ - module: "ceilometer.central.manager"
+ message: "get_samples\\(\\) got an unexpected keyword argument 'resources'"
+
ceilometer-alarm-evaluator:
- module: "ceilometer.alarm.service"
message: "alarm evaluation cycle failed"
@@ -127,6 +135,8 @@
message: "but the actual state is deleting to caller"
- module: "nova.openstack.common.rpc.common"
message: "Traceback \\(most recent call last"
+ - module: "nova.openstack.common.threadgroup"
+ message: "Service with host .* topic conductor exists."
n-sch:
- module: "nova.scheduler.filter_scheduler"
diff --git a/requirements.txt b/requirements.txt
index 0c4a659..8c0f872 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,24 +1,25 @@
pbr>=0.5.21,<1.0
anyjson>=0.3.3
nose
-httplib2
-jsonschema>=1.3.0,!=1.4.0
-testtools>=0.9.32
+httplib2>=0.7.5
+jsonschema>=2.0.0,<3.0.0
+testtools>=0.9.34
lxml>=2.3
boto>=2.12.0,!=2.13.0
-paramiko>=1.8.0
+paramiko>=1.9.0
netaddr>=0.7.6
python-glanceclient>=0.9.0
-python-keystoneclient>=0.4.1
+python-keystoneclient>=0.4.2
python-novaclient>=2.15.0
-python-neutronclient>=2.3.0,<3
+python-neutronclient>=2.3.3,<3
python-cinderclient>=1.0.6
python-heatclient>=0.2.3
python-swiftclient>=1.5
testresources>=0.2.4
-keyring>=1.6.1,<2.0
+keyring>=1.6.1,<2.0,>=2.1
testrepository>=0.0.17
oslo.config>=1.2.0
six>=1.4.1
iso8601>=0.1.8
fixtures>=0.3.14
+testscenarios>=0.4
diff --git a/run_tempest.sh b/run_tempest.sh
new file mode 100755
index 0000000..f6c330d
--- /dev/null
+++ b/run_tempest.sh
@@ -0,0 +1,167 @@
+#!/usr/bin/env bash
+
+function usage {
+ echo "Usage: $0 [OPTION]..."
+ echo "Run Tempest test suite"
+ echo ""
+ echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
+ echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
+ echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment"
+ echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
+ echo " -u, --update Update the virtual environment with any newer package versions"
+ echo " -s, --smoke Only run smoke tests"
+ echo " -t, --serial Run testr serially"
+ echo " -C, --config Config file location"
+ echo " -h, --help Print this usage message"
+ echo " -d, --debug Run tests with testtools instead of testr. This allows you to use PDB"
+ echo " -l, --logging Enable logging"
+ echo " -L, --logging-config Logging config file location. Default is etc/logging.conf"
+ echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
+}
+
+testrargs=""
+venv=.venv
+with_venv=tools/with_venv.sh
+serial=0
+always_venv=0
+never_venv=0
+no_site_packages=0
+debug=0
+force=0
+wrapper=""
+config_file=""
+update=0
+logging=0
+logging_config=etc/logging.conf
+
+if ! options=$(getopt -o VNnfusthdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,help,debug,config:,logging,logging-config: -- "$@")
+then
+ # parse error
+ usage
+ exit 1
+fi
+
+eval set -- $options
+first_uu=yes
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help) usage; exit;;
+ -V|--virtual-env) always_venv=1; never_venv=0;;
+ -N|--no-virtual-env) always_venv=0; never_venv=1;;
+ -n|--no-site-packages) no_site_packages=1;;
+ -f|--force) force=1;;
+ -u|--update) update=1;;
+ -d|--debug) debug=1;;
+ -C|--config) config_file=$2; shift;;
+ -s|--smoke) testrargs+="smoke"; noseargs+="--attr=type=smoke";;
+ -t|--serial) serial=1;;
+ -l|--logging) logging=1;;
+ -L|--logging-config) logging_config=$2; shift;;
+ --) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
+ *) testrargs="$testrargs $1"; noseargs+=" $1" ;;
+ esac
+ shift
+done
+
+if [ -n "$config_file" ]; then
+ config_file=`readlink -f "$config_file"`
+ export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
+ export TEMPEST_CONFIG=`basename "$config_file"`
+fi
+
+if [ $logging -eq 1 ]; then
+ if [ ! -f "$logging_config" ]; then
+ echo "No such logging config file: $logging_config"
+ exit 1
+ fi
+ logging_config=`readlink -f "$logging_config"`
+ export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
+ export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
+fi
+
+cd `dirname "$0"`
+
+if [ $no_site_packages -eq 1 ]; then
+ installvenvopts="--no-site-packages"
+fi
+
+function testr_init {
+ if [ ! -d .testrepository ]; then
+ ${wrapper} testr init
+ fi
+}
+
+function run_tests {
+ testr_init
+ ${wrapper} find . -type f -name "*.pyc" -delete
+ export OS_TEST_PATH=./tempest/test_discover
+ if [ $debug -eq 1 ]; then
+ if [ "$testrargs" = "" ]; then
+ testrargs="discover ./tempest/test_discover"
+ fi
+ ${wrapper} python -m testtools.run $testrargs
+ return $?
+ fi
+
+ if [ $serial -eq 1 ]; then
+ ${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
+ else
+ ${wrapper} testr run --parallel --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
+ fi
+}
+
+function run_tests_nose {
+ export NOSE_WITH_OPENSTACK=1
+ export NOSE_OPENSTACK_COLOR=1
+ export NOSE_OPENSTACK_RED=15.00
+ export NOSE_OPENSTACK_YELLOW=3.00
+ export NOSE_OPENSTACK_SHOW_ELAPSED=1
+ export NOSE_OPENSTACK_STDOUT=1
+ export TEMPEST_PY26_NOSE_COMPAT=1
+ if [[ "x$noseargs" =~ "tempest" ]]; then
+ noseargs="$testrargs"
+ else
+ noseargs="$noseargs tempest"
+ fi
+ ${wrapper} nosetests $noseargs
+}
+
+if [ $never_venv -eq 0 ]
+then
+ # Remove the virtual environment if --force used
+ if [ $force -eq 1 ]; then
+ echo "Cleaning virtualenv..."
+ rm -rf ${venv}
+ fi
+ if [ $update -eq 1 ]; then
+ echo "Updating virtualenv..."
+ python tools/install_venv.py $installvenvopts
+ fi
+ if [ -e ${venv} ]; then
+ wrapper="${with_venv}"
+ else
+ if [ $always_venv -eq 1 ]; then
+ # Automatically install the virtualenv
+ python tools/install_venv.py $installvenvopts
+ wrapper="${with_venv}"
+ else
+ echo -e "No virtual environment found...create one? (Y/n) \c"
+ read use_ve
+ if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
+ # Install the virtualenv and run the test suite in it
+ python tools/install_venv.py $installvenvopts
+ wrapper=${with_venv}
+ fi
+ fi
+ fi
+fi
+
+py_version=`${wrapper} python --version 2>&1`
+if [[ $py_version =~ "2.6" ]] ; then
+ run_tests_nose
+else
+ run_tests
+fi
+retval=$?
+
+exit $retval
diff --git a/run_tests.sh b/run_tests.sh
index 3c9c051..eaa7fd7 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -2,21 +2,18 @@
function usage {
echo "Usage: $0 [OPTION]..."
- echo "Run Tempest test suite"
+ echo "Run Tempest unit tests"
echo ""
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
echo " -n, --no-site-packages Isolate the virtualenv from the global Python environment"
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
echo " -u, --update Update the virtual environment with any newer package versions"
- echo " -s, --smoke Only run smoke tests"
echo " -t, --serial Run testr serially"
- echo " -C, --config Config file location"
echo " -p, --pep8 Just run pep8"
+ echo " -c, --coverage Generate coverage report"
echo " -h, --help Print this usage message"
- echo " -d, --debug Debug this script -- set -o xtrace"
- echo " -l, --logging Enable logging"
- echo " -L, --logging-config Logging config file location. Default is etc/logging.conf"
+ echo " -d, --debug Run tests with testtools instead of testr. This allows you to use PDB"
echo " -- [TESTROPTIONS] After the first '--' you can pass arbitrary arguments to testr "
}
@@ -28,14 +25,14 @@
always_venv=0
never_venv=0
no_site_packages=0
+debug=0
force=0
+coverage=0
wrapper=""
config_file=""
update=0
-logging=0
-logging_config=etc/logging.conf
-if ! options=$(getopt -o VNnfustphdC:lL: -l virtual-env,no-virtual-env,no-site-packages,force,update,smoke,serial,pep8,help,debug,config:,logging,logging-config: -- "$@")
+if ! options=$(getopt -o VNnfuctphd -l virtual-env,no-virtual-env,no-site-packages,force,update,serial,coverage,pep8,help,debug -- "$@")
then
# parse error
usage
@@ -52,34 +49,16 @@
-n|--no-site-packages) no_site_packages=1;;
-f|--force) force=1;;
-u|--update) update=1;;
- -d|--debug) set -o xtrace;;
- -C|--config) config_file=$2; shift;;
+ -d|--debug) debug=1;;
-p|--pep8) let just_pep8=1;;
- -s|--smoke) testrargs+="smoke"; noseargs+="--attr=type=smoke";;
+ -c|--coverage) coverage=1;;
-t|--serial) serial=1;;
- -l|--logging) logging=1;;
- -L|--logging-config) logging_config=$2; shift;;
--) [ "yes" == "$first_uu" ] || testrargs="$testrargs $1"; first_uu=no ;;
*) testrargs="$testrargs $1"; noseargs+=" $1" ;;
esac
shift
done
-if [ -n "$config_file" ]; then
- config_file=`readlink -f "$config_file"`
- export TEMPEST_CONFIG_DIR=`dirname "$config_file"`
- export TEMPEST_CONFIG=`basename "$config_file"`
-fi
-
-if [ $logging -eq 1 ]; then
- if [ ! -f "$logging_config" ]; then
- echo "No such logging config file: $logging_config"
- exit 1
- fi
- logging_config=`readlink -f "$logging_config"`
- export TEMPEST_LOG_CONFIG_DIR=`dirname "$logging_config"`
- export TEMPEST_LOG_CONFIG=`basename "$logging_config"`
-fi
cd `dirname "$0"`
@@ -96,6 +75,15 @@
function run_tests {
testr_init
${wrapper} find . -type f -name "*.pyc" -delete
+ export OS_TEST_PATH=./tempest/tests
+ if [ $debug -eq 1 ]; then
+ if [ "$testrargs" = "" ]; then
+ testrargs="discover ./tempest/tests"
+ fi
+ ${wrapper} python -m testtools.run $testrargs
+ return $?
+ fi
+
if [ $serial -eq 1 ]; then
${wrapper} testr run --subunit $testrargs | ${wrapper} subunit-2to1 | ${wrapper} tools/colorizer.py
else
@@ -103,22 +91,6 @@
fi
}
-function run_tests_nose {
- export NOSE_WITH_OPENSTACK=1
- export NOSE_OPENSTACK_COLOR=1
- export NOSE_OPENSTACK_RED=15.00
- export NOSE_OPENSTACK_YELLOW=3.00
- export NOSE_OPENSTACK_SHOW_ELAPSED=1
- export NOSE_OPENSTACK_STDOUT=1
- export TEMPEST_PY26_NOSE_COMPAT=1
- if [[ "x$noseargs" =~ "tempest" ]]; then
- noseargs="$testrargs"
- else
- noseargs="$noseargs tempest"
- fi
- ${wrapper} nosetests $noseargs
-}
-
function run_pep8 {
echo "Running flake8 ..."
if [ $never_venv -eq 1 ]; then
@@ -163,12 +135,11 @@
exit
fi
-py_version=`${wrapper} python --version 2>&1`
-if [[ $py_version =~ "2.6" ]] ; then
- run_tests_nose
-else
- run_tests
+if [ $coverage -eq 1 ]; then
+ $testrargs = "--coverage $testrargs"
fi
+
+run_tests
retval=$?
if [ -z "$testrargs" ]; then
diff --git a/tempest/api/__init__.py b/tempest/api/__init__.py
index 0b3d2db..e69de29 100644
--- a/tempest/api/__init__.py
+++ b/tempest/api/__init__.py
@@ -1,16 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# 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.
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/api/baremetal/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/api/baremetal/__init__.py
diff --git a/tempest/api/baremetal/base.py b/tempest/api/baremetal/base.py
new file mode 100644
index 0000000..2e745f8
--- /dev/null
+++ b/tempest/api/baremetal/base.py
@@ -0,0 +1,172 @@
+# 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 functools
+
+from tempest import clients
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import exceptions as exc
+from tempest import test
+
+CONF = config.CONF
+
+
+def creates(resource):
+ """Decorator that adds resources to the appropriate cleanup list."""
+
+ def decorator(f):
+ @functools.wraps(f)
+ def wrapper(cls, *args, **kwargs):
+ result = f(cls, *args, **kwargs)
+ body = result[resource]
+
+ if 'uuid' in body:
+ cls.created_objects[resource].add(body['uuid'])
+
+ return result
+ return wrapper
+ return decorator
+
+
+class BaseBaremetalTest(test.BaseTestCase):
+ """Base class for Baremetal API tests."""
+
+ @classmethod
+ def setUpClass(cls):
+ super(BaseBaremetalTest, cls).setUpClass()
+
+ if not CONF.service_available.ironic:
+ skip_msg = ('%s skipped as Ironic is not available' % cls.__name__)
+ raise cls.skipException(skip_msg)
+
+ mgr = clients.AdminManager()
+ cls.client = mgr.baremetal_client
+
+ cls.created_objects = {'chassis': set(),
+ 'port': set(),
+ 'node': set()}
+
+ @classmethod
+ def tearDownClass(cls):
+ """Ensure that all created objects get destroyed."""
+
+ try:
+ for resource, uuids in cls.created_objects.iteritems():
+ delete_method = getattr(cls.client, 'delete_%s' % resource)
+ for u in uuids:
+ delete_method(u, ignore_errors=exc.NotFound)
+ finally:
+ super(BaseBaremetalTest, cls).tearDownClass()
+
+ @classmethod
+ @creates('chassis')
+ def create_chassis(cls, description=None, expect_errors=False):
+ """
+ Wrapper utility for creating test chassis.
+
+ :param description: A description of the chassis. if not supplied,
+ a random value will be generated.
+ :return: Created chassis.
+
+ """
+ description = description or data_utils.rand_name('test-chassis-')
+ resp, body = cls.client.create_chassis(description=description)
+
+ return {'chassis': body, 'response': resp}
+
+ @classmethod
+ @creates('node')
+ def create_node(cls, chassis_id, cpu_arch='x86', cpu_num=8, storage=1024,
+ memory=4096, driver='fake'):
+ """
+ Wrapper utility for creating test baremetal nodes.
+
+ :param cpu_arch: CPU architecture of the node. Default: x86.
+ :param cpu_num: Number of CPUs. Default: 8.
+ :param storage: Disk size. Default: 1024.
+ :param memory: Available RAM. Default: 4096.
+ :return: Created node.
+
+ """
+ resp, body = cls.client.create_node(chassis_id, cpu_arch=cpu_arch,
+ cpu_num=cpu_num, storage=storage,
+ memory=memory, driver=driver)
+
+ return {'node': body, 'response': resp}
+
+ @classmethod
+ @creates('port')
+ def create_port(cls, node_id, address=None):
+ """
+ Wrapper utility for creating test ports.
+
+ :param address: MAC address of the port. If not supplied, a random
+ value will be generated.
+ :return: Created port.
+
+ """
+ address = address or data_utils.rand_mac_address()
+ resp, body = cls.client.create_port(address=address, node_id=node_id)
+
+ return {'port': body, 'response': resp}
+
+ @classmethod
+ def delete_chassis(cls, chassis_id):
+ """
+ Deletes a chassis having the specified UUID.
+
+ :param uuid: The unique identifier of the chassis.
+ :return: Server response.
+
+ """
+
+ resp, body = cls.client.delete_chassis(chassis_id)
+
+ if chassis_id in cls.created_objects['chassis']:
+ cls.created_objects['chassis'].remove(chassis_id)
+
+ return resp
+
+ @classmethod
+ def delete_node(cls, node_id):
+ """
+ Deletes a node having the specified UUID.
+
+ :param uuid: The unique identifier of the node.
+ :return: Server response.
+
+ """
+
+ resp, body = cls.client.delete_node(node_id)
+
+ if node_id in cls.created_objects['node']:
+ cls.created_objects['node'].remove(node_id)
+
+ return resp
+
+ @classmethod
+ def delete_port(cls, port_id):
+ """
+ Deletes a port having the specified UUID.
+
+ :param uuid: The unique identifier of the port.
+ :return: Server response.
+
+ """
+
+ resp, body = cls.client.delete_port(port_id)
+
+ if port_id in cls.created_objects['port']:
+ cls.created_objects['port'].remove(port_id)
+
+ return resp
diff --git a/tempest/api/baremetal/test_api_discovery.py b/tempest/api/baremetal/test_api_discovery.py
new file mode 100644
index 0000000..e594b3e
--- /dev/null
+++ b/tempest/api/baremetal/test_api_discovery.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.
+
+from tempest.api.baremetal import base
+from tempest import test
+
+
+class TestApiDiscovery(base.BaseBaremetalTest):
+ """Tests for API discovery features."""
+
+ @test.attr(type='smoke')
+ def test_api_versions(self):
+ resp, descr = self.client.get_api_description()
+ expected_versions = ('v1',)
+
+ versions = [version['id'] for version in descr['versions']]
+
+ for v in expected_versions:
+ self.assertIn(v, versions)
+
+ @test.attr(type='smoke')
+ def test_default_version(self):
+ resp, descr = self.client.get_api_description()
+ default_version = descr['default_version']
+
+ self.assertEqual(default_version['id'], 'v1')
+
+ @test.attr(type='smoke')
+ def test_version_1_resources(self):
+ resp, descr = self.client.get_version_description(version='v1')
+ expected_resources = ('nodes', 'chassis',
+ 'ports', 'links', 'media_types')
+
+ for res in expected_resources:
+ self.assertIn(res, descr)
diff --git a/tempest/api/baremetal/test_chassis.py b/tempest/api/baremetal/test_chassis.py
new file mode 100644
index 0000000..7af1336
--- /dev/null
+++ b/tempest/api/baremetal/test_chassis.py
@@ -0,0 +1,76 @@
+# -*- 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.
+
+from tempest.api.baremetal import base
+from tempest.common.utils import data_utils
+from tempest import exceptions as exc
+from tempest import test
+
+
+class TestChassis(base.BaseBaremetalTest):
+ """Tests for chassis."""
+
+ @test.attr(type='smoke')
+ def test_create_chassis(self):
+ descr = data_utils.rand_name('test-chassis-')
+ ch = self.create_chassis(description=descr)['chassis']
+
+ self.assertEqual(ch['description'], descr)
+
+ @test.attr(type='smoke')
+ def test_create_chassis_unicode_description(self):
+ # Use a unicode string for testing:
+ # 'We ♡ OpenStack in Ukraine'
+ descr = u'В Україні ♡ OpenStack!'
+ ch = self.create_chassis(description=descr)['chassis']
+
+ self.assertEqual(ch['description'], descr)
+
+ @test.attr(type='smoke')
+ def test_show_chassis(self):
+ descr = data_utils.rand_name('test-chassis-')
+ uuid = self.create_chassis(description=descr)['chassis']['uuid']
+
+ resp, chassis = self.client.show_chassis(uuid)
+
+ self.assertEqual(chassis['uuid'], uuid)
+ self.assertEqual(chassis['description'], descr)
+
+ @test.attr(type="smoke")
+ def test_list_chassis(self):
+ created_ids = [self.create_chassis()['chassis']['uuid']
+ for i in range(0, 5)]
+
+ resp, body = self.client.list_chassis()
+ loaded_ids = [ch['uuid'] for ch in body['chassis']]
+
+ for i in created_ids:
+ self.assertIn(i, loaded_ids)
+
+ @test.attr(type='smoke')
+ def test_delete_chassis(self):
+ uuid = self.create_chassis()['chassis']['uuid']
+
+ self.delete_chassis(uuid)
+
+ self.assertRaises(exc.NotFound, self.client.show_chassis, uuid)
+
+ @test.attr(type='smoke')
+ def test_update_chassis(self):
+ chassis_id = self.create_chassis()['chassis']['uuid']
+
+ new_description = data_utils.rand_name('new-description-')
+ self.client.update_chassis(chassis_id, description=new_description)
+
+ resp, chassis = self.client.show_chassis(chassis_id)
+ self.assertEqual(chassis['description'], new_description)
diff --git a/tempest/api/baremetal/test_nodes.py b/tempest/api/baremetal/test_nodes.py
new file mode 100644
index 0000000..0f585cb
--- /dev/null
+++ b/tempest/api/baremetal/test_nodes.py
@@ -0,0 +1,95 @@
+# 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 six
+
+from tempest.api.baremetal import base
+from tempest import exceptions as exc
+from tempest import test
+
+
+class TestNodes(base.BaseBaremetalTest):
+ '''Tests for baremetal nodes.'''
+
+ def setUp(self):
+ super(TestNodes, self).setUp()
+
+ self.chassis = self.create_chassis()['chassis']
+
+ @test.attr(type='smoke')
+ def test_create_node(self):
+ params = {'cpu_arch': 'x86_64',
+ 'cpu_num': '12',
+ 'storage': '10240',
+ 'memory': '1024'}
+
+ node = self.create_node(self.chassis['uuid'], **params)['node']
+
+ for key in params:
+ self.assertEqual(node['properties'][key], params[key])
+
+ @test.attr(type='smoke')
+ def test_delete_node(self):
+ node = self.create_node(self.chassis['uuid'])['node']
+ node_id = node['uuid']
+
+ resp = self.delete_node(node_id)
+
+ self.assertEqual(resp['status'], '204')
+ self.assertRaises(exc.NotFound, self.client.show_node, node_id)
+
+ @test.attr(type='smoke')
+ def test_show_node(self):
+ params = {'cpu_arch': 'x86_64',
+ 'cpu_num': '4',
+ 'storage': '100',
+ 'memory': '512'}
+
+ created_node = self.create_node(self.chassis['uuid'], **params)['node']
+ resp, loaded_node = self.client.show_node(created_node['uuid'])
+
+ for key, val in created_node.iteritems():
+ if key not in ('created_at', 'updated_at'):
+ self.assertEqual(loaded_node[key], val)
+
+ @test.attr(type='smoke')
+ def test_list_nodes(self):
+ uuids = [self.create_node(self.chassis['uuid'])['node']['uuid']
+ for i in range(0, 5)]
+
+ resp, body = self.client.list_nodes()
+ loaded_uuids = [n['uuid'] for n in body['nodes']]
+
+ for u in uuids:
+ self.assertIn(u, loaded_uuids)
+
+ @test.attr(type='smoke')
+ def test_update_node(self):
+ props = {'cpu_arch': 'x86_64',
+ 'cpu_num': '12',
+ 'storage': '10',
+ 'memory': '128'}
+
+ node = self.create_node(self.chassis['uuid'], **props)['node']
+ node_id = node['uuid']
+
+ new_props = {'cpu_arch': 'x86',
+ 'cpu_num': '1',
+ 'storage': '10000',
+ 'memory': '12300'}
+
+ self.client.update_node(node_id, properties=new_props)
+ resp, node = self.client.show_node(node_id)
+
+ for name, value in six.iteritems(new_props):
+ if name not in ('created_at', 'updated_at'):
+ self.assertEqual(node['properties'][name], value)
diff --git a/tempest/api/baremetal/test_ports.py b/tempest/api/baremetal/test_ports.py
new file mode 100644
index 0000000..fb2acc7
--- /dev/null
+++ b/tempest/api/baremetal/test_ports.py
@@ -0,0 +1,83 @@
+# 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 tempest.api.baremetal import base
+from tempest.common.utils import data_utils
+from tempest import exceptions as exc
+from tempest import test
+
+
+class TestPorts(base.BaseBaremetalTest):
+ """Tests for ports."""
+
+ def setUp(self):
+ super(TestPorts, self).setUp()
+
+ chassis = self.create_chassis()['chassis']
+ self.node = self.create_node(chassis['uuid'])['node']
+
+ @test.attr(type='smoke')
+ def test_create_port(self):
+ node_id = self.node['uuid']
+ address = data_utils.rand_mac_address()
+
+ port = self.create_port(node_id=node_id, address=address)['port']
+
+ self.assertEqual(port['address'], address)
+ self.assertEqual(port['node_uuid'], node_id)
+
+ @test.attr(type='smoke')
+ def test_delete_port(self):
+ node_id = self.node['uuid']
+ port_id = self.create_port(node_id=node_id)['port']['uuid']
+
+ resp = self.delete_port(port_id)
+
+ self.assertEqual(resp['status'], '204')
+ self.assertRaises(exc.NotFound, self.client.show_port, port_id)
+
+ @test.attr(type='smoke')
+ def test_show_port(self):
+ node_id = self.node['uuid']
+ address = data_utils.rand_mac_address()
+
+ port_id = self.create_port(node_id=node_id,
+ address=address)['port']['uuid']
+
+ resp, port = self.client.show_port(port_id)
+
+ self.assertEqual(port['uuid'], port_id)
+ self.assertEqual(port['address'], address)
+
+ @test.attr(type='smoke')
+ def test_list_ports(self):
+ node_id = self.node['uuid']
+
+ uuids = [self.create_port(node_id=node_id)['port']['uuid']
+ for i in range(0, 5)]
+
+ resp, body = self.client.list_ports()
+ loaded_uuids = [p['uuid'] for p in body['ports']]
+
+ for u in uuids:
+ self.assertIn(u, loaded_uuids)
+
+ @test.attr(type='smoke')
+ def test_update_port(self):
+ node_id = self.node['uuid']
+ port_id = self.create_port(node_id=node_id)['port']['uuid']
+
+ new_address = data_utils.rand_mac_address()
+ self.client.update_port(port_id, address=new_address)
+
+ resp, body = self.client.show_port(port_id)
+ self.assertEqual(body['address'], new_address)
diff --git a/tempest/api/baremetal/test_ports_negative.py b/tempest/api/baremetal/test_ports_negative.py
new file mode 100644
index 0000000..6cb8812
--- /dev/null
+++ b/tempest/api/baremetal/test_ports_negative.py
@@ -0,0 +1,40 @@
+# 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 tempest.api.baremetal import base
+from tempest.common.utils import data_utils
+from tempest import exceptions as exc
+from tempest import test
+
+
+class TestPortsNegative(base.BaseBaremetalTest):
+ """Negative tests for ports."""
+
+ def setUp(self):
+ super(TestPortsNegative, self).setUp()
+
+ chassis = self.create_chassis()['chassis']
+ self.node = self.create_node(chassis['uuid'])['node']
+
+ @test.attr(type='negative')
+ def test_create_port_invalid_mac(self):
+ node_id = self.node['uuid']
+ address = 'not an uuid'
+
+ self.assertRaises(exc.BadRequest,
+ self.create_port, node_id=node_id, address=address)
+
+ @test.attr(type='negative')
+ def test_create_port_wrong_node_id(self):
+ node_id = str(data_utils.rand_uuid())
+
+ self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id)
diff --git a/tempest/api/compute/admin/test_aggregates.py b/tempest/api/compute/admin/test_aggregates.py
index 609d2c6..08d8a0d 100644
--- a/tempest/api/compute/admin/test_aggregates.py
+++ b/tempest/api/compute/admin/test_aggregates.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -46,7 +44,7 @@
def test_aggregate_create_delete(self):
# Create and delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.assertEqual(aggregate_name, aggregate['name'])
self.assertEqual(None, aggregate['availability_zone'])
@@ -60,7 +58,8 @@
# Create and delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
+ resp, aggregate = self.client.create_aggregate(
+ name=aggregate_name, availability_zone=az_name)
self.assertEqual(200, resp.status)
self.assertEqual(aggregate_name, aggregate['name'])
self.assertEqual(az_name, aggregate['availability_zone'])
@@ -73,7 +72,7 @@
def test_aggregate_create_verify_entry_in_list(self):
# Create an aggregate and ensure it is listed.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, aggregates = self.client.list_aggregates()
@@ -86,7 +85,7 @@
def test_aggregate_create_update_metadata_get_details(self):
# Create an aggregate and ensure its details are returned.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, body = self.client.get_aggregate(aggregate['id'])
@@ -110,10 +109,10 @@
@attr(type='gate')
def test_aggregate_create_update_with_az(self):
# Update an aggregate and ensure properties are updated correctly
- self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
+ resp, aggregate = self.client.create_aggregate(
+ name=aggregate_name, availability_zone=az_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertEqual(200, resp.status)
@@ -144,7 +143,7 @@
# Add an host to the given aggregate and remove.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, body = self.client.add_host(aggregate['id'], self.host)
@@ -166,7 +165,7 @@
# Add an host to the given aggregate and list.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.client.add_host(aggregate['id'], self.host)
self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
@@ -184,7 +183,7 @@
# Add an host to the given aggregate and get details.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.client.add_host(aggregate['id'], self.host)
self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
@@ -200,7 +199,8 @@
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
+ resp, aggregate = self.client.create_aggregate(
+ name=aggregate_name, availability_zone=az_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.client.add_host(aggregate['id'], self.host)
self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
diff --git a/tempest/api/compute/admin/test_aggregates_negative.py b/tempest/api/compute/admin/test_aggregates_negative.py
index 8506206..7d92532 100644
--- a/tempest/api/compute/admin/test_aggregates_negative.py
+++ b/tempest/api/compute/admin/test_aggregates_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -49,14 +47,14 @@
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
self.assertRaises(exceptions.Unauthorized,
self.user_client.create_aggregate,
- aggregate_name)
+ name=aggregate_name)
@attr(type=['negative', 'gate'])
def test_aggregate_create_aggregate_name_length_less_than_1(self):
# the length of aggregate name should >= 1 and <=255
self.assertRaises(exceptions.BadRequest,
self.client.create_aggregate,
- '')
+ name='')
@attr(type=['negative', 'gate'])
def test_aggregate_create_aggregate_name_length_exceeds_255(self):
@@ -64,25 +62,25 @@
aggregate_name = 'a' * 256
self.assertRaises(exceptions.BadRequest,
self.client.create_aggregate,
- aggregate_name)
+ name=aggregate_name)
@attr(type=['negative', 'gate'])
def test_aggregate_create_with_existent_aggregate_name(self):
# creating an aggregate with existent aggregate name is forbidden
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(exceptions.Conflict,
self.client.create_aggregate,
- aggregate_name)
+ name=aggregate_name)
@attr(type=['negative', 'gate'])
def test_aggregate_delete_as_user(self):
# Regular user is not allowed to delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -100,7 +98,7 @@
def test_aggregate_get_details_as_user(self):
# Regular user is not allowed to get aggregate details.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -131,7 +129,7 @@
break
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(exceptions.NotFound, self.client.add_host,
@@ -141,7 +139,7 @@
def test_aggregate_add_host_as_user(self):
# Regular user is not allowed to add a host to an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -153,7 +151,7 @@
def test_aggregate_add_existent_host(self):
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -169,7 +167,7 @@
# Regular user is not allowed to remove a host from an aggregate.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, body = self.client.add_host(aggregate['id'], self.host)
@@ -184,7 +182,7 @@
def test_aggregate_remove_nonexistent_host(self):
non_exist_host = data_utils.rand_name('nonexist_host_')
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(200, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
diff --git a/tempest/api/compute/admin/test_availability_zone.py b/tempest/api/compute/admin/test_availability_zone.py
index e1a1a5d..18e4452 100644
--- a/tempest/api/compute/admin/test_availability_zone.py
+++ b/tempest/api/compute/admin/test_availability_zone.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_availability_zone_negative.py b/tempest/api/compute/admin/test_availability_zone_negative.py
index 6ba8d58..d13618c 100644
--- a/tempest/api/compute/admin/test_availability_zone_negative.py
+++ b/tempest/api/compute/admin/test_availability_zone_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/compute/admin/test_fixed_ips.py b/tempest/api/compute/admin/test_fixed_ips.py
index 4989d6f..cfb2f0e 100644
--- a/tempest/api/compute/admin/test_fixed_ips.py
+++ b/tempest/api/compute/admin/test_fixed_ips.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -16,8 +14,11 @@
# under the License.
from tempest.api.compute import base
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
+
class FixedIPsTestJson(base.BaseV2ComputeAdminTest):
_interface = 'json'
@@ -25,7 +26,7 @@
@classmethod
def setUpClass(cls):
super(FixedIPsTestJson, cls).setUpClass()
- if cls.config.service_available.neutron:
+ if CONF.service_available.neutron:
msg = ("%s skipped as neutron is available" % cls.__name__)
raise cls.skipException(msg)
cls.client = cls.os_adm.fixed_ips_client
diff --git a/tempest/api/compute/admin/test_fixed_ips_negative.py b/tempest/api/compute/admin/test_fixed_ips_negative.py
index cf48f0a..def9810 100644
--- a/tempest/api/compute/admin/test_fixed_ips_negative.py
+++ b/tempest/api/compute/admin/test_fixed_ips_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -15,9 +13,12 @@
# under the License.
from tempest.api.compute import base
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
+
class FixedIPsNegativeTestJson(base.BaseV2ComputeAdminTest):
_interface = 'json'
@@ -25,7 +26,7 @@
@classmethod
def setUpClass(cls):
super(FixedIPsNegativeTestJson, cls).setUpClass()
- if cls.config.service_available.neutron:
+ if CONF.service_available.neutron:
msg = ("%s skipped as neutron is available" % cls.__name__)
raise cls.skipException(msg)
cls.client = cls.os_adm.fixed_ips_client
diff --git a/tempest/api/compute/admin/test_flavors.py b/tempest/api/compute/admin/test_flavors.py
index 0fb9460..252f4be 100644
--- a/tempest/api/compute/admin/test_flavors.py
+++ b/tempest/api/compute/admin/test_flavors.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_flavors_access.py b/tempest/api/compute/admin/test_flavors_access.py
index 048312b..da11ab5 100644
--- a/tempest/api/compute/admin/test_flavors_access.py
+++ b/tempest/api/compute/admin/test_flavors_access.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_flavors_access_negative.py b/tempest/api/compute/admin/test_flavors_access_negative.py
index 976124e..c4d54b6 100644
--- a/tempest/api/compute/admin/test_flavors_access_negative.py
+++ b/tempest/api/compute/admin/test_flavors_access_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_flavors_extra_specs.py b/tempest/api/compute/admin/test_flavors_extra_specs.py
index 875f742..1afa693 100644
--- a/tempest/api/compute/admin/test_flavors_extra_specs.py
+++ b/tempest/api/compute/admin/test_flavors_extra_specs.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_flavors_extra_specs_negative.py b/tempest/api/compute/admin/test_flavors_extra_specs_negative.py
index fb09a63..cdf97cc 100644
--- a/tempest/api/compute/admin/test_flavors_extra_specs_negative.py
+++ b/tempest/api/compute/admin/test_flavors_extra_specs_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
# Copyright 2013 IBM Corp.
diff --git a/tempest/api/compute/admin/test_flavors_negative.py b/tempest/api/compute/admin/test_flavors_negative.py
index 1d9198a..ad4ceeb 100644
--- a/tempest/api/compute/admin/test_flavors_negative.py
+++ b/tempest/api/compute/admin/test_flavors_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_hosts.py b/tempest/api/compute/admin/test_hosts.py
index 22e6cf1..a3b4b47 100644
--- a/tempest/api/compute/admin/test_hosts.py
+++ b/tempest/api/compute/admin/test_hosts.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/compute/admin/test_hosts_negative.py b/tempest/api/compute/admin/test_hosts_negative.py
index dbf7967..cb034c9 100644
--- a/tempest/api/compute/admin/test_hosts_negative.py
+++ b/tempest/api/compute/admin/test_hosts_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -66,7 +64,9 @@
self.assertRaises(exceptions.Unauthorized,
self.non_admin_client.update_host,
- hostname)
+ hostname,
+ status='enable',
+ maintenance_mode='enable')
@test.skip_because(bug="1261964", interface="xml")
@test.attr(type=['negative', 'gate'])
diff --git a/tempest/api/compute/admin/test_hypervisor.py b/tempest/api/compute/admin/test_hypervisor.py
index bd431d4..989c0d8 100644
--- a/tempest/api/compute/admin/test_hypervisor.py
+++ b/tempest/api/compute/admin/test_hypervisor.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_hypervisor_negative.py b/tempest/api/compute/admin/test_hypervisor_negative.py
index c6455b5..e41bd18 100644
--- a/tempest/api/compute/admin/test_hypervisor_negative.py
+++ b/tempest/api/compute/admin/test_hypervisor_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_instance_usage_audit_log.py b/tempest/api/compute/admin/test_instance_usage_audit_log.py
index cea6e92..c617178 100644
--- a/tempest/api/compute/admin/test_instance_usage_audit_log.py
+++ b/tempest/api/compute/admin/test_instance_usage_audit_log.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_instance_usage_audit_log_negative.py b/tempest/api/compute/admin/test_instance_usage_audit_log_negative.py
index dcf41c5..10bb1aa 100644
--- a/tempest/api/compute/admin/test_instance_usage_audit_log_negative.py
+++ b/tempest/api/compute/admin/test_instance_usage_audit_log_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_quotas.py b/tempest/api/compute/admin/test_quotas.py
index 66d41b8..d4a32e6 100644
--- a/tempest/api/compute/admin/test_quotas.py
+++ b/tempest/api/compute/admin/test_quotas.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,12 +15,7 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
-from tempest import config
-from tempest import exceptions
-from tempest.test import attr
-from tempest.test import skip_because
-
-CONF = config.CONF
+from tempest import test
class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
@@ -32,11 +25,8 @@
@classmethod
def setUpClass(cls):
super(QuotasAdminTestJSON, cls).setUpClass()
- cls.auth_url = cls.config.identity.uri
cls.client = cls.os.quotas_client
cls.adm_client = cls.os_adm.quotas_client
- cls.identity_admin_client = cls._get_identity_admin_client()
- cls.sg_client = cls.security_groups_client
# NOTE(afazekas): these test cases should always create and use a new
# tenant most of them should be skipped if we can't do that
@@ -51,7 +41,7 @@
'instances', 'security_group_rules',
'cores', 'security_groups'))
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_get_default_quotas(self):
# Admin can get the default resource quota set for a tenant
expected_quota_set = self.default_quota_set | set(['id'])
@@ -62,7 +52,7 @@
sorted(quota_set.keys()))
self.assertEqual(quota_set['id'], self.demo_tenant_id)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_update_all_quota_resources_for_tenant(self):
# Admin can update all the resource quota limits for a tenant
resp, default_quota_set = self.client.get_default_quota_set(
@@ -86,7 +76,7 @@
self.assertEqual(new_quota_set, quota_set)
# TODO(afazekas): merge these test cases
- @attr(type='gate')
+ @test.attr(type='gate')
def test_get_updated_quotas(self):
# Verify that GET shows the updated quota set
tenant_name = data_utils.rand_name('cpu_quota_tenant_')
@@ -104,119 +94,6 @@
self.assertEqual(200, resp.status)
self.assertEqual(quota_set['ram'], 5120)
- # TODO(afazekas): Add dedicated tenant to the skiped quota tests
- # it can be moved into the setUpClass as well
- @attr(type='gate')
- def test_create_server_when_cpu_quota_is_full(self):
- # Disallow server creation when tenant's vcpu quota is full
- resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
- default_vcpu_quota = quota_set['cores']
- vcpu_quota = 0 # Set the quota to zero to conserve resources
-
- resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
- force=True,
- cores=vcpu_quota)
-
- self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
- cores=default_vcpu_quota)
- self.assertRaises(exceptions.OverLimit, self.create_test_server)
-
- @attr(type='gate')
- def test_create_server_when_memory_quota_is_full(self):
- # Disallow server creation when tenant's memory quota is full
- resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
- default_mem_quota = quota_set['ram']
- mem_quota = 0 # Set the quota to zero to conserve resources
-
- self.adm_client.update_quota_set(self.demo_tenant_id,
- force=True,
- ram=mem_quota)
-
- self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
- ram=default_mem_quota)
- self.assertRaises(exceptions.OverLimit, self.create_test_server)
-
- @attr(type='gate')
- def test_update_quota_normal_user(self):
- self.assertRaises(exceptions.Unauthorized,
- self.client.update_quota_set,
- self.demo_tenant_id,
- ram=0)
-
- @attr(type=['negative', 'gate'])
- def test_create_server_when_instances_quota_is_full(self):
- # Once instances quota limit is reached, disallow server creation
- resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
- default_instances_quota = quota_set['instances']
- instances_quota = 0 # Set quota to zero to disallow server creation
-
- self.adm_client.update_quota_set(self.demo_tenant_id,
- force=True,
- instances=instances_quota)
- self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
- instances=default_instances_quota)
- self.assertRaises(exceptions.OverLimit, self.create_test_server)
-
- @skip_because(bug="1186354",
- condition=CONF.service_available.neutron)
- @attr(type=['negative', 'gate'])
- def test_security_groups_exceed_limit(self):
- # Negative test: Creation Security Groups over limit should FAIL
-
- resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
- default_sg_quota = quota_set['security_groups']
- sg_quota = 0 # Set the quota to zero to conserve resources
-
- resp, quota_set =\
- self.adm_client.update_quota_set(self.demo_tenant_id,
- force=True,
- security_groups=sg_quota)
-
- self.addCleanup(self.adm_client.update_quota_set,
- self.demo_tenant_id,
- security_groups=default_sg_quota)
-
- # Check we cannot create anymore
- self.assertRaises(exceptions.OverLimit,
- self.sg_client.create_security_group,
- "sg-overlimit", "sg-desc")
-
- @skip_because(bug="1186354",
- condition=CONF.service_available.neutron)
- @attr(type=['negative', 'gate'])
- def test_security_groups_rules_exceed_limit(self):
- # Negative test: Creation of Security Group Rules should FAIL
- # when we reach limit maxSecurityGroupRules
-
- resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
- default_sg_rules_quota = quota_set['security_group_rules']
- sg_rules_quota = 0 # Set the quota to zero to conserve resources
-
- resp, quota_set =\
- self.adm_client.update_quota_set(
- self.demo_tenant_id,
- force=True,
- security_group_rules=sg_rules_quota)
-
- self.addCleanup(self.adm_client.update_quota_set,
- self.demo_tenant_id,
- security_group_rules=default_sg_rules_quota)
-
- s_name = data_utils.rand_name('securitygroup-')
- s_description = data_utils.rand_name('description-')
- resp, securitygroup =\
- self.sg_client.create_security_group(s_name, s_description)
- self.addCleanup(self.sg_client.delete_security_group,
- securitygroup['id'])
-
- secgroup_id = securitygroup['id']
- ip_protocol = 'tcp'
-
- # Check we cannot create SG rule anymore
- self.assertRaises(exceptions.OverLimit,
- self.sg_client.create_security_group_rule,
- secgroup_id, ip_protocol, 1025, 1025)
-
class QuotasAdminTestXML(QuotasAdminTestJSON):
_interface = 'xml'
diff --git a/tempest/api/compute/admin/test_quotas_negative.py b/tempest/api/compute/admin/test_quotas_negative.py
new file mode 100644
index 0000000..d3696a1
--- /dev/null
+++ b/tempest/api/compute/admin/test_quotas_negative.py
@@ -0,0 +1,155 @@
+# Copyright 2014 NEC Corporation. All rights reserved.
+#
+# 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 tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import exceptions
+from tempest import test
+
+CONF = config.CONF
+
+
+class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
+ _interface = 'json'
+ force_tenant_isolation = True
+
+ @classmethod
+ def setUpClass(cls):
+ super(QuotasAdminNegativeTestJSON, cls).setUpClass()
+ cls.client = cls.os.quotas_client
+ cls.adm_client = cls.os_adm.quotas_client
+ cls.sg_client = cls.security_groups_client
+
+ # NOTE(afazekas): these test cases should always create and use a new
+ # tenant most of them should be skipped if we can't do that
+ cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
+ 'tenantId')
+
+ @test.attr(type=['negative', 'gate'])
+ def test_update_quota_normal_user(self):
+ self.assertRaises(exceptions.Unauthorized,
+ self.client.update_quota_set,
+ self.demo_tenant_id,
+ ram=0)
+
+ # TODO(afazekas): Add dedicated tenant to the skiped quota tests
+ # it can be moved into the setUpClass as well
+ @test.attr(type=['negative', 'gate'])
+ def test_create_server_when_cpu_quota_is_full(self):
+ # Disallow server creation when tenant's vcpu quota is full
+ resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
+ default_vcpu_quota = quota_set['cores']
+ vcpu_quota = 0 # Set the quota to zero to conserve resources
+
+ resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
+ force=True,
+ cores=vcpu_quota)
+
+ self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
+ cores=default_vcpu_quota)
+ self.assertRaises(exceptions.OverLimit, self.create_test_server)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_create_server_when_memory_quota_is_full(self):
+ # Disallow server creation when tenant's memory quota is full
+ resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
+ default_mem_quota = quota_set['ram']
+ mem_quota = 0 # Set the quota to zero to conserve resources
+
+ self.adm_client.update_quota_set(self.demo_tenant_id,
+ force=True,
+ ram=mem_quota)
+
+ self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
+ ram=default_mem_quota)
+ self.assertRaises(exceptions.OverLimit, self.create_test_server)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_create_server_when_instances_quota_is_full(self):
+ # Once instances quota limit is reached, disallow server creation
+ resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
+ default_instances_quota = quota_set['instances']
+ instances_quota = 0 # Set quota to zero to disallow server creation
+
+ self.adm_client.update_quota_set(self.demo_tenant_id,
+ force=True,
+ instances=instances_quota)
+ self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
+ instances=default_instances_quota)
+ self.assertRaises(exceptions.OverLimit, self.create_test_server)
+
+ @test.skip_because(bug="1186354",
+ condition=CONF.service_available.neutron)
+ @test.attr(type='gate')
+ def test_security_groups_exceed_limit(self):
+ # Negative test: Creation Security Groups over limit should FAIL
+
+ resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
+ default_sg_quota = quota_set['security_groups']
+ sg_quota = 0 # Set the quota to zero to conserve resources
+
+ resp, quota_set =\
+ self.adm_client.update_quota_set(self.demo_tenant_id,
+ force=True,
+ security_groups=sg_quota)
+
+ self.addCleanup(self.adm_client.update_quota_set,
+ self.demo_tenant_id,
+ security_groups=default_sg_quota)
+
+ # Check we cannot create anymore
+ self.assertRaises(exceptions.OverLimit,
+ self.sg_client.create_security_group,
+ "sg-overlimit", "sg-desc")
+
+ @test.skip_because(bug="1186354",
+ condition=CONF.service_available.neutron)
+ @test.attr(type=['negative', 'gate'])
+ def test_security_groups_rules_exceed_limit(self):
+ # Negative test: Creation of Security Group Rules should FAIL
+ # when we reach limit maxSecurityGroupRules
+
+ resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
+ default_sg_rules_quota = quota_set['security_group_rules']
+ sg_rules_quota = 0 # Set the quota to zero to conserve resources
+
+ resp, quota_set =\
+ self.adm_client.update_quota_set(
+ self.demo_tenant_id,
+ force=True,
+ security_group_rules=sg_rules_quota)
+
+ self.addCleanup(self.adm_client.update_quota_set,
+ self.demo_tenant_id,
+ security_group_rules=default_sg_rules_quota)
+
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
+ resp, securitygroup =\
+ self.sg_client.create_security_group(s_name, s_description)
+ self.addCleanup(self.sg_client.delete_security_group,
+ securitygroup['id'])
+
+ secgroup_id = securitygroup['id']
+ ip_protocol = 'tcp'
+
+ # Check we cannot create SG rule anymore
+ self.assertRaises(exceptions.OverLimit,
+ self.sg_client.create_security_group_rule,
+ secgroup_id, ip_protocol, 1025, 1025)
+
+
+class QuotasAdminNegativeTestXML(QuotasAdminNegativeTestJSON):
+ _interface = 'xml'
diff --git a/tempest/api/compute/admin/test_security_groups.py b/tempest/api/compute/admin/test_security_groups.py
index da2a1a1..0cfa344 100644
--- a/tempest/api/compute/admin/test_security_groups.py
+++ b/tempest/api/compute/admin/test_security_groups.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NTT Data
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_servers.py b/tempest/api/compute/admin/test_servers.py
index 6fe3186..2cee78a 100644
--- a/tempest/api/compute/admin/test_servers.py
+++ b/tempest/api/compute/admin/test_servers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -44,6 +42,7 @@
cls.s2_name = data_utils.rand_name('server')
resp, server = cls.create_test_server(name=cls.s2_name,
wait_until='ACTIVE')
+ cls.s2_id = server['id']
def _get_unused_flavor_id(self):
flavor_id = data_utils.rand_int_id(start=1000)
@@ -64,6 +63,22 @@
self.assertEqual([], servers)
@attr(type='gate')
+ def test_list_servers_filter_by_error_status(self):
+ # Filter the list of servers by server error status
+ params = {'status': 'error'}
+ resp, server = self.client.reset_state(self.s1_id, state='error')
+ resp, body = self.non_admin_client.list_servers(params)
+ # Reset server's state to 'active'
+ resp, server = self.client.reset_state(self.s1_id, state='active')
+ # Verify server's state
+ resp, server = self.client.get_server(self.s1_id)
+ self.assertEqual(server['status'], 'ACTIVE')
+ servers = body['servers']
+ # Verify error server in list result
+ self.assertIn(self.s1_id, map(lambda x: x['id'], servers))
+ self.assertNotIn(self.s2_id, map(lambda x: x['id'], servers))
+
+ @attr(type='gate')
def test_list_servers_by_admin_with_all_tenants(self):
# Listing servers by admin user with all tenants parameter
# Here should be listed all servers
@@ -84,6 +99,18 @@
self.servers_client.wait_for_server_termination(server['id'])
@attr(type='gate')
+ def test_delete_server_while_in_error_state(self):
+ # Delete a server while it's VM state is error
+ resp, server = self.create_test_server(wait_until='ACTIVE')
+ resp, body = self.client.reset_state(server['id'], state='error')
+ self.assertEqual(202, resp.status)
+ # Verify server's state
+ resp, server = self.client.get_server(server['id'])
+ self.assertEqual(server['status'], 'ERROR')
+ resp, _ = self.client.delete_server(server['id'])
+ self.assertEqual('204', resp['status'])
+
+ @attr(type='gate')
def test_reset_state_server(self):
# Reset server's state to 'error'
resp, server = self.client.reset_state(self.s1_id)
diff --git a/tempest/api/compute/admin/test_servers_negative.py b/tempest/api/compute/admin/test_servers_negative.py
index 77d873b..9580a06 100644
--- a/tempest/api/compute/admin/test_servers_negative.py
+++ b/tempest/api/compute/admin/test_servers_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/compute/admin/test_services.py b/tempest/api/compute/admin/test_services.py
index 6122758..16dcfcc 100644
--- a/tempest/api/compute/admin/test_services.py
+++ b/tempest/api/compute/admin/test_services.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
diff --git a/tempest/api/compute/admin/test_services_negative.py b/tempest/api/compute/admin/test_services_negative.py
index da1482e..a1809c4 100644
--- a/tempest/api/compute/admin/test_services_negative.py
+++ b/tempest/api/compute/admin/test_services_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/compute/admin/test_simple_tenant_usage.py b/tempest/api/compute/admin/test_simple_tenant_usage.py
index c416ad2..dcb9aed 100644
--- a/tempest/api/compute/admin/test_simple_tenant_usage.py
+++ b/tempest/api/compute/admin/test_simple_tenant_usage.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/admin/test_simple_tenant_usage_negative.py b/tempest/api/compute/admin/test_simple_tenant_usage_negative.py
index 7e5168e..2a30348 100644
--- a/tempest/api/compute/admin/test_simple_tenant_usage_negative.py
+++ b/tempest/api/compute/admin/test_simple_tenant_usage_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index b060f15..fd069e7 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,10 +17,12 @@
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
import tempest.test
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -35,22 +35,19 @@
@classmethod
def setUpClass(cls):
super(BaseComputeTest, cls).setUpClass()
- if not cls.config.service_available.nova:
- skip_msg = ("%s skipped as nova is not available" % cls.__name__)
- raise cls.skipException(skip_msg)
os = cls.get_client_manager()
cls.os = os
- cls.build_interval = cls.config.compute.build_interval
- cls.build_timeout = cls.config.compute.build_timeout
- cls.ssh_user = cls.config.compute.ssh_user
- cls.image_ref = cls.config.compute.image_ref
- cls.image_ref_alt = cls.config.compute.image_ref_alt
- cls.flavor_ref = cls.config.compute.flavor_ref
- cls.flavor_ref_alt = cls.config.compute.flavor_ref_alt
- cls.image_ssh_user = cls.config.compute.image_ssh_user
- cls.image_ssh_password = cls.config.compute.image_ssh_password
+ cls.build_interval = CONF.compute.build_interval
+ cls.build_timeout = CONF.compute.build_timeout
+ cls.ssh_user = CONF.compute.ssh_user
+ cls.image_ref = CONF.compute.image_ref
+ cls.image_ref_alt = CONF.compute.image_ref_alt
+ cls.flavor_ref = CONF.compute.flavor_ref
+ cls.flavor_ref_alt = CONF.compute.flavor_ref_alt
+ cls.image_ssh_user = CONF.compute.image_ssh_user
+ cls.image_ssh_password = CONF.compute.image_ssh_password
cls.servers = []
cls.images = []
cls.multi_user = cls.get_multi_user()
@@ -62,14 +59,14 @@
# used in testing. If the test cases are allowed to create
# users (config.compute.allow_tenant_isolation is true,
# then we allow multi-user.
- if not cls.config.compute.allow_tenant_isolation:
- user1 = cls.config.identity.username
- user2 = cls.config.identity.alt_username
+ if not CONF.compute.allow_tenant_isolation:
+ user1 = CONF.identity.username
+ user2 = CONF.identity.alt_username
if not user2 or user1 == user2:
multi_user = False
else:
- user2_password = cls.config.identity.alt_password
- user2_tenant_name = cls.config.identity.alt_tenant_name
+ user2_password = CONF.identity.alt_password
+ user2_tenant_name = CONF.identity.alt_tenant_name
if not user2_password or not user2_tenant_name:
msg = ("Alternate user specified but not alternate "
"tenant or password: alt_tenant_name=%s "
@@ -130,12 +127,22 @@
r, b = cls.servers_client.list_servers()
servers = [s for s in b['servers'] if s['name'].startswith(name)]
- cls.servers.extend(servers)
-
if 'wait_until' in kwargs:
for server in servers:
- cls.servers_client.wait_for_server_status(
- server['id'], kwargs['wait_until'])
+ try:
+ cls.servers_client.wait_for_server_status(
+ server['id'], kwargs['wait_until'])
+ except Exception as ex:
+ if ('preserve_server_on_error' not in kwargs
+ or kwargs['preserve_server_on_error'] is False):
+ for server in servers:
+ try:
+ cls.servers_client.delete_server(server['id'])
+ except Exception:
+ pass
+ raise ex
+
+ cls.servers.extend(servers)
return resp, body
@@ -154,11 +161,25 @@
return
time.sleep(self.build_interval)
+ @staticmethod
+ def _delete_volume(volumes_client, volume_id):
+ """Deletes the given volume and waits for it to be gone."""
+ try:
+ resp, _ = volumes_client.delete_volume(volume_id)
+ # TODO(mriedem): We should move the wait_for_resource_deletion
+ # into the delete_volume method as a convenience to the caller.
+ volumes_client.wait_for_resource_deletion(volume_id)
+ except exceptions.NotFound:
+ LOG.warn("Unable to delete volume '%s' since it was not found. "
+ "Maybe it was already deleted?" % volume_id)
+
class BaseV2ComputeTest(BaseComputeTest):
@classmethod
def setUpClass(cls):
+ # By default compute tests do not create network resources
+ cls.set_network_resources()
super(BaseV2ComputeTest, cls).setUpClass()
cls.servers_client = cls.os.servers_client
cls.flavors_client = cls.os.flavors_client
@@ -179,7 +200,6 @@
cls.instance_usages_audit_log_client = \
cls.os.instance_usages_audit_log_client
cls.hypervisor_client = cls.os.hypervisor_client
- cls.servers_client_v3_auth = cls.os.servers_client_v3_auth
cls.certificates_client = cls.os.certificates_client
@classmethod
@@ -220,6 +240,11 @@
cls.password = server['adminPass']
return server['id']
+ @classmethod
+ def delete_volume(cls, volume_id):
+ """Deletes the given volume and waits for it to be gone."""
+ cls._delete_volume(cls.volumes_extensions_client, volume_id)
+
class BaseV2ComputeAdminTest(BaseV2ComputeTest):
"""Base test case class for Compute Admin V2 API tests."""
@@ -227,14 +252,14 @@
@classmethod
def setUpClass(cls):
super(BaseV2ComputeAdminTest, cls).setUpClass()
- admin_username = cls.config.compute_admin.username
- admin_password = cls.config.compute_admin.password
- admin_tenant = cls.config.compute_admin.tenant_name
+ admin_username = CONF.compute_admin.username
+ admin_password = CONF.compute_admin.password
+ admin_tenant = CONF.compute_admin.tenant_name
if not (admin_username and admin_password and admin_tenant):
msg = ("Missing Compute Admin API credentials "
"in configuration.")
raise cls.skipException(msg)
- if (cls.config.compute.allow_tenant_isolation or
+ if (CONF.compute.allow_tenant_isolation or
cls.force_tenant_isolation is True):
creds = cls.isolated_creds.get_admin_creds()
admin_username, admin_tenant_name, admin_password = creds
@@ -250,8 +275,15 @@
@classmethod
def setUpClass(cls):
+ # By default compute tests do not create network resources
+ if cls._interface == "xml":
+ skip_msg = ("XML interface is being removed from Nova v3. "
+ "%s will be removed shortly" % cls.__name__)
+ raise cls.skipException(skip_msg)
+
+ cls.set_network_resources()
super(BaseV3ComputeTest, cls).setUpClass()
- if not cls.config.compute_feature_enabled.api_v3:
+ if not CONF.compute_feature_enabled.api_v3:
cls.tearDownClass()
skip_msg = ("%s skipped as nova v3 api is not available" %
cls.__name__)
@@ -264,6 +296,8 @@
cls.extensions_client = cls.os.extensions_v3_client
cls.availability_zone_client = cls.os.availability_zone_v3_client
cls.interfaces_client = cls.os.interfaces_v3_client
+ cls.instance_usages_audit_log_client = \
+ cls.os.instance_usages_audit_log_v3_client
cls.hypervisor_client = cls.os.hypervisor_v3_client
cls.keypairs_client = cls.os.keypairs_v3_client
cls.tenant_usages_client = cls.os.tenant_usages_v3_client
@@ -273,6 +307,7 @@
cls.aggregates_client = cls.os.aggregates_v3_client
cls.hosts_client = cls.os.hosts_v3_client
cls.quotas_client = cls.os.quotas_v3_client
+ cls.version_client = cls.os.version_v3_client
@classmethod
def create_image_from_server(cls, server_id, **kwargs):
@@ -306,6 +341,11 @@
cls.password = server['admin_password']
return server['id']
+ @classmethod
+ def delete_volume(cls, volume_id):
+ """Deletes the given volume and waits for it to be gone."""
+ cls._delete_volume(cls.volumes_client, volume_id)
+
class BaseV3ComputeAdminTest(BaseV3ComputeTest):
"""Base test case class for all Compute Admin API V3 tests."""
@@ -313,14 +353,14 @@
@classmethod
def setUpClass(cls):
super(BaseV3ComputeAdminTest, cls).setUpClass()
- admin_username = cls.config.compute_admin.username
- admin_password = cls.config.compute_admin.password
- admin_tenant = cls.config.compute_admin.tenant_name
+ admin_username = CONF.compute_admin.username
+ admin_password = CONF.compute_admin.password
+ admin_tenant = CONF.compute_admin.tenant_name
if not (admin_username and admin_password and admin_tenant):
msg = ("Missing Compute Admin API credentials "
"in configuration.")
raise cls.skipException(msg)
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_admin_creds()
admin_username, admin_tenant_name, admin_password = creds
os_adm = clients.Manager(username=admin_username,
@@ -332,6 +372,8 @@
cls.os_adm = os_adm
cls.servers_admin_client = cls.os_adm.servers_v3_client
+ cls.instance_usages_audit_log_admin_client = \
+ cls.os_adm.instance_usages_audit_log_v3_client
cls.services_admin_client = cls.os_adm.services_v3_client
cls.availability_zone_admin_client = \
cls.os_adm.availability_zone_v3_client
diff --git a/tempest/api/compute/certificates/test_certificates.py b/tempest/api/compute/certificates/test_certificates.py
index 4be1cff..79619bc 100644
--- a/tempest/api/compute/certificates/test_certificates.py
+++ b/tempest/api/compute/certificates/test_certificates.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/flavors/test_flavors.py b/tempest/api/compute/flavors/test_flavors.py
index 092fd65..b0a7fed 100644
--- a/tempest/api/compute/flavors/test_flavors.py
+++ b/tempest/api/compute/flavors/test_flavors.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/flavors/test_flavors_negative.py b/tempest/api/compute/flavors/test_flavors_negative.py
index 0b20e90..8ac6182 100644
--- a/tempest/api/compute/flavors/test_flavors_negative.py
+++ b/tempest/api/compute/flavors/test_flavors_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,40 +13,42 @@
# License for the specific language governing permissions and limitations
# under the License.
-import uuid
+import testscenarios
from tempest.api.compute import base
-from tempest import exceptions
-from tempest.test import attr
+from tempest import test
-class FlavorsNegativeTestJSON(base.BaseV2ComputeTest):
+load_tests = testscenarios.load_tests_apply_scenarios
+
+
+class FlavorsListNegativeTestJSON(base.BaseV2ComputeTest,
+ test.NegativeAutoTest):
_interface = 'json'
+ _service = 'compute'
+ _schema_file = 'compute/flavors/flavors_list.json'
+
+ scenarios = test.NegativeAutoTest.generate_scenario(_schema_file)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_list_flavors_with_detail(self):
+ self.execute(self._schema_file)
+
+
+class FlavorDetailsNegativeTestJSON(base.BaseV2ComputeTest,
+ test.NegativeAutoTest):
+ _interface = 'json'
+ _service = 'compute'
+ _schema_file = 'compute/flavors/flavor_details.json'
+
+ scenarios = test.NegativeAutoTest.generate_scenario(_schema_file)
@classmethod
def setUpClass(cls):
- super(FlavorsNegativeTestJSON, cls).setUpClass()
- cls.client = cls.flavors_client
+ super(FlavorDetailsNegativeTestJSON, cls).setUpClass()
+ cls.set_resource("flavor", cls.flavor_ref)
- @attr(type=['negative', 'gate'])
- def test_invalid_minRam_filter(self):
- self.assertRaises(exceptions.BadRequest,
- self.client.list_flavors_with_detail,
- {'minRam': 'invalid'})
-
- @attr(type=['negative', 'gate'])
- def test_invalid_minDisk_filter(self):
- self.assertRaises(exceptions.BadRequest,
- self.client.list_flavors_with_detail,
- {'minDisk': 'invalid'})
-
- @attr(type=['negative', 'gate'])
- def test_non_existent_flavor_id(self):
+ @test.attr(type=['negative', 'gate'])
+ def test_get_flavor_details(self):
# flavor details are not returned for non-existent flavors
- nonexistent_flavor_id = str(uuid.uuid4())
- self.assertRaises(exceptions.NotFound, self.client.get_flavor_details,
- nonexistent_flavor_id)
-
-
-class FlavorsNegativeTestXML(FlavorsNegativeTestJSON):
- _interface = 'xml'
+ self.execute(self._schema_file)
diff --git a/tempest/api/compute/flavors/test_flavors_negative_xml.py b/tempest/api/compute/flavors/test_flavors_negative_xml.py
new file mode 100644
index 0000000..c93c7c9
--- /dev/null
+++ b/tempest/api/compute/flavors/test_flavors_negative_xml.py
@@ -0,0 +1,48 @@
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 uuid
+
+from tempest.api.compute import base
+from tempest import exceptions
+from tempest.test import attr
+
+
+class FlavorsNegativeTestXML(base.BaseV2ComputeTest):
+ _interface = 'xml'
+
+ @classmethod
+ def setUpClass(cls):
+ super(FlavorsNegativeTestXML, cls).setUpClass()
+ cls.client = cls.flavors_client
+
+ @attr(type=['negative', 'gate'])
+ def test_invalid_minRam_filter(self):
+ self.assertRaises(exceptions.BadRequest,
+ self.client.list_flavors_with_detail,
+ {'minRam': 'invalid'})
+
+ @attr(type=['negative', 'gate'])
+ def test_invalid_minDisk_filter(self):
+ self.assertRaises(exceptions.BadRequest,
+ self.client.list_flavors_with_detail,
+ {'minDisk': 'invalid'})
+
+ @attr(type=['negative', 'gate'])
+ def test_non_existent_flavor_id(self):
+ # flavor details are not returned for non-existent flavors
+ nonexistent_flavor_id = str(uuid.uuid4())
+ self.assertRaises(exceptions.NotFound, self.client.get_flavor_details,
+ nonexistent_flavor_id)
diff --git a/tempest/api/compute/floating_ips/base.py b/tempest/api/compute/floating_ips/base.py
new file mode 100644
index 0000000..fd76e62
--- /dev/null
+++ b/tempest/api/compute/floating_ips/base.py
@@ -0,0 +1,26 @@
+# Copyright 2014 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+
+
+class BaseFloatingIPsTest(base.BaseV2ComputeTest):
+
+ @classmethod
+ def setUpClass(cls):
+ # Floating IP actions might need a full network configuration
+ cls.set_network_resources(network=True, subnet=True,
+ router=True, dhcp=True)
+ super(BaseFloatingIPsTest, cls).setUpClass()
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions.py b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
index 32e7b39..56bd291 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,13 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest.api.compute import base
+from tempest.api.compute.floating_ips import base
from tempest.common.utils.data_utils import rand_name
from tempest import exceptions
from tempest.test import attr
-class FloatingIPsTestJSON(base.BaseV2ComputeTest):
+class FloatingIPsTestJSON(base.BaseFloatingIPsTest):
_interface = 'json'
server_id = None
floating_ip = None
@@ -98,9 +96,7 @@
# to specific server should change the association of the Floating IP
# Create server so as to use for Multiple association
new_name = rand_name('floating_server')
- resp, body = self.servers_client.create_server(new_name,
- self.image_ref,
- self.flavor_ref)
+ resp, body = self.create_test_server(name=new_name)
self.servers_client.wait_for_server_status(body['id'], 'ACTIVE')
self.new_server_id = body['id']
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py b/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
index 89315bb..f24343b 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,13 +15,16 @@
import uuid
-from tempest.api.compute import base
+from tempest.api.compute.floating_ips import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
-class FloatingIPsNegativeTestJSON(base.BaseV2ComputeTest):
+
+class FloatingIPsNegativeTestJSON(base.BaseFloatingIPsTest):
_interface = 'json'
server_id = None
@@ -42,7 +43,7 @@
cls.floating_ip_ids.append(body[i]['id'])
while True:
cls.non_exist_id = data_utils.rand_int_id(start=999)
- if cls.config.service_available.neutron:
+ if CONF.service_available.neutron:
cls.non_exist_id = str(uuid.uuid4())
if cls.non_exist_id not in cls.floating_ip_ids:
break
diff --git a/tempest/api/compute/floating_ips/test_list_floating_ips.py b/tempest/api/compute/floating_ips/test_list_floating_ips.py
index 9238994..fa2d558 100644
--- a/tempest/api/compute/floating_ips/test_list_floating_ips.py
+++ b/tempest/api/compute/floating_ips/test_list_floating_ips.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/floating_ips/test_list_floating_ips_negative.py b/tempest/api/compute/floating_ips/test_list_floating_ips_negative.py
index e7dc8ee..8d60e7d 100644
--- a/tempest/api/compute/floating_ips/test_list_floating_ips_negative.py
+++ b/tempest/api/compute/floating_ips/test_list_floating_ips_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,9 +17,12 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
+
class FloatingIPDetailsNegativeTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
@@ -36,7 +37,7 @@
# Negative test:Should not be able to GET the details
# of non-existent floating IP
# Creating a non-existent floatingIP id
- if self.config.service_available.neutron:
+ if CONF.service_available.neutron:
non_exist_id = str(uuid.uuid4())
else:
non_exist_id = data_utils.rand_int_id(start=999)
diff --git a/tempest/api/compute/images/test_image_metadata.py b/tempest/api/compute/images/test_image_metadata.py
index 76e0cae..4115d65 100644
--- a/tempest/api/compute/images/test_image_metadata.py
+++ b/tempest/api/compute/images/test_image_metadata.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,8 +15,11 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
+
class ImagesMetadataTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
@@ -26,7 +27,7 @@
@classmethod
def setUpClass(cls):
super(ImagesMetadataTestJSON, cls).setUpClass()
- if not cls.config.service_available.glance:
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
diff --git a/tempest/api/compute/images/test_image_metadata_negative.py b/tempest/api/compute/images/test_image_metadata_negative.py
index 1767e5d..4878936 100644
--- a/tempest/api/compute/images/test_image_metadata_negative.py
+++ b/tempest/api/compute/images/test_image_metadata_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/images/test_images.py b/tempest/api/compute/images/test_images.py
index f7db89b..4cc36c9 100644
--- a/tempest/api/compute/images/test_images.py
+++ b/tempest/api/compute/images/test_images.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -17,9 +15,12 @@
from tempest.api.compute import base
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
+
class ImagesTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
@@ -27,7 +28,7 @@
@classmethod
def setUpClass(cls):
super(ImagesTestJSON, cls).setUpClass()
- if not cls.config.service_available.glance:
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
cls.client = cls.images_client
@@ -36,7 +37,7 @@
cls.image_ids = []
if cls.multi_user:
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.alt_manager = clients.Manager(username=username,
diff --git a/tempest/api/compute/images/test_images_oneserver.py b/tempest/api/compute/images/test_images_oneserver.py
index 26cc3f6..8d60623 100644
--- a/tempest/api/compute/images/test_images_oneserver.py
+++ b/tempest/api/compute/images/test_images_oneserver.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -57,7 +55,7 @@
def setUpClass(cls):
super(ImagesOneServerTestJSON, cls).setUpClass()
cls.client = cls.images_client
- if not cls.config.service_available.glance:
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
@@ -71,7 +69,7 @@
cls.image_ids = []
if cls.multi_user:
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.alt_manager = clients.Manager(username=username,
diff --git a/tempest/api/compute/images/test_images_oneserver_negative.py b/tempest/api/compute/images/test_images_oneserver_negative.py
index 5e235d1..c96c4a4 100644
--- a/tempest/api/compute/images/test_images_oneserver_negative.py
+++ b/tempest/api/compute/images/test_images_oneserver_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -19,11 +17,14 @@
from tempest.api.compute import base
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.test import attr
from tempest.test import skip_because
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -59,7 +60,7 @@
def setUpClass(cls):
super(ImagesOneServerNegativeTestJSON, cls).setUpClass()
cls.client = cls.images_client
- if not cls.config.service_available.glance:
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
@@ -73,7 +74,7 @@
cls.image_ids = []
if cls.multi_user:
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.alt_manager = clients.Manager(username=username,
diff --git a/tempest/api/compute/images/test_list_image_filters.py b/tempest/api/compute/images/test_list_image_filters.py
index bfdd8b2..f82143e 100644
--- a/tempest/api/compute/images/test_list_image_filters.py
+++ b/tempest/api/compute/images/test_list_image_filters.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,10 +14,12 @@
# under the License.
from tempest.api.compute import base
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.test import attr
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -30,7 +30,7 @@
@classmethod
def setUpClass(cls):
super(ListImageFiltersTestJSON, cls).setUpClass()
- if not cls.config.service_available.glance:
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
cls.client = cls.images_client
@@ -222,7 +222,7 @@
self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
@attr(type=['negative', 'gate'])
- def test_get_nonexistant_image(self):
+ def test_get_nonexistent_image(self):
# Negative test: GET on non-existent image should fail
self.assertRaises(exceptions.NotFound, self.client.get_image, 999)
diff --git a/tempest/api/compute/images/test_list_images.py b/tempest/api/compute/images/test_list_images.py
index a6726b6..ed38442 100644
--- a/tempest/api/compute/images/test_list_images.py
+++ b/tempest/api/compute/images/test_list_images.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,8 +14,11 @@
# under the License.
from tempest.api.compute import base
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
+
class ListImagesTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
@@ -25,7 +26,7 @@
@classmethod
def setUpClass(cls):
super(ListImagesTestJSON, cls).setUpClass()
- if not cls.config.service_available.glance:
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
cls.client = cls.images_client
diff --git a/tempest/api/compute/keypairs/test_keypairs.py b/tempest/api/compute/keypairs/test_keypairs.py
index b36595c..d4554bc 100644
--- a/tempest/api/compute/keypairs/test_keypairs.py
+++ b/tempest/api/compute/keypairs/test_keypairs.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/keypairs/test_keypairs_negative.py b/tempest/api/compute/keypairs/test_keypairs_negative.py
index 621487c..93b0692 100644
--- a/tempest/api/compute/keypairs/test_keypairs_negative.py
+++ b/tempest/api/compute/keypairs/test_keypairs_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 IBM Corp
# All Rights Reserved.
@@ -43,9 +41,9 @@
self._create_keypair, k_name, pub_key)
@test.attr(type=['negative', 'gate'])
- def test_keypair_delete_nonexistant_key(self):
- # Non-existant key deletion should throw a proper error
- k_name = data_utils.rand_name("keypair-non-existant-")
+ def test_keypair_delete_nonexistent_key(self):
+ # Non-existent key deletion should throw a proper error
+ k_name = data_utils.rand_name("keypair-non-existent-")
self.assertRaises(exceptions.NotFound, self.client.delete_keypair,
k_name)
diff --git a/tempest/api/compute/limits/test_absolute_limits.py b/tempest/api/compute/limits/test_absolute_limits.py
index 908d537..0e234fb 100644
--- a/tempest/api/compute/limits/test_absolute_limits.py
+++ b/tempest/api/compute/limits/test_absolute_limits.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/limits/test_absolute_limits_negative.py b/tempest/api/compute/limits/test_absolute_limits_negative.py
index 8547403..ac8af3b 100644
--- a/tempest/api/compute/limits/test_absolute_limits_negative.py
+++ b/tempest/api/compute/limits/test_absolute_limits_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/security_groups/base.py b/tempest/api/compute/security_groups/base.py
new file mode 100644
index 0000000..6838ce1
--- /dev/null
+++ b/tempest/api/compute/security_groups/base.py
@@ -0,0 +1,25 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+
+
+class BaseSecurityGroupsTest(base.BaseV2ComputeTest):
+
+ @classmethod
+ def setUpClass(cls):
+ # A network and a subnet will be created for these tests
+ cls.set_network_resources(network=True, subnet=True)
+ super(BaseSecurityGroupsTest, cls).setUpClass()
diff --git a/tempest/api/compute/security_groups/test_security_group_rules.py b/tempest/api/compute/security_groups/test_security_group_rules.py
index 2ccc3a8..375105e 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,19 +13,22 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest.api.compute import base
+from tempest.api.compute.security_groups import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
-class SecurityGroupRulesTestJSON(base.BaseV2ComputeTest):
+
+class SecurityGroupRulesTestJSON(base.BaseSecurityGroupsTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
super(SecurityGroupRulesTestJSON, cls).setUpClass()
cls.client = cls.security_groups_client
- cls.neutron_available = cls.config.service_available.neutron
+ cls.neutron_available = CONF.service_available.neutron
@attr(type='smoke')
def test_security_group_rules_create(self):
diff --git a/tempest/api/compute/security_groups/test_security_group_rules_negative.py b/tempest/api/compute/security_groups/test_security_group_rules_negative.py
index c0b202d..4831939 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules_negative.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -17,7 +15,7 @@
import testtools
-from tempest.api.compute import base
+from tempest.api.compute.security_groups import base
from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
@@ -27,7 +25,7 @@
CONF = config.CONF
-class SecurityGroupRulesNegativeTestJSON(base.BaseV2ComputeTest):
+class SecurityGroupRulesNegativeTestJSON(base.BaseSecurityGroupsTest):
_interface = 'json'
@classmethod
diff --git a/tempest/api/compute/security_groups/test_security_groups.py b/tempest/api/compute/security_groups/test_security_groups.py
index 4ae65be..2c67581 100644
--- a/tempest/api/compute/security_groups/test_security_groups.py
+++ b/tempest/api/compute/security_groups/test_security_groups.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,13 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest.api.compute import base
+from tempest.api.compute.security_groups import base
from tempest.common.utils import data_utils
from tempest import exceptions
from tempest import test
-class SecurityGroupsTestJSON(base.BaseV2ComputeTest):
+class SecurityGroupsTestJSON(base.BaseSecurityGroupsTest):
_interface = 'json'
@classmethod
@@ -123,9 +121,7 @@
# Create server and add the security group created
# above to the server we just created
server_name = data_utils.rand_name('server')
- resp, server = self.servers_client.create_server(server_name,
- self.image_ref,
- self.flavor_ref)
+ resp, server = self.create_test_server(name=server_name)
server_id = server['id']
self.servers_client.wait_for_server_status(server_id, 'ACTIVE')
resp, body = self.servers_client.add_security_group(server_id,
diff --git a/tempest/api/compute/security_groups/test_security_groups_negative.py b/tempest/api/compute/security_groups/test_security_groups_negative.py
index 6a8e604..ce1eada 100644
--- a/tempest/api/compute/security_groups/test_security_groups_negative.py
+++ b/tempest/api/compute/security_groups/test_security_groups_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -17,7 +15,7 @@
import testtools
-from tempest.api.compute import base
+from tempest.api.compute.security_groups import base
from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
@@ -26,14 +24,14 @@
CONF = config.CONF
-class SecurityGroupsNegativeTestJSON(base.BaseV2ComputeTest):
+class SecurityGroupsNegativeTestJSON(base.BaseSecurityGroupsTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
super(SecurityGroupsNegativeTestJSON, cls).setUpClass()
cls.client = cls.security_groups_client
- cls.neutron_available = cls.config.service_available.neutron
+ cls.neutron_available = CONF.service_available.neutron
def _delete_security_group(self, securitygroup_id):
resp, _ = self.client.delete_security_group(securitygroup_id)
diff --git a/tempest/api/compute/servers/test_attach_interfaces.py b/tempest/api/compute/servers/test_attach_interfaces.py
index dbb7d75..9cdac55 100644
--- a/tempest/api/compute/servers/test_attach_interfaces.py
+++ b/tempest/api/compute/servers/test_attach_interfaces.py
@@ -14,18 +14,24 @@
# under the License.
from tempest.api.compute import base
+from tempest import config
+from tempest import exceptions
from tempest.test import attr
import time
+CONF = config.CONF
+
class AttachInterfacesTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- if not cls.config.service_available.neutron:
+ if not CONF.service_available.neutron:
raise cls.skipException("Neutron is required")
+ # This test class requires network and subnet
+ cls.set_network_resources(network=True, subnet=True)
super(AttachInterfacesTestJSON, cls).setUpClass()
cls.client = cls.os.interfaces_client
@@ -73,15 +79,19 @@
# NOTE(danms): delete not the first or last, but one in the middle
iface = ifs[1]
self.client.delete_interface(server['id'], iface['port_id'])
- for i in range(0, 5):
- _r, _ifs = self.client.list_interfaces(server['id'])
- if len(ifs) != len(_ifs):
- break
- time.sleep(1)
+ _ifs = self.client.list_interfaces(server['id'])[1]
+ start = int(time.time())
- self.assertEqual(len(_ifs), len(ifs) - 1)
- for _iface in _ifs:
- self.assertNotEqual(iface['port_id'], _iface['port_id'])
+ while len(ifs) == len(_ifs):
+ time.sleep(self.build_interval)
+ _ifs = self.client.list_interfaces(server['id'])[1]
+ timed_out = int(time.time()) - start >= self.build_timeout
+ if len(ifs) == len(_ifs) and timed_out:
+ message = ('Failed to delete interface within '
+ 'the required time: %s sec.' % self.build_timeout)
+ raise exceptions.TimeoutException(message)
+
+ self.assertNotIn(iface['port_id'], [i['port_id'] for i in _ifs])
return _ifs
def _compare_iface_list(self, list1, list2):
diff --git a/tempest/api/compute/servers/test_create_server.py b/tempest/api/compute/servers/test_create_server.py
index 5d62e1b..887608f 100644
--- a/tempest/api/compute/servers/test_create_server.py
+++ b/tempest/api/compute/servers/test_create_server.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -109,6 +107,104 @@
self.assertTrue(linux_client.hostname_equals_servername(self.name))
+class ServersWithSpecificFlavorTestJSON(base.BaseV2ComputeAdminTest):
+ _interface = 'json'
+ run_ssh = CONF.compute.run_ssh
+ disk_config = 'AUTO'
+
+ @classmethod
+ def setUpClass(cls):
+ super(ServersWithSpecificFlavorTestJSON, cls).setUpClass()
+ cls.meta = {'hello': 'world'}
+ cls.accessIPv4 = '1.1.1.1'
+ cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
+ cls.name = data_utils.rand_name('server')
+ file_contents = 'This is a test file.'
+ personality = [{'path': '/test.txt',
+ 'contents': base64.b64encode(file_contents)}]
+ cls.client = cls.servers_client
+ cls.flavor_client = cls.os_adm.flavors_client
+ cli_resp = cls.create_test_server(name=cls.name,
+ meta=cls.meta,
+ accessIPv4=cls.accessIPv4,
+ accessIPv6=cls.accessIPv6,
+ personality=personality,
+ disk_config=cls.disk_config)
+ cls.resp, cls.server_initial = cli_resp
+ cls.password = cls.server_initial['adminPass']
+ cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
+ resp, cls.server = cls.client.get_server(cls.server_initial['id'])
+
+ @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
+ @attr(type='gate')
+ def test_verify_created_server_ephemeral_disk(self):
+ # Verify that the ephemeral disk is created when creating server
+
+ def create_flavor_with_extra_specs(self):
+ flavor_with_eph_disk_name = data_utils.rand_name('eph_flavor')
+ flavor_with_eph_disk_id = data_utils.rand_int_id(start=1000)
+ ram = 64
+ vcpus = 1
+ disk = 0
+
+ # Create a flavor with extra specs
+ resp, flavor = (self.flavor_client.
+ create_flavor(flavor_with_eph_disk_name,
+ ram, vcpus, disk,
+ flavor_with_eph_disk_id,
+ ephemeral=1))
+ self.addCleanup(self.flavor_clean_up, flavor['id'])
+ self.assertEqual(200, resp.status)
+
+ return flavor['id']
+
+ def create_flavor_without_extra_specs(self):
+ flavor_no_eph_disk_name = data_utils.rand_name('no_eph_flavor')
+ flavor_no_eph_disk_id = data_utils.rand_int_id(start=1000)
+
+ ram = 64
+ vcpus = 1
+ disk = 0
+
+ # Create a flavor without extra specs
+ resp, flavor = (self.flavor_client.
+ create_flavor(flavor_no_eph_disk_name,
+ ram, vcpus, disk,
+ flavor_no_eph_disk_id))
+ self.addCleanup(self.flavor_clean_up, flavor['id'])
+ self.assertEqual(200, resp.status)
+
+ return flavor['id']
+
+ def flavor_clean_up(self, flavor_id):
+ resp, body = self.flavor_client.delete_flavor(flavor_id)
+ self.assertEqual(resp.status, 202)
+ self.flavor_client.wait_for_resource_deletion(flavor_id)
+
+ flavor_with_eph_disk_id = self.create_flavor_with_extra_specs()
+ flavor_no_eph_disk_id = self.create_flavor_without_extra_specs()
+
+ admin_pass = self.image_ssh_password
+
+ resp, server_no_eph_disk = (self.
+ create_test_server(
+ wait_until='ACTIVE',
+ adminPass=admin_pass,
+ flavor=flavor_no_eph_disk_id))
+ resp, server_with_eph_disk = (self.create_test_server(
+ wait_until='ACTIVE',
+ adminPass=admin_pass,
+ flavor=flavor_with_eph_disk_id))
+ # Get partition number of server without extra specs.
+ linux_client = RemoteClient(server_no_eph_disk,
+ self.ssh_user, self.password)
+ partition_num = len(linux_client.get_partitions())
+
+ linux_client = RemoteClient(server_with_eph_disk,
+ self.ssh_user, self.password)
+ self.assertEqual(partition_num + 1, linux_client.get_partitions())
+
+
class ServersTestManualDisk(ServersTestJSON):
disk_config = 'MANUAL'
@@ -122,3 +218,7 @@
class ServersTestXML(ServersTestJSON):
_interface = 'xml'
+
+
+class ServersWithSpecificFlavorTestXML(ServersWithSpecificFlavorTestJSON):
+ _interface = 'xml'
diff --git a/tempest/api/compute/servers/test_disk_config.py b/tempest/api/compute/servers/test_disk_config.py
index 358728e..0d79161 100644
--- a/tempest/api/compute/servers/test_disk_config.py
+++ b/tempest/api/compute/servers/test_disk_config.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/servers/test_instance_actions.py b/tempest/api/compute/servers/test_instance_actions.py
index 5019003..667b84f 100644
--- a/tempest/api/compute/servers/test_instance_actions.py
+++ b/tempest/api/compute/servers/test_instance_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -16,8 +14,7 @@
# under the License.
from tempest.api.compute import base
-from tempest import exceptions
-from tempest.test import attr
+from tempest import test
class InstanceActionsTestJSON(base.BaseV2ComputeTest):
@@ -31,7 +28,7 @@
cls.request_id = resp['x-compute-request-id']
cls.server_id = server['id']
- @attr(type='gate')
+ @test.attr(type='gate')
def test_list_instance_actions(self):
# List actions of the provided server
resp, body = self.client.reboot(self.server_id, 'HARD')
@@ -43,7 +40,7 @@
self.assertTrue(any([i for i in body if i['action'] == 'create']))
self.assertTrue(any([i for i in body if i['action'] == 'reboot']))
- @attr(type='gate')
+ @test.attr(type='gate')
def test_get_instance_action(self):
# Get the action details of the provided server
resp, body = self.client.get_instance_action(self.server_id,
@@ -52,18 +49,6 @@
self.assertEqual(self.server_id, body['instance_uuid'])
self.assertEqual('create', body['action'])
- @attr(type=['negative', 'gate'])
- def test_list_instance_actions_invalid_server(self):
- # List actions of the invalid server id
- self.assertRaises(exceptions.NotFound,
- self.client.list_instance_actions, 'server-999')
-
- @attr(type=['negative', 'gate'])
- def test_get_instance_action_invalid_request(self):
- # Get the action details of the provided server with invalid request
- self.assertRaises(exceptions.NotFound, self.client.get_instance_action,
- self.server_id, '999')
-
class InstanceActionsTestXML(InstanceActionsTestJSON):
_interface = 'xml'
diff --git a/tempest/api/compute/servers/test_instance_actions_negative.py b/tempest/api/compute/servers/test_instance_actions_negative.py
new file mode 100644
index 0000000..2503eb2
--- /dev/null
+++ b/tempest/api/compute/servers/test_instance_actions_negative.py
@@ -0,0 +1,48 @@
+# Copyright 2013 NEC Corporation
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest import test
+
+
+class InstanceActionsNegativeTestJSON(base.BaseV2ComputeTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(InstanceActionsNegativeTestJSON, cls).setUpClass()
+ cls.client = cls.servers_client
+ resp, server = cls.create_test_server(wait_until='ACTIVE')
+ cls.server_id = server['id']
+
+ @test.attr(type=['negative', 'gate'])
+ def test_list_instance_actions_non_existent_server(self):
+ # List actions of the non-existent server id
+ non_existent_server_id = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound,
+ self.client.list_instance_actions,
+ non_existent_server_id)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_get_instance_action_invalid_request(self):
+ # Get the action details of the provided server with invalid request
+ self.assertRaises(exceptions.NotFound, self.client.get_instance_action,
+ self.server_id, '999')
+
+
+class InstanceActionsNegativeTestXML(InstanceActionsNegativeTestJSON):
+ _interface = 'xml'
diff --git a/tempest/api/compute/servers/test_list_server_filters.py b/tempest/api/compute/servers/test_list_server_filters.py
index 3748e37..15b7b9e 100644
--- a/tempest/api/compute/servers/test_list_server_filters.py
+++ b/tempest/api/compute/servers/test_list_server_filters.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -73,7 +71,7 @@
flavor=cls.flavor_ref_alt,
wait_until='ACTIVE')
- cls.fixed_network_name = cls.config.compute.fixed_network_name
+ cls.fixed_network_name = CONF.compute.fixed_network_name
@utils.skip_unless_attr('multiple_images', 'Only one image found')
@attr(type='gate')
@@ -121,6 +119,23 @@
self.assertIn(self.s3['id'], map(lambda x: x['id'], servers))
@attr(type='gate')
+ def test_list_servers_filter_by_shutoff_status(self):
+ # Filter the list of servers by server shutoff status
+ params = {'status': 'shutoff'}
+ self.client.stop(self.s1['id'])
+ self.client.wait_for_server_status(self.s1['id'],
+ 'SHUTOFF')
+ resp, body = self.client.list_servers(params)
+ self.client.start(self.s1['id'])
+ self.client.wait_for_server_status(self.s1['id'],
+ 'ACTIVE')
+ servers = body['servers']
+
+ self.assertIn(self.s1['id'], map(lambda x: x['id'], servers))
+ self.assertNotIn(self.s2['id'], map(lambda x: x['id'], servers))
+ self.assertNotIn(self.s3['id'], map(lambda x: x['id'], servers))
+
+ @attr(type='gate')
def test_list_servers_filter_by_limit(self):
# Verify only the expected number of servers are returned
params = {'limit': 1}
@@ -128,6 +143,22 @@
# when _interface='xml', one element for servers_links in servers
self.assertEqual(1, len([x for x in servers['servers'] if 'id' in x]))
+ @attr(type='gate')
+ def test_list_servers_filter_by_zero_limit(self):
+ # Verify only the expected number of servers are returned
+ params = {'limit': 0}
+ resp, servers = self.client.list_servers(params)
+ self.assertEqual(0, len(servers['servers']))
+
+ @attr(type='gate')
+ def test_list_servers_filter_by_exceed_limit(self):
+ # Verify only the expected number of servers are returned
+ params = {'limit': 100000}
+ resp, servers = self.client.list_servers(params)
+ resp, all_servers = self.client.list_servers()
+ self.assertEqual(len([x for x in all_servers['servers'] if 'id' in x]),
+ len([x for x in servers['servers'] if 'id' in x]))
+
@utils.skip_unless_attr('multiple_images', 'Only one image found')
@attr(type='gate')
def test_list_servers_detailed_filter_by_image(self):
diff --git a/tempest/api/compute/servers/test_list_servers_negative.py b/tempest/api/compute/servers/test_list_servers_negative.py
index 521a480..a0aefd8 100644
--- a/tempest/api/compute/servers/test_list_servers_negative.py
+++ b/tempest/api/compute/servers/test_list_servers_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/servers/test_multiple_create.py b/tempest/api/compute/servers/test_multiple_create.py
index 91c350e..cf4d646 100644
--- a/tempest/api/compute/servers/test_multiple_create.py
+++ b/tempest/api/compute/servers/test_multiple_create.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
diff --git a/tempest/api/compute/servers/test_multiple_create_negative.py b/tempest/api/compute/servers/test_multiple_create_negative.py
index a9d9945..e289717 100644
--- a/tempest/api/compute/servers/test_multiple_create_negative.py
+++ b/tempest/api/compute/servers/test_multiple_create_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
diff --git a/tempest/api/compute/servers/test_server_actions.py b/tempest/api/compute/servers/test_server_actions.py
index f195562..f113047 100644
--- a/tempest/api/compute/servers/test_server_actions.py
+++ b/tempest/api/compute/servers/test_server_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -86,7 +84,8 @@
# Log in and verify the boot time has changed
linux_client = RemoteClient(server, self.ssh_user, self.password)
new_boot_time = linux_client.get_boot_time()
- self.assertGreater(new_boot_time, boot_time)
+ self.assertTrue(new_boot_time > boot_time,
+ '%s > %s' % (new_boot_time, boot_time))
@skip_because(bug="1014647")
@attr(type='smoke')
@@ -106,7 +105,8 @@
# Log in and verify the boot time has changed
linux_client = RemoteClient(server, self.ssh_user, self.password)
new_boot_time = linux_client.get_boot_time()
- self.assertGreater(new_boot_time, boot_time)
+ self.assertTrue(new_boot_time > boot_time,
+ '%s > %s' % (new_boot_time, boot_time))
@attr(type='smoke')
def test_rebuild_server(self):
@@ -174,7 +174,7 @@
def _detect_server_image_flavor(self, server_id):
# Detects the current server image flavor ref.
- resp, server = self.client.get_server(self.server_id)
+ resp, server = self.client.get_server(server_id)
current_flavor = server['flavor']['id']
new_flavor_ref = self.flavor_ref_alt \
if current_flavor == self.flavor_ref else self.flavor_ref
@@ -232,7 +232,7 @@
def test_create_backup(self):
# Positive test:create backup successfully and rotate backups correctly
# create the first and the second backup
- backup1 = data_utils.rand_name('backup')
+ backup1 = data_utils.rand_name('backup-1')
resp, _ = self.servers_client.create_backup(self.server_id,
'daily',
2,
@@ -249,7 +249,7 @@
self.assertEqual(202, resp.status)
self.os.image_client.wait_for_image_status(image1_id, 'active')
- backup2 = data_utils.rand_name('backup')
+ backup2 = data_utils.rand_name('backup-2')
self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
resp, _ = self.servers_client.create_backup(self.server_id,
'daily',
@@ -268,6 +268,7 @@
}
resp, image_list = self.os.image_client.image_list_detail(
properties,
+ status='active',
sort_key='created_at',
sort_dir='asc')
self.assertEqual(200, resp.status)
@@ -277,7 +278,7 @@
# create the third one, due to the rotation is 2,
# the first one will be deleted
- backup3 = data_utils.rand_name('backup')
+ backup3 = data_utils.rand_name('backup-3')
self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
resp, _ = self.servers_client.create_backup(self.server_id,
'daily',
@@ -292,10 +293,15 @@
oldest_backup_exist = False
resp, image_list = self.os.image_client.image_list_detail(
properties,
+ status='active',
sort_key='created_at',
sort_dir='asc')
self.assertEqual(200, resp.status)
- self.assertEqual(2, len(image_list))
+ self.assertEqual(2, len(image_list),
+ 'Unexpected number of images for '
+ 'v2:test_create_backup; was the oldest backup not '
+ 'yet deleted? Image list: %s' %
+ [image['name'] for image in image_list])
self.assertEqual((backup2, backup3),
(image_list[0]['name'], image_list[1]['name']))
@@ -363,7 +369,7 @@
resp, server = self.client.shelve_server(self.server_id)
self.assertEqual(202, resp.status)
- offload_time = self.config.compute.shelved_offload_time
+ offload_time = CONF.compute.shelved_offload_time
if offload_time >= 0:
self.client.wait_for_server_status(self.server_id,
'SHELVED_OFFLOADED',
diff --git a/tempest/api/compute/servers/test_server_addresses.py b/tempest/api/compute/servers/test_server_addresses.py
index 1e55afb..8e432c4 100644
--- a/tempest/api/compute/servers/test_server_addresses.py
+++ b/tempest/api/compute/servers/test_server_addresses.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -24,6 +22,8 @@
@classmethod
def setUpClass(cls):
+ # This test module might use a network and a subnet
+ cls.set_network_resources(network=True, subnet=True)
super(ServerAddressesTestJSON, cls).setUpClass()
cls.client = cls.servers_client
diff --git a/tempest/api/compute/servers/test_server_addresses_negative.py b/tempest/api/compute/servers/test_server_addresses_negative.py
index 30aa7d1..c69c5eb 100644
--- a/tempest/api/compute/servers/test_server_addresses_negative.py
+++ b/tempest/api/compute/servers/test_server_addresses_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -25,6 +23,7 @@
@classmethod
def setUpClass(cls):
+ cls.set_network_resources(network=True, subnet=True)
super(ServerAddressesNegativeTestJSON, cls).setUpClass()
cls.client = cls.servers_client
diff --git a/tempest/api/compute/servers/test_server_metadata.py b/tempest/api/compute/servers/test_server_metadata.py
index ee0f4a9..ad4931c 100644
--- a/tempest/api/compute/servers/test_server_metadata.py
+++ b/tempest/api/compute/servers/test_server_metadata.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,8 +14,7 @@
# under the License.
from tempest.api.compute import base
-from tempest import exceptions
-from tempest.test import attr
+from tempest import test
class ServerMetadataTestJSON(base.BaseV2ComputeTest):
@@ -30,8 +27,6 @@
cls.quotas = cls.quotas_client
cls.admin_client = cls._get_identity_admin_client()
resp, tenants = cls.admin_client.list_tenants()
- cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
- cls.client.tenant_name][0]
resp, server = cls.create_test_server(meta={}, wait_until='ACTIVE')
cls.server_id = server['id']
@@ -42,7 +37,7 @@
resp, _ = self.client.set_server_metadata(self.server_id, meta)
self.assertEqual(resp.status, 200)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_list_server_metadata(self):
# All metadata key/value pairs for a server should be returned
resp, resp_metadata = self.client.list_server_metadata(self.server_id)
@@ -52,7 +47,7 @@
expected = {'key1': 'value1', 'key2': 'value2'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_set_server_metadata(self):
# The server's metadata should be replaced with the provided values
# Create a new set of metadata for the server
@@ -66,22 +61,7 @@
resp, resp_metadata = self.client.list_server_metadata(self.server_id)
self.assertEqual(resp_metadata, req_metadata)
- @attr(type='gate')
- def test_server_create_metadata_key_too_long(self):
- # Attempt to start a server with a meta-data key that is > 255
- # characters
-
- # Try a few values
- for sz in [256, 257, 511, 1023]:
- key = "k" * sz
- meta = {key: 'data1'}
- self.assertRaises(exceptions.OverLimit,
- self.create_test_server,
- meta=meta)
-
- # no teardown - all creates should fail
-
- @attr(type='gate')
+ @test.attr(type='gate')
def test_update_server_metadata(self):
# The server's metadata values should be updated to the
# provided values
@@ -95,7 +75,7 @@
expected = {'key1': 'alt1', 'key2': 'value2', 'key3': 'value3'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_update_metadata_empty_body(self):
# The original metadata should not be lost if empty metadata body is
# passed
@@ -105,14 +85,14 @@
expected = {'key1': 'value1', 'key2': 'value2'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_get_server_metadata_item(self):
# The value for a specific metadata key should be returned
resp, meta = self.client.get_server_metadata_item(self.server_id,
'key2')
self.assertEqual('value2', meta['key2'])
- @attr(type='gate')
+ @test.attr(type='gate')
def test_set_server_metadata_item(self):
# The item's value should be updated to the provided value
# Update the metadata value
@@ -126,7 +106,7 @@
expected = {'key1': 'value1', 'key2': 'value2', 'nova': 'alt'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_delete_server_metadata_item(self):
# The metadata value/key pair should be deleted from the server
resp, meta = self.client.delete_server_metadata_item(self.server_id,
@@ -138,80 +118,6 @@
expected = {'key2': 'value2'}
self.assertEqual(expected, resp_metadata)
- @attr(type=['negative', 'gate'])
- def test_server_metadata_negative(self):
- # Blank key should trigger an error.
- meta = {'': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.create_test_server,
- meta=meta)
-
- # GET on a non-existent server should not succeed
- self.assertRaises(exceptions.NotFound,
- self.client.get_server_metadata_item, 999, 'test2')
-
- # List metadata on a non-existent server should not succeed
- self.assertRaises(exceptions.NotFound,
- self.client.list_server_metadata, 999)
-
- # Raise BadRequest if key in uri does not match
- # the key passed in body.
- meta = {'testkey': 'testvalue'}
- self.assertRaises(exceptions.BadRequest,
- self.client.set_server_metadata_item,
- self.server_id, 'key', meta)
-
- # Set metadata on a non-existent server should not succeed
- meta = {'meta1': 'data1'}
- self.assertRaises(exceptions.NotFound,
- self.client.set_server_metadata, 999, meta)
-
- # An update should not happen for a non-existent image
- meta = {'key1': 'value1', 'key2': 'value2'}
- self.assertRaises(exceptions.NotFound,
- self.client.update_server_metadata, 999, meta)
-
- # Blank key should trigger an error
- meta = {'': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.client.update_server_metadata,
- self.server_id, meta=meta)
-
- # Should not be able to delete metadata item from a non-existent server
- self.assertRaises(exceptions.NotFound,
- self.client.delete_server_metadata_item, 999, 'd')
-
- # Raise a 413 OverLimit exception while exceeding metadata items limit
- # for tenant.
- _, quota_set = self.quotas.get_quota_set(self.tenant_id)
- quota_metadata = quota_set['metadata_items']
- req_metadata = {}
- for num in range(1, quota_metadata + 2):
- req_metadata['key' + str(num)] = 'val' + str(num)
- self.assertRaises(exceptions.OverLimit,
- self.client.set_server_metadata,
- self.server_id, req_metadata)
-
- # Raise a 413 OverLimit exception while exceeding metadata items limit
- # for tenant (update).
- self.assertRaises(exceptions.OverLimit,
- self.client.update_server_metadata,
- self.server_id, req_metadata)
-
- # Raise a bad request error for blank key.
- # set_server_metadata will replace all metadata with new value
- meta = {'': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.client.set_server_metadata,
- self.server_id, meta=meta)
-
- # Raise a bad request error for a missing metadata field
- # set_server_metadata will replace all metadata with new value
- meta = {'meta1': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.client.set_server_metadata,
- self.server_id, meta=meta, no_metadata_field=True)
-
class ServerMetadataTestXML(ServerMetadataTestJSON):
_interface = 'xml'
diff --git a/tempest/api/compute/servers/test_server_metadata_negative.py b/tempest/api/compute/servers/test_server_metadata_negative.py
new file mode 100644
index 0000000..e52ea4a
--- /dev/null
+++ b/tempest/api/compute/servers/test_server_metadata_negative.py
@@ -0,0 +1,163 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest import test
+
+
+class ServerMetadataNegativeTestJSON(base.BaseV2ComputeTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(ServerMetadataNegativeTestJSON, cls).setUpClass()
+ cls.client = cls.servers_client
+ cls.quotas = cls.quotas_client
+ cls.admin_client = cls._get_identity_admin_client()
+ resp, tenants = cls.admin_client.list_tenants()
+ cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
+ cls.client.tenant_name][0]
+ resp, server = cls.create_test_server(meta={}, wait_until='ACTIVE')
+
+ cls.server_id = server['id']
+
+ @test.attr(type=['gate', 'negative'])
+ def test_server_create_metadata_key_too_long(self):
+ # Attempt to start a server with a meta-data key that is > 255
+ # characters
+
+ # Tryset_server_metadata_item a few values
+ for sz in [256, 257, 511, 1023]:
+ key = "k" * sz
+ meta = {key: 'data1'}
+ self.assertRaises(exceptions.OverLimit,
+ self.create_test_server,
+ meta=meta)
+
+ # no teardown - all creates should fail
+
+ @test.attr(type=['negative', 'gate'])
+ def test_create_server_metadata_blank_key(self):
+ # Blank key should trigger an error.
+ meta = {'': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.create_test_server,
+ meta=meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_server_metadata_non_existent_server(self):
+ # GET on a non-existent server should not succeed
+ non_existent_server_id = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound,
+ self.client.get_server_metadata_item,
+ non_existent_server_id,
+ 'test2')
+
+ @test.attr(type=['negative', 'gate'])
+ def test_list_server_metadata_non_existent_server(self):
+ # List metadata on a non-existent server should not succeed
+ non_existent_server_id = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound,
+ self.client.list_server_metadata,
+ non_existent_server_id)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_wrong_key_passed_in_body(self):
+ # Raise BadRequest if key in uri does not match
+ # the key passed in body.
+ meta = {'testkey': 'testvalue'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.set_server_metadata_item,
+ self.server_id, 'key', meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_set_metadata_non_existent_server(self):
+ # Set metadata on a non-existent server should not succeed
+ non_existent_server_id = data_utils.rand_uuid()
+ meta = {'meta1': 'data1'}
+ self.assertRaises(exceptions.NotFound,
+ self.client.set_server_metadata,
+ non_existent_server_id,
+ meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_update_metadata_non_existent_server(self):
+ # An update should not happen for a non-existent server
+ non_existent_server_id = data_utils.rand_uuid()
+ meta = {'key1': 'value1', 'key2': 'value2'}
+ self.assertRaises(exceptions.NotFound,
+ self.client.update_server_metadata,
+ non_existent_server_id,
+ meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_update_metadata_with_blank_key(self):
+ # Blank key should trigger an error
+ meta = {'': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.update_server_metadata,
+ self.server_id, meta=meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_delete_metadata_non_existent_server(self):
+ # Should not be able to delete metadata item from a non-existent server
+ non_existent_server_id = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_server_metadata_item,
+ non_existent_server_id,
+ 'd')
+
+ @test.attr(type=['negative', 'gate'])
+ def test_metadata_items_limit(self):
+ # Raise a 413 OverLimit exception while exceeding metadata items limit
+ # for tenant.
+ _, quota_set = self.quotas.get_quota_set(self.tenant_id)
+ quota_metadata = quota_set['metadata_items']
+ req_metadata = {}
+ for num in range(1, quota_metadata + 2):
+ req_metadata['key' + str(num)] = 'val' + str(num)
+ self.assertRaises(exceptions.OverLimit,
+ self.client.set_server_metadata,
+ self.server_id, req_metadata)
+
+ # Raise a 413 OverLimit exception while exceeding metadata items limit
+ # for tenant (update).
+ self.assertRaises(exceptions.OverLimit,
+ self.client.update_server_metadata,
+ self.server_id, req_metadata)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_set_server_metadata_blank_key(self):
+ # Raise a bad request error for blank key.
+ # set_server_metadata will replace all metadata with new value
+ meta = {'': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.set_server_metadata,
+ self.server_id, meta=meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_set_server_metadata_missing_metadata(self):
+ # Raise a bad request error for a missing metadata field
+ # set_server_metadata will replace all metadata with new value
+ meta = {'meta1': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.set_server_metadata,
+ self.server_id, meta=meta, no_metadata_field=True)
+
+
+class ServerMetadataNegativeTestXML(ServerMetadataNegativeTestJSON):
+ _interface = 'xml'
diff --git a/tempest/api/compute/servers/test_server_password.py b/tempest/api/compute/servers/test_server_password.py
index 93c6e44..06697a5 100644
--- a/tempest/api/compute/servers/test_server_password.py
+++ b/tempest/api/compute/servers/test_server_password.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/servers/test_server_personality.py b/tempest/api/compute/servers/test_server_personality.py
index c6d2e44..bb14a4c 100644
--- a/tempest/api/compute/servers/test_server_personality.py
+++ b/tempest/api/compute/servers/test_server_personality.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/servers/test_server_rescue.py b/tempest/api/compute/servers/test_server_rescue.py
index 1008670..0bf604c 100644
--- a/tempest/api/compute/servers/test_server_rescue.py
+++ b/tempest/api/compute/servers/test_server_rescue.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
#
@@ -26,6 +24,7 @@
@classmethod
def setUpClass(cls):
+ cls.set_network_resources(network=True, subnet=True, router=True)
super(ServerRescueTestJSON, cls).setUpClass()
cls.device = 'vdf'
@@ -43,20 +42,10 @@
cls.sg_id = cls.sg['id']
# Create a volume and wait for it to become ready for attach
- resp, cls.volume_to_attach = \
- cls.volumes_extensions_client.create_volume(1,
- display_name=
- 'test_attach')
+ resp, cls.volume = cls.volumes_extensions_client.create_volume(
+ 1, display_name=data_utils.rand_name(cls.__name__ + '_volume'))
cls.volumes_extensions_client.wait_for_volume_status(
- cls.volume_to_attach['id'], 'available')
-
- # Create a volume and wait for it to become ready for attach
- resp, cls.volume_to_detach = \
- cls.volumes_extensions_client.create_volume(1,
- display_name=
- 'test_detach')
- cls.volumes_extensions_client.wait_for_volume_status(
- cls.volume_to_detach['id'], 'available')
+ cls.volume['id'], 'available')
# Server for positive tests
resp, server = cls.create_test_server(wait_until='BUILD')
@@ -70,7 +59,7 @@
cls.rescue_password = resc_server['adminPass']
cls.servers_client.rescue_server(
- cls.rescue_id, cls.rescue_password)
+ cls.rescue_id, adminPass=cls.rescue_password)
cls.servers_client.wait_for_server_status(cls.rescue_id, 'RESCUE')
def setUp(self):
@@ -80,9 +69,7 @@
def tearDownClass(cls):
# Deleting the floating IP which is created in this method
cls.floating_ips_client.delete_floating_ip(cls.floating_ip_id)
- client = cls.volumes_extensions_client
- client.delete_volume(str(cls.volume_to_attach['id']).strip())
- client.delete_volume(str(cls.volume_to_detach['id']).strip())
+ cls.delete_volume(cls.volume['id'])
resp, cls.sg = cls.security_groups_client.delete_security_group(
cls.sg_id)
super(ServerRescueTestJSON, cls).tearDownClass()
@@ -95,9 +82,6 @@
self.volumes_extensions_client.wait_for_volume_status(volume_id,
'available')
- def _delete(self, volume_id):
- self.volumes_extensions_client.delete_volume(volume_id)
-
def _unrescue(self, server_id):
resp, body = self.servers_client.unrescue_server(server_id)
self.assertEqual(202, resp.status)
@@ -111,7 +95,7 @@
@attr(type='smoke')
def test_rescue_unrescue_instance(self):
resp, body = self.servers_client.rescue_server(
- self.server_id, self.password)
+ self.server_id, adminPass=self.password)
self.assertEqual(200, resp.status)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
resp, body = self.servers_client.unrescue_server(self.server_id)
@@ -152,7 +136,8 @@
@attr(type=['negative', 'gate'])
def test_rescued_vm_attach_volume(self):
# Rescue the server
- self.servers_client.rescue_server(self.server_id, self.password)
+ self.servers_client.rescue_server(self.server_id,
+ adminPass=self.password)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
self.addCleanup(self._unrescue, self.server_id)
@@ -160,37 +145,37 @@
self.assertRaises(exceptions.Conflict,
self.servers_client.attach_volume,
self.server_id,
- self.volume_to_attach['id'],
+ self.volume['id'],
device='/dev/%s' % self.device)
@attr(type=['negative', 'gate'])
def test_rescued_vm_detach_volume(self):
# Attach the volume to the server
self.servers_client.attach_volume(self.server_id,
- self.volume_to_detach['id'],
+ self.volume['id'],
device='/dev/%s' % self.device)
self.volumes_extensions_client.wait_for_volume_status(
- self.volume_to_detach['id'], 'in-use')
+ self.volume['id'], 'in-use')
# Rescue the server
- self.servers_client.rescue_server(self.server_id, self.password)
+ self.servers_client.rescue_server(self.server_id,
+ adminPass=self.password)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
# addCleanup is a LIFO queue
- self.addCleanup(self._detach, self.server_id,
- self.volume_to_detach['id'])
+ self.addCleanup(self._detach, self.server_id, self.volume['id'])
self.addCleanup(self._unrescue, self.server_id)
# Detach the volume from the server expecting failure
self.assertRaises(exceptions.Conflict,
self.servers_client.detach_volume,
self.server_id,
- self.volume_to_detach['id'])
+ self.volume['id'])
@attr(type='gate')
def test_rescued_vm_associate_dissociate_floating_ip(self):
# Rescue the server
self.servers_client.rescue_server(
- self.server_id, self.password)
+ self.server_id, adminPass=self.password)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
self.addCleanup(self._unrescue, self.server_id)
@@ -210,8 +195,9 @@
def test_rescued_vm_add_remove_security_group(self):
# Rescue the server
self.servers_client.rescue_server(
- self.server_id, self.password)
+ self.server_id, adminPass=self.password)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
+ self.addCleanup(self._unrescue, self.server_id)
# Add Security group
resp, body = self.servers_client.add_security_group(self.server_id,
@@ -223,11 +209,6 @@
self.sg_name)
self.assertEqual(202, resp.status)
- # Unrescue the server
- resp, body = self.servers_client.unrescue_server(self.server_id)
- self.assertEqual(202, resp.status)
- self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
-
class ServerRescueTestXML(ServerRescueTestJSON):
_interface = 'xml'
diff --git a/tempest/api/compute/servers/test_servers.py b/tempest/api/compute/servers/test_servers.py
index d72476d..203832e 100644
--- a/tempest/api/compute/servers/test_servers.py
+++ b/tempest/api/compute/servers/test_servers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -106,6 +104,24 @@
self.assertEqual('::babe:202:202', server['accessIPv6'])
@attr(type='gate')
+ def test_delete_server_while_in_shutoff_state(self):
+ # Delete a server while it's VM state is Shutoff
+ resp, server = self.create_test_server(wait_until='ACTIVE')
+ resp, body = self.client.stop(server['id'])
+ self.client.wait_for_server_status(server['id'], 'SHUTOFF')
+ resp, _ = self.client.delete_server(server['id'])
+ self.assertEqual('204', resp['status'])
+
+ @attr(type='gate')
+ def test_delete_server_while_in_pause_state(self):
+ # Delete a server while it's VM state is Pause
+ resp, server = self.create_test_server(wait_until='ACTIVE')
+ resp, body = self.client.pause_server(server['id'])
+ self.client.wait_for_server_status(server['id'], 'PAUSED')
+ resp, _ = self.client.delete_server(server['id'])
+ self.assertEqual('204', resp['status'])
+
+ @attr(type='gate')
def test_delete_server_while_in_building_state(self):
# Delete a server while it's VM state is Building
resp, server = self.create_test_server(wait_until='BUILD')
diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py
index 6532032..e0181b9 100644
--- a/tempest/api/compute/servers/test_servers_negative.py
+++ b/tempest/api/compute/servers/test_servers_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -21,9 +19,12 @@
from tempest.api.compute import base
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest import test
+CONF = config.CONF
+
class ServersNegativeTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
@@ -197,7 +198,7 @@
networks=networks)
@test.attr(type=['negative', 'gate'])
- def test_create_with_non_existant_keypair(self):
+ def test_create_with_non_existent_keypair(self):
# Pass a non-existent keypair while creating a server
key_name = data_utils.rand_name('key')
@@ -410,7 +411,7 @@
self.assertEqual(202, resp.status)
self.addCleanup(self.client.unshelve_server, self.server_id)
- offload_time = self.config.compute.shelved_offload_time
+ offload_time = CONF.compute.shelved_offload_time
if offload_time >= 0:
self.client.wait_for_server_status(self.server_id,
'SHELVED_OFFLOADED',
diff --git a/tempest/api/compute/servers/test_servers_negative_new.py b/tempest/api/compute/servers/test_servers_negative_new.py
new file mode 100644
index 0000000..2b2fcf1
--- /dev/null
+++ b/tempest/api/compute/servers/test_servers_negative_new.py
@@ -0,0 +1,41 @@
+# Copyright 2014 Red Hat, Inc & Deutsche Telekom AG
+# All Rights Reserved.
+#
+# 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 testscenarios
+
+from tempest.api.compute import base
+from tempest import test
+
+
+load_tests = testscenarios.load_tests_apply_scenarios
+
+
+class GetConsoleOutputNegativeTestJSON(base.BaseV2ComputeTest,
+ test.NegativeAutoTest):
+ _interface = 'json'
+ _service = 'compute'
+ _schema_file = 'compute/servers/get_console_output.json'
+
+ scenarios = test.NegativeAutoTest.generate_scenario(_schema_file)
+
+ @classmethod
+ def setUpClass(cls):
+ super(GetConsoleOutputNegativeTestJSON, cls).setUpClass()
+ _resp, server = cls.create_test_server()
+ cls.set_resource("server", server['id'])
+
+ @test.attr(type=['negative', 'gate'])
+ def test_get_console_output(self):
+ self.execute(self._schema_file)
diff --git a/tempest/api/compute/servers/test_virtual_interfaces.py b/tempest/api/compute/servers/test_virtual_interfaces.py
index 968ae47..95703d4 100644
--- a/tempest/api/compute/servers/test_virtual_interfaces.py
+++ b/tempest/api/compute/servers/test_virtual_interfaces.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -21,14 +19,16 @@
from tempest import config
from tempest import test
+CONF = config.CONF
+
class VirtualInterfacesTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
- CONF = config.CONF
-
@classmethod
def setUpClass(cls):
+ # This test needs a network and a subnet
+ cls.set_network_resources(network=True, subnet=True)
super(VirtualInterfacesTestJSON, cls).setUpClass()
cls.client = cls.servers_client
resp, server = cls.create_test_server(wait_until='ACTIVE')
diff --git a/tempest/api/compute/servers/test_virtual_interfaces_negative.py b/tempest/api/compute/servers/test_virtual_interfaces_negative.py
index a2a6c11..f73218c 100644
--- a/tempest/api/compute/servers/test_virtual_interfaces_negative.py
+++ b/tempest/api/compute/servers/test_virtual_interfaces_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -27,6 +25,8 @@
@classmethod
def setUpClass(cls):
+ # For this test no network resources are needed
+ cls.set_network_resources()
super(VirtualInterfacesNegativeTestJSON, cls).setUpClass()
cls.client = cls.servers_client
diff --git a/tempest/api/compute/test_authorization.py b/tempest/api/compute/test_authorization.py
index 327c7d1..ed72061 100644
--- a/tempest/api/compute/test_authorization.py
+++ b/tempest/api/compute/test_authorization.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,10 +16,13 @@
from tempest.api.compute import base
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.test import attr
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -30,6 +31,8 @@
@classmethod
def setUpClass(cls):
+ # No network resources required for this test
+ cls.set_network_resources()
super(AuthorizationTestJSON, cls).setUpClass()
if not cls.multi_user:
msg = "Need >1 user"
@@ -39,7 +42,7 @@
cls.keypairs_client = cls.os.keypairs_client
cls.security_client = cls.os.security_groups_client
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.alt_manager = clients.Manager(username=username,
@@ -54,7 +57,6 @@
cls.alt_keypairs_client = cls.alt_manager.keypairs_client
cls.alt_security_client = cls.alt_manager.security_groups_client
- cls.alt_security_client._set_auth()
resp, server = cls.create_test_server(wait_until='ACTIVE')
resp, cls.server = cls.client.get_server(server['id'])
@@ -171,16 +173,14 @@
def test_create_server_fails_when_tenant_incorrect(self):
# A create server request should fail if the tenant id does not match
# the current user
- saved_base_url = self.alt_client.base_url
- try:
- # Change the base URL to impersonate another user
- self.alt_client.base_url = self.client.base_url
- self.assertRaises(exceptions.BadRequest,
- self.alt_client.create_server, 'test',
- self.image['id'], self.flavor_ref)
- finally:
- # Reset the base_url...
- self.alt_client.base_url = saved_base_url
+ # Change the base URL to impersonate another user
+ self.alt_client.auth_provider.set_alt_auth_data(
+ request_part='url',
+ auth_data=self.client.auth_provider.auth_data
+ )
+ self.assertRaises(exceptions.BadRequest,
+ self.alt_client.create_server, 'test',
+ self.image['id'], self.flavor_ref)
@attr(type='gate')
def test_create_keypair_in_analt_user_tenant(self):
@@ -188,18 +188,18 @@
# the current user
# POST keypair with other user tenant
k_name = data_utils.rand_name('keypair-')
- self.alt_keypairs_client._set_auth()
- self.saved_base_url = self.alt_keypairs_client.base_url
try:
# Change the base URL to impersonate another user
- self.alt_keypairs_client.base_url = self.keypairs_client.base_url
+ self.alt_keypairs_client.auth_provider.set_alt_auth_data(
+ request_part='url',
+ auth_data=self.keypairs_client.auth_provider.auth_data
+ )
resp = {}
resp['status'] = None
self.assertRaises(exceptions.BadRequest,
self.alt_keypairs_client.create_keypair, k_name)
finally:
- # Reset the base_url...
- self.alt_keypairs_client.base_url = self.saved_base_url
+ # Next request the base_url is back to normal
if (resp['status'] is not None):
resp, _ = self.alt_keypairs_client.delete_keypair(k_name)
LOG.error("Create keypair request should not happen "
@@ -239,18 +239,19 @@
# POST security group with other user tenant
s_name = data_utils.rand_name('security-')
s_description = data_utils.rand_name('security')
- self.saved_base_url = self.alt_security_client.base_url
try:
# Change the base URL to impersonate another user
- self.alt_security_client.base_url = self.security_client.base_url
+ self.alt_security_client.auth_provider.set_alt_auth_data(
+ request_part='url',
+ auth_data=self.security_client.auth_provider.auth_data
+ )
resp = {}
resp['status'] = None
self.assertRaises(exceptions.BadRequest,
self.alt_security_client.create_security_group,
s_name, s_description)
finally:
- # Reset the base_url...
- self.alt_security_client.base_url = self.saved_base_url
+ # Next request the base_url is back to normal
if resp['status'] is not None:
self.alt_security_client.delete_security_group(resp['id'])
LOG.error("Create Security Group request should not happen if"
@@ -279,10 +280,12 @@
ip_protocol = 'icmp'
from_port = -1
to_port = -1
- self.saved_base_url = self.alt_security_client.base_url
try:
# Change the base URL to impersonate another user
- self.alt_security_client.base_url = self.security_client.base_url
+ self.alt_security_client.auth_provider.set_alt_auth_data(
+ request_part='url',
+ auth_data=self.security_client.auth_provider.auth_data
+ )
resp = {}
resp['status'] = None
self.assertRaises(exceptions.BadRequest,
@@ -291,8 +294,7 @@
parent_group_id, ip_protocol, from_port,
to_port)
finally:
- # Reset the base_url...
- self.alt_security_client.base_url = self.saved_base_url
+ # Next request the base_url is back to normal
if resp['status'] is not None:
self.alt_security_client.delete_security_group_rule(resp['id'])
LOG.error("Create security group rule request should not "
diff --git a/tempest/api/compute/test_extensions.py b/tempest/api/compute/test_extensions.py
index b0bffc4..55146e5 100644
--- a/tempest/api/compute/test_extensions.py
+++ b/tempest/api/compute/test_extensions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,25 +15,38 @@
from tempest.api.compute import base
+from tempest import config
+from tempest.openstack.common import log as logging
from tempest import test
-import testtools
+
+CONF = config.CONF
+
+
+LOG = logging.getLogger(__name__)
class ExtensionsTestJSON(base.BaseV2ComputeTest):
_interface = 'json'
- @testtools.skipIf(not test.is_extension_enabled('os-consoles', 'compute'),
- 'os-consoles extension not enabled.')
@test.attr(type='gate')
def test_list_extensions(self):
# List of all extensions
+ if len(CONF.compute_feature_enabled.api_extensions) == 0:
+ raise self.skipException('There are not any extensions configured')
resp, extensions = self.extensions_client.list_extensions()
- self.assertIn("extensions", extensions)
self.assertEqual(200, resp.status)
- self.assertTrue(self.extensions_client.is_enabled("Consoles"))
+ ext = CONF.compute_feature_enabled.api_extensions[0]
+ if ext == 'all':
+ self.assertIn('Hosts', map(lambda x: x['name'], extensions))
+ elif ext:
+ self.assertIn(ext, map(lambda x: x['name'], extensions))
+ else:
+ raise self.skipException('There are not any extensions configured')
+ # Log extensions list
+ extension_list = map(lambda x: x['name'], extensions)
+ LOG.debug("Nova extensions: %s" % ','.join(extension_list))
- @testtools.skipIf(not test.is_extension_enabled('os-consoles', 'compute'),
- 'os-consoles extension not enabled.')
+ @test.requires_ext(extension='os-consoles', service='compute')
@test.attr(type='gate')
def test_get_extension(self):
# get the specified extensions
diff --git a/tempest/api/compute/test_live_block_migration.py b/tempest/api/compute/test_live_block_migration.py
index d2a3d28..fcd055b 100644
--- a/tempest/api/compute/test_live_block_migration.py
+++ b/tempest/api/compute/test_live_block_migration.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -25,13 +23,13 @@
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
+
class LiveBlockMigrationTestJSON(base.BaseV2ComputeAdminTest):
_host_key = 'OS-EXT-SRV-ATTR:host'
_interface = 'json'
- CONF = config.CONF
-
@classmethod
def setUpClass(cls):
super(LiveBlockMigrationTestJSON, cls).setUpClass()
@@ -59,8 +57,7 @@
def _migrate_server_to(self, server_id, dest_host):
_resp, body = self.admin_servers_client.live_migrate_server(
server_id, dest_host,
- self.config.compute_feature_enabled.
- block_migration_for_live_migration)
+ CONF.compute_feature_enabled.block_migration_for_live_migration)
return body
def _get_host_other_than(self, host):
diff --git a/tempest/api/compute/test_quotas.py b/tempest/api/compute/test_quotas.py
index 475d055..112e4fb 100644
--- a/tempest/api/compute/test_quotas.py
+++ b/tempest/api/compute/test_quotas.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/compute/v3/admin/test_aggregates.py b/tempest/api/compute/v3/admin/test_aggregates.py
index 144dc44..b8b478d 100644
--- a/tempest/api/compute/v3/admin/test_aggregates.py
+++ b/tempest/api/compute/v3/admin/test_aggregates.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -21,7 +19,7 @@
from tempest import test
-class AggregatesAdminV3TestJSON(base.BaseV3ComputeAdminTest):
+class AggregatesAdminV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Aggregates API that require admin privileges
@@ -32,7 +30,7 @@
@classmethod
def setUpClass(cls):
- super(AggregatesAdminV3TestJSON, cls).setUpClass()
+ super(AggregatesAdminV3Test, cls).setUpClass()
cls.client = cls.aggregates_admin_client
cls.user_client = cls.aggregates_client
cls.aggregate_name_prefix = 'test_aggregate_'
@@ -47,7 +45,7 @@
def test_aggregate_create_delete(self):
# Create and delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.assertEqual(aggregate_name, aggregate['name'])
self.assertEqual(None, aggregate['availability_zone'])
@@ -61,7 +59,8 @@
# Create and delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
+ resp, aggregate = self.client.create_aggregate(
+ name=aggregate_name, availability_zone=az_name)
self.assertEqual(201, resp.status)
self.assertEqual(aggregate_name, aggregate['name'])
self.assertEqual(az_name, aggregate['availability_zone'])
@@ -74,7 +73,7 @@
def test_aggregate_create_verify_entry_in_list(self):
# Create an aggregate and ensure it is listed.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, aggregates = self.client.list_aggregates()
@@ -87,7 +86,7 @@
def test_aggregate_create_update_metadata_get_details(self):
# Create an aggregate and ensure its details are returned.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, body = self.client.get_aggregate(aggregate['id'])
@@ -114,7 +113,8 @@
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
+ resp, aggregate = self.client.create_aggregate(
+ name=aggregate_name, availability_zone=az_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertEqual(201, resp.status)
@@ -145,7 +145,7 @@
# Add an host to the given aggregate and remove.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, body = self.client.add_host(aggregate['id'], self.host)
@@ -167,7 +167,7 @@
# Add an host to the given aggregate and list.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.client.add_host(aggregate['id'], self.host)
self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
@@ -185,7 +185,7 @@
# Add an host to the given aggregate and get details.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.client.add_host(aggregate['id'], self.host)
self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
@@ -201,7 +201,8 @@
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name, az_name)
+ resp, aggregate = self.client.create_aggregate(
+ name=aggregate_name, availability_zone=az_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.client.add_host(aggregate['id'], self.host)
self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
@@ -212,10 +213,3 @@
wait_until='ACTIVE')
resp, body = admin_servers_client.get_server(server['id'])
self.assertEqual(self.host, body[self._host_key])
-
-
-class AggregatesAdminV3TestXML(AggregatesAdminV3TestJSON):
- _host_key = (
- '{http://docs.openstack.org/compute/ext/'
- 'extended_server_attributes/api/v3}host')
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_aggregates_negative.py b/tempest/api/compute/v3/admin/test_aggregates_negative.py
index 87eadce..5700460 100644
--- a/tempest/api/compute/v3/admin/test_aggregates_negative.py
+++ b/tempest/api/compute/v3/admin/test_aggregates_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -22,7 +20,7 @@
from tempest import test
-class AggregatesAdminNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class AggregatesAdminNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Aggregates API that require admin privileges
@@ -32,7 +30,7 @@
@classmethod
def setUpClass(cls):
- super(AggregatesAdminNegativeV3TestJSON, cls).setUpClass()
+ super(AggregatesAdminNegativeV3Test, cls).setUpClass()
cls.client = cls.aggregates_admin_client
cls.user_client = cls.aggregates_client
cls.aggregate_name_prefix = 'test_aggregate_'
@@ -49,14 +47,14 @@
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
self.assertRaises(exceptions.Unauthorized,
self.user_client.create_aggregate,
- aggregate_name)
+ name=aggregate_name)
@test.attr(type=['negative', 'gate'])
def test_aggregate_create_aggregate_name_length_less_than_1(self):
# the length of aggregate name should >= 1 and <=255
self.assertRaises(exceptions.BadRequest,
self.client.create_aggregate,
- '')
+ name='')
@test.attr(type=['negative', 'gate'])
def test_aggregate_create_aggregate_name_length_exceeds_255(self):
@@ -64,25 +62,25 @@
aggregate_name = 'a' * 256
self.assertRaises(exceptions.BadRequest,
self.client.create_aggregate,
- aggregate_name)
+ name=aggregate_name)
@test.attr(type=['negative', 'gate'])
def test_aggregate_create_with_existent_aggregate_name(self):
# creating an aggregate with existent aggregate name is forbidden
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(exceptions.Conflict,
self.client.create_aggregate,
- aggregate_name)
+ name=aggregate_name)
@test.attr(type=['negative', 'gate'])
def test_aggregate_delete_as_user(self):
# Regular user is not allowed to delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -100,7 +98,7 @@
def test_aggregate_get_details_as_user(self):
# Regular user is not allowed to get aggregate details.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -131,7 +129,7 @@
break
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(exceptions.NotFound, self.client.add_host,
@@ -141,7 +139,7 @@
def test_aggregate_add_host_as_user(self):
# Regular user is not allowed to add a host to an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -153,7 +151,7 @@
def test_aggregate_add_existent_host(self):
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
@@ -169,7 +167,7 @@
# Regular user is not allowed to remove a host from an aggregate.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
resp, body = self.client.add_host(aggregate['id'], self.host)
@@ -184,13 +182,9 @@
def test_aggregate_remove_nonexistent_host(self):
non_exist_host = data_utils.rand_name('nonexist_host_')
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
- resp, aggregate = self.client.create_aggregate(aggregate_name)
+ resp, aggregate = self.client.create_aggregate(name=aggregate_name)
self.assertEqual(201, resp.status)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(exceptions.NotFound, self.client.remove_host,
aggregate['id'], non_exist_host)
-
-
-class AggregatesAdminNegativeV3TestXML(AggregatesAdminNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_availability_zone.py b/tempest/api/compute/v3/admin/test_availability_zone.py
index dca556f..57ac869 100644
--- a/tempest/api/compute/v3/admin/test_availability_zone.py
+++ b/tempest/api/compute/v3/admin/test_availability_zone.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -19,7 +17,7 @@
from tempest.test import attr
-class AZAdminV3TestJSON(base.BaseV3ComputeAdminTest):
+class AZAdminV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Availability Zone API List
@@ -29,7 +27,7 @@
@classmethod
def setUpClass(cls):
- super(AZAdminV3TestJSON, cls).setUpClass()
+ super(AZAdminV3Test, cls).setUpClass()
cls.client = cls.availability_zone_admin_client
cls.non_adm_client = cls.availability_zone_client
@@ -55,7 +53,3 @@
self.non_adm_client.get_availability_zone_list()
self.assertEqual(200, resp.status)
self.assertTrue(len(availability_zone) > 0)
-
-
-class AZAdminV3TestXML(AZAdminV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_availability_zone_negative.py b/tempest/api/compute/v3/admin/test_availability_zone_negative.py
index 93a57e3..180f298 100644
--- a/tempest/api/compute/v3/admin/test_availability_zone_negative.py
+++ b/tempest/api/compute/v3/admin/test_availability_zone_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -20,7 +18,7 @@
from tempest.test import attr
-class AZAdminNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class AZAdminNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Availability Zone API List
@@ -30,7 +28,7 @@
@classmethod
def setUpClass(cls):
- super(AZAdminNegativeV3TestJSON, cls).setUpClass()
+ super(AZAdminNegativeV3Test, cls).setUpClass()
cls.client = cls.availability_zone_admin_client
cls.non_adm_client = cls.availability_zone_client
@@ -41,7 +39,3 @@
self.assertRaises(
exceptions.Unauthorized,
self.non_adm_client.get_availability_zone_list_detail)
-
-
-class AZAdminNegativeV3TestXML(AZAdminNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_flavors_access.py b/tempest/api/compute/v3/admin/test_flavors_access.py
index 86194af..43dc726 100644
--- a/tempest/api/compute/v3/admin/test_flavors_access.py
+++ b/tempest/api/compute/v3/admin/test_flavors_access.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -20,7 +18,7 @@
from tempest import test
-class FlavorsAccessV3TestJSON(base.BaseV3ComputeAdminTest):
+class FlavorsAccessV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Flavor Access API extension.
@@ -31,7 +29,7 @@
@classmethod
def setUpClass(cls):
- super(FlavorsAccessV3TestJSON, cls).setUpClass()
+ super(FlavorsAccessV3Test, cls).setUpClass()
cls.client = cls.flavors_admin_client
admin_client = cls._get_identity_admin_client()
@@ -46,6 +44,7 @@
cls.vcpus = 1
cls.disk = 10
+ @test.skip_because(bug='1265416')
@test.attr(type='gate')
def test_flavor_access_list_with_private_flavor(self):
# Test to list flavor access successfully by querying private flavor
@@ -65,6 +64,7 @@
self.assertEqual(str(new_flavor_id), str(first_flavor['flavor_id']))
self.assertEqual(self.adm_tenant_id, first_flavor['tenant_id'])
+ @test.skip_because(bug='1265416')
@test.attr(type='gate')
def test_flavor_access_add_remove(self):
# Test to add and remove flavor access to a given tenant.
@@ -101,7 +101,3 @@
resp, flavors = self.flavors_client.list_flavors_with_detail()
self.assertEqual(resp.status, 200)
self.assertNotIn(new_flavor['id'], map(lambda x: x['id'], flavors))
-
-
-class FlavorsAdminV3TestXML(FlavorsAccessV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_flavors_access_negative.py b/tempest/api/compute/v3/admin/test_flavors_access_negative.py
index df6557e..6a2e826 100644
--- a/tempest/api/compute/v3/admin/test_flavors_access_negative.py
+++ b/tempest/api/compute/v3/admin/test_flavors_access_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -23,7 +21,7 @@
from tempest import test
-class FlavorsAccessNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class FlavorsAccessNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Flavor Access API extension.
@@ -34,7 +32,7 @@
@classmethod
def setUpClass(cls):
- super(FlavorsAccessNegativeV3TestJSON, cls).setUpClass()
+ super(FlavorsAccessNegativeV3Test, cls).setUpClass()
cls.client = cls.flavors_admin_client
admin_client = cls._get_identity_admin_client()
@@ -65,6 +63,7 @@
self.client.list_flavor_access,
new_flavor_id)
+ @test.skip_because(bug='1265416')
@test.attr(type=['negative', 'gate'])
def test_flavor_non_admin_add(self):
# Test to add flavor access as a user without admin privileges.
@@ -81,6 +80,7 @@
new_flavor['id'],
self.tenant_id)
+ @test.skip_because(bug='1265416')
@test.attr(type=['negative', 'gate'])
def test_flavor_non_admin_remove(self):
# Test to remove flavor access as a user without admin privileges.
@@ -101,6 +101,7 @@
new_flavor['id'],
self.tenant_id)
+ @test.skip_because(bug='1265416')
@test.attr(type=['negative', 'gate'])
def test_add_flavor_access_duplicate(self):
# Create a new flavor.
@@ -125,6 +126,7 @@
new_flavor['id'],
self.tenant_id)
+ @test.skip_because(bug='1265416')
@test.attr(type=['negative', 'gate'])
def test_remove_flavor_access_not_found(self):
# Create a new flavor.
@@ -142,7 +144,3 @@
self.client.remove_flavor_access,
new_flavor['id'],
str(uuid.uuid4()))
-
-
-class FlavorsAdminNegativeV3TestXML(FlavorsAccessNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_flavors_extra_specs.py b/tempest/api/compute/v3/admin/test_flavors_extra_specs.py
index d745829..4d22027 100644
--- a/tempest/api/compute/v3/admin/test_flavors_extra_specs.py
+++ b/tempest/api/compute/v3/admin/test_flavors_extra_specs.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,7 +18,7 @@
from tempest import test
-class FlavorsExtraSpecsV3TestJSON(base.BaseV3ComputeAdminTest):
+class FlavorsExtraSpecsV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Flavor Extra Spec API extension.
@@ -32,7 +30,7 @@
@classmethod
def setUpClass(cls):
- super(FlavorsExtraSpecsV3TestJSON, cls).setUpClass()
+ super(FlavorsExtraSpecsV3Test, cls).setUpClass()
cls.client = cls.flavors_admin_client
flavor_name = data_utils.rand_name('test_flavor')
@@ -55,7 +53,7 @@
def tearDownClass(cls):
resp, body = cls.client.delete_flavor(cls.flavor['id'])
cls.client.wait_for_resource_deletion(cls.flavor['id'])
- super(FlavorsExtraSpecsV3TestJSON, cls).tearDownClass()
+ super(FlavorsExtraSpecsV3Test, cls).tearDownClass()
@test.attr(type='gate')
def test_flavor_set_get_update_show_unset_keys(self):
@@ -122,7 +120,3 @@
self.assertEqual(resp.status, 200)
self.assertEqual(body['key1'], 'value1')
self.assertNotIn('key2', body)
-
-
-class FlavorsExtraSpecsV3TestXML(FlavorsExtraSpecsV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_flavors_extra_specs_negative.py b/tempest/api/compute/v3/admin/test_flavors_extra_specs_negative.py
index 1d5e447..98e6e3d 100644
--- a/tempest/api/compute/v3/admin/test_flavors_extra_specs_negative.py
+++ b/tempest/api/compute/v3/admin/test_flavors_extra_specs_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
# Copyright 2013 IBM Corp.
@@ -22,7 +20,7 @@
from tempest import test
-class FlavorsExtraSpecsNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class FlavorsExtraSpecsNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Negative Tests Flavor Extra Spec API extension.
@@ -33,7 +31,7 @@
@classmethod
def setUpClass(cls):
- super(FlavorsExtraSpecsNegativeV3TestJSON, cls).setUpClass()
+ super(FlavorsExtraSpecsNegativeV3Test, cls).setUpClass()
cls.client = cls.flavors_admin_client
flavor_name = data_utils.rand_name('test_flavor')
@@ -56,7 +54,7 @@
def tearDownClass(cls):
resp, body = cls.client.delete_flavor(cls.flavor['id'])
cls.client.wait_for_resource_deletion(cls.flavor['id'])
- super(FlavorsExtraSpecsNegativeV3TestJSON, cls).tearDownClass()
+ super(FlavorsExtraSpecsNegativeV3Test, cls).tearDownClass()
@test.attr(type=['negative', 'gate'])
def test_flavor_non_admin_set_keys(self):
@@ -126,7 +124,3 @@
"key1",
key1="value",
key2="value")
-
-
-class FlavorsExtraSpecsNegativeV3TestXML(FlavorsExtraSpecsNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_hosts.py b/tempest/api/compute/v3/admin/test_hosts.py
index 896d6a7..2c9369f 100644
--- a/tempest/api/compute/v3/admin/test_hosts.py
+++ b/tempest/api/compute/v3/admin/test_hosts.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -19,7 +17,7 @@
from tempest import test
-class HostsAdminV3TestJSON(base.BaseV3ComputeAdminTest):
+class HostsAdminV3Test(base.BaseV3ComputeAdminTest):
"""
Tests hosts API using admin privileges.
@@ -29,7 +27,7 @@
@classmethod
def setUpClass(cls):
- super(HostsAdminV3TestJSON, cls).setUpClass()
+ super(HostsAdminV3Test, cls).setUpClass()
cls.client = cls.hosts_admin_client
@test.attr(type='gate')
@@ -88,7 +86,3 @@
self.assertIsNotNone(host_resource['memory_mb'])
self.assertIsNotNone(host_resource['project'])
self.assertEqual(hostname, host_resource['host'])
-
-
-class HostsAdminV3TestXML(HostsAdminV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_hosts_negative.py b/tempest/api/compute/v3/admin/test_hosts_negative.py
index 755fa2b..ac5d7de 100644
--- a/tempest/api/compute/v3/admin/test_hosts_negative.py
+++ b/tempest/api/compute/v3/admin/test_hosts_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -20,7 +18,7 @@
from tempest import test
-class HostsAdminNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class HostsAdminNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Tests hosts API using admin privileges.
@@ -30,7 +28,7 @@
@classmethod
def setUpClass(cls):
- super(HostsAdminNegativeV3TestJSON, cls).setUpClass()
+ super(HostsAdminNegativeV3Test, cls).setUpClass()
cls.client = cls.hosts_admin_client
cls.non_admin_client = cls.hosts_client
@@ -66,7 +64,9 @@
self.assertRaises(exceptions.Unauthorized,
self.non_admin_client.update_host,
- hostname)
+ hostname,
+ status='enable',
+ maintenance_mode='enable')
@test.attr(type=['negative', 'gate'])
def test_update_host_with_extra_param(self):
@@ -168,7 +168,3 @@
self.assertRaises(exceptions.Unauthorized,
self.non_admin_client.reboot_host,
hostname)
-
-
-class HostsAdminNegativeV3TestXML(HostsAdminNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_hypervisor.py b/tempest/api/compute/v3/admin/test_hypervisor.py
index 3da3369..0f96bba 100644
--- a/tempest/api/compute/v3/admin/test_hypervisor.py
+++ b/tempest/api/compute/v3/admin/test_hypervisor.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -19,7 +17,7 @@
from tempest.test import attr
-class HypervisorAdminV3TestJSON(base.BaseV3ComputeAdminTest):
+class HypervisorAdminV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Hypervisors API that require admin privileges
@@ -29,7 +27,7 @@
@classmethod
def setUpClass(cls):
- super(HypervisorAdminV3TestJSON, cls).setUpClass()
+ super(HypervisorAdminV3Test, cls).setUpClass()
cls.client = cls.hypervisor_admin_client
def _list_hypervisors(self):
@@ -99,7 +97,3 @@
hypers[0]['hypervisor_hostname'])
self.assertEqual(200, resp.status)
self.assertTrue(len(hypers) > 0)
-
-
-class HypervisorAdminV3TestXML(HypervisorAdminV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_hypervisor_negative.py b/tempest/api/compute/v3/admin/test_hypervisor_negative.py
index 847679e..aee354a 100644
--- a/tempest/api/compute/v3/admin/test_hypervisor_negative.py
+++ b/tempest/api/compute/v3/admin/test_hypervisor_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -23,7 +21,7 @@
from tempest.test import attr
-class HypervisorAdminNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class HypervisorAdminNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Hypervisors API that require admin privileges
@@ -33,7 +31,7 @@
@classmethod
def setUpClass(cls):
- super(HypervisorAdminNegativeV3TestJSON, cls).setUpClass()
+ super(HypervisorAdminNegativeV3Test, cls).setUpClass()
cls.client = cls.hypervisor_admin_client
cls.non_adm_client = cls.hypervisor_client
@@ -138,7 +136,3 @@
exceptions.Unauthorized,
self.non_adm_client.search_hypervisor,
hypers[0]['hypervisor_hostname'])
-
-
-class HypervisorAdminNegativeV3TestXML(HypervisorAdminNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_instance_usage_audit_log.py b/tempest/api/compute/v3/admin/test_instance_usage_audit_log.py
index cea6e92..a86b7f5 100644
--- a/tempest/api/compute/v3/admin/test_instance_usage_audit_log.py
+++ b/tempest/api/compute/v3/admin/test_instance_usage_audit_log.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -16,22 +14,22 @@
# under the License.
import datetime
-
-from tempest.api.compute import base
-from tempest.test import attr
import urllib
+from tempest.api.compute import base
+from tempest import test
-class InstanceUsageAuditLogTestJSON(base.BaseV2ComputeAdminTest):
+
+class InstanceUsageAuditLogV3Test(base.BaseV3ComputeAdminTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(InstanceUsageAuditLogTestJSON, cls).setUpClass()
- cls.adm_client = cls.os_adm.instance_usages_audit_log_client
+ super(InstanceUsageAuditLogV3Test, cls).setUpClass()
+ cls.adm_client = cls.instance_usages_audit_log_admin_client
- @attr(type='gate')
+ @test.attr(type='gate')
def test_list_instance_usage_audit_logs(self):
# list instance usage audit logs
resp, body = self.adm_client.list_instance_usage_audit_logs()
@@ -44,12 +42,12 @@
for item in expected_items:
self.assertIn(item, body)
- @attr(type='gate')
- def test_get_instance_usage_audit_log(self):
+ @test.attr(type='gate')
+ def test_list_instance_usage_audit_logs_with_filter_before(self):
# Get instance usage audit log before specified time
- now = datetime.datetime.now()
- resp, body = self.adm_client.get_instance_usage_audit_log(
- urllib.quote(now.strftime("%Y-%m-%d %H:%M:%S")))
+ ending_time = datetime.datetime(2012, 12, 24)
+ resp, body = self.adm_client.list_instance_usage_audit_logs(
+ urllib.quote(ending_time.strftime("%Y-%m-%d %H:%M:%S")))
self.assertEqual(200, resp.status)
expected_items = ['total_errors', 'total_instances', 'log',
@@ -58,7 +56,4 @@
'period_beginning', 'num_hosts_not_run']
for item in expected_items:
self.assertIn(item, body)
-
-
-class InstanceUsageAuditLogTestXML(InstanceUsageAuditLogTestJSON):
- _interface = 'xml'
+ self.assertEqual(body['period_ending'], "2012-12-23 23:00:00")
diff --git a/tempest/api/compute/v3/admin/test_instance_usage_audit_log_negative.py b/tempest/api/compute/v3/admin/test_instance_usage_audit_log_negative.py
index dcf41c5..0438825 100644
--- a/tempest/api/compute/v3/admin/test_instance_usage_audit_log_negative.py
+++ b/tempest/api/compute/v3/admin/test_instance_usage_audit_log_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -15,42 +13,29 @@
# License for the specific language governing permissions and limitations
# under the License.
-import datetime
-
from tempest.api.compute import base
from tempest import exceptions
-from tempest.test import attr
-import urllib
+from tempest import test
-class InstanceUsageAuditLogNegativeTestJSON(base.BaseV2ComputeAdminTest):
+class InstanceUsageLogNegativeV3Test(base.BaseV3ComputeAdminTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(InstanceUsageAuditLogNegativeTestJSON, cls).setUpClass()
- cls.adm_client = cls.os_adm.instance_usages_audit_log_client
+ super(InstanceUsageLogNegativeV3Test, cls).setUpClass()
+ cls.adm_client = cls.instance_usages_audit_log_admin_client
- @attr(type=['negative', 'gate'])
+ @test.attr(type=['negative', 'gate'])
def test_instance_usage_audit_logs_with_nonadmin_user(self):
# the instance_usage_audit_logs API just can be accessed by admin user
self.assertRaises(exceptions.Unauthorized,
self.instance_usages_audit_log_client.
list_instance_usage_audit_logs)
- now = datetime.datetime.now()
- self.assertRaises(exceptions.Unauthorized,
- self.instance_usages_audit_log_client.
- get_instance_usage_audit_log,
- urllib.quote(now.strftime("%Y-%m-%d %H:%M:%S")))
- @attr(type=['negative', 'gate'])
+ @test.attr(type=['negative', 'gate'])
def test_get_instance_usage_audit_logs_with_invalid_time(self):
self.assertRaises(exceptions.BadRequest,
- self.adm_client.get_instance_usage_audit_log,
+ self.adm_client.list_instance_usage_audit_logs,
"invalid_time")
-
-
-class InstanceUsageAuditLogNegativeTestXML(
- InstanceUsageAuditLogNegativeTestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_quotas.py b/tempest/api/compute/v3/admin/test_quotas.py
index e67ed8f..ccb9d8e 100644
--- a/tempest/api/compute/v3/admin/test_quotas.py
+++ b/tempest/api/compute/v3/admin/test_quotas.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,18 +15,21 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest import test
+CONF = config.CONF
-class QuotasAdminV3TestJSON(base.BaseV3ComputeAdminTest):
+
+class QuotasAdminV3Test(base.BaseV3ComputeAdminTest):
_interface = 'json'
force_tenant_isolation = True
@classmethod
def setUpClass(cls):
- super(QuotasAdminV3TestJSON, cls).setUpClass()
- cls.auth_url = cls.config.identity.uri
+ super(QuotasAdminV3Test, cls).setUpClass()
+ cls.auth_url = CONF.identity.uri
cls.client = cls.quotas_client
cls.adm_client = cls.quotas_admin_client
cls.identity_admin_client = cls._get_identity_admin_client()
@@ -149,7 +150,3 @@
self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
instances=default_instances_quota)
self.assertRaises(exceptions.OverLimit, self.create_test_server)
-
-
-class QuotasAdminV3TestXML(QuotasAdminV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_servers.py b/tempest/api/compute/v3/admin/test_servers.py
index 6fe3186..ef9eedc 100644
--- a/tempest/api/compute/v3/admin/test_servers.py
+++ b/tempest/api/compute/v3/admin/test_servers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -17,11 +15,12 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
from tempest import exceptions
+from tempest import test
from tempest.test import attr
from tempest.test import skip_because
-class ServersAdminTestJSON(base.BaseV2ComputeAdminTest):
+class ServersAdminV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Servers API using admin privileges
@@ -31,10 +30,10 @@
@classmethod
def setUpClass(cls):
- super(ServersAdminTestJSON, cls).setUpClass()
- cls.client = cls.os_adm.servers_client
+ super(ServersAdminV3Test, cls).setUpClass()
+ cls.client = cls.servers_admin_client
cls.non_admin_client = cls.servers_client
- cls.flavors_client = cls.os_adm.flavors_client
+ cls.flavors_client = cls.flavors_admin_client
cls.s1_name = data_utils.rand_name('server')
resp, server = cls.create_test_server(name=cls.s1_name,
@@ -44,6 +43,7 @@
cls.s2_name = data_utils.rand_name('server')
resp, server = cls.create_test_server(name=cls.s2_name,
wait_until='ACTIVE')
+ cls.s2_id = server['id']
def _get_unused_flavor_id(self):
flavor_id = data_utils.rand_int_id(start=1000)
@@ -63,6 +63,7 @@
self.assertEqual('200', resp['status'])
self.assertEqual([], servers)
+ @test.skip_because(bug='1265416')
@attr(type='gate')
def test_list_servers_by_admin_with_all_tenants(self):
# Listing servers by admin user with all tenants parameter
@@ -84,6 +85,18 @@
self.servers_client.wait_for_server_termination(server['id'])
@attr(type='gate')
+ def test_delete_server_while_in_error_state(self):
+ # Delete a server while it's VM state is error
+ resp, server = self.create_test_server(wait_until='ACTIVE')
+ resp, body = self.client.reset_state(server['id'], state='error')
+ self.assertEqual(202, resp.status)
+ # Verify server's state
+ resp, server = self.client.get_server(server['id'])
+ self.assertEqual(server['status'], 'ERROR')
+ resp, _ = self.client.delete_server(server['id'])
+ self.assertEqual('204', resp['status'])
+
+ @attr(type='gate')
def test_reset_state_server(self):
# Reset server's state to 'error'
resp, server = self.client.reset_state(self.s1_id)
@@ -114,6 +127,22 @@
self.assertIn(key, str(diagnostic.keys()))
@attr(type='gate')
+ def test_list_servers_filter_by_error_status(self):
+ # Filter the list of servers by server error status
+ params = {'status': 'error'}
+ resp, server = self.client.reset_state(self.s1_id, state='error')
+ resp, body = self.non_admin_client.list_servers(params)
+ # Reset server's state to 'active'
+ resp, server = self.client.reset_state(self.s1_id, state='active')
+ # Verify server's state
+ resp, server = self.client.get_server(self.s1_id)
+ self.assertEqual(server['status'], 'ACTIVE')
+ servers = body['servers']
+ # Verify error server in list result
+ self.assertIn(self.s1_id, map(lambda x: x['id'], servers))
+ self.assertNotIn(self.s2_id, map(lambda x: x['id'], servers))
+
+ @attr(type='gate')
def test_rebuild_server_in_error_state(self):
# The server in error state should be rebuilt using the provided
# image and changed to ACTIVE state
@@ -140,7 +169,3 @@
resp, server = self.non_admin_client.get_server(rebuilt_server['id'])
rebuilt_image_id = server['image']['id']
self.assertEqual(self.image_ref_alt, rebuilt_image_id)
-
-
-class ServersAdminTestXML(ServersAdminTestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_servers_negative.py b/tempest/api/compute/v3/admin/test_servers_negative.py
index 77d873b..a6a5736 100644
--- a/tempest/api/compute/v3/admin/test_servers_negative.py
+++ b/tempest/api/compute/v3/admin/test_servers_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -22,7 +20,7 @@
from tempest.test import attr
-class ServersAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
+class ServersAdminNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Servers API using admin privileges
@@ -32,10 +30,10 @@
@classmethod
def setUpClass(cls):
- super(ServersAdminNegativeTestJSON, cls).setUpClass()
- cls.client = cls.os_adm.servers_client
+ super(ServersAdminNegativeV3Test, cls).setUpClass()
+ cls.client = cls.servers_admin_client
cls.non_adm_client = cls.servers_client
- cls.flavors_client = cls.os_adm.flavors_client
+ cls.flavors_client = cls.flavors_admin_client
cls.identity_client = cls._get_identity_admin_client()
tenant = cls.identity_client.get_tenant_by_name(
cls.client.tenant_name)
@@ -137,7 +135,3 @@
self.assertRaises(exceptions.Conflict,
self.client.migrate_server,
server_id)
-
-
-class ServersAdminNegativeTestXML(ServersAdminNegativeTestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_services.py b/tempest/api/compute/v3/admin/test_services.py
index 602f914..8d6e549 100644
--- a/tempest/api/compute/v3/admin/test_services.py
+++ b/tempest/api/compute/v3/admin/test_services.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -20,7 +18,7 @@
from tempest.test import attr
-class ServicesAdminV3TestJSON(base.BaseV3ComputeAdminTest):
+class ServicesAdminV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Services API. List and Enable/Disable require admin privileges.
@@ -30,7 +28,7 @@
@classmethod
def setUpClass(cls):
- super(ServicesAdminV3TestJSON, cls).setUpClass()
+ super(ServicesAdminV3Test, cls).setUpClass()
cls.client = cls.services_admin_client
@attr(type='gate')
@@ -78,7 +76,3 @@
self.assertEqual(1, len(services))
self.assertEqual(host_name, services[0]['host'])
self.assertEqual(binary_name, services[0]['binary'])
-
-
-class ServicesAdminV3TestXML(ServicesAdminV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_services_negative.py b/tempest/api/compute/v3/admin/test_services_negative.py
index 337c051..c270842 100644
--- a/tempest/api/compute/v3/admin/test_services_negative.py
+++ b/tempest/api/compute/v3/admin/test_services_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -21,7 +19,7 @@
from tempest.test import attr
-class ServicesAdminNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class ServicesAdminNegativeV3Test(base.BaseV3ComputeAdminTest):
"""
Tests Services API. List and Enable/Disable require admin privileges.
@@ -31,7 +29,7 @@
@classmethod
def setUpClass(cls):
- super(ServicesAdminNegativeV3TestJSON, cls).setUpClass()
+ super(ServicesAdminNegativeV3Test, cls).setUpClass()
cls.client = cls.services_admin_client
cls.non_admin_client = cls.services_client
@@ -66,7 +64,3 @@
resp, services = self.client.list_services(params)
self.assertEqual(200, resp.status)
self.assertEqual(0, len(services))
-
-
-class ServicesAdminNegativeV3TestXML(ServicesAdminNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_simple_tenant_usage.py b/tempest/api/compute/v3/admin/test_simple_tenant_usage.py
index 99f2c52..e16332f 100644
--- a/tempest/api/compute/v3/admin/test_simple_tenant_usage.py
+++ b/tempest/api/compute/v3/admin/test_simple_tenant_usage.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -18,17 +16,18 @@
import datetime
from tempest.api.compute import base
+from tempest import test
from tempest.test import attr
import time
-class TenantUsagesV3TestJSON(base.BaseV3ComputeAdminTest):
+class TenantUsagesV3Test(base.BaseV3ComputeAdminTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(TenantUsagesV3TestJSON, cls).setUpClass()
+ super(TenantUsagesV3Test, cls).setUpClass()
cls.adm_client = cls.tenant_usages_admin_client
cls.client = cls.tenant_usages_client
cls.identity_client = cls._get_identity_admin_client()
@@ -50,6 +49,7 @@
# Returns formatted datetime
return at.strftime('%Y-%m-%dT%H:%M:%S.%f')
+ @test.skip_because(bug='1265416')
@attr(type='gate')
def test_list_usage_all_tenants(self):
# Get usage for all tenants
@@ -60,6 +60,7 @@
self.assertEqual(200, resp.status)
self.assertEqual(len(tenant_usage), 8)
+ @test.skip_because(bug='1265416')
@attr(type='gate')
def test_get_usage_tenant(self):
# Get usage for a specific tenant
@@ -71,6 +72,7 @@
self.assertEqual(200, resp.status)
self.assertEqual(len(tenant_usage), 8)
+ @test.skip_because(bug='1265416')
@attr(type='gate')
def test_get_usage_tenant_with_non_admin_user(self):
# Get usage for a specific tenant with non admin user
@@ -81,7 +83,3 @@
self.assertEqual(200, resp.status)
self.assertEqual(len(tenant_usage), 8)
-
-
-class TenantUsagesV3TestXML(TenantUsagesV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/admin/test_simple_tenant_usage_negative.py b/tempest/api/compute/v3/admin/test_simple_tenant_usage_negative.py
index ef49ed7..17849c5 100644
--- a/tempest/api/compute/v3/admin/test_simple_tenant_usage_negative.py
+++ b/tempest/api/compute/v3/admin/test_simple_tenant_usage_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -19,16 +17,17 @@
from tempest.api.compute import base
from tempest import exceptions
+from tempest import test
from tempest.test import attr
-class TenantUsagesNegativeV3TestJSON(base.BaseV3ComputeAdminTest):
+class TenantUsagesNegativeV3Test(base.BaseV3ComputeAdminTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(TenantUsagesNegativeV3TestJSON, cls).setUpClass()
+ super(TenantUsagesNegativeV3Test, cls).setUpClass()
cls.adm_client = cls.os_adm.tenant_usages_client
cls.client = cls.os.tenant_usages_client
cls.identity_client = cls._get_identity_admin_client()
@@ -50,6 +49,7 @@
self.adm_client.get_tenant_usage,
'', params)
+ @test.skip_because(bug='1265416')
@attr(type=['negative', 'gate'])
def test_get_usage_tenant_with_invalid_date(self):
# Get usage for tenant with invalid date
@@ -62,6 +62,7 @@
self.adm_client.get_tenant_usage,
tenant_id, params)
+ @test.skip_because(bug='1265416')
@attr(type=['negative', 'gate'])
def test_list_usage_all_tenants_with_non_admin_user(self):
# Get usage for all tenants with non admin user
@@ -70,7 +71,3 @@
'detailed': int(bool(True))}
self.assertRaises(exceptions.Unauthorized,
self.client.list_tenant_usages, params)
-
-
-class TenantUsagesNegativeV3TestXML(TenantUsagesNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/certificates/test_certificates.py b/tempest/api/compute/v3/certificates/test_certificates.py
index fa6f191..5c980c0 100644
--- a/tempest/api/compute/v3/certificates/test_certificates.py
+++ b/tempest/api/compute/v3/certificates/test_certificates.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,7 +17,7 @@
from tempest.test import attr
-class CertificatesV3TestJSON(base.BaseV3ComputeTest):
+class CertificatesV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@attr(type='gate')
@@ -34,7 +32,3 @@
self.assertEqual(200, resp.status)
self.assertIn('data', body)
self.assertIn('private_key', body)
-
-
-class CertificatesV3TestXML(CertificatesV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/images/test_image_metadata.py b/tempest/api/compute/v3/images/test_image_metadata.py
new file mode 100644
index 0000000..cd4e5e7
--- /dev/null
+++ b/tempest/api/compute/v3/images/test_image_metadata.py
@@ -0,0 +1,111 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest.test import attr
+
+CONF = config.CONF
+
+
+class ImagesMetadataTest(base.BaseV2ComputeTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(ImagesMetadataTest, cls).setUpClass()
+ if not CONF.service_available.glance:
+ skip_msg = ("%s skipped as glance is not available" % cls.__name__)
+ raise cls.skipException(skip_msg)
+
+ cls.servers_client = cls.servers_client
+ cls.client = cls.images_client
+
+ resp, server = cls.create_test_server(wait_until='ACTIVE')
+ cls.server_id = server['id']
+
+ # Snapshot the server once to save time
+ name = data_utils.rand_name('image')
+ resp, _ = cls.client.create_image(cls.server_id, name, {})
+ cls.image_id = resp['location'].rsplit('/', 1)[1]
+
+ cls.client.wait_for_image_status(cls.image_id, 'ACTIVE')
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.client.delete_image(cls.image_id)
+ super(ImagesMetadataTest, cls).tearDownClass()
+
+ def setUp(self):
+ super(ImagesMetadataTest, self).setUp()
+ meta = {'key1': 'value1', 'key2': 'value2'}
+ resp, _ = self.client.set_image_metadata(self.image_id, meta)
+ self.assertEqual(resp.status, 200)
+
+ @attr(type='gate')
+ def test_list_image_metadata(self):
+ # All metadata key/value pairs for an image should be returned
+ resp, resp_metadata = self.client.list_image_metadata(self.image_id)
+ expected = {'key1': 'value1', 'key2': 'value2'}
+ self.assertEqual(expected, resp_metadata)
+
+ @attr(type='gate')
+ def test_set_image_metadata(self):
+ # The metadata for the image should match the new values
+ req_metadata = {'meta2': 'value2', 'meta3': 'value3'}
+ resp, body = self.client.set_image_metadata(self.image_id,
+ req_metadata)
+
+ resp, resp_metadata = self.client.list_image_metadata(self.image_id)
+ self.assertEqual(req_metadata, resp_metadata)
+
+ @attr(type='gate')
+ def test_update_image_metadata(self):
+ # The metadata for the image should match the updated values
+ req_metadata = {'key1': 'alt1', 'key3': 'value3'}
+ resp, metadata = self.client.update_image_metadata(self.image_id,
+ req_metadata)
+
+ resp, resp_metadata = self.client.list_image_metadata(self.image_id)
+ expected = {'key1': 'alt1', 'key2': 'value2', 'key3': 'value3'}
+ self.assertEqual(expected, resp_metadata)
+
+ @attr(type='gate')
+ def test_get_image_metadata_item(self):
+ # The value for a specific metadata key should be returned
+ resp, meta = self.client.get_image_metadata_item(self.image_id,
+ 'key2')
+ self.assertEqual('value2', meta['key2'])
+
+ @attr(type='gate')
+ def test_set_image_metadata_item(self):
+ # The value provided for the given meta item should be set for
+ # the image
+ meta = {'key1': 'alt'}
+ resp, body = self.client.set_image_metadata_item(self.image_id,
+ 'key1', meta)
+ resp, resp_metadata = self.client.list_image_metadata(self.image_id)
+ expected = {'key1': 'alt', 'key2': 'value2'}
+ self.assertEqual(expected, resp_metadata)
+
+ @attr(type='gate')
+ def test_delete_image_metadata_item(self):
+ # The metadata value/key pair should be deleted from the image
+ resp, body = self.client.delete_image_metadata_item(self.image_id,
+ 'key1')
+ resp, resp_metadata = self.client.list_image_metadata(self.image_id)
+ expected = {'key2': 'value2'}
+ self.assertEqual(expected, resp_metadata)
diff --git a/tempest/api/compute/v3/images/test_image_metadata_negative.py b/tempest/api/compute/v3/images/test_image_metadata_negative.py
new file mode 100644
index 0000000..e76af2c
--- /dev/null
+++ b/tempest/api/compute/v3/images/test_image_metadata_negative.py
@@ -0,0 +1,75 @@
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest.test import attr
+
+
+class ImagesMetadataTest(base.BaseV2ComputeTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(ImagesMetadataTest, cls).setUpClass()
+ cls.client = cls.images_client
+
+ @attr(type=['negative', 'gate'])
+ def test_list_nonexistent_image_metadata(self):
+ # Negative test: List on nonexistent image
+ # metadata should not happen
+ self.assertRaises(exceptions.NotFound, self.client.list_image_metadata,
+ data_utils.rand_uuid())
+
+ @attr(type=['negative', 'gate'])
+ def test_update_nonexistent_image_metadata(self):
+ # Negative test:An update should not happen for a non-existent image
+ meta = {'key1': 'alt1', 'key2': 'alt2'}
+ self.assertRaises(exceptions.NotFound,
+ self.client.update_image_metadata,
+ data_utils.rand_uuid(), meta)
+
+ @attr(type=['negative', 'gate'])
+ def test_get_nonexistent_image_metadata_item(self):
+ # Negative test: Get on non-existent image should not happen
+ self.assertRaises(exceptions.NotFound,
+ self.client.get_image_metadata_item,
+ data_utils.rand_uuid(), 'key2')
+
+ @attr(type=['negative', 'gate'])
+ def test_set_nonexistent_image_metadata(self):
+ # Negative test: Metadata should not be set to a non-existent image
+ meta = {'key1': 'alt1', 'key2': 'alt2'}
+ self.assertRaises(exceptions.NotFound, self.client.set_image_metadata,
+ data_utils.rand_uuid(), meta)
+
+ @attr(type=['negative', 'gate'])
+ def test_set_nonexistent_image_metadata_item(self):
+ # Negative test: Metadata item should not be set to a
+ # nonexistent image
+ meta = {'key1': 'alt'}
+ self.assertRaises(exceptions.NotFound,
+ self.client.set_image_metadata_item,
+ data_utils.rand_uuid(), 'key1',
+ meta)
+
+ @attr(type=['negative', 'gate'])
+ def test_delete_nonexistent_image_metadata_item(self):
+ # Negative test: Shouldn't be able to delete metadata
+ # item from non-existent image
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_image_metadata_item,
+ data_utils.rand_uuid(), 'key1')
diff --git a/tempest/api/compute/v3/images/test_images.py b/tempest/api/compute/v3/images/test_images.py
index a179d65..bbb84fb 100644
--- a/tempest/api/compute/v3/images/test_images.py
+++ b/tempest/api/compute/v3/images/test_images.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -17,24 +15,27 @@
from tempest.api.compute import base
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
-class ImagesV3TestJSON(base.BaseV3ComputeTest):
+
+class ImagesV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(ImagesV3TestJSON, cls).setUpClass()
- if not cls.config.service_available.glance:
+ super(ImagesV3Test, cls).setUpClass()
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
cls.client = cls.images_client
cls.servers_client = cls.servers_client
if cls.multi_user:
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.alt_manager = clients.Manager(username=username,
@@ -120,7 +121,3 @@
self.assertRaises(exceptions.NotFound,
self.servers_client.create_image,
test_uuid, snapshot_name)
-
-
-class ImagesV3TestXML(ImagesV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/images/test_images_oneserver.py b/tempest/api/compute/v3/images/test_images_oneserver.py
new file mode 100644
index 0000000..18772df
--- /dev/null
+++ b/tempest/api/compute/v3/images/test_images_oneserver.py
@@ -0,0 +1,128 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 testtools
+
+from tempest.api.compute import base
+from tempest import clients
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest.openstack.common import log as logging
+from tempest.test import attr
+
+CONF = config.CONF
+LOG = logging.getLogger(__name__)
+
+
+class ImagesOneServerTest(base.BaseV2ComputeTest):
+ _interface = 'json'
+
+ def tearDown(self):
+ """Terminate test instances created after a test is executed."""
+ for image_id in self.image_ids:
+ self.client.delete_image(image_id)
+ self.image_ids.remove(image_id)
+ super(ImagesOneServerTest, self).tearDown()
+
+ def setUp(self):
+ # NOTE(afazekas): Normally we use the same server with all test cases,
+ # but if it has an issue, we build a new one
+ super(ImagesOneServerTest, self).setUp()
+ # Check if the server is in a clean state after test
+ try:
+ self.servers_client.wait_for_server_status(self.server_id,
+ 'ACTIVE')
+ except Exception:
+ LOG.exception('server %s timed out to become ACTIVE. rebuilding'
+ % self.server_id)
+ # Rebuild server if cannot reach the ACTIVE state
+ # Usually it means the server had a serious accident
+ self.__class__.server_id = self.rebuild_server(self.server_id)
+
+ @classmethod
+ def setUpClass(cls):
+ super(ImagesOneServerTest, cls).setUpClass()
+ cls.client = cls.images_client
+ if not CONF.service_available.glance:
+ skip_msg = ("%s skipped as glance is not available" % cls.__name__)
+ raise cls.skipException(skip_msg)
+
+ try:
+ resp, server = cls.create_test_server(wait_until='ACTIVE')
+ cls.server_id = server['id']
+ except Exception:
+ cls.tearDownClass()
+ raise
+
+ cls.image_ids = []
+
+ if cls.multi_user:
+ if CONF.compute.allow_tenant_isolation:
+ creds = cls.isolated_creds.get_alt_creds()
+ username, tenant_name, password = creds
+ cls.alt_manager = clients.Manager(username=username,
+ password=password,
+ tenant_name=tenant_name)
+ else:
+ # Use the alt_XXX credentials in the config file
+ cls.alt_manager = clients.AltManager()
+ cls.alt_client = cls.alt_manager.images_client
+
+ def _get_default_flavor_disk_size(self, flavor_id):
+ resp, flavor = self.flavors_client.get_flavor_details(flavor_id)
+ return flavor['disk']
+
+ @testtools.skipUnless(CONF.compute_feature_enabled.create_image,
+ 'Environment unable to create images.')
+ @attr(type='smoke')
+ def test_create_delete_image(self):
+
+ # Create a new image
+ name = data_utils.rand_name('image')
+ meta = {'image_type': 'test'}
+ resp, body = self.client.create_image(self.server_id, name, meta)
+ self.assertEqual(202, resp.status)
+ image_id = data_utils.parse_image_id(resp['location'])
+ self.client.wait_for_image_status(image_id, 'ACTIVE')
+
+ # Verify the image was created correctly
+ resp, image = self.client.get_image(image_id)
+ self.assertEqual(name, image['name'])
+ self.assertEqual('test', image['metadata']['image_type'])
+
+ resp, original_image = self.client.get_image(self.image_ref)
+
+ # Verify minRAM is the same as the original image
+ self.assertEqual(image['minRam'], original_image['minRam'])
+
+ # Verify minDisk is the same as the original image or the flavor size
+ flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
+ self.assertIn(str(image['minDisk']),
+ (str(original_image['minDisk']), str(flavor_disk_size)))
+
+ # Verify the image was deleted correctly
+ resp, body = self.client.delete_image(image_id)
+ self.assertEqual('204', resp['status'])
+ self.client.wait_for_resource_deletion(image_id)
+
+ @attr(type=['gate'])
+ def test_create_image_specify_multibyte_character_image_name(self):
+ # prefix character is:
+ # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm
+ utf8_name = data_utils.rand_name(u'\xF0\x9F\x92\xA9')
+ resp, body = self.client.create_image(self.server_id, utf8_name)
+ image_id = data_utils.parse_image_id(resp['location'])
+ self.addCleanup(self.client.delete_image, image_id)
+ self.assertEqual('202', resp['status'])
diff --git a/tempest/api/compute/v3/images/test_images_oneserver_negative.py b/tempest/api/compute/v3/images/test_images_oneserver_negative.py
new file mode 100644
index 0000000..bc276d1
--- /dev/null
+++ b/tempest/api/compute/v3/images/test_images_oneserver_negative.py
@@ -0,0 +1,157 @@
+# Copyright 2012 OpenStack Foundation
+# Copyright 2013 IBM Corp.
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+from tempest import clients
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import exceptions
+from tempest.openstack.common import log as logging
+from tempest.test import attr
+from tempest.test import skip_because
+
+CONF = config.CONF
+
+LOG = logging.getLogger(__name__)
+
+
+class ImagesOneServerNegativeTest(base.BaseV2ComputeTest):
+ _interface = 'json'
+
+ def tearDown(self):
+ """Terminate test instances created after a test is executed."""
+ for image_id in self.image_ids:
+ self.client.delete_image(image_id)
+ self.image_ids.remove(image_id)
+ super(ImagesOneServerNegativeTest, self).tearDown()
+
+ def setUp(self):
+ # NOTE(afazekas): Normally we use the same server with all test cases,
+ # but if it has an issue, we build a new one
+ super(ImagesOneServerNegativeTest, self).setUp()
+ # Check if the server is in a clean state after test
+ try:
+ self.servers_client.wait_for_server_status(self.server_id,
+ 'ACTIVE')
+ except Exception:
+ LOG.exception('server %s timed out to become ACTIVE. rebuilding'
+ % self.server_id)
+ # Rebuild server if cannot reach the ACTIVE state
+ # Usually it means the server had a serious accident
+ self._reset_server()
+
+ def _reset_server(self):
+ self.__class__.server_id = self.rebuild_server(self.server_id)
+
+ @classmethod
+ def setUpClass(cls):
+ super(ImagesOneServerNegativeTest, cls).setUpClass()
+ cls.client = cls.images_client
+ if not CONF.service_available.glance:
+ skip_msg = ("%s skipped as glance is not available" % cls.__name__)
+ raise cls.skipException(skip_msg)
+
+ try:
+ resp, server = cls.create_test_server(wait_until='ACTIVE')
+ cls.server_id = server['id']
+ except Exception:
+ cls.tearDownClass()
+ raise
+
+ cls.image_ids = []
+
+ if cls.multi_user:
+ if CONF.compute.allow_tenant_isolation:
+ creds = cls.isolated_creds.get_alt_creds()
+ username, tenant_name, password = creds
+ cls.alt_manager = clients.Manager(username=username,
+ password=password,
+ tenant_name=tenant_name)
+ else:
+ # Use the alt_XXX credentials in the config file
+ cls.alt_manager = clients.AltManager()
+ cls.alt_client = cls.alt_manager.images_client
+
+ @skip_because(bug="1006725")
+ @attr(type=['negative', 'gate'])
+ def test_create_image_specify_multibyte_character_image_name(self):
+ # invalid multibyte sequence from:
+ # http://stackoverflow.com/questions/1301402/
+ # example-invalid-utf8-string
+ invalid_name = data_utils.rand_name(u'\xc3\x28')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_image, self.server_id,
+ invalid_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_create_image_specify_invalid_metadata(self):
+ # Return an error when creating image with invalid metadata
+ snapshot_name = data_utils.rand_name('test-snap-')
+ meta = {'': ''}
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ self.server_id, snapshot_name, meta)
+
+ @attr(type=['negative', 'gate'])
+ def test_create_image_specify_metadata_over_limits(self):
+ # Return an error when creating image with meta data over 256 chars
+ snapshot_name = data_utils.rand_name('test-snap-')
+ meta = {'a' * 260: 'b' * 260}
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ self.server_id, snapshot_name, meta)
+
+ @attr(type=['negative', 'gate'])
+ def test_create_second_image_when_first_image_is_being_saved(self):
+ # Disallow creating another image when first image is being saved
+
+ # Create first snapshot
+ snapshot_name = data_utils.rand_name('test-snap-')
+ resp, body = self.client.create_image(self.server_id,
+ snapshot_name)
+ self.assertEqual(202, resp.status)
+ image_id = data_utils.parse_image_id(resp['location'])
+ self.image_ids.append(image_id)
+ self.addCleanup(self._reset_server)
+
+ # Create second snapshot
+ alt_snapshot_name = data_utils.rand_name('test-snap-')
+ self.assertRaises(exceptions.Conflict, self.client.create_image,
+ self.server_id, alt_snapshot_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_create_image_specify_name_over_256_chars(self):
+ # Return an error if snapshot name over 256 characters is passed
+
+ snapshot_name = data_utils.rand_name('a' * 260)
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ self.server_id, snapshot_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_delete_image_that_is_not_yet_active(self):
+ # Return an error while trying to delete an image what is creating
+
+ snapshot_name = data_utils.rand_name('test-snap-')
+ resp, body = self.client.create_image(self.server_id, snapshot_name)
+ self.assertEqual(202, resp.status)
+ image_id = data_utils.parse_image_id(resp['location'])
+ self.image_ids.append(image_id)
+ self.addCleanup(self._reset_server)
+
+ # Do not wait, attempt to delete the image, ensure it's successful
+ resp, body = self.client.delete_image(image_id)
+ self.assertEqual('204', resp['status'])
+ self.image_ids.remove(image_id)
+
+ self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
diff --git a/tempest/api/compute/v3/images/test_list_image_filters.py b/tempest/api/compute/v3/images/test_list_image_filters.py
new file mode 100644
index 0000000..457ca53
--- /dev/null
+++ b/tempest/api/compute/v3/images/test_list_image_filters.py
@@ -0,0 +1,225 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+from tempest import config
+from tempest import exceptions
+from tempest.openstack.common import log as logging
+from tempest.test import attr
+
+CONF = config.CONF
+
+LOG = logging.getLogger(__name__)
+
+
+class ListImageFiltersTest(base.BaseV2ComputeTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(ListImageFiltersTest, cls).setUpClass()
+ if not CONF.service_available.glance:
+ skip_msg = ("%s skipped as glance is not available" % cls.__name__)
+ raise cls.skipException(skip_msg)
+ cls.client = cls.images_client
+ cls.image_ids = []
+
+ try:
+ resp, cls.server1 = cls.create_test_server()
+ resp, cls.server2 = cls.create_test_server(wait_until='ACTIVE')
+ # NOTE(sdague) this is faster than doing the sync wait_util on both
+ cls.servers_client.wait_for_server_status(cls.server1['id'],
+ 'ACTIVE')
+
+ # Create images to be used in the filter tests
+ resp, cls.image1 = cls.create_image_from_server(
+ cls.server1['id'], wait_until='ACTIVE')
+ cls.image1_id = cls.image1['id']
+
+ # Servers have a hidden property for when they are being imaged
+ # Performing back-to-back create image calls on a single
+ # server will sometimes cause failures
+ resp, cls.image3 = cls.create_image_from_server(
+ cls.server2['id'], wait_until='ACTIVE')
+ cls.image3_id = cls.image3['id']
+
+ # Wait for the server to be active after the image upload
+ resp, cls.image2 = cls.create_image_from_server(
+ cls.server1['id'], wait_until='ACTIVE')
+ cls.image2_id = cls.image2['id']
+ except Exception:
+ LOG.exception('setUpClass failed')
+ cls.tearDownClass()
+ raise
+
+ @attr(type=['negative', 'gate'])
+ def test_get_image_not_existing(self):
+ # Check raises a NotFound
+ self.assertRaises(exceptions.NotFound, self.client.get_image,
+ "nonexistingimageid")
+
+ @attr(type='gate')
+ def test_list_images_filter_by_status(self):
+ # The list of images should contain only images with the
+ # provided status
+ params = {'status': 'ACTIVE'}
+ resp, images = self.client.list_images(params)
+
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image2_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image3_id]))
+
+ @attr(type='gate')
+ def test_list_images_filter_by_name(self):
+ # List of all images should contain the expected images filtered
+ # by name
+ params = {'name': self.image1['name']}
+ resp, images = self.client.list_images(params)
+
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
+ self.assertFalse(any([i for i in images if i['id'] == self.image2_id]))
+ self.assertFalse(any([i for i in images if i['id'] == self.image3_id]))
+
+ @attr(type='gate')
+ def test_list_images_filter_by_server_id(self):
+ # The images should contain images filtered by server id
+ params = {'server': self.server1['id']}
+ resp, images = self.client.list_images(params)
+
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]),
+ "Failed to find image %s in images. Got images %s" %
+ (self.image1_id, images))
+ self.assertTrue(any([i for i in images if i['id'] == self.image2_id]))
+ self.assertFalse(any([i for i in images if i['id'] == self.image3_id]))
+
+ @attr(type='gate')
+ def test_list_images_filter_by_server_ref(self):
+ # The list of servers should be filtered by server ref
+ server_links = self.server2['links']
+
+ # Try all server link types
+ for link in server_links:
+ params = {'server': link['href']}
+ resp, images = self.client.list_images(params)
+
+ self.assertFalse(any([i for i in images
+ if i['id'] == self.image1_id]))
+ self.assertFalse(any([i for i in images
+ if i['id'] == self.image2_id]))
+ self.assertTrue(any([i for i in images
+ if i['id'] == self.image3_id]))
+
+ @attr(type='gate')
+ def test_list_images_filter_by_type(self):
+ # The list of servers should be filtered by image type
+ params = {'type': 'snapshot'}
+ resp, images = self.client.list_images(params)
+
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image2_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image3_id]))
+ self.assertFalse(any([i for i in images if i['id'] == self.image_ref]))
+
+ @attr(type='gate')
+ def test_list_images_limit_results(self):
+ # Verify only the expected number of results are returned
+ params = {'limit': '1'}
+ resp, images = self.client.list_images(params)
+ self.assertEqual(1, len([x for x in images if 'id' in x]))
+
+ @attr(type='gate')
+ def test_list_images_filter_by_changes_since(self):
+ # Verify only updated images are returned in the detailed list
+
+ # Becoming ACTIVE will modify the updated time
+ # Filter by the image's created time
+ params = {'changes-since': self.image3['created']}
+ resp, images = self.client.list_images(params)
+ found = any([i for i in images if i['id'] == self.image3_id])
+ self.assertTrue(found)
+
+ @attr(type='gate')
+ def test_list_images_with_detail_filter_by_status(self):
+ # Detailed list of all images should only contain images
+ # with the provided status
+ params = {'status': 'ACTIVE'}
+ resp, images = self.client.list_images_with_detail(params)
+
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image2_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image3_id]))
+
+ @attr(type='gate')
+ def test_list_images_with_detail_filter_by_name(self):
+ # Detailed list of all images should contain the expected
+ # images filtered by name
+ params = {'name': self.image1['name']}
+ resp, images = self.client.list_images_with_detail(params)
+
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
+ self.assertFalse(any([i for i in images if i['id'] == self.image2_id]))
+ self.assertFalse(any([i for i in images if i['id'] == self.image3_id]))
+
+ @attr(type='gate')
+ def test_list_images_with_detail_limit_results(self):
+ # Verify only the expected number of results (with full details)
+ # are returned
+ params = {'limit': '1'}
+ resp, images = self.client.list_images_with_detail(params)
+ self.assertEqual(1, len(images))
+
+ @attr(type='gate')
+ def test_list_images_with_detail_filter_by_server_ref(self):
+ # Detailed list of servers should be filtered by server ref
+ server_links = self.server2['links']
+
+ # Try all server link types
+ for link in server_links:
+ params = {'server': link['href']}
+ resp, images = self.client.list_images_with_detail(params)
+
+ self.assertFalse(any([i for i in images
+ if i['id'] == self.image1_id]))
+ self.assertFalse(any([i for i in images
+ if i['id'] == self.image2_id]))
+ self.assertTrue(any([i for i in images
+ if i['id'] == self.image3_id]))
+
+ @attr(type='gate')
+ def test_list_images_with_detail_filter_by_type(self):
+ # The detailed list of servers should be filtered by image type
+ params = {'type': 'snapshot'}
+ resp, images = self.client.list_images_with_detail(params)
+ resp, image4 = self.client.get_image(self.image_ref)
+
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image2_id]))
+ self.assertTrue(any([i for i in images if i['id'] == self.image3_id]))
+ self.assertFalse(any([i for i in images if i['id'] == self.image_ref]))
+
+ @attr(type='gate')
+ def test_list_images_with_detail_filter_by_changes_since(self):
+ # Verify an update image is returned
+
+ # Becoming ACTIVE will modify the updated time
+ # Filter by the image's created time
+ params = {'changes-since': self.image1['created']}
+ resp, images = self.client.list_images_with_detail(params)
+ self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
+
+ @attr(type=['negative', 'gate'])
+ def test_get_nonexistent_image(self):
+ # Negative test: GET on non-existent image should fail
+ self.assertRaises(exceptions.NotFound, self.client.get_image, 999)
diff --git a/tempest/api/compute/v3/keypairs/test_keypairs.py b/tempest/api/compute/v3/keypairs/test_keypairs.py
index 029633f..8eef811 100644
--- a/tempest/api/compute/v3/keypairs/test_keypairs.py
+++ b/tempest/api/compute/v3/keypairs/test_keypairs.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,12 +18,12 @@
from tempest import test
-class KeyPairsV3TestJSON(base.BaseV3ComputeTest):
+class KeyPairsV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(KeyPairsV3TestJSON, cls).setUpClass()
+ super(KeyPairsV3Test, cls).setUpClass()
cls.client = cls.keypairs_client
def _delete_keypair(self, keypair_name):
@@ -118,7 +116,3 @@
self.assertEqual(key_name, k_name,
"The created keypair name is not equal "
"to the requested name!")
-
-
-class KeyPairsV3TestXML(KeyPairsV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/keypairs/test_keypairs_negative.py b/tempest/api/compute/v3/keypairs/test_keypairs_negative.py
index edc0c26..ae22ccc 100644
--- a/tempest/api/compute/v3/keypairs/test_keypairs_negative.py
+++ b/tempest/api/compute/v3/keypairs/test_keypairs_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 IBM Corp
# All Rights Reserved.
@@ -22,12 +20,12 @@
from tempest import test
-class KeyPairsNegativeV3TestJSON(base.BaseV3ComputeTest):
+class KeyPairsNegativeV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(KeyPairsNegativeV3TestJSON, cls).setUpClass()
+ super(KeyPairsNegativeV3Test, cls).setUpClass()
cls.client = cls.keypairs_client
def _create_keypair(self, keypair_name, pub_key=None):
@@ -43,9 +41,9 @@
self._create_keypair, k_name, pub_key)
@test.attr(type=['negative', 'gate'])
- def test_keypair_delete_nonexistant_key(self):
- # Non-existant key deletion should throw a proper error
- k_name = data_utils.rand_name("keypair-non-existant-")
+ def test_keypair_delete_nonexistent_key(self):
+ # Non-existent key deletion should throw a proper error
+ k_name = data_utils.rand_name("keypair-non-existent-")
self.assertRaises(exceptions.NotFound, self.client.delete_keypair,
k_name)
@@ -95,7 +93,3 @@
k_name = 'key_/.\@:'
self.assertRaises(exceptions.BadRequest, self._create_keypair,
k_name)
-
-
-class KeyPairsNegativeV3TestXML(KeyPairsNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_attach_interfaces.py b/tempest/api/compute/v3/servers/test_attach_interfaces.py
index d12f708..272cb53 100644
--- a/tempest/api/compute/v3/servers/test_attach_interfaces.py
+++ b/tempest/api/compute/v3/servers/test_attach_interfaces.py
@@ -14,19 +14,25 @@
# under the License.
from tempest.api.compute import base
+from tempest import config
+from tempest import exceptions
from tempest.test import attr
import time
+CONF = config.CONF
-class AttachInterfacesV3TestJSON(base.BaseV3ComputeTest):
+
+class AttachInterfacesV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- if not cls.config.service_available.neutron:
+ if not CONF.service_available.neutron:
raise cls.skipException("Neutron is required")
- super(AttachInterfacesV3TestJSON, cls).setUpClass()
+ # This test class requires network and subnet
+ cls.set_network_resources(network=True, subnet=True)
+ super(AttachInterfacesV3Test, cls).setUpClass()
cls.client = cls.interfaces_client
def _check_interface(self, iface, port_id=None, network_id=None,
@@ -73,15 +79,19 @@
# NOTE(danms): delete not the first or last, but one in the middle
iface = ifs[1]
self.client.delete_interface(server['id'], iface['port_id'])
- for i in range(0, 5):
- _r, _ifs = self.client.list_interfaces(server['id'])
- if len(ifs) != len(_ifs):
- break
- time.sleep(1)
+ _ifs = self.client.list_interfaces(server['id'])[1]
+ start = int(time.time())
- self.assertEqual(len(_ifs), len(ifs) - 1)
- for _iface in _ifs:
- self.assertNotEqual(iface['port_id'], _iface['port_id'])
+ while len(ifs) == len(_ifs):
+ time.sleep(self.build_interval)
+ _ifs = self.client.list_interfaces(server['id'])[1]
+ timed_out = int(time.time()) - start >= self.build_timeout
+ if len(ifs) == len(_ifs) and timed_out:
+ message = ('Failed to delete interface within '
+ 'the required time: %s sec.' % self.build_timeout)
+ raise exceptions.TimeoutException(message)
+
+ self.assertNotIn(iface['port_id'], [i['port_id'] for i in _ifs])
return _ifs
def _compare_iface_list(self, list1, list2):
@@ -112,7 +122,3 @@
_ifs = self._test_delete_interface(server, ifs)
self.assertEqual(len(ifs) - 1, len(_ifs))
-
-
-class AttachInterfacesV3TestXML(AttachInterfacesV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_attach_volume.py b/tempest/api/compute/v3/servers/test_attach_volume.py
index a030584..d693be5 100644
--- a/tempest/api/compute/v3/servers/test_attach_volume.py
+++ b/tempest/api/compute/v3/servers/test_attach_volume.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
@@ -25,21 +23,21 @@
CONF = config.CONF
-class AttachVolumeV3TestJSON(base.BaseV3ComputeTest):
+class AttachVolumeV3Test(base.BaseV3ComputeTest):
_interface = 'json'
run_ssh = CONF.compute.run_ssh
def __init__(self, *args, **kwargs):
- super(AttachVolumeV3TestJSON, self).__init__(*args, **kwargs)
+ super(AttachVolumeV3Test, self).__init__(*args, **kwargs)
self.server = None
self.volume = None
self.attached = False
@classmethod
def setUpClass(cls):
- super(AttachVolumeV3TestJSON, cls).setUpClass()
- cls.device = cls.config.compute.volume_device_name
- if not cls.config.service_available.cinder:
+ super(AttachVolumeV3Test, cls).setUpClass()
+ cls.device = CONF.compute.volume_device_name
+ if not CONF.service_available.cinder:
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
raise cls.skipException(skip_msg)
@@ -114,7 +112,3 @@
server['admin_password'])
partitions = linux_client.get_partitions()
self.assertNotIn(self.device, partitions)
-
-
-class AttachVolumeV3TestXML(AttachVolumeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_create_server.py b/tempest/api/compute/v3/servers/test_create_server.py
index e1bb160..7a4c877 100644
--- a/tempest/api/compute/v3/servers/test_create_server.py
+++ b/tempest/api/compute/v3/servers/test_create_server.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -29,14 +27,14 @@
CONF = config.CONF
-class ServersV3TestJSON(base.BaseV3ComputeTest):
+class ServersV3Test(base.BaseV3ComputeTest):
_interface = 'json'
run_ssh = CONF.compute.run_ssh
disk_config = 'AUTO'
@classmethod
def setUpClass(cls):
- super(ServersV3TestJSON, cls).setUpClass()
+ super(ServersV3Test, cls).setUpClass()
cls.meta = {'hello': 'world'}
cls.accessIPv4 = '1.1.1.1'
cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
@@ -117,7 +115,105 @@
self.assertTrue(linux_client.hostname_equals_servername(self.name))
-class ServersV3TestManualDisk(ServersV3TestJSON):
+class ServersWithSpecificFlavorV3Test(base.BaseV3ComputeAdminTest):
+ _interface = 'json'
+ run_ssh = CONF.compute.run_ssh
+ disk_config = 'AUTO'
+
+ @classmethod
+ def setUpClass(cls):
+ super(ServersWithSpecificFlavorV3Test, cls).setUpClass()
+ cls.meta = {'hello': 'world'}
+ cls.accessIPv4 = '1.1.1.1'
+ cls.accessIPv6 = '0000:0000:0000:0000:0000:babe:220.12.22.2'
+ cls.name = data_utils.rand_name('server')
+ file_contents = 'This is a test file.'
+ personality = [{'path': '/test.txt',
+ 'contents': base64.b64encode(file_contents)}]
+ cls.client = cls.servers_client
+ cls.flavor_client = cls.flavors_admin_client
+ cli_resp = cls.create_test_server(name=cls.name,
+ meta=cls.meta,
+ access_ip_v4=cls.accessIPv4,
+ access_ip_v6=cls.accessIPv6,
+ personality=personality,
+ disk_config=cls.disk_config)
+ cls.resp, cls.server_initial = cli_resp
+ cls.password = cls.server_initial['admin_password']
+ cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
+ resp, cls.server = cls.client.get_server(cls.server_initial['id'])
+
+ @testtools.skipIf(not run_ssh, 'Instance validation tests are disabled.')
+ @test.attr(type='gate')
+ def test_verify_created_server_ephemeral_disk(self):
+ # Verify that the ephemeral disk is created when creating server
+
+ def create_flavor_with_extra_specs(self):
+ flavor_with_eph_disk_name = data_utils.rand_name('eph_flavor')
+ flavor_with_eph_disk_id = data_utils.rand_int_id(start=1000)
+ ram = 512
+ vcpus = 1
+ disk = 10
+
+ # Create a flavor with extra specs
+ resp, flavor = (self.flavor_client.
+ create_flavor(flavor_with_eph_disk_name,
+ ram, vcpus, disk,
+ flavor_with_eph_disk_id,
+ ephemeral=1, swap=1024, rxtx=1))
+ self.addCleanup(self.flavor_clean_up, flavor['id'])
+ self.assertEqual(200, resp.status)
+
+ return flavor['id']
+
+ def create_flavor_without_extra_specs(self):
+ flavor_no_eph_disk_name = data_utils.rand_name('no_eph_flavor')
+ flavor_no_eph_disk_id = data_utils.rand_int_id(start=1000)
+
+ ram = 512
+ vcpus = 1
+ disk = 10
+
+ # Create a flavor without extra specs
+ resp, flavor = (self.flavor_client.
+ create_flavor(flavor_no_eph_disk_name,
+ ram, vcpus, disk,
+ flavor_no_eph_disk_id))
+ self.addCleanup(self.flavor_clean_up, flavor['id'])
+ self.assertEqual(200, resp.status)
+
+ return flavor['id']
+
+ def flavor_clean_up(self, flavor_id):
+ resp, body = self.flavor_client.delete_flavor(flavor_id)
+ self.assertEqual(resp.status, 202)
+ self.flavor_client.wait_for_resource_deletion(flavor_id)
+
+ flavor_with_eph_disk_id = self.create_flavor_with_extra_specs()
+ flavor_no_eph_disk_id = self.create_flavor_without_extra_specs()
+
+ admin_pass = self.image_ssh_password
+
+ resp, server_no_eph_disk = (self.
+ create_test_server(
+ wait_until='ACTIVE',
+ adminPass=admin_pass,
+ flavor=flavor_no_eph_disk_id))
+ resp, server_with_eph_disk = (self.create_test_server(
+ wait_until='ACTIVE',
+ adminPass=admin_pass,
+ flavor=flavor_with_eph_disk_id))
+ # Get partition number of server without extra specs.
+ linux_client = RemoteClient(server_no_eph_disk,
+ self.ssh_user, self.password)
+ partition_num = len(linux_client.get_partitions())
+
+ linux_client = RemoteClient(server_with_eph_disk,
+ self.ssh_user, self.password)
+ self.assertEqual(partition_num + 1, linux_client.get_partitions())
+
+
+class ServersV3TestManualDisk(ServersV3Test):
disk_config = 'MANUAL'
@classmethod
@@ -126,7 +222,3 @@
msg = "DiskConfig extension not enabled."
raise cls.skipException(msg)
super(ServersV3TestManualDisk, cls).setUpClass()
-
-
-class ServersV3TestXML(ServersV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_instance_actions.py b/tempest/api/compute/v3/servers/test_instance_actions.py
index ea92c9f..d536871 100644
--- a/tempest/api/compute/v3/servers/test_instance_actions.py
+++ b/tempest/api/compute/v3/servers/test_instance_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -20,12 +18,12 @@
from tempest.test import attr
-class InstanceActionsV3TestJSON(base.BaseV3ComputeTest):
+class InstanceActionsV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(InstanceActionsV3TestJSON, cls).setUpClass()
+ super(InstanceActionsV3Test, cls).setUpClass()
cls.client = cls.servers_client
resp, server = cls.create_test_server(wait_until='ACTIVE')
cls.request_id = resp['x-compute-request-id']
@@ -63,7 +61,3 @@
# Get the action details of the provided server with invalid request
self.assertRaises(exceptions.NotFound, self.client.get_instance_action,
self.server_id, '999')
-
-
-class InstanceActionsV3TestXML(InstanceActionsV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_list_server_filters.py b/tempest/api/compute/v3/servers/test_list_server_filters.py
index 3dd7b0b..9082eda 100644
--- a/tempest/api/compute/v3/servers/test_list_server_filters.py
+++ b/tempest/api/compute/v3/servers/test_list_server_filters.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -26,12 +24,12 @@
CONF = config.CONF
-class ListServerFiltersV3TestJSON(base.BaseV3ComputeTest):
+class ListServerFiltersV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(ListServerFiltersV3TestJSON, cls).setUpClass()
+ super(ListServerFiltersV3Test, cls).setUpClass()
cls.client = cls.servers_client
# Check to see if the alternate image ref actually exists...
@@ -73,7 +71,7 @@
flavor=cls.flavor_ref_alt,
wait_until='ACTIVE')
- cls.fixed_network_name = cls.config.compute.fixed_network_name
+ cls.fixed_network_name = CONF.compute.fixed_network_name
@utils.skip_unless_attr('multiple_images', 'Only one image found')
@attr(type='gate')
@@ -125,9 +123,24 @@
# Verify only the expected number of servers are returned
params = {'limit': 1}
resp, servers = self.client.list_servers(params)
- # when _interface='xml', one element for servers_links in servers
self.assertEqual(1, len([x for x in servers['servers'] if 'id' in x]))
+ @attr(type='gate')
+ def test_list_servers_filter_by_zero_limit(self):
+ # Verify only the expected number of servers are returned
+ params = {'limit': 0}
+ resp, servers = self.client.list_servers(params)
+ self.assertEqual(0, len(servers['servers']))
+
+ @attr(type='gate')
+ def test_list_servers_filter_by_exceed_limit(self):
+ # Verify only the expected number of servers are returned
+ params = {'limit': 100000}
+ resp, servers = self.client.list_servers(params)
+ resp, all_servers = self.client.list_servers()
+ self.assertEqual(len([x for x in all_servers['servers'] if 'id' in x]),
+ len([x for x in servers['servers'] if 'id' in x]))
+
@utils.skip_unless_attr('multiple_images', 'Only one image found')
@attr(type='gate')
def test_list_servers_detailed_filter_by_image(self):
@@ -176,6 +189,23 @@
self.assertEqual(['ACTIVE'] * 3, [x['status'] for x in servers])
@attr(type='gate')
+ def test_list_servers_filter_by_shutoff_status(self):
+ # Filter the list of servers by server shutoff status
+ params = {'status': 'shutoff'}
+ self.client.stop(self.s1['id'])
+ self.client.wait_for_server_status(self.s1['id'],
+ 'SHUTOFF')
+ resp, body = self.client.list_servers(params)
+ self.client.start(self.s1['id'])
+ self.client.wait_for_server_status(self.s1['id'],
+ 'ACTIVE')
+ servers = body['servers']
+
+ self.assertIn(self.s1['id'], map(lambda x: x['id'], servers))
+ self.assertNotIn(self.s2['id'], map(lambda x: x['id'], servers))
+ self.assertNotIn(self.s3['id'], map(lambda x: x['id'], servers))
+
+ @attr(type='gate')
def test_list_servers_filtered_by_name_wildcard(self):
# List all servers that contains '-instance' in name
params = {'name': '-instance'}
@@ -235,7 +265,3 @@
params = {'limit': 1}
resp, servers = self.client.list_servers_with_detail(params)
self.assertEqual(1, len(servers['servers']))
-
-
-class ListServerFiltersV3TestXML(ListServerFiltersV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_list_servers_negative.py b/tempest/api/compute/v3/servers/test_list_servers_negative.py
index 3f7f885..09e1bb6 100644
--- a/tempest/api/compute/v3/servers/test_list_servers_negative.py
+++ b/tempest/api/compute/v3/servers/test_list_servers_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,69 +16,18 @@
import datetime
from tempest.api.compute import base
-from tempest import clients
from tempest import exceptions
from tempest.test import attr
-class ListServersNegativeV3TestJSON(base.BaseV3ComputeTest):
+class ListServersNegativeV3Test(base.BaseV3ComputeTest):
_interface = 'json'
-
- @classmethod
- def _ensure_no_servers(cls, servers, username, tenant_name):
- """
- If there are servers and there is tenant isolation then a
- skipException is raised to skip the test since it requires no servers
- to already exist for the given user/tenant.
- If there are servers and there is not tenant isolation then the test
- blocks while the servers are being deleted.
- """
- if len(servers):
- if not cls.config.compute.allow_tenant_isolation:
- for srv in servers:
- cls.client.wait_for_server_termination(srv['id'],
- ignore_error=True)
- else:
- msg = ("User/tenant %(u)s/%(t)s already have "
- "existing server instances. Skipping test." %
- {'u': username, 't': tenant_name})
- raise cls.skipException(msg)
+ force_tenant_isolation = True
@classmethod
def setUpClass(cls):
- super(ListServersNegativeV3TestJSON, cls).setUpClass()
+ super(ListServersNegativeV3Test, cls).setUpClass()
cls.client = cls.servers_client
- cls.servers = []
-
- if cls.multi_user:
- if cls.config.compute.allow_tenant_isolation:
- creds = cls.isolated_creds.get_alt_creds()
- username, tenant_name, password = creds
- cls.alt_manager = clients.Manager(username=username,
- password=password,
- tenant_name=tenant_name)
- else:
- # Use the alt_XXX credentials in the config file
- cls.alt_manager = clients.AltManager()
- cls.alt_client = cls.alt_manager.servers_client
-
- # Under circumstances when there is not a tenant/user
- # created for the test case, the test case checks
- # to see if there are existing servers for the
- # either the normal user/tenant or the alt user/tenant
- # and if so, the whole test is skipped. We do this
- # because we assume a baseline of no servers at the
- # start of the test instead of destroying any existing
- # servers.
- resp, body = cls.client.list_servers()
- cls._ensure_no_servers(body['servers'],
- cls.os.username,
- cls.os.tenant_name)
-
- resp, body = cls.alt_client.list_servers()
- cls._ensure_no_servers(body['servers'],
- cls.alt_manager.username,
- cls.alt_manager.tenant_name)
# The following servers are created for use
# by the test methods in this class. These
@@ -156,7 +103,6 @@
# List servers by specifying limits
resp, body = self.client.list_servers({'limit': 1})
self.assertEqual('200', resp['status'])
- # when _interface='xml', one element for servers_links in servers
self.assertEqual(1, len([x for x in body['servers'] if 'id' in x]))
@attr(type=['negative', 'gate'])
@@ -215,7 +161,3 @@
if srv['id'] in deleted_ids]
self.assertEqual('200', resp['status'])
self.assertEqual([], actual)
-
-
-class ListServersNegativeV3TestXML(ListServersNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_multiple_create.py b/tempest/api/compute/v3/servers/test_multiple_create.py
index 3ee46ad..f1ae5f8 100644
--- a/tempest/api/compute/v3/servers/test_multiple_create.py
+++ b/tempest/api/compute/v3/servers/test_multiple_create.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -21,7 +19,7 @@
from tempest import test
-class MultipleCreateV3TestJSON(base.BaseV3ComputeTest):
+class MultipleCreateV3Test(base.BaseV3ComputeTest):
_interface = 'json'
_name = 'multiple-create-test'
@@ -89,7 +87,3 @@
return_reservation_id=True)
self.assertEqual(resp['status'], '202')
self.assertIn('reservation_id', body)
-
-
-class MultipleCreateV3TestXML(MultipleCreateV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_server_actions.py b/tempest/api/compute/v3/servers/test_server_actions.py
index 602bd5b..0dae796 100644
--- a/tempest/api/compute/v3/servers/test_server_actions.py
+++ b/tempest/api/compute/v3/servers/test_server_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import base64
import time
import testtools
@@ -31,7 +28,7 @@
CONF = config.CONF
-class ServerActionsV3TestJSON(base.BaseV3ComputeTest):
+class ServerActionsV3Test(base.BaseV3ComputeTest):
_interface = 'json'
resize_available = CONF.compute_feature_enabled.resize
run_ssh = CONF.compute.run_ssh
@@ -39,7 +36,7 @@
def setUp(self):
# NOTE(afazekas): Normally we use the same server with all test cases,
# but if it has an issue, we build a new one
- super(ServerActionsV3TestJSON, self).setUp()
+ super(ServerActionsV3Test, self).setUp()
# Check if the server is in a clean state after test
try:
self.client.wait_for_server_status(self.server_id, 'ACTIVE')
@@ -49,7 +46,7 @@
@classmethod
def setUpClass(cls):
- super(ServerActionsV3TestJSON, cls).setUpClass()
+ super(ServerActionsV3Test, cls).setUpClass()
cls.client = cls.servers_client
cls.server_id = cls.rebuild_server(None)
@@ -113,15 +110,11 @@
# The server should be rebuilt using the provided image and data
meta = {'rebuild': 'server'}
new_name = data_utils.rand_name('server')
- file_contents = 'Test server rebuild.'
- personality = [{'path': 'rebuild.txt',
- 'contents': base64.b64encode(file_contents)}]
password = 'rebuildPassw0rd'
resp, rebuilt_server = self.client.rebuild(self.server_id,
self.image_ref_alt,
name=new_name,
metadata=meta,
- personality=personality,
admin_password=password)
self.addCleanup(self.client.rebuild, self.server_id, self.image_ref)
@@ -134,9 +127,9 @@
# Verify the server properties after the rebuild completes
self.client.wait_for_server_status(rebuilt_server['id'], 'ACTIVE')
resp, server = self.client.get_server(rebuilt_server['id'])
- rebuilt_image_id = rebuilt_server['image']['id']
+ rebuilt_image_id = server['image']['id']
self.assertTrue(self.image_ref_alt.endswith(rebuilt_image_id))
- self.assertEqual(new_name, rebuilt_server['name'])
+ self.assertEqual(new_name, server['name'])
if self.run_ssh:
# Verify that the user can authenticate with the provided password
@@ -174,7 +167,7 @@
def _detect_server_image_flavor(self, server_id):
# Detects the current server image flavor ref.
- resp, server = self.client.get_server(self.server_id)
+ resp, server = self.client.get_server(server_id)
current_flavor = server['flavor']['id']
new_flavor_ref = self.flavor_ref_alt \
if current_flavor == self.flavor_ref else self.flavor_ref
@@ -232,7 +225,7 @@
def test_create_backup(self):
# Positive test:create backup successfully and rotate backups correctly
# create the first and the second backup
- backup1 = data_utils.rand_name('backup')
+ backup1 = data_utils.rand_name('backup-1')
resp, _ = self.servers_client.create_backup(self.server_id,
'daily',
2,
@@ -249,7 +242,7 @@
self.assertEqual(202, resp.status)
self.images_client.wait_for_image_status(image1_id, 'active')
- backup2 = data_utils.rand_name('backup')
+ backup2 = data_utils.rand_name('backup-2')
self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
resp, _ = self.servers_client.create_backup(self.server_id,
'daily',
@@ -277,7 +270,7 @@
# create the third one, due to the rotation is 2,
# the first one will be deleted
- backup3 = data_utils.rand_name('backup')
+ backup3 = data_utils.rand_name('backup-3')
self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
resp, _ = self.servers_client.create_backup(self.server_id,
'daily',
@@ -294,7 +287,11 @@
sort_key='created_at',
sort_dir='asc')
self.assertEqual(200, resp.status)
- self.assertEqual(2, len(image_list))
+ self.assertEqual(2, len(image_list),
+ 'Unexpected number of images for '
+ 'v3:test_create_backup; was the oldest backup not '
+ 'yet deleted? Image list: %s' %
+ [image['name'] for image in image_list])
self.assertEqual((backup2, backup3),
(image_list[0]['name'], image_list[1]['name']))
@@ -362,7 +359,7 @@
resp, server = self.client.shelve_server(self.server_id)
self.assertEqual(202, resp.status)
- offload_time = self.config.compute.shelved_offload_time
+ offload_time = CONF.compute.shelved_offload_time
if offload_time >= 0:
self.client.wait_for_server_status(self.server_id,
'SHELVED_OFFLOADED',
@@ -409,7 +406,3 @@
resp, server = self.servers_client.start(self.server_id)
self.assertEqual(202, resp.status)
self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
-
-
-class ServerActionsV3TestXML(ServerActionsV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_server_addresses.py b/tempest/api/compute/v3/servers/test_server_addresses.py
index 82588b6..bffa7c4 100644
--- a/tempest/api/compute/v3/servers/test_server_addresses.py
+++ b/tempest/api/compute/v3/servers/test_server_addresses.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -25,6 +23,8 @@
@classmethod
def setUpClass(cls):
+ # This test module might use a network and a subnet
+ cls.set_network_resources(network=True, subnet=True)
super(ServerAddressesV3Test, cls).setUpClass()
cls.client = cls.servers_client
@@ -78,7 +78,3 @@
addr = addr[addr_type]
for address in addresses[addr_type]:
self.assertTrue(any([a for a in addr if a == address]))
-
-
-class ServerAddressesV3TestXML(ServerAddressesV3Test):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_server_metadata.py b/tempest/api/compute/v3/servers/test_server_metadata.py
index ee0f4a9..13c82dd 100644
--- a/tempest/api/compute/v3/servers/test_server_metadata.py
+++ b/tempest/api/compute/v3/servers/test_server_metadata.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,16 +14,15 @@
# under the License.
from tempest.api.compute import base
-from tempest import exceptions
-from tempest.test import attr
+from tempest import test
-class ServerMetadataTestJSON(base.BaseV2ComputeTest):
+class ServerMetadataV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(ServerMetadataTestJSON, cls).setUpClass()
+ super(ServerMetadataV3Test, cls).setUpClass()
cls.client = cls.servers_client
cls.quotas = cls.quotas_client
cls.admin_client = cls._get_identity_admin_client()
@@ -37,12 +34,12 @@
cls.server_id = server['id']
def setUp(self):
- super(ServerMetadataTestJSON, self).setUp()
+ super(ServerMetadataV3Test, self).setUp()
meta = {'key1': 'value1', 'key2': 'value2'}
resp, _ = self.client.set_server_metadata(self.server_id, meta)
self.assertEqual(resp.status, 200)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_list_server_metadata(self):
# All metadata key/value pairs for a server should be returned
resp, resp_metadata = self.client.list_server_metadata(self.server_id)
@@ -52,7 +49,7 @@
expected = {'key1': 'value1', 'key2': 'value2'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_set_server_metadata(self):
# The server's metadata should be replaced with the provided values
# Create a new set of metadata for the server
@@ -66,36 +63,21 @@
resp, resp_metadata = self.client.list_server_metadata(self.server_id)
self.assertEqual(resp_metadata, req_metadata)
- @attr(type='gate')
- def test_server_create_metadata_key_too_long(self):
- # Attempt to start a server with a meta-data key that is > 255
- # characters
-
- # Try a few values
- for sz in [256, 257, 511, 1023]:
- key = "k" * sz
- meta = {key: 'data1'}
- self.assertRaises(exceptions.OverLimit,
- self.create_test_server,
- meta=meta)
-
- # no teardown - all creates should fail
-
- @attr(type='gate')
+ @test.attr(type='gate')
def test_update_server_metadata(self):
# The server's metadata values should be updated to the
# provided values
meta = {'key1': 'alt1', 'key3': 'value3'}
resp, metadata = self.client.update_server_metadata(self.server_id,
meta)
- self.assertEqual(200, resp.status)
+ self.assertEqual(201, resp.status)
# Verify the values have been updated to the proper values
resp, resp_metadata = self.client.list_server_metadata(self.server_id)
expected = {'key1': 'alt1', 'key2': 'value2', 'key3': 'value3'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_update_metadata_empty_body(self):
# The original metadata should not be lost if empty metadata body is
# passed
@@ -105,14 +87,14 @@
expected = {'key1': 'value1', 'key2': 'value2'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_get_server_metadata_item(self):
# The value for a specific metadata key should be returned
resp, meta = self.client.get_server_metadata_item(self.server_id,
'key2')
self.assertEqual('value2', meta['key2'])
- @attr(type='gate')
+ @test.attr(type='gate')
def test_set_server_metadata_item(self):
# The item's value should be updated to the provided value
# Update the metadata value
@@ -126,7 +108,7 @@
expected = {'key1': 'value1', 'key2': 'value2', 'nova': 'alt'}
self.assertEqual(expected, resp_metadata)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_delete_server_metadata_item(self):
# The metadata value/key pair should be deleted from the server
resp, meta = self.client.delete_server_metadata_item(self.server_id,
@@ -137,81 +119,3 @@
resp, resp_metadata = self.client.list_server_metadata(self.server_id)
expected = {'key2': 'value2'}
self.assertEqual(expected, resp_metadata)
-
- @attr(type=['negative', 'gate'])
- def test_server_metadata_negative(self):
- # Blank key should trigger an error.
- meta = {'': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.create_test_server,
- meta=meta)
-
- # GET on a non-existent server should not succeed
- self.assertRaises(exceptions.NotFound,
- self.client.get_server_metadata_item, 999, 'test2')
-
- # List metadata on a non-existent server should not succeed
- self.assertRaises(exceptions.NotFound,
- self.client.list_server_metadata, 999)
-
- # Raise BadRequest if key in uri does not match
- # the key passed in body.
- meta = {'testkey': 'testvalue'}
- self.assertRaises(exceptions.BadRequest,
- self.client.set_server_metadata_item,
- self.server_id, 'key', meta)
-
- # Set metadata on a non-existent server should not succeed
- meta = {'meta1': 'data1'}
- self.assertRaises(exceptions.NotFound,
- self.client.set_server_metadata, 999, meta)
-
- # An update should not happen for a non-existent image
- meta = {'key1': 'value1', 'key2': 'value2'}
- self.assertRaises(exceptions.NotFound,
- self.client.update_server_metadata, 999, meta)
-
- # Blank key should trigger an error
- meta = {'': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.client.update_server_metadata,
- self.server_id, meta=meta)
-
- # Should not be able to delete metadata item from a non-existent server
- self.assertRaises(exceptions.NotFound,
- self.client.delete_server_metadata_item, 999, 'd')
-
- # Raise a 413 OverLimit exception while exceeding metadata items limit
- # for tenant.
- _, quota_set = self.quotas.get_quota_set(self.tenant_id)
- quota_metadata = quota_set['metadata_items']
- req_metadata = {}
- for num in range(1, quota_metadata + 2):
- req_metadata['key' + str(num)] = 'val' + str(num)
- self.assertRaises(exceptions.OverLimit,
- self.client.set_server_metadata,
- self.server_id, req_metadata)
-
- # Raise a 413 OverLimit exception while exceeding metadata items limit
- # for tenant (update).
- self.assertRaises(exceptions.OverLimit,
- self.client.update_server_metadata,
- self.server_id, req_metadata)
-
- # Raise a bad request error for blank key.
- # set_server_metadata will replace all metadata with new value
- meta = {'': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.client.set_server_metadata,
- self.server_id, meta=meta)
-
- # Raise a bad request error for a missing metadata field
- # set_server_metadata will replace all metadata with new value
- meta = {'meta1': 'data1'}
- self.assertRaises(exceptions.BadRequest,
- self.client.set_server_metadata,
- self.server_id, meta=meta, no_metadata_field=True)
-
-
-class ServerMetadataTestXML(ServerMetadataTestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_server_metadata_negative.py b/tempest/api/compute/v3/servers/test_server_metadata_negative.py
new file mode 100644
index 0000000..ce6c340
--- /dev/null
+++ b/tempest/api/compute/v3/servers/test_server_metadata_negative.py
@@ -0,0 +1,159 @@
+# Copyright 2014 NEC Corporation. All rights reserved.
+#
+# 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 tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest import test
+
+
+class ServerMetadataV3NegativeTest(base.BaseV3ComputeTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(ServerMetadataV3NegativeTest, cls).setUpClass()
+ cls.client = cls.servers_client
+ cls.quotas = cls.quotas_client
+ cls.admin_client = cls._get_identity_admin_client()
+ resp, tenants = cls.admin_client.list_tenants()
+ cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
+ cls.client.tenant_name][0]
+ resp, server = cls.create_test_server(meta={}, wait_until='ACTIVE')
+
+ cls.server_id = server['id']
+
+ @test.skip_because(bug="1273948")
+ @test.attr(type=['gate', 'negative'])
+ def test_server_create_metadata_key_too_long(self):
+ # Attempt to start a server with a meta-data key that is > 255
+ # characters
+
+ # Tryset_server_metadata_item a few values
+ for sz in [256, 257, 511, 1023]:
+ key = "k" * sz
+ meta = {key: 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.create_test_server,
+ meta=meta)
+
+ # no teardown - all creates should fail
+
+ @test.attr(type=['negative', 'gate'])
+ def test_create_server_metadata_blank_key(self):
+ # Blank key should trigger an error.
+ meta = {'': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.create_test_server,
+ meta=meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_server_metadata_non_existent_server(self):
+ # GET on a non-existent server should not succeed
+ non_existent_server_id = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound,
+ self.client.get_server_metadata_item,
+ non_existent_server_id,
+ 'test2')
+
+ @test.attr(type=['negative', 'gate'])
+ def test_list_server_metadata_non_existent_server(self):
+ # List metadata on a non-existent server should not succeed
+ non_existent_server_id = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound,
+ self.client.list_server_metadata,
+ non_existent_server_id)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_wrong_key_passed_in_body(self):
+ # Raise BadRequest if key in uri does not match
+ # the key passed in body.
+ meta = {'testkey': 'testvalue'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.set_server_metadata_item,
+ self.server_id, 'key', meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_set_metadata_non_existent_server(self):
+ # Set metadata on a non-existent server should not succeed
+ non_existent_server_id = data_utils.rand_uuid()
+ meta = {'meta1': 'data1'}
+ self.assertRaises(exceptions.NotFound,
+ self.client.set_server_metadata,
+ non_existent_server_id,
+ meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_update_metadata_non_existent_server(self):
+ # An update should not happen for a non-existent server
+ non_existent_server_id = data_utils.rand_uuid()
+ meta = {'key1': 'value1', 'key2': 'value2'}
+ self.assertRaises(exceptions.NotFound,
+ self.client.update_server_metadata,
+ non_existent_server_id,
+ meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_update_metadata_with_blank_key(self):
+ # Blank key should trigger an error
+ meta = {'': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.update_server_metadata,
+ self.server_id, meta=meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_delete_metadata_non_existent_server(self):
+ # Should not be able to delete metadata item from a non-existent server
+ non_existent_server_id = data_utils.rand_uuid()
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_server_metadata_item,
+ non_existent_server_id,
+ 'd')
+
+ @test.attr(type=['negative', 'gate'])
+ def test_metadata_items_limit(self):
+ # Raise a 413 OverLimit exception while exceeding metadata items limit
+ # for tenant.
+ _, quota_set = self.quotas.get_quota_set(self.tenant_id)
+ quota_metadata = quota_set['metadata_items']
+ req_metadata = {}
+ for num in range(1, quota_metadata + 2):
+ req_metadata['key' + str(num)] = 'val' + str(num)
+ self.assertRaises(exceptions.OverLimit,
+ self.client.set_server_metadata,
+ self.server_id, req_metadata)
+
+ # Raise a 413 OverLimit exception while exceeding metadata items limit
+ # for tenant (update).
+ self.assertRaises(exceptions.OverLimit,
+ self.client.update_server_metadata,
+ self.server_id, req_metadata)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_set_server_metadata_blank_key(self):
+ # Raise a bad request error for blank key.
+ # set_server_metadata will replace all metadata with new value
+ meta = {'': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.set_server_metadata,
+ self.server_id, meta=meta)
+
+ @test.attr(type=['negative', 'gate'])
+ def test_set_server_metadata_missing_metadata(self):
+ # Raise a bad request error for a missing metadata field
+ # set_server_metadata will replace all metadata with new value
+ meta = {'meta1': 'data1'}
+ self.assertRaises(exceptions.BadRequest,
+ self.client.set_server_metadata,
+ self.server_id, meta=meta, no_metadata_field=True)
diff --git a/tempest/api/compute/v3/servers/test_server_personality.py b/tempest/api/compute/v3/servers/test_server_personality.py
deleted file mode 100644
index c6d2e44..0000000
--- a/tempest/api/compute/v3/servers/test_server_personality.py
+++ /dev/null
@@ -1,68 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# 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 base64
-
-from tempest.api.compute import base
-from tempest import exceptions
-from tempest.test import attr
-
-
-class ServerPersonalityTestJSON(base.BaseV2ComputeTest):
- _interface = 'json'
-
- @classmethod
- def setUpClass(cls):
- super(ServerPersonalityTestJSON, cls).setUpClass()
- cls.client = cls.servers_client
- cls.user_client = cls.limits_client
-
- @attr(type='gate')
- def test_personality_files_exceed_limit(self):
- # Server creation should fail if greater than the maximum allowed
- # number of files are injected into the server.
- file_contents = 'This is a test file.'
- personality = []
- max_file_limit = \
- self.user_client.get_specific_absolute_limit("maxPersonality")
- for i in range(0, int(max_file_limit) + 1):
- path = 'etc/test' + str(i) + '.txt'
- personality.append({'path': path,
- 'contents': base64.b64encode(file_contents)})
- self.assertRaises(exceptions.OverLimit, self.create_test_server,
- personality=personality)
-
- @attr(type='gate')
- def test_can_create_server_with_max_number_personality_files(self):
- # Server should be created successfully if maximum allowed number of
- # files is injected into the server during creation.
- file_contents = 'This is a test file.'
- max_file_limit = \
- self.user_client.get_specific_absolute_limit("maxPersonality")
- person = []
- for i in range(0, int(max_file_limit)):
- path = 'etc/test' + str(i) + '.txt'
- person.append({
- 'path': path,
- 'contents': base64.b64encode(file_contents),
- })
- resp, server = self.create_test_server(personality=person)
- self.assertEqual('202', resp['status'])
-
-
-class ServerPersonalityTestXML(ServerPersonalityTestJSON):
- _interface = "xml"
diff --git a/tempest/api/compute/v3/servers/test_server_rescue.py b/tempest/api/compute/v3/servers/test_server_rescue.py
index eebd4d8..fa7def0 100644
--- a/tempest/api/compute/v3/servers/test_server_rescue.py
+++ b/tempest/api/compute/v3/servers/test_server_rescue.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
#
@@ -16,33 +14,24 @@
# under the License.
from tempest.api.compute import base
+from tempest.common.utils import data_utils
from tempest import exceptions
from tempest.test import attr
-class ServerRescueV3TestJSON(base.BaseV3ComputeTest):
+class ServerRescueV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(ServerRescueV3TestJSON, cls).setUpClass()
+ super(ServerRescueV3Test, cls).setUpClass()
cls.device = 'vdf'
# Create a volume and wait for it to become ready for attach
- resp, cls.volume_to_attach = \
- cls.volumes_client.create_volume(1,
- display_name=
- 'test_attach')
+ resp, cls.volume = cls.volumes_client.create_volume(
+ 1, display_name=data_utils.rand_name(cls.__name__ + '_volume'))
cls.volumes_client.wait_for_volume_status(
- cls.volume_to_attach['id'], 'available')
-
- # Create a volume and wait for it to become ready for attach
- resp, cls.volume_to_detach = \
- cls.volumes_client.create_volume(1,
- display_name=
- 'test_detach')
- cls.volumes_client.wait_for_volume_status(
- cls.volume_to_detach['id'], 'available')
+ cls.volume['id'], 'available')
# Server for positive tests
resp, server = cls.create_test_server(wait_until='BUILD')
@@ -56,30 +45,25 @@
cls.rescue_password = resc_server['admin_password']
cls.servers_client.rescue_server(
- cls.rescue_id, cls.rescue_password)
+ cls.rescue_id, admin_password=cls.rescue_password)
cls.servers_client.wait_for_server_status(cls.rescue_id, 'RESCUE')
def setUp(self):
- super(ServerRescueV3TestJSON, self).setUp()
+ super(ServerRescueV3Test, self).setUp()
@classmethod
def tearDownClass(cls):
- client = cls.volumes_client
- client.delete_volume(str(cls.volume_to_attach['id']).strip())
- client.delete_volume(str(cls.volume_to_detach['id']).strip())
- super(ServerRescueV3TestJSON, cls).tearDownClass()
+ cls.delete_volume(cls.volume['id'])
+ super(ServerRescueV3Test, cls).tearDownClass()
def tearDown(self):
- super(ServerRescueV3TestJSON, self).tearDown()
+ super(ServerRescueV3Test, self).tearDown()
def _detach(self, server_id, volume_id):
self.servers_client.detach_volume(server_id, volume_id)
self.volumes_client.wait_for_volume_status(volume_id,
'available')
- def _delete(self, volume_id):
- self.volumes_client.delete_volume(volume_id)
-
def _unrescue(self, server_id):
resp, body = self.servers_client.unrescue_server(server_id)
self.assertEqual(202, resp.status)
@@ -93,7 +77,7 @@
@attr(type='smoke')
def test_rescue_unrescue_instance(self):
resp, body = self.servers_client.rescue_server(
- self.server_id, self.password)
+ self.server_id, admin_password=self.password)
self.assertEqual(202, resp.status)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
resp, body = self.servers_client.unrescue_server(self.server_id)
@@ -134,7 +118,8 @@
@attr(type=['negative', 'gate'])
def test_rescued_vm_attach_volume(self):
# Rescue the server
- self.servers_client.rescue_server(self.server_id, self.password)
+ self.servers_client.rescue_server(self.server_id,
+ admin_password=self.password)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
self.addCleanup(self._unrescue, self.server_id)
@@ -142,32 +127,27 @@
self.assertRaises(exceptions.Conflict,
self.servers_client.attach_volume,
self.server_id,
- self.volume_to_attach['id'],
+ self.volume['id'],
device='/dev/%s' % self.device)
@attr(type=['negative', 'gate'])
def test_rescued_vm_detach_volume(self):
# Attach the volume to the server
self.servers_client.attach_volume(self.server_id,
- self.volume_to_detach['id'],
+ self.volume['id'],
device='/dev/%s' % self.device)
- self.volumes_client.wait_for_volume_status(
- self.volume_to_detach['id'], 'in-use')
+ self.volumes_client.wait_for_volume_status(self.volume['id'], 'in-use')
# Rescue the server
- self.servers_client.rescue_server(self.server_id, self.password)
+ self.servers_client.rescue_server(self.server_id,
+ admin_password=self.password)
self.servers_client.wait_for_server_status(self.server_id, 'RESCUE')
# addCleanup is a LIFO queue
- self.addCleanup(self._detach, self.server_id,
- self.volume_to_detach['id'])
+ self.addCleanup(self._detach, self.server_id, self.volume['id'])
self.addCleanup(self._unrescue, self.server_id)
# Detach the volume from the server expecting failure
self.assertRaises(exceptions.Conflict,
self.servers_client.detach_volume,
self.server_id,
- self.volume_to_detach['id'])
-
-
-class ServerRescueV3TestXML(ServerRescueV3TestJSON):
- _interface = 'xml'
+ self.volume['id'])
diff --git a/tempest/api/compute/v3/servers/test_servers.py b/tempest/api/compute/v3/servers/test_servers.py
index 9eff462..dc64c40 100644
--- a/tempest/api/compute/v3/servers/test_servers.py
+++ b/tempest/api/compute/v3/servers/test_servers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,17 +18,17 @@
from tempest import test
-class ServersV3TestJSON(base.BaseV3ComputeTest):
+class ServersV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(ServersV3TestJSON, cls).setUpClass()
+ super(ServersV3Test, cls).setUpClass()
cls.client = cls.servers_client
def tearDown(self):
self.clear_servers()
- super(ServersV3TestJSON, self).tearDown()
+ super(ServersV3Test, self).tearDown()
@test.attr(type='gate')
def test_create_server_with_admin_password(self):
@@ -107,6 +105,24 @@
server['os-access-ips:access_ip_v6'])
@test.attr(type='gate')
+ def test_delete_server_while_in_shutoff_state(self):
+ # Delete a server while it's VM state is Shutoff
+ resp, server = self.create_test_server(wait_until='ACTIVE')
+ resp, body = self.client.stop(server['id'])
+ self.client.wait_for_server_status(server['id'], 'SHUTOFF')
+ resp, _ = self.client.delete_server(server['id'])
+ self.assertEqual('204', resp['status'])
+
+ @test.attr(type='gate')
+ def test_delete_server_while_in_pause_state(self):
+ # Delete a server while it's VM state is Pause
+ resp, server = self.create_test_server(wait_until='ACTIVE')
+ resp, body = self.client.pause_server(server['id'])
+ self.client.wait_for_server_status(server['id'], 'PAUSED')
+ resp, _ = self.client.delete_server(server['id'])
+ self.assertEqual('204', resp['status'])
+
+ @test.attr(type='gate')
def test_delete_server_while_in_building_state(self):
# Delete a server while it's VM state is Building
resp, server = self.create_test_server(wait_until='BUILD')
@@ -128,7 +144,3 @@
self.client.wait_for_server_status(server['id'], 'ACTIVE')
resp, server = self.client.get_server(server['id'])
self.assertEqual('2001:2001::3', server['os-access-ips:access_ip_v6'])
-
-
-class ServersV3TestXML(ServersV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/servers/test_servers_negative.py b/tempest/api/compute/v3/servers/test_servers_negative.py
index 85fe47c..12e0ad8 100644
--- a/tempest/api/compute/v3/servers/test_servers_negative.py
+++ b/tempest/api/compute/v3/servers/test_servers_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -21,15 +19,18 @@
from tempest.api.compute import base
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest import test
+CONF = config.CONF
-class ServersNegativeV3TestJSON(base.BaseV3ComputeTest):
+
+class ServersNegativeV3Test(base.BaseV3ComputeTest):
_interface = 'json'
def setUp(self):
- super(ServersNegativeV3TestJSON, self).setUp()
+ super(ServersNegativeV3Test, self).setUp()
try:
self.client.wait_for_server_status(self.server_id, 'ACTIVE')
except Exception:
@@ -37,7 +38,7 @@
@classmethod
def setUpClass(cls):
- super(ServersNegativeV3TestJSON, cls).setUpClass()
+ super(ServersNegativeV3Test, cls).setUpClass()
cls.client = cls.servers_client
cls.alt_os = clients.AltManager()
cls.alt_client = cls.alt_os.servers_v3_client
@@ -157,9 +158,6 @@
@test.attr(type=['negative', 'gate'])
def test_create_numeric_server_name(self):
# Create a server with a numeric name
- if self.__class__._interface == "xml":
- raise self.skipException("Not testable in XML")
-
server_name = 12345
self.assertRaises(exceptions.BadRequest,
self.create_test_server,
@@ -185,7 +183,7 @@
networks=networks)
@test.attr(type=['negative', 'gate'])
- def test_create_with_non_existant_keypair(self):
+ def test_create_with_non_existent_keypair(self):
# Pass a non-existent keypair while creating a server
key_name = data_utils.rand_name('key')
@@ -193,12 +191,13 @@
self.create_test_server,
key_name=key_name)
+ @test.skip_because(bug="1273948")
@test.attr(type=['negative', 'gate'])
def test_create_server_metadata_exceeds_length_limit(self):
# Pass really long metadata while creating a server
metadata = {'a': 'b' * 260}
- self.assertRaises(exceptions.OverLimit,
+ self.assertRaises(exceptions.BadRequest,
self.create_test_server,
meta=metadata)
@@ -398,7 +397,7 @@
self.assertEqual(202, resp.status)
self.addCleanup(self.client.unshelve_server, self.server_id)
- offload_time = self.config.compute.shelved_offload_time
+ offload_time = CONF.compute.shelved_offload_time
if offload_time >= 0:
self.client.wait_for_server_status(self.server_id,
'SHELVED_OFFLOADED',
@@ -430,7 +429,3 @@
self.assertRaises(exceptions.Conflict,
self.client.unshelve_server,
self.server_id)
-
-
-class ServersNegativeV3TestXML(ServersNegativeV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/test_extensions.py b/tempest/api/compute/v3/test_extensions.py
index 2affd86..09f5ab4 100644
--- a/tempest/api/compute/v3/test_extensions.py
+++ b/tempest/api/compute/v3/test_extensions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,19 +15,35 @@
from tempest.api.compute import base
+from tempest import config
+from tempest.openstack.common import log as logging
from tempest import test
+CONF = config.CONF
-class ExtensionsV3TestJSON(base.BaseV3ComputeTest):
+LOG = logging.getLogger(__name__)
+
+
+class ExtensionsV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@test.attr(type='gate')
def test_list_extensions(self):
# List of all extensions
+ if len(CONF.compute_feature_enabled.api_v3_extensions) == 0:
+ raise self.skipException('There are not any extensions configured')
resp, extensions = self.extensions_client.list_extensions()
- self.assertIn("extensions", extensions)
self.assertEqual(200, resp.status)
- self.assertTrue(self.extensions_client.is_enabled("Consoles"))
+ ext = CONF.compute_feature_enabled.api_v3_extensions[0]
+ if ext == 'all':
+ self.assertIn('Hosts', map(lambda x: x['name'], extensions))
+ elif ext:
+ self.assertIn(ext, map(lambda x: x['name'], extensions))
+ else:
+ raise self.skipException('There are not any extensions configured')
+ # Log extensions list
+ extension_list = map(lambda x: x['name'], extensions)
+ LOG.debug("Nova extensions: %s" % ','.join(extension_list))
@test.attr(type='gate')
def test_get_extension(self):
@@ -37,7 +51,3 @@
resp, extension = self.extensions_client.get_extension('servers')
self.assertEqual(200, resp.status)
self.assertEqual('servers', extension['alias'])
-
-
-class ExtensionsV3TestXML(ExtensionsV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/test_live_block_migration.py b/tempest/api/compute/v3/test_live_block_migration.py
index 3de50c8..144cadb 100644
--- a/tempest/api/compute/v3/test_live_block_migration.py
+++ b/tempest/api/compute/v3/test_live_block_migration.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -25,16 +23,16 @@
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
-class LiveBlockMigrationV3TestJSON(base.BaseV3ComputeAdminTest):
+
+class LiveBlockMigrationV3Test(base.BaseV3ComputeAdminTest):
_host_key = 'os-extended-server-attributes:host'
_interface = 'json'
- CONF = config.CONF
-
@classmethod
def setUpClass(cls):
- super(LiveBlockMigrationV3TestJSON, cls).setUpClass()
+ super(LiveBlockMigrationV3Test, cls).setUpClass()
cls.admin_hosts_client = cls.hosts_admin_client
cls.admin_servers_client = cls.servers_admin_client
@@ -59,7 +57,7 @@
def _migrate_server_to(self, server_id, dest_host):
_resp, body = self.admin_servers_client.live_migrate_server(
server_id, dest_host,
- self.config.compute_feature_enabled.
+ CONF.compute_feature_enabled.
block_migration_for_live_migration)
return body
@@ -163,11 +161,4 @@
for server_id in cls.created_server_ids:
cls.servers_client.delete_server(server_id)
- super(LiveBlockMigrationV3TestJSON, cls).tearDownClass()
-
-
-class LiveBlockMigrationV3TestXML(LiveBlockMigrationV3TestJSON):
- _host_key = (
- '{http://docs.openstack.org/compute/ext/'
- 'extended_server_attributes/api/v3}host')
- _interface = 'xml'
+ super(LiveBlockMigrationV3Test, cls).tearDownClass()
diff --git a/tempest/api/compute/v3/test_quotas.py b/tempest/api/compute/v3/test_quotas.py
index d2f80a5..33b90ff 100644
--- a/tempest/api/compute/v3/test_quotas.py
+++ b/tempest/api/compute/v3/test_quotas.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,12 +17,12 @@
from tempest import test
-class QuotasV3TestJSON(base.BaseV3ComputeTest):
+class QuotasV3Test(base.BaseV3ComputeTest):
_interface = 'json'
@classmethod
def setUpClass(cls):
- super(QuotasV3TestJSON, cls).setUpClass()
+ super(QuotasV3Test, cls).setUpClass()
cls.client = cls.quotas_client
cls.admin_client = cls._get_identity_admin_client()
resp, tenants = cls.admin_client.list_tenants()
@@ -65,7 +63,3 @@
resp, tenant_quota_set = self.client.get_quota_set(self.tenant_id)
self.assertEqual(200, resp.status)
self.assertEqual(defualt_quota_set, tenant_quota_set)
-
-
-class QuotasV3TestXML(QuotasV3TestJSON):
- _interface = 'xml'
diff --git a/tempest/api/compute/v3/test_version.py b/tempest/api/compute/v3/test_version.py
new file mode 100644
index 0000000..9161d4d
--- /dev/null
+++ b/tempest/api/compute/v3/test_version.py
@@ -0,0 +1,30 @@
+# Copyright 2014 NEC Corporation.
+# All Rights Reserved.
+#
+# 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 tempest.api.compute import base
+from tempest import test
+
+
+class VersionV3Test(base.BaseV3ComputeTest):
+ _interface = 'json'
+
+ @test.attr(type='gate')
+ def test_version(self):
+ # Get version information
+ resp, version = self.version_client.get_version()
+ self.assertEqual(200, resp.status)
+ self.assertIn("id", version)
+ self.assertEqual("v3.0", version["id"])
diff --git a/tempest/api/compute/volumes/test_attach_volume.py b/tempest/api/compute/volumes/test_attach_volume.py
index c1ebc08..8d8e3ec 100644
--- a/tempest/api/compute/volumes/test_attach_volume.py
+++ b/tempest/api/compute/volumes/test_attach_volume.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
@@ -38,8 +36,8 @@
@classmethod
def setUpClass(cls):
super(AttachVolumeTestJSON, cls).setUpClass()
- cls.device = cls.config.compute.volume_device_name
- if not cls.config.service_available.cinder:
+ cls.device = CONF.compute.volume_device_name
+ if not CONF.service_available.cinder:
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
raise cls.skipException(skip_msg)
diff --git a/tempest/api/compute/volumes/test_volumes_get.py b/tempest/api/compute/volumes/test_volumes_get.py
index ae6996d..bcab891 100644
--- a/tempest/api/compute/volumes/test_volumes_get.py
+++ b/tempest/api/compute/volumes/test_volumes_get.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,7 +15,11 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
+from testtools.matchers import ContainsAll
+
+CONF = config.CONF
class VolumesGetTestJSON(base.BaseV2ComputeTest):
@@ -28,7 +30,7 @@
def setUpClass(cls):
super(VolumesGetTestJSON, cls).setUpClass()
cls.client = cls.volumes_extensions_client
- if not cls.config.service_available.cinder:
+ if not CONF.service_available.cinder:
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
raise cls.skipException(skip_msg)
@@ -42,7 +44,7 @@
resp, volume = self.client.create_volume(size=1,
display_name=v_name,
metadata=metadata)
- self.addCleanup(self._delete_volume, volume)
+ self.addCleanup(self.delete_volume, volume['id'])
self.assertEqual(200, resp.status)
self.assertIn('id', volume)
self.assertIn('displayName', volume)
@@ -56,7 +58,7 @@
# GET Volume
resp, fetched_volume = self.client.get_volume(volume['id'])
self.assertEqual(200, resp.status)
- # Verfication of details of fetched Volume
+ # Verification of details of fetched Volume
self.assertEqual(v_name,
fetched_volume['displayName'],
'The fetched Volume is different '
@@ -65,39 +67,10 @@
fetched_volume['id'],
'The fetched Volume is different '
'from the created Volume')
- self.assertEqual(metadata,
- fetched_volume['metadata'],
- 'The fetched Volume is different '
- 'from the created Volume')
-
- @attr(type='gate')
- def test_volume_get_metadata_none(self):
- # CREATE, GET empty metadata dict
- v_name = data_utils.rand_name('Volume-')
- # Create volume
- resp, volume = self.client.create_volume(size=1,
- display_name=v_name,
- metadata={})
- self.addCleanup(self._delete_volume, volume)
- self.assertEqual(200, resp.status)
- self.assertIn('id', volume)
- self.assertIn('displayName', volume)
- # Wait for Volume status to become ACTIVE
- self.client.wait_for_volume_status(volume['id'], 'available')
- # GET Volume
- resp, fetched_volume = self.client.get_volume(volume['id'])
- self.assertEqual(200, resp.status)
- self.assertEqual(fetched_volume['metadata'], {})
-
- def _delete_volume(self, volume):
- # Delete the Volume created in this method
- try:
- resp, _ = self.client.delete_volume(volume['id'])
- self.assertEqual(202, resp.status)
- # Checking if the deleted Volume still exists
- self.client.wait_for_resource_deletion(volume['id'])
- except KeyError:
- return
+ self.assertThat(fetched_volume['metadata'].items(),
+ ContainsAll(metadata.items()),
+ 'The fetched Volume metadata misses data '
+ 'from the created Volume')
class VolumesGetTestXML(VolumesGetTestJSON):
diff --git a/tempest/api/compute/volumes/test_volumes_list.py b/tempest/api/compute/volumes/test_volumes_list.py
index b57dcfe..48b1b7e 100644
--- a/tempest/api/compute/volumes/test_volumes_list.py
+++ b/tempest/api/compute/volumes/test_volumes_list.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,8 +15,11 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
+
class VolumesTestJSON(base.BaseV2ComputeTest):
@@ -36,7 +37,7 @@
def setUpClass(cls):
super(VolumesTestJSON, cls).setUpClass()
cls.client = cls.volumes_extensions_client
- if not cls.config.service_available.cinder:
+ if not CONF.service_available.cinder:
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
raise cls.skipException(skip_msg)
# Create 3 Volumes
@@ -61,7 +62,7 @@
# too small. So, here, we clean up whatever we did manage
# to create and raise a SkipTest
for volume in cls.volume_list:
- cls.client.delete_volume(volume)
+ cls.delete_volume(volume['id'])
msg = ("Failed to create ALL necessary volumes to run "
"test. This typically means that the backing file "
"size of the nova-volumes group is too small to "
@@ -73,8 +74,7 @@
def tearDownClass(cls):
# Delete the created Volumes
for volume in cls.volume_list:
- resp, _ = cls.client.delete_volume(volume['id'])
- cls.client.wait_for_resource_deletion(volume['id'])
+ cls.delete_volume(volume['id'])
super(VolumesTestJSON, cls).tearDownClass()
@attr(type='gate')
diff --git a/tempest/api/compute/volumes/test_volumes_negative.py b/tempest/api/compute/volumes/test_volumes_negative.py
index 785902e..85b30e2 100644
--- a/tempest/api/compute/volumes/test_volumes_negative.py
+++ b/tempest/api/compute/volumes/test_volumes_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,9 +17,12 @@
from tempest.api.compute import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
+
class VolumesNegativeTest(base.BaseV2ComputeTest):
_interface = 'json'
@@ -30,23 +31,23 @@
def setUpClass(cls):
super(VolumesNegativeTest, cls).setUpClass()
cls.client = cls.volumes_extensions_client
- if not cls.config.service_available.cinder:
+ if not CONF.service_available.cinder:
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
raise cls.skipException(skip_msg)
@attr(type=['negative', 'gate'])
- def test_volume_get_nonexistant_volume_id(self):
- # Negative: Should not be able to get details of nonexistant volume
- # Creating a nonexistant volume id
- # Trying to GET a non existant volume
+ def test_volume_get_nonexistent_volume_id(self):
+ # Negative: Should not be able to get details of nonexistent volume
+ # Creating a nonexistent volume id
+ # Trying to GET a non existent volume
self.assertRaises(exceptions.NotFound, self.client.get_volume,
str(uuid.uuid4()))
@attr(type=['negative', 'gate'])
- def test_volume_delete_nonexistant_volume_id(self):
- # Negative: Should not be able to delete nonexistant Volume
- # Creating nonexistant volume id
- # Trying to DELETE a non existant volume
+ def test_volume_delete_nonexistent_volume_id(self):
+ # Negative: Should not be able to delete nonexistent Volume
+ # Creating nonexistent volume id
+ # Trying to DELETE a non existent volume
self.assertRaises(exceptions.NotFound, self.client.delete_volume,
str(uuid.uuid4()))
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/api/data_processing/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/api/data_processing/__init__.py
diff --git a/tempest/api/data_processing/base.py b/tempest/api/data_processing/base.py
new file mode 100644
index 0000000..5b272ef
--- /dev/null
+++ b/tempest/api/data_processing/base.py
@@ -0,0 +1,91 @@
+# Copyright (c) 2013 Mirantis Inc.
+#
+# 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 tempest import config
+import tempest.test
+
+
+CONF = config.CONF
+
+
+class BaseDataProcessingTest(tempest.test.BaseTestCase):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(BaseDataProcessingTest, cls).setUpClass()
+ os = cls.get_client_manager()
+ if not CONF.service_available.savanna:
+ raise cls.skipException("Savanna support is required")
+ cls.client = os.data_processing_client
+
+ # set some constants
+ cls.flavor_ref = CONF.compute.flavor_ref
+ cls.simple_node_group_template = {
+ 'plugin_name': 'vanilla',
+ 'hadoop_version': '1.2.1',
+ 'node_processes': [
+ "datanode",
+ "tasktracker"
+ ],
+ 'flavor_id': cls.flavor_ref,
+ 'node_configs': {
+ 'HDFS': {
+ 'Data Node Heap Size': 1024
+ },
+ 'MapReduce': {
+ 'Task Tracker Heap Size': 1024
+ }
+ }
+ }
+
+ # add lists for watched resources
+ cls._node_group_templates = []
+
+ @classmethod
+ def tearDownClass(cls):
+ # cleanup node group templates
+ for ngt_id in cls._node_group_templates:
+ try:
+ cls.client.delete_node_group_template(ngt_id)
+ except Exception:
+ # ignore errors while auto removing created resource
+ pass
+ cls.clear_isolated_creds()
+ super(BaseDataProcessingTest, cls).tearDownClass()
+
+ @classmethod
+ def create_node_group_template(cls, name, plugin_name, hadoop_version,
+ node_processes, flavor_id,
+ node_configs=None, **kwargs):
+ """Creates watched node group template with specified params.
+
+ It supports passing additional params using kwargs and returns created
+ object. All resources created in this method will be automatically
+ removed in tearDownClass method.
+ """
+
+ resp, body = cls.client.create_node_group_template(name, plugin_name,
+ hadoop_version,
+ node_processes,
+ flavor_id,
+ node_configs,
+ **kwargs)
+
+ # store id of created node group template
+ template_id = body['id']
+ cls._node_group_templates.append(template_id)
+
+ return resp, body, template_id
diff --git a/tempest/api/data_processing/test_node_group_templates.py b/tempest/api/data_processing/test_node_group_templates.py
new file mode 100644
index 0000000..ff4fa6a
--- /dev/null
+++ b/tempest/api/data_processing/test_node_group_templates.py
@@ -0,0 +1,83 @@
+# Copyright (c) 2013 Mirantis Inc.
+#
+# 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 tempest.api.data_processing import base as dp_base
+from tempest.common.utils import data_utils
+from tempest.test import attr
+
+
+class NodeGroupTemplateTest(dp_base.BaseDataProcessingTest):
+ def _create_simple_node_group_template(self, template_name=None):
+ """Creates simple Node Group Template with optional name specified.
+
+ It creates template and ensures response status and template name.
+ Returns id and name of created template.
+ """
+
+ if template_name is None:
+ # generate random name if it's not specified
+ template_name = data_utils.rand_name('savanna')
+
+ # create simple node group template
+ resp, body, template_id = self.create_node_group_template(
+ template_name, **self.simple_node_group_template)
+
+ # ensure that template created successfully
+ self.assertEqual(202, resp.status)
+ self.assertEqual(template_name, body['name'])
+
+ return template_id, template_name
+
+ @attr(type='smoke')
+ def test_node_group_template_create(self):
+ # just create and ensure template
+ self._create_simple_node_group_template()
+
+ @attr(type='smoke')
+ def test_node_group_template_list(self):
+ template_info = self._create_simple_node_group_template()
+
+ # check for node group template in list
+ resp, templates = self.client.list_node_group_templates()
+
+ self.assertEqual(200, resp.status)
+ templates_info = list([(template['id'], template['name'])
+ for template in templates])
+ self.assertIn(template_info, templates_info)
+
+ @attr(type='smoke')
+ def test_node_group_template_get(self):
+ template_id, template_name = self._create_simple_node_group_template()
+
+ # check node group template fetch by id
+ resp, template = self.client.get_node_group_template(template_id)
+
+ self.assertEqual(200, resp.status)
+ self.assertEqual(template_name, template['name'])
+ self.assertEqual(self.simple_node_group_template['plugin_name'],
+ template['plugin_name'])
+ self.assertEqual(self.simple_node_group_template['node_processes'],
+ template['node_processes'])
+ self.assertEqual(self.simple_node_group_template['flavor_id'],
+ template['flavor_id'])
+
+ @attr(type='smoke')
+ def test_node_group_template_delete(self):
+ template_id, template_name = self._create_simple_node_group_template()
+
+ # delete the node group template by id
+ resp = self.client.delete_node_group_template(template_id)
+
+ self.assertEqual('204', resp[0]['status'])
diff --git a/tempest/api/data_processing/test_plugins.py b/tempest/api/data_processing/test_plugins.py
new file mode 100644
index 0000000..3b941d8
--- /dev/null
+++ b/tempest/api/data_processing/test_plugins.py
@@ -0,0 +1,58 @@
+# Copyright (c) 2013 Mirantis Inc.
+#
+# 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 tempest.api.data_processing import base as dp_base
+from tempest.test import attr
+
+
+class PluginsTest(dp_base.BaseDataProcessingTest):
+ def _list_all_plugin_names(self):
+ """Returns all enabled plugin names.
+
+ It ensures response status and main plugins availability.
+ """
+ resp, plugins = self.client.list_plugins()
+
+ self.assertEqual(200, resp.status)
+
+ plugins_names = list([plugin['name'] for plugin in plugins])
+ self.assertIn('vanilla', plugins_names)
+ self.assertIn('hdp', plugins_names)
+
+ return plugins_names
+
+ @attr(type='smoke')
+ def test_plugin_list(self):
+ self._list_all_plugin_names()
+
+ @attr(type='smoke')
+ def test_plugin_get(self):
+ for plugin_name in self._list_all_plugin_names():
+ resp, plugin = self.client.get_plugin(plugin_name)
+
+ self.assertEqual(200, resp.status)
+ self.assertEqual(plugin_name, plugin['name'])
+
+ for plugin_version in plugin['versions']:
+ resp, detailed_plugin = self.client.get_plugin(plugin_name,
+ plugin_version)
+
+ self.assertEqual(200, resp.status)
+ self.assertEqual(plugin_name, detailed_plugin['name'])
+
+ # check that required image tags contains name and version
+ image_tags = detailed_plugin['required_image_tags']
+ self.assertIn(plugin_name, image_tags)
+ self.assertIn(plugin_version, image_tags)
diff --git a/tempest/api/identity/__init__.py b/tempest/api/identity/__init__.py
index c9d43e9..9614b49 100644
--- a/tempest/api/identity/__init__.py
+++ b/tempest/api/identity/__init__.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/test_roles.py b/tempest/api/identity/admin/test_roles.py
index 8205d15..f1124e4 100644
--- a/tempest/api/identity/admin/test_roles.py
+++ b/tempest/api/identity/admin/test_roles.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/test_roles_negative.py b/tempest/api/identity/admin/test_roles_negative.py
index 83d1d4d..e5c04de 100644
--- a/tempest/api/identity/admin/test_roles_negative.py
+++ b/tempest/api/identity/admin/test_roles_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -43,10 +41,10 @@
@attr(type=['negative', 'gate'])
def test_list_roles_request_without_token(self):
# Request to list roles without a valid token should fail
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.list_roles)
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_role_create_blank_name(self):
@@ -63,12 +61,12 @@
@attr(type=['negative', 'gate'])
def test_create_role_request_without_token(self):
# Request to create role without a valid token should fail
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
role_name = data_utils.rand_name(name='role-')
self.assertRaises(exceptions.Unauthorized,
self.client.create_role, role_name)
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_role_create_duplicate(self):
@@ -101,12 +99,12 @@
self.assertEqual(200, resp.status)
self.data.roles.append(body)
role_id = body.get('id')
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized,
self.client.delete_role,
role_id)
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_delete_role_non_existent(self):
@@ -128,20 +126,12 @@
def test_assign_user_role_request_without_token(self):
# Request to assign a role to a user without a valid token
(user, tenant, role) = self._get_role_params()
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized,
self.client.assign_user_role, tenant['id'],
user['id'], role['id'])
- self.client.clear_auth()
-
- @attr(type=['negative', 'gate'])
- def test_assign_user_role_for_non_existent_user(self):
- # Attempt to assign a role to a non existent user should fail
- (user, tenant, role) = self._get_role_params()
- non_existent_user = str(uuid.uuid4().hex)
- self.assertRaises(exceptions.NotFound, self.client.assign_user_role,
- tenant['id'], non_existent_user, role['id'])
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_assign_user_role_for_non_existent_role(self):
@@ -186,45 +176,34 @@
resp, user_role = self.client.assign_user_role(tenant['id'],
user['id'],
role['id'])
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized,
self.client.remove_user_role, tenant['id'],
user['id'], role['id'])
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
- def test_remove_user_role_non_existant_user(self):
- # Attempt to remove a role from a non existent user should fail
- (user, tenant, role) = self._get_role_params()
- resp, user_role = self.client.assign_user_role(tenant['id'],
- user['id'],
- role['id'])
- non_existant_user = str(uuid.uuid4().hex)
- self.assertRaises(exceptions.NotFound, self.client.remove_user_role,
- tenant['id'], non_existant_user, role['id'])
-
- @attr(type=['negative', 'gate'])
- def test_remove_user_role_non_existant_role(self):
+ def test_remove_user_role_non_existent_role(self):
# Attempt to delete a non existent role from a user should fail
(user, tenant, role) = self._get_role_params()
resp, user_role = self.client.assign_user_role(tenant['id'],
user['id'],
role['id'])
- non_existant_role = str(uuid.uuid4().hex)
+ non_existent_role = str(uuid.uuid4().hex)
self.assertRaises(exceptions.NotFound, self.client.remove_user_role,
- tenant['id'], user['id'], non_existant_role)
+ tenant['id'], user['id'], non_existent_role)
@attr(type=['negative', 'gate'])
- def test_remove_user_role_non_existant_tenant(self):
+ def test_remove_user_role_non_existent_tenant(self):
# Attempt to remove a role from a non existent tenant should fail
(user, tenant, role) = self._get_role_params()
resp, user_role = self.client.assign_user_role(tenant['id'],
user['id'],
role['id'])
- non_existant_tenant = str(uuid.uuid4().hex)
+ non_existent_tenant = str(uuid.uuid4().hex)
self.assertRaises(exceptions.NotFound, self.client.remove_user_role,
- non_existant_tenant, user['id'], role['id'])
+ non_existent_tenant, user['id'], role['id'])
@attr(type=['negative', 'gate'])
def test_list_user_roles_by_unauthorized_user(self):
@@ -240,22 +219,14 @@
def test_list_user_roles_request_without_token(self):
# Request to list user's roles without a valid token should fail
(user, tenant, role) = self._get_role_params()
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
try:
self.assertRaises(exceptions.Unauthorized,
self.client.list_user_roles, tenant['id'],
user['id'])
finally:
- self.client.clear_auth()
-
- @attr(type=['negative', 'gate'])
- def test_list_user_roles_for_non_existent_user(self):
- # Attempt to list roles of a non existent user should fail
- (user, tenant, role) = self._get_role_params()
- non_existent_user = str(uuid.uuid4().hex)
- self.assertRaises(exceptions.NotFound, self.client.list_user_roles,
- tenant['id'], non_existent_user)
+ self.client.auth_provider.clear_auth()
class RolesTestXML(RolesNegativeTestJSON):
diff --git a/tempest/api/identity/admin/test_services.py b/tempest/api/identity/admin/test_services.py
index 872adb8..8ba333f 100644
--- a/tempest/api/identity/admin/test_services.py
+++ b/tempest/api/identity/admin/test_services.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/test_tenant_negative.py b/tempest/api/identity/admin/test_tenant_negative.py
index d10080b..e9eddc8 100644
--- a/tempest/api/identity/admin/test_tenant_negative.py
+++ b/tempest/api/identity/admin/test_tenant_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -35,10 +33,10 @@
@attr(type=['negative', 'gate'])
def test_list_tenant_request_without_token(self):
# Request to list tenants without a valid token should fail
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.list_tenants)
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_tenant_delete_by_unauthorized_user(self):
@@ -57,11 +55,11 @@
resp, tenant = self.client.create_tenant(tenant_name)
self.assertEqual(200, resp.status)
self.data.tenants.append(tenant)
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.delete_tenant,
tenant['id'])
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_delete_non_existent_tenant(self):
@@ -95,11 +93,11 @@
def test_create_tenant_request_without_token(self):
# Create tenant request without a token should not be authorized
tenant_name = data_utils.rand_name(name='tenant-')
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.create_tenant,
tenant_name)
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_create_tenant_with_empty_name(self):
@@ -137,11 +135,11 @@
resp, tenant = self.client.create_tenant(tenant_name)
self.assertEqual(200, resp.status)
self.data.tenants.append(tenant)
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.update_tenant,
tenant['id'])
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
class TenantsNegativeTestXML(TenantsNegativeTestJSON):
diff --git a/tempest/api/identity/admin/test_tenants.py b/tempest/api/identity/admin/test_tenants.py
index e36b543..46fa7a9 100644
--- a/tempest/api/identity/admin/test_tenants.py
+++ b/tempest/api/identity/admin/test_tenants.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/test_tokens.py b/tempest/api/identity/admin/test_tokens.py
index 334a5aa..620e293 100644
--- a/tempest/api/identity/admin/test_tokens.py
+++ b/tempest/api/identity/admin/test_tokens.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
@@ -15,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import json
-
from tempest.api.identity import base
from tempest.common.utils import data_utils
from tempest.test import attr
@@ -44,12 +40,11 @@
rsp, body = self.token_client.auth(user_name,
user_password,
tenant['name'])
- access_data = json.loads(body)['access']
self.assertEqual(rsp['status'], '200')
- self.assertEqual(access_data['token']['tenant']['name'],
+ self.assertEqual(body['token']['tenant']['name'],
tenant['name'])
# then delete the token
- token_id = access_data['token']['id']
+ token_id = body['token']['id']
resp, body = self.client.delete_token(token_id)
self.assertEqual(resp['status'], '204')
diff --git a/tempest/api/identity/admin/test_users.py b/tempest/api/identity/admin/test_users.py
index 5d5a814..39ef947 100644
--- a/tempest/api/identity/admin/test_users.py
+++ b/tempest/api/identity/admin/test_users.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -117,7 +115,7 @@
self.token_client.auth(self.data.test_user, self.data.test_password,
self.data.test_tenant)
# Get the token of the current client
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
# Delete the token from database
self.client.delete_token(token)
# Re-auth
@@ -125,7 +123,7 @@
self.data.test_password,
self.data.test_tenant)
self.assertEqual('200', resp['status'])
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type='smoke')
def test_get_users(self):
diff --git a/tempest/api/identity/admin/test_users_negative.py b/tempest/api/identity/admin/test_users_negative.py
index 3163c16..060f24a 100644
--- a/tempest/api/identity/admin/test_users_negative.py
+++ b/tempest/api/identity/admin/test_users_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -66,7 +64,7 @@
self.data.tenant['id'], self.data.test_email)
@attr(type=['negative', 'gate'])
- def test_create_user_for_non_existant_tenant(self):
+ def test_create_user_for_non_existent_tenant(self):
# Attempt to create a user in a non-existent tenant should fail
self.assertRaises(exceptions.NotFound, self.client.create_user,
self.alt_user, self.alt_password, '49ffgg99999',
@@ -77,7 +75,7 @@
# Request to create a user without a valid token should fail
self.data.setup_test_tenant()
# Get the token of the current client
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
# Delete the token from database
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.create_user,
@@ -85,7 +83,7 @@
self.data.tenant['id'], self.alt_email)
# Unset the token to allow further tests to generate a new token
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_create_user_with_enabled_non_bool(self):
@@ -98,7 +96,7 @@
self.alt_email, enabled=3)
@attr(type=['negative', 'gate'])
- def test_update_user_for_non_existant_user(self):
+ def test_update_user_for_non_existent_user(self):
# Attempt to update a user non-existent user should fail
user_name = data_utils.rand_name('user-')
non_existent_id = str(uuid.uuid4())
@@ -110,14 +108,14 @@
# Request to update a user without a valid token should fail
# Get the token of the current client
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
# Delete the token from database
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.update_user,
self.alt_user)
# Unset the token to allow further tests to generate a new token
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_update_user_by_unauthorized_user(self):
@@ -135,7 +133,7 @@
self.data.user['id'])
@attr(type=['negative', 'gate'])
- def test_delete_non_existant_user(self):
+ def test_delete_non_existent_user(self):
# Attempt to delete a non-existent user should fail
self.assertRaises(exceptions.NotFound, self.client.delete_user,
'junk12345123')
@@ -145,14 +143,14 @@
# Request to delete a user without a valid token should fail
# Get the token of the current client
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
# Delete the token from database
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.delete_user,
self.alt_user)
# Unset the token to allow further tests to generate a new token
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_authentication_for_disabled_user(self):
@@ -209,10 +207,10 @@
@attr(type=['negative', 'gate'])
def test_get_users_request_without_token(self):
# Request to get list of users without a valid token should fail
- token = self.client.get_auth()
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.get_users)
- self.client.clear_auth()
+ self.client.auth_provider.clear_auth()
@attr(type=['negative', 'gate'])
def test_list_users_with_invalid_tenant(self):
diff --git a/tempest/api/identity/admin/v3/test_credentials.py b/tempest/api/identity/admin/v3/test_credentials.py
index 0b494f3..753eaa6 100644
--- a/tempest/api/identity/admin/v3/test_credentials.py
+++ b/tempest/api/identity/admin/v3/test_credentials.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_domains.py b/tempest/api/identity/admin/v3/test_domains.py
index ed776cd..4017b62 100644
--- a/tempest/api/identity/admin/v3/test_domains.py
+++ b/tempest/api/identity/admin/v3/test_domains.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_endpoints.py b/tempest/api/identity/admin/v3/test_endpoints.py
index d4d2109..4ae7884 100644
--- a/tempest/api/identity/admin/v3/test_endpoints.py
+++ b/tempest/api/identity/admin/v3/test_endpoints.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_groups.py b/tempest/api/identity/admin/v3/test_groups.py
new file mode 100644
index 0000000..70afec7
--- /dev/null
+++ b/tempest/api/identity/admin/v3/test_groups.py
@@ -0,0 +1,82 @@
+# Copyright 2013 IBM Corp.
+# All Rights Reserved.
+#
+# 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 tempest.api.identity import base
+from tempest.common.utils import data_utils
+from tempest import test
+
+
+class GroupsV3TestJSON(base.BaseIdentityAdminTest):
+ _interface = 'json'
+
+ @classmethod
+ def setUpClass(cls):
+ super(GroupsV3TestJSON, cls).setUpClass()
+
+ @test.attr(type='smoke')
+ def test_group_create_update_get(self):
+ name = data_utils.rand_name('Group')
+ description = data_utils.rand_name('Description')
+ resp, group = self.v3_client.create_group(name,
+ description=description)
+ self.addCleanup(self.v3_client.delete_group, group['id'])
+ self.assertEqual(resp['status'], '201')
+ self.assertEqual(group['name'], name)
+ self.assertEqual(group['description'], description)
+
+ new_name = data_utils.rand_name('UpdateGroup')
+ new_desc = data_utils.rand_name('UpdateDescription')
+ resp, updated_group = self.v3_client.update_group(group['id'],
+ name=new_name,
+ description=new_desc)
+ self.assertEqual(resp['status'], '200')
+ self.assertEqual(updated_group['name'], new_name)
+ self.assertEqual(updated_group['description'], new_desc)
+
+ resp, new_group = self.v3_client.get_group(group['id'])
+ self.assertEqual(resp['status'], '200')
+ self.assertEqual(group['id'], new_group['id'])
+ self.assertEqual(new_name, new_group['name'])
+ self.assertEqual(new_desc, new_group['description'])
+
+ @test.attr(type='smoke')
+ def test_group_users_add_list_delete(self):
+ name = data_utils.rand_name('Group')
+ resp, group = self.v3_client.create_group(name)
+ self.addCleanup(self.v3_client.delete_group, group['id'])
+ # add user into group
+ users = []
+ for i in range(3):
+ name = data_utils.rand_name('User')
+ resp, user = self.v3_client.create_user(name)
+ users.append(user)
+ self.addCleanup(self.v3_client.delete_user, user['id'])
+ self.v3_client.add_group_user(group['id'], user['id'])
+
+ # list users in group
+ resp, group_users = self.v3_client.list_group_users(group['id'])
+ self.assertEqual(resp['status'], '200')
+ self.assertEqual(users.sort(), group_users.sort())
+ # delete user in group
+ for user in users:
+ resp, body = self.v3_client.delete_group_user(group['id'],
+ user['id'])
+ self.assertEqual(resp['status'], '204')
+ resp, group_users = self.v3_client.list_group_users(group['id'])
+ self.assertEqual(len(group_users), 0)
+
+
+class GroupsV3TestXML(GroupsV3TestJSON):
+ _interface = 'xml'
diff --git a/tempest/api/identity/admin/v3/test_policies.py b/tempest/api/identity/admin/v3/test_policies.py
index 48f8fcd..0e8e4c3 100644
--- a/tempest/api/identity/admin/v3/test_policies.py
+++ b/tempest/api/identity/admin/v3/test_policies.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_projects.py b/tempest/api/identity/admin/v3/test_projects.py
index cbfcd04..1fc5a6a 100644
--- a/tempest/api/identity/admin/v3/test_projects.py
+++ b/tempest/api/identity/admin/v3/test_projects.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack, LLC
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_roles.py b/tempest/api/identity/admin/v3/test_roles.py
index a6a2bd7..efaed39 100644
--- a/tempest/api/identity/admin/v3/test_roles.py
+++ b/tempest/api/identity/admin/v3/test_roles.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_services.py b/tempest/api/identity/admin/v3/test_services.py
index 1751638..4d6c22f 100644
--- a/tempest/api/identity/admin/v3/test_services.py
+++ b/tempest/api/identity/admin/v3/test_services.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_tokens.py b/tempest/api/identity/admin/v3/test_tokens.py
index 2541e25..d17dc4a 100644
--- a/tempest/api/identity/admin/v3/test_tokens.py
+++ b/tempest/api/identity/admin/v3/test_tokens.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/admin/v3/test_trusts.py b/tempest/api/identity/admin/v3/test_trusts.py
index 1ecc90c..1bebad4 100644
--- a/tempest/api/identity/admin/v3/test_trusts.py
+++ b/tempest/api/identity/admin/v3/test_trusts.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -17,21 +15,24 @@
from tempest.api.identity import base
from tempest import clients
from tempest.common.utils.data_utils import rand_name
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import timeutils
from tempest.test import attr
+CONF = config.CONF
+
class BaseTrustsV3Test(base.BaseIdentityAdminTest):
def setUp(self):
super(BaseTrustsV3Test, self).setUp()
# Use alt_username as the trustee
- self.trustee_username = self.config.identity.alt_username
+ if not CONF.identity_feature_enabled.trust:
+ raise self.skipException("Trusts aren't enabled")
+ self.trustee_username = CONF.identity.alt_username
self.trust_id = None
- self.create_trustor_and_roles()
- self.addCleanup(self.cleanup_user_and_roles)
def tearDown(self):
if self.trust_id:
@@ -50,7 +51,7 @@
# Create a trustor User
self.trustor_username = rand_name('user-')
u_desc = self.trustor_username + 'description'
- u_email = self.trustor_username + '@testmail.tm'
+ u_email = self.trustor_username + '@testmail.xx'
self.trustor_password = rand_name('pass-')
resp, user = self.v3_client.create_user(
self.trustor_username,
@@ -193,6 +194,7 @@
def setUp(self):
super(TrustsV3TestJSON, self).setUp()
self.create_trustor_and_roles()
+ self.addCleanup(self.cleanup_user_and_roles)
@attr(type='smoke')
def test_trust_impersonate(self):
diff --git a/tempest/api/identity/admin/v3/test_users.py b/tempest/api/identity/admin/v3/test_users.py
index b1c4d82..7cae856 100644
--- a/tempest/api/identity/admin/v3/test_users.py
+++ b/tempest/api/identity/admin/v3/test_users.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index 876edfd..a3fc65a 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py
index 28ed5b6..e439238 100644
--- a/tempest/api/image/base.py
+++ b/tempest/api/image/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -19,10 +17,13 @@
from tempest import clients
from tempest.common import isolated_creds
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
import tempest.test
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -31,14 +32,16 @@
@classmethod
def setUpClass(cls):
+ cls.set_network_resources()
super(BaseImageTest, cls).setUpClass()
cls.created_images = []
cls._interface = 'json'
- cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
- if not cls.config.service_available.glance:
+ cls.isolated_creds = isolated_creds.IsolatedCreds(
+ cls.__name__, network_resources=cls.network_resources)
+ if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
raise cls.skipException(skip_msg)
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_primary_creds()
username, tenant_name, password = creds
cls.os = clients.Manager(username=username,
@@ -83,7 +86,7 @@
def setUpClass(cls):
super(BaseV1ImageTest, cls).setUpClass()
cls.client = cls.os.image_client
- if not cls.config.image_feature_enabled.api_v1:
+ if not CONF.image_feature_enabled.api_v1:
msg = "Glance API v1 not supported"
raise cls.skipException(msg)
@@ -92,7 +95,7 @@
@classmethod
def setUpClass(cls):
super(BaseV1ImageMembersTest, cls).setUpClass()
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.os_alt = clients.Manager(username=username,
@@ -103,7 +106,7 @@
cls.os_alt = clients.AltManager()
identity_client = cls._get_identity_admin_client()
cls.alt_tenant_id = identity_client.get_tenant_by_name(
- cls.os_alt.tenant_name)['id']
+ cls.os_alt.credentials['tenant_name'])['id']
cls.alt_img_cli = cls.os_alt.image_client
@@ -124,17 +127,17 @@
def setUpClass(cls):
super(BaseV2ImageTest, cls).setUpClass()
cls.client = cls.os.image_client_v2
- if not cls.config.image_feature_enabled.api_v2:
+ if not CONF.image_feature_enabled.api_v2:
msg = "Glance API v2 not supported"
raise cls.skipException(msg)
-class BaseV2MemeberImageTest(BaseImageTest):
+class BaseV2MemberImageTest(BaseV2ImageTest):
@classmethod
def setUpClass(cls):
- super(BaseV2MemeberImageTest, cls).setUpClass()
- if cls.config.compute.allow_tenant_isolation:
+ super(BaseV2MemberImageTest, cls).setUpClass()
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.os_alt = clients.Manager(username=username,
@@ -144,7 +147,7 @@
cls.alt_tenant_id = cls.isolated_creds.get_alt_tenant()['id']
else:
cls.os_alt = clients.AltManager()
- alt_tenant_name = cls.os_alt.tenant_name
+ alt_tenant_name = cls.os_alt.credentials['tenant_name']
identity_client = cls._get_identity_admin_client()
cls.alt_tenant_id = identity_client.get_tenant_by_name(
alt_tenant_name)['id']
diff --git a/tempest/api/image/v1/test_image_members.py b/tempest/api/image/v1/test_image_members.py
index 437527d..e6a078e 100644
--- a/tempest/api/image/v1/test_image_members.py
+++ b/tempest/api/image/v1/test_image_members.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/image/v1/test_image_members_negative.py b/tempest/api/image/v1/test_image_members_negative.py
index 83f7a0f..d68ef03 100644
--- a/tempest/api/image/v1/test_image_members_negative.py
+++ b/tempest/api/image/v1/test_image_members_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/image/v1/test_images.py b/tempest/api/image/v1/test_images.py
index 558e2ec..d8b79ca 100644
--- a/tempest/api/image/v1/test_images.py
+++ b/tempest/api/image/v1/test_images.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,8 +16,11 @@
import cStringIO as StringIO
from tempest.api.image import base
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
+
class CreateRegisterImagesTest(base.BaseV1ImageTest):
"""Here we test the registration and creation of images."""
@@ -70,7 +71,7 @@
resp, body = self.create_image(name='New Http Image',
container_format='bare',
disk_format='raw', is_public=True,
- copy_from=self.config.images.http_image)
+ copy_from=CONF.image.http_image)
self.assertIn('id', body)
image_id = body.get('id')
self.assertEqual('New Http Image', body.get('name'))
diff --git a/tempest/api/image/v1/test_images_negative.py b/tempest/api/image/v1/test_images_negative.py
index 1bcf120..5695884 100644
--- a/tempest/api/image/v1/test_images_negative.py
+++ b/tempest/api/image/v1/test_images_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py
index 090f31f..2a5401f 100644
--- a/tempest/api/image/v2/test_images.py
+++ b/tempest/api/image/v2/test_images.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# Copyright 2013 IBM Corp
# All Rights Reserved.
@@ -201,8 +199,8 @@
@attr(type='gate')
def test_list_images_param_status(self):
- # Test to get all available images
- params = {"status": "available"}
+ # Test to get all active images
+ params = {"status": "active"}
self._list_by_param_value_and_assert(params)
@attr(type='gate')
diff --git a/tempest/api/image/v2/test_images_member.py b/tempest/api/image/v2/test_images_member.py
index 954c79d..41fc49d 100644
--- a/tempest/api/image/v2/test_images_member.py
+++ b/tempest/api/image/v2/test_images_member.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -16,7 +14,7 @@
from tempest.test import attr
-class ImagesMemberTest(base.BaseV2MemeberImageTest):
+class ImagesMemberTest(base.BaseV2MemberImageTest):
_interface = 'json'
@attr(type='gate')
diff --git a/tempest/api/image/v2/test_images_member_negative.py b/tempest/api/image/v2/test_images_member_negative.py
index 3c17959..4c7cc5a 100644
--- a/tempest/api/image/v2/test_images_member_negative.py
+++ b/tempest/api/image/v2/test_images_member_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -17,7 +15,7 @@
from tempest.test import attr
-class ImagesMemberNegativeTest(base.BaseV2MemeberImageTest):
+class ImagesMemberNegativeTest(base.BaseV2MemberImageTest):
_interface = 'json'
@attr(type=['negative', 'gate'])
diff --git a/tempest/api/image/v2/test_images_negative.py b/tempest/api/image/v2/test_images_negative.py
index 1cd6f29..b8ba868 100644
--- a/tempest/api/image/v2/test_images_negative.py
+++ b/tempest/api/image/v2/test_images_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
# Copyright 2013 IBM Corp.
diff --git a/tempest/api/image/v2/test_images_tags.py b/tempest/api/image/v2/test_images_tags.py
index e37e462..f0e343d 100644
--- a/tempest/api/image/v2/test_images_tags.py
+++ b/tempest/api/image/v2/test_images_tags.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/image/v2/test_images_tags_negative.py b/tempest/api/image/v2/test_images_tags_negative.py
index e0d84de..0628d29 100644
--- a/tempest/api/image/v2/test_images_tags_negative.py
+++ b/tempest/api/image/v2/test_images_tags_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/api/network/admin/test_agent_management.py b/tempest/api/network/admin/test_agent_management.py
index 94659b2..342bc6a 100644
--- a/tempest/api/network/admin/test_agent_management.py
+++ b/tempest/api/network/admin/test_agent_management.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -16,7 +14,7 @@
from tempest.api.network import base
from tempest.common import tempest_fixtures as fixtures
-from tempest.test import attr
+from tempest import test
class AgentManagementTestJSON(base.BaseAdminNetworkTest):
@@ -25,25 +23,38 @@
@classmethod
def setUpClass(cls):
super(AgentManagementTestJSON, cls).setUpClass()
+ if not test.is_extension_enabled('agent', 'network'):
+ msg = "agent extension not enabled."
+ raise cls.skipException(msg)
resp, body = cls.admin_client.list_agents()
agents = body['agents']
cls.agent = agents[0]
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_list_agent(self):
resp, body = self.admin_client.list_agents()
self.assertEqual('200', resp['status'])
agents = body['agents']
+ # Hearthbeats must be excluded from comparison
+ self.agent.pop('heartbeat_timestamp', None)
+ for agent in agents:
+ agent.pop('heartbeat_timestamp', None)
self.assertIn(self.agent, agents)
- @attr(type='smoke')
+ @test.attr(type=['smoke'])
+ def test_list_agents_non_admin(self):
+ resp, body = self.client.list_agents()
+ self.assertEqual('200', resp['status'])
+ self.assertEqual(len(body["agents"]), 0)
+
+ @test.attr(type='smoke')
def test_show_agent(self):
resp, body = self.admin_client.show_agent(self.agent['id'])
agent = body['agent']
self.assertEqual('200', resp['status'])
self.assertEqual(agent['id'], self.agent['id'])
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_update_agent_status(self):
origin_status = self.agent['admin_state_up']
# Try to update the 'admin_state_up' to the original
@@ -55,7 +66,7 @@
self.assertEqual('200', resp['status'])
self.assertEqual(origin_status, updated_status)
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_update_agent_description(self):
self.useFixture(fixtures.LockFixture('agent_description'))
description = 'description for update agent.'
diff --git a/tempest/api/network/admin/test_dhcp_agent_scheduler.py b/tempest/api/network/admin/test_dhcp_agent_scheduler.py
index ac10e68..ecd992a 100644
--- a/tempest/api/network/admin/test_dhcp_agent_scheduler.py
+++ b/tempest/api/network/admin/test_dhcp_agent_scheduler.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -15,7 +13,7 @@
# under the License.
from tempest.api.network import base
-from tempest.test import attr
+from tempest import test
class DHCPAgentSchedulersTestJSON(base.BaseAdminNetworkTest):
@@ -24,6 +22,9 @@
@classmethod
def setUpClass(cls):
super(DHCPAgentSchedulersTestJSON, cls).setUpClass()
+ if not test.is_extension_enabled('dhcp_agent_scheduler', 'network'):
+ msg = "dhcp_agent_scheduler extension not enabled."
+ raise cls.skipException(msg)
# Create a network and make sure it will be hosted by a
# dhcp agent.
cls.network = cls.create_network()
@@ -31,13 +32,13 @@
cls.cidr = cls.subnet['cidr']
cls.port = cls.create_port(cls.network)
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_list_dhcp_agent_hosting_network(self):
resp, body = self.admin_client.list_dhcp_agent_hosting_network(
self.network['id'])
self.assertEqual(resp['status'], '200')
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_list_networks_hosted_by_one_dhcp(self):
resp, body = self.admin_client.list_dhcp_agent_hosting_network(
self.network['id'])
@@ -57,7 +58,7 @@
network_ids.append(network['id'])
return network_id in network_ids
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_remove_network_from_dhcp_agent(self):
resp, body = self.admin_client.list_dhcp_agent_hosting_network(
self.network['id'])
diff --git a/tempest/api/network/admin/test_l3_agent_scheduler.py b/tempest/api/network/admin/test_l3_agent_scheduler.py
index 64ab051..7c02787 100644
--- a/tempest/api/network/admin/test_l3_agent_scheduler.py
+++ b/tempest/api/network/admin/test_l3_agent_scheduler.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -19,7 +17,7 @@
from tempest import test
-class L3AgentSchedulerJSON(base.BaseAdminNetworkTest):
+class L3AgentSchedulerTestJSON(base.BaseAdminNetworkTest):
_interface = 'json'
"""
@@ -35,7 +33,7 @@
@classmethod
def setUpClass(cls):
- super(L3AgentSchedulerJSON, cls).setUpClass()
+ super(L3AgentSchedulerTestJSON, cls).setUpClass()
if not test.is_extension_enabled('l3_agent_scheduler', 'network'):
msg = "L3 Agent Scheduler Extension not enabled."
raise cls.skipException(msg)
@@ -63,5 +61,5 @@
self.assertEqual(204, resp.status)
-class L3AgentSchedulerXML(L3AgentSchedulerJSON):
+class L3AgentSchedulerTestXML(L3AgentSchedulerTestJSON):
_interface = 'xml'
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index dcad101..b129786 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,10 +17,13 @@
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
import tempest.test
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -48,13 +49,20 @@
neutron as True
"""
+ force_tenant_isolation = False
+
@classmethod
def setUpClass(cls):
+ # Create no network resources for these test.
+ cls.set_network_resources()
super(BaseNetworkTest, cls).setUpClass()
os = clients.Manager(interface=cls._interface)
- cls.network_cfg = os.config.network
- if not cls.config.service_available.neutron:
+ if not CONF.service_available.neutron:
raise cls.skipException("Neutron support is required")
+
+ os = cls.get_client_manager()
+
+ cls.network_cfg = CONF.network
cls.client = os.network_client
cls.networks = []
cls.subnets = []
@@ -108,6 +116,7 @@
# Clean up networks
for network in cls.networks:
cls.client.delete_network(network['id'])
+ cls.clear_isolated_creds()
super(BaseNetworkTest, cls).tearDownClass()
@classmethod
@@ -115,23 +124,25 @@
"""Wrapper utility that returns a test network."""
network_name = network_name or data_utils.rand_name('test-network-')
- resp, body = cls.client.create_network(network_name)
+ resp, body = cls.client.create_network(name=network_name)
network = body['network']
cls.networks.append(network)
return network
@classmethod
- def create_subnet(cls, network):
+ def create_subnet(cls, network, ip_version=4):
"""Wrapper utility that returns a test subnet."""
- cidr = netaddr.IPNetwork(cls.network_cfg.tenant_network_cidr)
- mask_bits = cls.network_cfg.tenant_network_mask_bits
+ cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
+ mask_bits = CONF.network.tenant_network_mask_bits
# Find a cidr that is not in use yet and create a subnet with it
body = None
failure = None
for subnet_cidr in cidr.subnet(mask_bits):
try:
- resp, body = cls.client.create_subnet(network['id'],
- str(subnet_cidr))
+ resp, body = cls.client.create_subnet(
+ network_id=network['id'],
+ cidr=str(subnet_cidr),
+ ip_version=ip_version)
break
except exceptions.BadRequest as e:
is_overlapping_cidr = 'overlaps with another subnet' in str(e)
@@ -150,7 +161,7 @@
@classmethod
def create_port(cls, network):
"""Wrapper utility that returns a test port."""
- resp, body = cls.client.create_port(network['id'])
+ resp, body = cls.client.create_port(network_id=network['id'])
port = body['port']
cls.ports.append(port)
return port
@@ -258,12 +269,21 @@
@classmethod
def setUpClass(cls):
super(BaseAdminNetworkTest, cls).setUpClass()
- admin_username = cls.config.compute_admin.username
- admin_password = cls.config.compute_admin.password
- admin_tenant = cls.config.compute_admin.tenant_name
+ admin_username = CONF.compute_admin.username
+ admin_password = CONF.compute_admin.password
+ admin_tenant = CONF.compute_admin.tenant_name
if not (admin_username and admin_password and admin_tenant):
msg = ("Missing Administrative Network API credentials "
"in configuration.")
raise cls.skipException(msg)
- cls.admin_manager = clients.AdminManager(interface=cls._interface)
- cls.admin_client = cls.admin_manager.network_client
+ if (CONF.compute.allow_tenant_isolation or
+ cls.force_tenant_isolation is True):
+ creds = cls.isolated_creds.get_admin_creds()
+ admin_username, admin_tenant_name, admin_password = creds
+ cls.os_adm = clients.Manager(username=admin_username,
+ password=admin_password,
+ tenant_name=admin_tenant_name,
+ interface=cls._interface)
+ else:
+ cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
+ cls.admin_client = cls.os_adm.network_client
diff --git a/tempest/api/network/base_routers.py b/tempest/api/network/base_routers.py
index 9baef04..304b2ca 100644
--- a/tempest/api/network/base_routers.py
+++ b/tempest/api/network/base_routers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/network/base_security_groups.py b/tempest/api/network/base_security_groups.py
index 5ab1748..38ae4ac 100644
--- a/tempest/api/network/base_security_groups.py
+++ b/tempest/api/network/base_security_groups.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/network/common.py b/tempest/api/network/common.py
index ae0eda1..d68ff1a 100644
--- a/tempest/api/network/common.py
+++ b/tempest/api/network/common.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
#
@@ -128,3 +126,21 @@
def delete(self):
self.client.delete_security_group_rule(self.id)
+
+
+class DeletablePool(DeletableResource):
+
+ def delete(self):
+ self.client.delete_pool(self.id)
+
+
+class DeletableMember(DeletableResource):
+
+ def delete(self):
+ self.client.delete_member(self.id)
+
+
+class DeletableVip(DeletableResource):
+
+ def delete(self):
+ self.client.delete_vip(self.id)
diff --git a/tempest/api/network/test_extensions.py b/tempest/api/network/test_extensions.py
index 9d872f9..529f8e9 100644
--- a/tempest/api/network/test_extensions.py
+++ b/tempest/api/network/test_extensions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack, Foundation
# All Rights Reserved.
#
@@ -46,6 +44,8 @@
'agent', 'dhcp_agent_scheduler', 'provider',
'router', 'extraroute', 'external-net',
'allowed-address-pairs', 'extra_dhcp_opt']
+ expected_alias = [ext for ext in expected_alias if
+ test.is_extension_enabled(ext, 'network')]
actual_alias = list()
resp, extensions = self.client.list_extensions()
self.assertEqual('200', resp['status'])
diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py
index 6f3fa4b..b31c090 100644
--- a/tempest/api/network/test_floating_ips.py
+++ b/tempest/api/network/test_floating_ips.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,7 +15,10 @@
from tempest.api.network import base
from tempest.common.utils import data_utils
-from tempest.test import attr
+from tempest import config
+from tempest import test
+
+CONF = config.CONF
class FloatingIPTestJSON(base.BaseNetworkTest):
@@ -45,7 +46,10 @@
@classmethod
def setUpClass(cls):
super(FloatingIPTestJSON, cls).setUpClass()
- cls.ext_net_id = cls.config.network.public_network_id
+ if not test.is_extension_enabled('router', 'network'):
+ msg = "router extension not enabled."
+ raise cls.skipException(msg)
+ cls.ext_net_id = CONF.network.public_network_id
# Create network, subnet, router and add interface
cls.network = cls.create_network()
@@ -58,7 +62,7 @@
for i in range(2):
cls.create_port(cls.network)
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_create_list_show_update_delete_floating_ip(self):
# Creates a floating IP
created_floating_ip = self.create_floating_ip(
@@ -109,12 +113,12 @@
self.assertIsNone(updated_floating_ip['fixed_ip_address'])
self.assertIsNone(updated_floating_ip['router_id'])
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_floating_ip_delete_port(self):
# Create a floating IP
created_floating_ip = self.create_floating_ip(self.ext_net_id)
# Create a port
- resp, port = self.client.create_port(self.network['id'])
+ resp, port = self.client.create_port(network_id=self.network['id'])
created_port = port['port']
resp, floating_ip = self.client.update_floating_ip(
created_floating_ip['id'], port_id=created_port['id'])
@@ -132,7 +136,7 @@
self.assertIsNone(shown_floating_ip['fixed_ip_address'])
self.assertIsNone(shown_floating_ip['router_id'])
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_floating_ip_update_different_router(self):
# Associate a floating IP to a port on a router
created_floating_ip = self.create_floating_ip(
diff --git a/tempest/api/network/test_load_balancer.py b/tempest/api/network/test_load_balancer.py
index d1ad134..d5f2b5b 100644
--- a/tempest/api/network/test_load_balancer.py
+++ b/tempest/api/network/test_load_balancer.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,7 +18,7 @@
from tempest import test
-class LoadBalancerJSON(base.BaseNetworkTest):
+class LoadBalancerTestJSON(base.BaseNetworkTest):
_interface = 'json'
"""
@@ -41,7 +39,7 @@
@classmethod
def setUpClass(cls):
- super(LoadBalancerJSON, cls).setUpClass()
+ super(LoadBalancerTestJSON, cls).setUpClass()
if not test.is_extension_enabled('lbaas', 'network'):
msg = "lbaas extension not enabled."
raise cls.skipException(msg)
@@ -212,5 +210,5 @@
self.assertEqual('204', resp['status'])
-class LoadBalancerXML(LoadBalancerJSON):
+class LoadBalancerTestXML(LoadBalancerTestJSON):
_interface = 'xml'
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index a064d44..e614ac1 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,9 +17,12 @@
from tempest.api.network import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
+
class NetworksTestJSON(base.BaseNetworkTest):
_interface = 'json'
@@ -67,23 +68,25 @@
def test_create_update_delete_network_subnet(self):
# Creates a network
name = data_utils.rand_name('network-')
- resp, body = self.client.create_network(name)
+ resp, body = self.client.create_network(name=name)
self.assertEqual('201', resp['status'])
network = body['network']
net_id = network['id']
# Verification of network update
new_name = "New_network"
- resp, body = self.client.update_network(net_id, new_name)
+ resp, body = self.client.update_network(net_id, name=new_name)
self.assertEqual('200', resp['status'])
updated_net = body['network']
self.assertEqual(updated_net['name'], new_name)
# Find a cidr that is not in use yet and create a subnet with it
- cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
- mask_bits = self.network_cfg.tenant_network_mask_bits
+ cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
+ mask_bits = CONF.network.tenant_network_mask_bits
for subnet_cidr in cidr.subnet(mask_bits):
try:
- resp, body = self.client.create_subnet(net_id,
- str(subnet_cidr))
+ resp, body = self.client.create_subnet(
+ network_id=net_id,
+ cidr=str(subnet_cidr),
+ ip_version=4)
break
except exceptions.BadRequest as e:
is_overlapping_cidr = 'overlaps with another subnet' in str(e)
@@ -94,7 +97,8 @@
subnet_id = subnet['id']
# Verification of subnet update
new_subnet = "New_subnet"
- resp, body = self.client.update_subnet(subnet_id, new_subnet)
+ resp, body = self.client.update_subnet(subnet_id,
+ name=new_subnet)
self.assertEqual('200', resp['status'])
updated_subnet = body['subnet']
self.assertEqual(updated_subnet['name'], new_subnet)
@@ -139,6 +143,21 @@
self.assertIsNotNone(found, msg)
@attr(type='smoke')
+ def test_list_networks_fields(self):
+ # Verify listing some fields of the networks
+ resp, body = self.client.list_networks(fields='id')
+ self.assertEqual('200', resp['status'])
+ networks = body['networks']
+ found = None
+ for n in networks:
+ self.assertEqual(len(n), 1)
+ self.assertIn('id', n)
+ if (n['id'] == self.network['id']):
+ found = n['id']
+ self.assertIsNotNone(found,
+ "Created network id not found in the list")
+
+ @attr(type='smoke')
def test_show_subnet(self):
# Verifies the details of a subnet
resp, body = self.client.show_subnet(self.subnet['id'])
@@ -173,14 +192,30 @@
self.assertIsNotNone(found, msg)
@attr(type='smoke')
+ def test_list_subnets_fields(self):
+ # Verify listing some fields of the subnets
+ resp, body = self.client.list_subnets(fields='id')
+ self.assertEqual('200', resp['status'])
+ subnets = body['subnets']
+ found = None
+ for n in subnets:
+ self.assertEqual(len(n), 1)
+ self.assertIn('id', n)
+ if (n['id'] == self.subnet['id']):
+ found = n['id']
+ self.assertIsNotNone(found,
+ "Created subnet id not found in the list")
+
+ @attr(type='smoke')
def test_create_update_delete_port(self):
# Verify that successful port creation, update & deletion
- resp, body = self.client.create_port(self.network['id'])
+ resp, body = self.client.create_port(
+ network_id=self.network['id'])
self.assertEqual('201', resp['status'])
port = body['port']
# Verification of port update
new_port = "New_Port"
- resp, body = self.client.update_port(port['id'], new_port)
+ resp, body = self.client.update_port(port['id'], name=new_port)
self.assertEqual('200', resp['status'])
updated_port = body['port']
self.assertEqual(updated_port['name'], new_port)
@@ -219,12 +254,27 @@
found = n['id']
self.assertIsNotNone(found, "Port list doesn't contain created port")
+ @attr(type='smoke')
+ def test_list_ports_fields(self):
+ # Verify listing some fields of the ports
+ resp, body = self.client.list_ports(fields='id')
+ self.assertEqual('200', resp['status'])
+ ports_list = body['ports']
+ found = None
+ for n in ports_list:
+ self.assertEqual(len(n), 1)
+ self.assertIn('id', n)
+ if (n['id'] == self.port['id']):
+ found = n['id']
+ self.assertIsNotNone(found,
+ "Created port id not found in the list")
+
class NetworksTestXML(NetworksTestJSON):
_interface = 'xml'
-class BulkNetworkOpsJSON(base.BaseNetworkTest):
+class BulkNetworkOpsTestJSON(base.BaseNetworkTest):
_interface = 'json'
"""
@@ -233,7 +283,7 @@
bulk network creation
bulk subnet creation
- bulk subnet creation
+ bulk port creation
list tenant's networks
v2.0 of the Neutron API is assumed. It is also assumed that the following
@@ -248,7 +298,7 @@
@classmethod
def setUpClass(cls):
- super(BulkNetworkOpsJSON, cls).setUpClass()
+ super(BulkNetworkOpsTestJSON, cls).setUpClass()
cls.network1 = cls.create_network()
cls.network2 = cls.create_network()
@@ -309,8 +359,8 @@
@attr(type='smoke')
def test_bulk_create_delete_subnet(self):
# Creates 2 subnets in one request
- cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
- mask_bits = self.network_cfg.tenant_network_mask_bits
+ cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
+ mask_bits = CONF.network.tenant_network_mask_bits
cidrs = []
for subnet_cidr in cidr.subnet(mask_bits):
cidrs.append(subnet_cidr)
@@ -375,5 +425,5 @@
self.assertIn(n['id'], ports_list)
-class BulkNetworkOpsXML(BulkNetworkOpsJSON):
+class BulkNetworkOpsTestXML(BulkNetworkOpsTestJSON):
_interface = 'xml'
diff --git a/tempest/api/network/test_networks_negative.py b/tempest/api/network/test_networks_negative.py
index 6820c25..89c8a9f 100644
--- a/tempest/api/network/test_networks_negative.py
+++ b/tempest/api/network/test_networks_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD.
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
@@ -47,7 +45,7 @@
def test_update_non_existent_network(self):
non_exist_id = data_utils.rand_name('network')
self.assertRaises(exceptions.NotFound, self.client.update_network,
- non_exist_id, "new_name")
+ non_exist_id, name="new_name")
@attr(type=['negative', 'smoke'])
def test_delete_non_existent_network(self):
diff --git a/tempest/api/network/test_quotas.py b/tempest/api/network/test_quotas.py
index 8b77637..38784d8 100644
--- a/tempest/api/network/test_quotas.py
+++ b/tempest/api/network/test_quotas.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,7 +17,7 @@
from tempest.api.network import base
from tempest import clients
from tempest.common.utils import data_utils
-from tempest.test import attr
+from tempest import test
class QuotasTest(base.BaseNetworkTest):
@@ -48,11 +46,14 @@
@classmethod
def setUpClass(cls):
super(QuotasTest, cls).setUpClass()
+ if not test.is_extension_enabled('quotas', 'network'):
+ msg = "quotas extension not enabled."
+ raise cls.skipException(msg)
admin_manager = clients.AdminManager()
cls.admin_client = admin_manager.network_client
cls.identity_admin_client = admin_manager.identity_client
- @attr(type='gate')
+ @test.attr(type='gate')
def test_quotas(self):
# Add a tenant to conduct the test
test_tenant = data_utils.rand_name('test_tenant_')
diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py
index b6022e8..d552c70 100644
--- a/tempest/api/network/test_routers.py
+++ b/tempest/api/network/test_routers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,8 +17,11 @@
from tempest.api.network import base_routers as base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import test
+CONF = config.CONF
+
class RoutersTest(base.BaseRouterTest):
_interface = 'json'
@@ -28,6 +29,9 @@
@classmethod
def setUpClass(cls):
super(RoutersTest, cls).setUpClass()
+ if not test.is_extension_enabled('router', 'network'):
+ msg = "router extension not enabled."
+ raise cls.skipException(msg)
@test.attr(type='smoke')
def test_create_show_list_update_delete_router(self):
@@ -37,14 +41,14 @@
name = data_utils.rand_name('router-')
resp, create_body = self.client.create_router(
name, external_gateway_info={
- "network_id": self.network_cfg.public_network_id},
+ "network_id": CONF.network.public_network_id},
admin_state_up=False)
self.assertEqual('201', resp['status'])
self.addCleanup(self._delete_router, create_body['router']['id'])
self.assertEqual(create_body['router']['name'], name)
self.assertEqual(
create_body['router']['external_gateway_info']['network_id'],
- self.network_cfg.public_network_id)
+ CONF.network.public_network_id)
self.assertEqual(create_body['router']['admin_state_up'], False)
# Show details of the created router
resp, show_body = self.client.show_router(
@@ -53,7 +57,7 @@
self.assertEqual(show_body['router']['name'], name)
self.assertEqual(
show_body['router']['external_gateway_info']['network_id'],
- self.network_cfg.public_network_id)
+ CONF.network.public_network_id)
self.assertEqual(show_body['router']['admin_state_up'], False)
# List routers and verify if created router is there in response
resp, list_body = self.client.list_routers()
@@ -96,7 +100,8 @@
network = self.create_network()
self.create_subnet(network)
router = self.create_router(data_utils.rand_name('router-'))
- resp, port_body = self.client.create_port(network['id'])
+ resp, port_body = self.client.create_port(
+ network_id=network['id'])
# add router interface to port created above
resp, interface = self.client.add_router_interface_with_port_id(
router['id'], port_body['port']['id'])
@@ -124,14 +129,14 @@
def _verify_gateway_port(self, router_id):
resp, list_body = self.admin_client.list_ports(
- network_id=self.network_cfg.public_network_id,
+ network_id=CONF.network.public_network_id,
device_id=router_id)
self.assertEqual(len(list_body['ports']), 1)
gw_port = list_body['ports'][0]
fixed_ips = gw_port['fixed_ips']
self.assertEqual(len(fixed_ips), 1)
resp, public_net_body = self.admin_client.show_network(
- self.network_cfg.public_network_id)
+ CONF.network.public_network_id)
public_subnet_id = public_net_body['network']['subnets'][0]
self.assertEqual(fixed_ips[0]['subnet_id'], public_subnet_id)
@@ -141,40 +146,42 @@
self.client.update_router(
router['id'],
external_gateway_info={
- 'network_id': self.network_cfg.public_network_id})
+ 'network_id': CONF.network.public_network_id})
# Verify operation - router
resp, show_body = self.client.show_router(router['id'])
self.assertEqual('200', resp['status'])
self._verify_router_gateway(
router['id'],
- {'network_id': self.network_cfg.public_network_id})
+ {'network_id': CONF.network.public_network_id})
self._verify_gateway_port(router['id'])
+ @test.requires_ext(extension='ext-gw-mode', service='network')
@test.attr(type='smoke')
def test_update_router_set_gateway_with_snat_explicit(self):
router = self.create_router(data_utils.rand_name('router-'))
self.admin_client.update_router_with_snat_gw_info(
router['id'],
external_gateway_info={
- 'network_id': self.network_cfg.public_network_id,
+ 'network_id': CONF.network.public_network_id,
'enable_snat': True})
self._verify_router_gateway(
router['id'],
- {'network_id': self.network_cfg.public_network_id,
+ {'network_id': CONF.network.public_network_id,
'enable_snat': True})
self._verify_gateway_port(router['id'])
+ @test.requires_ext(extension='ext-gw-mode', service='network')
@test.attr(type='smoke')
def test_update_router_set_gateway_without_snat(self):
router = self.create_router(data_utils.rand_name('router-'))
self.admin_client.update_router_with_snat_gw_info(
router['id'],
external_gateway_info={
- 'network_id': self.network_cfg.public_network_id,
+ 'network_id': CONF.network.public_network_id,
'enable_snat': False})
self._verify_router_gateway(
router['id'],
- {'network_id': self.network_cfg.public_network_id,
+ {'network_id': CONF.network.public_network_id,
'enable_snat': False})
self._verify_gateway_port(router['id'])
@@ -182,28 +189,29 @@
def test_update_router_unset_gateway(self):
router = self.create_router(
data_utils.rand_name('router-'),
- external_network_id=self.network_cfg.public_network_id)
+ external_network_id=CONF.network.public_network_id)
self.client.update_router(router['id'], external_gateway_info={})
self._verify_router_gateway(router['id'])
# No gateway port expected
resp, list_body = self.admin_client.list_ports(
- network_id=self.network_cfg.public_network_id,
+ network_id=CONF.network.public_network_id,
device_id=router['id'])
self.assertFalse(list_body['ports'])
+ @test.requires_ext(extension='ext-gw-mode', service='network')
@test.attr(type='smoke')
def test_update_router_reset_gateway_without_snat(self):
router = self.create_router(
data_utils.rand_name('router-'),
- external_network_id=self.network_cfg.public_network_id)
+ external_network_id=CONF.network.public_network_id)
self.admin_client.update_router_with_snat_gw_info(
router['id'],
external_gateway_info={
- 'network_id': self.network_cfg.public_network_id,
+ 'network_id': CONF.network.public_network_id,
'enable_snat': False})
self._verify_router_gateway(
router['id'],
- {'network_id': self.network_cfg.public_network_id,
+ {'network_id': CONF.network.public_network_id,
'enable_snat': False})
self._verify_gateway_port(router['id'])
diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py
index 520a612..e6ad4de 100644
--- a/tempest/api/network/test_routers_negative.py
+++ b/tempest/api/network/test_routers_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,7 +16,7 @@
from tempest.api.network import base_routers as base
from tempest.common.utils import data_utils
from tempest import exceptions
-from tempest.test import attr
+from tempest import test
class RoutersNegativeTest(base.BaseRouterTest):
@@ -27,11 +25,14 @@
@classmethod
def setUpClass(cls):
super(RoutersNegativeTest, cls).setUpClass()
+ if not test.is_extension_enabled('router', 'network'):
+ msg = "router extension not enabled."
+ raise cls.skipException(msg)
cls.router = cls.create_router(data_utils.rand_name('router-'))
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
- @attr(type=['negative', 'smoke'])
+ @test.attr(type=['negative', 'smoke'])
def test_router_add_gateway_invalid_network_returns_404(self):
self.assertRaises(exceptions.NotFound,
self.client.update_router,
@@ -39,7 +40,7 @@
external_gateway_info={
'network_id': self.router['id']})
- @attr(type=['negative', 'smoke'])
+ @test.attr(type=['negative', 'smoke'])
def test_router_add_gateway_net_not_external_returns_400(self):
self.create_subnet(self.network)
self.assertRaises(exceptions.BadRequest,
@@ -48,7 +49,7 @@
external_gateway_info={
'network_id': self.network['id']})
- @attr(type=['negative', 'smoke'])
+ @test.attr(type=['negative', 'smoke'])
def test_router_remove_interface_in_use_returns_409(self):
self.client.add_router_interface_with_subnet_id(
self.router['id'], self.subnet['id'])
diff --git a/tempest/api/network/test_security_groups.py b/tempest/api/network/test_security_groups.py
index 9b0a3de..6eebf5b 100644
--- a/tempest/api/network/test_security_groups.py
+++ b/tempest/api/network/test_security_groups.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,13 +14,20 @@
# under the License.
from tempest.api.network import base_security_groups as base
-from tempest.test import attr
+from tempest import test
class SecGroupTest(base.BaseSecGroupTest):
_interface = 'json'
- @attr(type='smoke')
+ @classmethod
+ def setUpClass(cls):
+ super(SecGroupTest, cls).setUpClass()
+ if not test.is_extension_enabled('security-group', 'network'):
+ msg = "security-group extension not enabled."
+ raise cls.skipException(msg)
+
+ @test.attr(type='smoke')
def test_list_security_groups(self):
# Verify the that security group belonging to tenant exist in list
resp, body = self.client.list_security_groups()
@@ -35,7 +40,7 @@
msg = "Security-group list doesn't contain default security-group"
self.assertIsNotNone(found, msg)
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_create_show_delete_security_group(self):
group_create_body, name = self._create_security_group()
@@ -53,7 +58,7 @@
secgroup_list.append(secgroup['id'])
self.assertIn(group_create_body['security_group']['id'], secgroup_list)
- @attr(type='smoke')
+ @test.attr(type='smoke')
def test_create_show_delete_security_group_rule(self):
group_create_body, _ = self._create_security_group()
@@ -82,6 +87,36 @@
for rule in rule_list_body['security_group_rules']]
self.assertIn(rule_create_body['security_group_rule']['id'], rule_list)
+ @test.attr(type='smoke')
+ def test_create_security_group_rule_with_additional_args(self):
+ # Verify creating security group rule with the following
+ # arguments works: "protocol": "tcp", "port_range_max": 77,
+ # "port_range_min": 77, "direction":"ingress".
+ group_create_body, _ = self._create_security_group()
+
+ direction = 'ingress'
+ protocol = 'tcp'
+ port_range_min = 77
+ port_range_max = 77
+ resp, rule_create_body = self.client.create_security_group_rule(
+ group_create_body['security_group']['id'],
+ direction=direction,
+ protocol=protocol,
+ port_range_min=port_range_min,
+ port_range_max=port_range_max
+ )
+
+ self.assertEqual('201', resp['status'])
+ sec_group_rule = rule_create_body['security_group_rule']
+ self.addCleanup(self._delete_security_group_rule,
+ sec_group_rule['id']
+ )
+
+ self.assertEqual(sec_group_rule['direction'], direction)
+ self.assertEqual(sec_group_rule['protocol'], protocol)
+ self.assertEqual(int(sec_group_rule['port_range_min']), port_range_min)
+ self.assertEqual(int(sec_group_rule['port_range_max']), port_range_max)
+
class SecGroupTestXML(SecGroupTest):
_interface = 'xml'
diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py
index 32f4c95..e1f4055 100644
--- a/tempest/api/network/test_security_groups_negative.py
+++ b/tempest/api/network/test_security_groups_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,26 +17,33 @@
from tempest.api.network import base_security_groups as base
from tempest import exceptions
-from tempest.test import attr
+from tempest import test
class NegativeSecGroupTest(base.BaseSecGroupTest):
_interface = 'json'
- @attr(type=['negative', 'gate'])
+ @classmethod
+ def setUpClass(cls):
+ super(NegativeSecGroupTest, cls).setUpClass()
+ if not test.is_extension_enabled('security-group', 'network'):
+ msg = "security-group extension not enabled."
+ raise cls.skipException(msg)
+
+ @test.attr(type=['negative', 'gate'])
def test_show_non_existent_security_group(self):
non_exist_id = str(uuid.uuid4())
self.assertRaises(exceptions.NotFound, self.client.show_security_group,
non_exist_id)
- @attr(type=['negative', 'gate'])
+ @test.attr(type=['negative', 'gate'])
def test_show_non_existent_security_group_rule(self):
non_exist_id = str(uuid.uuid4())
self.assertRaises(exceptions.NotFound,
self.client.show_security_group_rule,
non_exist_id)
- @attr(type=['negative', 'gate'])
+ @test.attr(type=['negative', 'gate'])
def test_delete_non_existent_security_group(self):
non_exist_id = str(uuid.uuid4())
self.assertRaises(exceptions.NotFound,
@@ -46,7 +51,7 @@
non_exist_id
)
- @attr(type=['negative', 'gate'])
+ @test.attr(type=['negative', 'gate'])
def test_create_security_group_rule_with_bad_protocol(self):
group_create_body, _ = self._create_security_group()
@@ -57,7 +62,7 @@
group_create_body['security_group']['id'],
protocol=pname)
- @attr(type=['negative', 'gate'])
+ @test.attr(type=['negative', 'gate'])
def test_create_security_group_rule_with_invalid_ports(self):
group_create_body, _ = self._create_security_group()
@@ -75,7 +80,7 @@
port_range_max=pmax)
self.assertIn(msg, str(ex))
- @attr(type=['negative', 'smoke'])
+ @test.attr(type=['negative', 'smoke'])
def test_create_additional_default_security_group_fails(self):
# Create security group named 'default', it should be failed.
name = 'default'
@@ -83,7 +88,7 @@
self.client.create_security_group,
name)
- @attr(type=['negative', 'smoke'])
+ @test.attr(type=['negative', 'smoke'])
def test_create_security_group_rule_with_non_existent_security_group(self):
# Create security group rules with not existing security group.
non_existent_sg = str(uuid.uuid4())
diff --git a/tempest/api/network/test_service_type_management.py b/tempest/api/network/test_service_type_management.py
index da6800b..d272c47 100644
--- a/tempest/api/network/test_service_type_management.py
+++ b/tempest/api/network/test_service_type_management.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# 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
diff --git a/tempest/api/network/test_vpnaas_extensions.py b/tempest/api/network/test_vpnaas_extensions.py
index d196886..78bc80a 100644
--- a/tempest/api/network/test_vpnaas_extensions.py
+++ b/tempest/api/network/test_vpnaas_extensions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,8 +15,11 @@
from tempest.api.network import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import test
+CONF = config.CONF
+
class VPNaaSJSON(base.BaseNetworkTest):
_interface = 'json'
@@ -37,15 +38,15 @@
@classmethod
def setUpClass(cls):
- super(VPNaaSJSON, cls).setUpClass()
if not test.is_extension_enabled('vpnaas', 'network'):
msg = "vpnaas extension not enabled."
raise cls.skipException(msg)
+ super(VPNaaSJSON, cls).setUpClass()
cls.network = cls.create_network()
cls.subnet = cls.create_subnet(cls.network)
cls.router = cls.create_router(
data_utils.rand_name("router-"),
- external_network_id=cls.network_cfg.public_network_id)
+ external_network_id=CONF.network.public_network_id)
cls.create_router_interface(cls.router['id'], cls.subnet['id'])
cls.vpnservice = cls.create_vpnservice(cls.subnet['id'],
cls.router['id'])
diff --git a/tempest/api/object_storage/base.py b/tempest/api/object_storage/base.py
index e7cb806..ef36c3d 100644
--- a/tempest/api/object_storage/base.py
+++ b/tempest/api/object_storage/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,20 +18,25 @@
from tempest import clients
from tempest.common import custom_matchers
from tempest.common import isolated_creds
+from tempest import config
from tempest import exceptions
import tempest.test
+CONF = config.CONF
+
class BaseObjectTest(tempest.test.BaseTestCase):
@classmethod
def setUpClass(cls):
+ cls.set_network_resources()
super(BaseObjectTest, cls).setUpClass()
- if not cls.config.service_available.swift:
+ if not CONF.service_available.swift:
skip_msg = ("%s skipped as swift is not available" % cls.__name__)
raise cls.skipException(skip_msg)
- cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
- if cls.config.compute.allow_tenant_isolation:
+ cls.isolated_creds = isolated_creds.IsolatedCreds(
+ cls.__name__, network_resources=cls.network_resources)
+ if CONF.compute.allow_tenant_isolation:
# Get isolated creds for normal user
creds = cls.isolated_creds.get_primary_creds()
username, tenant_name, password = creds
@@ -71,6 +74,15 @@
cls.container_client_alt = cls.os_alt.container_client
cls.identity_client_alt = cls.os_alt.identity_client
+ # Make sure we get fresh auth data after assigning swift role
+ cls.object_client.auth_provider.clear_auth()
+ cls.container_client.auth_provider.clear_auth()
+ cls.account_client.auth_provider.clear_auth()
+ cls.custom_object_client.auth_provider.clear_auth()
+ cls.custom_account_client.auth_provider.clear_auth()
+ cls.object_client_alt.auth_provider.clear_auth()
+ cls.container_client_alt.auth_provider.clear_auth()
+
cls.data = DataGenerator(cls.identity_admin_client)
@classmethod
@@ -82,7 +94,7 @@
def _assign_member_role(cls):
primary_user = cls.isolated_creds.get_primary_user()
alt_user = cls.isolated_creds.get_alt_user()
- swift_role = cls.config.object_storage.operator_role
+ swift_role = CONF.object_storage.operator_role
try:
resp, roles = cls.os_admin.identity_client.list_roles()
role = next(r for r in roles if r['name'] == swift_role)
@@ -101,6 +113,7 @@
The containers should be visible from the container_client given.
Will not throw any error if the containers don't exist.
+ Will not check that object and container deletions succeed.
:param containers: list of container names to remove
:param container_client: if None, use cls.container_client, this means
diff --git a/tempest/api/object_storage/test_account_bulk.py b/tempest/api/object_storage/test_account_bulk.py
new file mode 100644
index 0000000..5fde76a
--- /dev/null
+++ b/tempest/api/object_storage/test_account_bulk.py
@@ -0,0 +1,136 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 NTT Corporation
+#
+# 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 tarfile
+import tempfile
+
+from tempest.api.object_storage import base
+from tempest.common import custom_matchers
+from tempest import test
+
+
+class BulkTest(base.BaseObjectTest):
+
+ def setUp(self):
+ super(BulkTest, self).setUp()
+ self.containers = []
+
+ def tearDown(self):
+ self.delete_containers(self.containers)
+ super(BulkTest, self).tearDown()
+
+ def _create_archive(self):
+ # Create an archived file for bulk upload testing.
+ # Directory and files contained in the directory correspond to
+ # container and subsidiary objects.
+ tmp_dir = tempfile.mkdtemp()
+ tmp_file = tempfile.mkstemp(dir=tmp_dir)
+
+ # Extract a container name and an object name
+ container_name = tmp_dir.split("/")[-1]
+ object_name = tmp_file[1].split("/")[-1]
+
+ # Create tar file
+ tarpath = tempfile.NamedTemporaryFile(suffix=".tar")
+ tar = tarfile.open(None, 'w', tarpath)
+ tar.add(tmp_dir, arcname=container_name)
+ tar.close()
+ tarpath.flush()
+
+ return tarpath.name, container_name, object_name
+
+ @test.attr(type='gate')
+ def test_extract_archive(self):
+ # Test bulk operation of file upload with an archived file
+ filepath, container_name, object_name = self._create_archive()
+
+ params = {'extract-archive': 'tar'}
+ with open(filepath) as fh:
+ mydata = fh.read()
+ resp, body = self.account_client.create_account(data=mydata,
+ params=params)
+
+ self.containers.append(container_name)
+
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
+
+ # When uploading an archived file with the bulk operation, the response
+ # does not contain 'content-length' header. This is the special case,
+ # therefore the existence of response headers is checked without
+ # custom matcher.
+ self.assertIn('transfer-encoding', resp)
+ self.assertIn('content-type', resp)
+ self.assertIn('x-trans-id', resp)
+ self.assertIn('date', resp)
+
+ # Check only the format of common headers with custom matcher
+ self.assertThat(resp, custom_matchers.AreAllWellFormatted())
+
+ param = {'format': 'json'}
+ resp, body = self.account_client.list_account_containers(param)
+
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Account', 'GET')
+
+ self.assertIn(container_name, [b['name'] for b in body])
+
+ param = {'format': 'json'}
+ resp, contents_list = self.container_client.list_container_contents(
+ container_name, param)
+
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+
+ self.assertIn(object_name, [c['name'] for c in contents_list])
+
+ @test.attr(type='gate')
+ def test_bulk_delete(self):
+ # Test bulk operation of deleting multiple files
+ filepath, container_name, object_name = self._create_archive()
+
+ params = {'extract-archive': 'tar'}
+ with open(filepath) as fh:
+ mydata = fh.read()
+ resp, body = self.account_client.create_account(data=mydata,
+ params=params)
+
+ data = '%s/%s\n%s' % (container_name, object_name, container_name)
+ params = {'bulk-delete': ''}
+ resp, body = self.account_client.delete_account(data=data,
+ params=params)
+
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
+
+ # When deleting multiple files using the bulk operation, the response
+ # does not contain 'content-length' header. This is the special case,
+ # therefore the existence of response headers is checked without
+ # custom matcher.
+ self.assertIn('transfer-encoding', resp)
+ self.assertIn('content-type', resp)
+ self.assertIn('x-trans-id', resp)
+ self.assertIn('date', resp)
+
+ # Check only the format of common headers with custom matcher
+ self.assertThat(resp, custom_matchers.AreAllWellFormatted())
+
+ # Check if a container is deleted
+ param = {'format': 'txt'}
+ resp, body = self.account_client.list_account_containers(param)
+
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Account', 'GET')
+
+ self.assertNotIn(container_name, body)
diff --git a/tempest/api/object_storage/test_account_quotas.py b/tempest/api/object_storage/test_account_quotas.py
index ac1c7d1..788292d 100644
--- a/tempest/api/object_storage/test_account_quotas.py
+++ b/tempest/api/object_storage/test_account_quotas.py
@@ -14,21 +14,14 @@
# License for the specific language governing permissions and limitations
# under the License.
-import testtools
-
from tempest.api.object_storage import base
from tempest import clients
from tempest.common.utils import data_utils
-from tempest import config
from tempest import exceptions
-from tempest.test import attr
-
-CONF = config.CONF
+from tempest import test
class AccountQuotasTest(base.BaseObjectTest):
- accounts_quotas_available = \
- CONF.object_storage_feature_enabled.accounts_quotas
@classmethod
def setUpClass(cls):
@@ -69,26 +62,34 @@
reseller_user_id,
reseller_role_id)
- # Retrieve a ResellerAdmin auth token and use it to set a quota
+ # Retrieve a ResellerAdmin auth data and use it to set a quota
# on the client's account
- cls.reselleradmin_token = cls.token_client.get_token(
- cls.data.test_user,
- cls.data.test_password,
- cls.data.test_tenant)
+ cls.reselleradmin_auth_data = \
+ cls.os_reselleradmin.get_auth_provider().auth_data
def setUp(self):
super(AccountQuotasTest, self).setUp()
+ # Set the reselleradmin auth in headers for next custom_account_client
+ # request
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.reselleradmin_auth_data
+ )
# Set a quota of 20 bytes on the user's account before each test
- headers = {"X-Auth-Token": self.reselleradmin_token,
- "X-Account-Meta-Quota-Bytes": "20"}
+ headers = {"X-Account-Meta-Quota-Bytes": "20"}
self.os.custom_account_client.request("POST", "", headers, "")
def tearDown(self):
+ # Set the reselleradmin auth in headers for next custom_account_client
+ # request
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.reselleradmin_auth_data
+ )
# remove the quota from the container
- headers = {"X-Auth-Token": self.reselleradmin_token,
- "X-Remove-Account-Meta-Quota-Bytes": "x"}
+ headers = {"X-Remove-Account-Meta-Quota-Bytes": "x"}
self.os.custom_account_client.request("POST", "", headers, "")
super(AccountQuotasTest, self).tearDown()
@@ -99,9 +100,8 @@
cls.data.teardown_all()
super(AccountQuotasTest, cls).tearDownClass()
- @testtools.skipIf(not accounts_quotas_available,
- "Account Quotas middleware not available")
- @attr(type="smoke")
+ @test.attr(type="smoke")
+ @test.requires_ext(extension='account_quotas', service='object')
def test_upload_valid_object(self):
object_name = data_utils.rand_name(name="TestObject")
data = data_utils.arbitrary_string()
@@ -111,19 +111,8 @@
self.assertEqual(resp["status"], "201")
self.assertHeaders(resp, 'Object', 'PUT')
- @testtools.skipIf(not accounts_quotas_available,
- "Account Quotas middleware not available")
- @attr(type=["negative", "smoke"])
- def test_upload_large_object(self):
- object_name = data_utils.rand_name(name="TestObject")
- data = data_utils.arbitrary_string(30)
- self.assertRaises(exceptions.OverLimit,
- self.object_client.create_object,
- self.container_name, object_name, data)
-
- @testtools.skipIf(not accounts_quotas_available,
- "Account Quotas middleware not available")
- @attr(type=["smoke"])
+ @test.attr(type=["smoke"])
+ @test.requires_ext(extension='account_quotas', service='object')
def test_admin_modify_quota(self):
"""Test that the ResellerAdmin is able to modify and remove the quota
on a user's account.
@@ -137,29 +126,14 @@
"""
for quota in ("25", "", "20"):
- headers = {"X-Auth-Token": self.reselleradmin_token,
- "X-Account-Meta-Quota-Bytes": quota}
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.reselleradmin_auth_data
+ )
+ headers = {"X-Account-Meta-Quota-Bytes": quota}
resp, _ = self.os.custom_account_client.request("POST", "",
headers, "")
self.assertEqual(resp["status"], "204")
self.assertHeaders(resp, 'Account', 'POST')
-
- @testtools.skipIf(not accounts_quotas_available,
- "Account Quotas middleware not available")
- @attr(type=["negative", "smoke"])
- def test_user_modify_quota(self):
- """Test that a user is not able to modify or remove a quota on
- its account.
- """
-
- # Not able to remove quota
- self.assertRaises(exceptions.Unauthorized,
- self.account_client.create_account_metadata,
- {"Quota-Bytes": ""})
-
- # Not able to modify quota
- self.assertRaises(exceptions.Unauthorized,
- self.account_client.create_account_metadata,
- {"Quota-Bytes": "100"})
diff --git a/tempest/api/object_storage/test_account_quotas_negative.py b/tempest/api/object_storage/test_account_quotas_negative.py
new file mode 100644
index 0000000..cab307d
--- /dev/null
+++ b/tempest/api/object_storage/test_account_quotas_negative.py
@@ -0,0 +1,126 @@
+# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
+#
+# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
+#
+# 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 tempest.api.object_storage import base
+from tempest import clients
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest import test
+
+
+class AccountQuotasNegativeTest(base.BaseObjectTest):
+
+ @classmethod
+ def setUpClass(cls):
+ super(AccountQuotasNegativeTest, cls).setUpClass()
+ cls.container_name = data_utils.rand_name(name="TestContainer")
+ cls.container_client.create_container(cls.container_name)
+
+ cls.data.setup_test_user()
+
+ cls.os_reselleradmin = clients.Manager(
+ cls.data.test_user,
+ cls.data.test_password,
+ cls.data.test_tenant)
+
+ # Retrieve the ResellerAdmin role id
+ reseller_role_id = None
+ try:
+ _, roles = cls.os_admin.identity_client.list_roles()
+ reseller_role_id = next(r['id'] for r in roles if r['name']
+ == 'ResellerAdmin')
+ except StopIteration:
+ msg = "No ResellerAdmin role found"
+ raise exceptions.NotFound(msg)
+
+ # Retrieve the ResellerAdmin tenant id
+ _, users = cls.os_admin.identity_client.get_users()
+ reseller_user_id = next(usr['id'] for usr in users if usr['name']
+ == cls.data.test_user)
+
+ # Retrieve the ResellerAdmin tenant id
+ _, tenants = cls.os_admin.identity_client.list_tenants()
+ reseller_tenant_id = next(tnt['id'] for tnt in tenants if tnt['name']
+ == cls.data.test_tenant)
+
+ # Assign the newly created user the appropriate ResellerAdmin role
+ cls.os_admin.identity_client.assign_user_role(
+ reseller_tenant_id,
+ reseller_user_id,
+ reseller_role_id)
+
+ # Retrieve a ResellerAdmin auth data and use it to set a quota
+ # on the client's account
+ cls.reselleradmin_auth_data = \
+ cls.os_reselleradmin.get_auth_provider().auth_data
+
+ def setUp(self):
+ super(AccountQuotasNegativeTest, self).setUp()
+ # Set the reselleradmin auth in headers for next custom_account_client
+ # request
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.reselleradmin_auth_data
+ )
+ # Set a quota of 20 bytes on the user's account before each test
+ headers = {"X-Account-Meta-Quota-Bytes": "20"}
+
+ self.os.custom_account_client.request("POST", "", headers, "")
+
+ def tearDown(self):
+ # Set the reselleradmin auth in headers for next custom_account_client
+ # request
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.reselleradmin_auth_data
+ )
+ # remove the quota from the container
+ headers = {"X-Remove-Account-Meta-Quota-Bytes": "x"}
+
+ self.os.custom_account_client.request("POST", "", headers, "")
+ super(AccountQuotasNegativeTest, self).tearDown()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.delete_containers([cls.container_name])
+ cls.data.teardown_all()
+ super(AccountQuotasNegativeTest, cls).tearDownClass()
+
+ @test.attr(type=["negative", "smoke"])
+ @test.requires_ext(extension='account_quotas', service='object')
+ def test_user_modify_quota(self):
+ """Test that a user is not able to modify or remove a quota on
+ its account.
+ """
+
+ # Not able to remove quota
+ self.assertRaises(exceptions.Unauthorized,
+ self.account_client.create_account_metadata,
+ {"Quota-Bytes": ""})
+
+ # Not able to modify quota
+ self.assertRaises(exceptions.Unauthorized,
+ self.account_client.create_account_metadata,
+ {"Quota-Bytes": "100"})
+
+ @test.attr(type=["negative", "smoke"])
+ @test.requires_ext(extension='account_quotas', service='object')
+ def test_upload_large_object(self):
+ object_name = data_utils.rand_name(name="TestObject")
+ data = data_utils.arbitrary_string(30)
+ self.assertRaises(exceptions.OverLimit,
+ self.object_client.create_object,
+ self.container_name, object_name, data)
diff --git a/tempest/api/object_storage/test_account_services.py b/tempest/api/object_storage/test_account_services.py
index 12c823b..79fd99d 100644
--- a/tempest/api/object_storage/test_account_services.py
+++ b/tempest/api/object_storage/test_account_services.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,8 +16,8 @@
import random
from tempest.api.object_storage import base
+from tempest.common import custom_matchers
from tempest.common.utils import data_utils
-from tempest import exceptions
from tempest.test import attr
from tempest.test import HTTP_SUCCESS
@@ -54,6 +52,13 @@
self.assertIn(container_name, container_names)
@attr(type='smoke')
+ def test_list_extensions(self):
+ resp, extensions = self.account_client.list_extensions()
+
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertThat(resp, custom_matchers.AreAllWellFormatted())
+
+ @attr(type='smoke')
def test_list_containers_with_limit(self):
# list containers one of them, half of them then all of them
for limit in (1, self.containers_count / 2, self.containers_count):
@@ -148,26 +153,3 @@
resp, _ = self.account_client.list_account_metadata()
self.assertHeaders(resp, 'Account', 'HEAD')
self.assertNotIn('x-account-meta-' + header, resp)
-
- @attr(type=['negative', 'gate'])
- def test_list_containers_with_non_authorized_user(self):
- # list containers using non-authorized user
-
- # create user
- self.data.setup_test_user()
- resp, body = \
- self.token_client.auth(self.data.test_user,
- self.data.test_password,
- self.data.test_tenant)
- new_token = \
- self.token_client.get_token(self.data.test_user,
- self.data.test_password,
- self.data.test_tenant)
- custom_headers = {'X-Auth-Token': new_token}
- params = {'format': 'json'}
- # list containers with non-authorized user token
- self.assertRaises(exceptions.Unauthorized,
- self.custom_account_client.list_account_containers,
- params=params, metadata=custom_headers)
- # delete the user which was created
- self.data.teardown_all()
diff --git a/tempest/api/object_storage/test_account_services_negative.py b/tempest/api/object_storage/test_account_services_negative.py
new file mode 100644
index 0000000..ea93aa3
--- /dev/null
+++ b/tempest/api/object_storage/test_account_services_negative.py
@@ -0,0 +1,53 @@
+# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
+#
+# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
+#
+# 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 tempest.api.object_storage import base
+from tempest import clients
+from tempest import exceptions
+from tempest.test import attr
+
+
+class AccountNegativeTest(base.BaseObjectTest):
+
+ @attr(type=['negative', 'gate'])
+ def test_list_containers_with_non_authorized_user(self):
+ # list containers using non-authorized user
+
+ # create user
+ self.data.setup_test_user()
+ test_os = clients.Manager(self.data.test_user,
+ self.data.test_password,
+ self.data.test_tenant)
+ test_auth_provider = test_os.get_auth_provider()
+ # Get auth for the test user
+ test_auth_provider.auth_data
+
+ # Get fresh auth for test user and set it to next auth request for
+ # custom_account_client
+ delattr(test_auth_provider, 'auth_data')
+ test_auth_new_data = test_auth_provider.auth_data
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=test_auth_new_data
+ )
+
+ params = {'format': 'json'}
+ # list containers with non-authorized user token
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_account_client.list_account_containers,
+ params=params)
+ # delete the user which was created
+ self.data.teardown_all()
diff --git a/tempest/api/object_storage/test_container_acl.py b/tempest/api/object_storage/test_container_acl.py
index b2dc20f..aae6b4d 100644
--- a/tempest/api/object_storage/test_container_acl.py
+++ b/tempest/api/object_storage/test_container_acl.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,8 +14,8 @@
# under the License.
from tempest.api.object_storage import base
+from tempest import clients
from tempest.common.utils import data_utils
-from tempest import exceptions
from tempest.test import attr
from tempest.test import HTTP_SUCCESS
@@ -27,10 +25,10 @@
def setUpClass(cls):
super(ObjectTestACLs, cls).setUpClass()
cls.data.setup_test_user()
- cls.new_token = cls.token_client.get_token(cls.data.test_user,
- cls.data.test_password,
- cls.data.test_tenant)
- cls.custom_headers = {'X-Auth-Token': cls.new_token}
+ test_os = clients.Manager(cls.data.test_user,
+ cls.data.test_password,
+ cls.data.test_tenant)
+ cls.test_auth_data = test_os.get_auth_provider().auth_data
@classmethod
def tearDownClass(cls):
@@ -46,108 +44,6 @@
self.delete_containers([self.container_name])
super(ObjectTestACLs, self).tearDown()
- @attr(type=['negative', 'gate'])
- def test_write_object_without_using_creds(self):
- # trying to create object with empty headers
- # X-Auth-Token is not provided
- object_name = data_utils.rand_name(name='Object')
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.create_object,
- self.container_name, object_name, 'data')
-
- @attr(type=['negative', 'gate'])
- def test_delete_object_without_using_creds(self):
- # create object
- object_name = data_utils.rand_name(name='Object')
- resp, _ = self.object_client.create_object(self.container_name,
- object_name, 'data')
- # trying to delete object with empty headers
- # X-Auth-Token is not provided
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.delete_object,
- self.container_name, object_name)
-
- @attr(type=['negative', 'gate'])
- def test_write_object_with_non_authorized_user(self):
- # attempt to upload another file using non-authorized user
- # User provided token is forbidden. ACL are not set
- object_name = data_utils.rand_name(name='Object')
- # trying to create object with non-authorized user
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.create_object,
- self.container_name, object_name, 'data',
- metadata=self.custom_headers)
-
- @attr(type=['negative', 'gate'])
- def test_read_object_with_non_authorized_user(self):
- # attempt to read object using non-authorized user
- # User provided token is forbidden. ACL are not set
- object_name = data_utils.rand_name(name='Object')
- resp, _ = self.object_client.create_object(
- self.container_name, object_name, 'data')
- self.assertEqual(resp['status'], '201')
- self.assertHeaders(resp, 'Object', 'PUT')
- # trying to get object with non authorized user token
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.get_object,
- self.container_name, object_name,
- metadata=self.custom_headers)
-
- @attr(type=['negative', 'gate'])
- def test_delete_object_with_non_authorized_user(self):
- # attempt to delete object using non-authorized user
- # User provided token is forbidden. ACL are not set
- object_name = data_utils.rand_name(name='Object')
- resp, _ = self.object_client.create_object(
- self.container_name, object_name, 'data')
- self.assertEqual(resp['status'], '201')
- self.assertHeaders(resp, 'Object', 'PUT')
- # trying to delete object with non-authorized user token
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.delete_object,
- self.container_name, object_name,
- metadata=self.custom_headers)
-
- @attr(type=['negative', 'smoke'])
- def test_read_object_without_rights(self):
- # attempt to read object using non-authorized user
- # update X-Container-Read metadata ACL
- cont_headers = {'X-Container-Read': 'badtenant:baduser'}
- resp_meta, body = self.container_client.update_container_metadata(
- self.container_name, metadata=cont_headers,
- metadata_prefix='')
- self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
- self.assertHeaders(resp_meta, 'Container', 'POST')
- # create object
- object_name = data_utils.rand_name(name='Object')
- resp, _ = self.object_client.create_object(self.container_name,
- object_name, 'data')
- self.assertEqual(resp['status'], '201')
- self.assertHeaders(resp, 'Object', 'PUT')
- # Trying to read the object without rights
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.get_object,
- self.container_name, object_name,
- metadata=self.custom_headers)
-
- @attr(type=['negative', 'smoke'])
- def test_write_object_without_rights(self):
- # attempt to write object using non-authorized user
- # update X-Container-Write metadata ACL
- cont_headers = {'X-Container-Write': 'badtenant:baduser'}
- resp_meta, body = self.container_client.update_container_metadata(
- self.container_name, metadata=cont_headers,
- metadata_prefix='')
- self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
- self.assertHeaders(resp_meta, 'Container', 'POST')
- # Trying to write the object without rights
- object_name = data_utils.rand_name(name='Object')
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.create_object,
- self.container_name,
- object_name, 'data',
- metadata=self.custom_headers)
-
@attr(type='smoke')
def test_read_object_with_rights(self):
# attempt to read object using authorized user
@@ -166,9 +62,12 @@
self.assertEqual(resp['status'], '201')
self.assertHeaders(resp, 'Object', 'PUT')
# Trying to read the object with rights
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
resp, _ = self.custom_object_client.get_object(
- self.container_name, object_name,
- metadata=self.custom_headers)
+ self.container_name, object_name)
self.assertIn(int(resp['status']), HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'GET')
@@ -184,55 +83,13 @@
self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
self.assertHeaders(resp_meta, 'Container', 'POST')
# Trying to write the object with rights
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
object_name = data_utils.rand_name(name='Object')
resp, _ = self.custom_object_client.create_object(
self.container_name,
- object_name, 'data',
- metadata=self.custom_headers)
+ object_name, 'data')
self.assertIn(int(resp['status']), HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'PUT')
-
- @attr(type=['negative', 'smoke'])
- def test_write_object_without_write_rights(self):
- # attempt to write object using non-authorized user
- # update X-Container-Read and X-Container-Write metadata ACL
- cont_headers = {'X-Container-Read':
- self.data.test_tenant + ':' + self.data.test_user,
- 'X-Container-Write': ''}
- resp_meta, body = self.container_client.update_container_metadata(
- self.container_name, metadata=cont_headers,
- metadata_prefix='')
- self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
- self.assertHeaders(resp_meta, 'Container', 'POST')
- # Trying to write the object without write rights
- object_name = data_utils.rand_name(name='Object')
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.create_object,
- self.container_name,
- object_name, 'data',
- metadata=self.custom_headers)
-
- @attr(type=['negative', 'smoke'])
- def test_delete_object_without_write_rights(self):
- # attempt to delete object using non-authorized user
- # update X-Container-Read and X-Container-Write metadata ACL
- cont_headers = {'X-Container-Read':
- self.data.test_tenant + ':' + self.data.test_user,
- 'X-Container-Write': ''}
- resp_meta, body = self.container_client.update_container_metadata(
- self.container_name, metadata=cont_headers,
- metadata_prefix='')
- self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
- self.assertHeaders(resp_meta, 'Container', 'POST')
- # create object
- object_name = data_utils.rand_name(name='Object')
- resp, _ = self.object_client.create_object(self.container_name,
- object_name, 'data')
- self.assertEqual(resp['status'], '201')
- self.assertHeaders(resp, 'Object', 'PUT')
- # Trying to delete the object without write rights
- self.assertRaises(exceptions.Unauthorized,
- self.custom_object_client.delete_object,
- self.container_name,
- object_name,
- metadata=self.custom_headers)
diff --git a/tempest/api/object_storage/test_container_acl_negative.py b/tempest/api/object_storage/test_container_acl_negative.py
new file mode 100644
index 0000000..1dc9bb5
--- /dev/null
+++ b/tempest/api/object_storage/test_container_acl_negative.py
@@ -0,0 +1,223 @@
+# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
+#
+# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
+#
+# 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 tempest.api.object_storage import base
+from tempest import clients
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest.test import attr
+from tempest.test import HTTP_SUCCESS
+
+
+class ObjectACLsNegativeTest(base.BaseObjectTest):
+ @classmethod
+ def setUpClass(cls):
+ super(ObjectACLsNegativeTest, cls).setUpClass()
+ cls.data.setup_test_user()
+ test_os = clients.Manager(cls.data.test_user,
+ cls.data.test_password,
+ cls.data.test_tenant)
+ cls.test_auth_data = test_os.get_auth_provider().auth_data
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.data.teardown_all()
+ super(ObjectACLsNegativeTest, cls).tearDownClass()
+
+ def setUp(self):
+ super(ObjectACLsNegativeTest, self).setUp()
+ self.container_name = data_utils.rand_name(name='TestContainer')
+ self.container_client.create_container(self.container_name)
+
+ def tearDown(self):
+ self.delete_containers([self.container_name])
+ super(ObjectACLsNegativeTest, self).tearDown()
+
+ @attr(type=['negative', 'gate'])
+ def test_write_object_without_using_creds(self):
+ # trying to create object with empty headers
+ # X-Auth-Token is not provided
+ object_name = data_utils.rand_name(name='Object')
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=None
+ )
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.create_object,
+ self.container_name, object_name, 'data')
+
+ @attr(type=['negative', 'gate'])
+ def test_delete_object_without_using_creds(self):
+ # create object
+ object_name = data_utils.rand_name(name='Object')
+ resp, _ = self.object_client.create_object(self.container_name,
+ object_name, 'data')
+ # trying to delete object with empty headers
+ # X-Auth-Token is not provided
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=None
+ )
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.delete_object,
+ self.container_name, object_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_write_object_with_non_authorized_user(self):
+ # attempt to upload another file using non-authorized user
+ # User provided token is forbidden. ACL are not set
+ object_name = data_utils.rand_name(name='Object')
+ # trying to create object with non-authorized user
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.create_object,
+ self.container_name, object_name, 'data')
+
+ @attr(type=['negative', 'gate'])
+ def test_read_object_with_non_authorized_user(self):
+ # attempt to read object using non-authorized user
+ # User provided token is forbidden. ACL are not set
+ object_name = data_utils.rand_name(name='Object')
+ resp, _ = self.object_client.create_object(
+ self.container_name, object_name, 'data')
+ self.assertEqual(resp['status'], '201')
+ self.assertHeaders(resp, 'Object', 'PUT')
+ # trying to get object with non authorized user token
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.get_object,
+ self.container_name, object_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_delete_object_with_non_authorized_user(self):
+ # attempt to delete object using non-authorized user
+ # User provided token is forbidden. ACL are not set
+ object_name = data_utils.rand_name(name='Object')
+ resp, _ = self.object_client.create_object(
+ self.container_name, object_name, 'data')
+ self.assertEqual(resp['status'], '201')
+ self.assertHeaders(resp, 'Object', 'PUT')
+ # trying to delete object with non-authorized user token
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.delete_object,
+ self.container_name, object_name)
+
+ @attr(type=['negative', 'smoke'])
+ def test_read_object_without_rights(self):
+ # attempt to read object using non-authorized user
+ # update X-Container-Read metadata ACL
+ cont_headers = {'X-Container-Read': 'badtenant:baduser'}
+ resp_meta, body = self.container_client.update_container_metadata(
+ self.container_name, metadata=cont_headers,
+ metadata_prefix='')
+ self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp_meta, 'Container', 'POST')
+ # create object
+ object_name = data_utils.rand_name(name='Object')
+ resp, _ = self.object_client.create_object(self.container_name,
+ object_name, 'data')
+ self.assertEqual(resp['status'], '201')
+ self.assertHeaders(resp, 'Object', 'PUT')
+ # Trying to read the object without rights
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.get_object,
+ self.container_name, object_name)
+
+ @attr(type=['negative', 'smoke'])
+ def test_write_object_without_rights(self):
+ # attempt to write object using non-authorized user
+ # update X-Container-Write metadata ACL
+ cont_headers = {'X-Container-Write': 'badtenant:baduser'}
+ resp_meta, body = self.container_client.update_container_metadata(
+ self.container_name, metadata=cont_headers,
+ metadata_prefix='')
+ self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp_meta, 'Container', 'POST')
+ # Trying to write the object without rights
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
+ object_name = data_utils.rand_name(name='Object')
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.create_object,
+ self.container_name,
+ object_name, 'data')
+
+ @attr(type=['negative', 'smoke'])
+ def test_write_object_without_write_rights(self):
+ # attempt to write object using non-authorized user
+ # update X-Container-Read and X-Container-Write metadata ACL
+ cont_headers = {'X-Container-Read':
+ self.data.test_tenant + ':' + self.data.test_user,
+ 'X-Container-Write': ''}
+ resp_meta, body = self.container_client.update_container_metadata(
+ self.container_name, metadata=cont_headers,
+ metadata_prefix='')
+ self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp_meta, 'Container', 'POST')
+ # Trying to write the object without write rights
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
+ object_name = data_utils.rand_name(name='Object')
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.create_object,
+ self.container_name,
+ object_name, 'data')
+
+ @attr(type=['negative', 'smoke'])
+ def test_delete_object_without_write_rights(self):
+ # attempt to delete object using non-authorized user
+ # update X-Container-Read and X-Container-Write metadata ACL
+ cont_headers = {'X-Container-Read':
+ self.data.test_tenant + ':' + self.data.test_user,
+ 'X-Container-Write': ''}
+ resp_meta, body = self.container_client.update_container_metadata(
+ self.container_name, metadata=cont_headers,
+ metadata_prefix='')
+ self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp_meta, 'Container', 'POST')
+ # create object
+ object_name = data_utils.rand_name(name='Object')
+ resp, _ = self.object_client.create_object(self.container_name,
+ object_name, 'data')
+ self.assertEqual(resp['status'], '201')
+ self.assertHeaders(resp, 'Object', 'PUT')
+ # Trying to delete the object without write rights
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=self.test_auth_data
+ )
+ self.assertRaises(exceptions.Unauthorized,
+ self.custom_object_client.delete_object,
+ self.container_name,
+ object_name)
diff --git a/tempest/api/object_storage/test_container_quotas.py b/tempest/api/object_storage/test_container_quotas.py
index 513d24a..59b84d9 100644
--- a/tempest/api/object_storage/test_container_quotas.py
+++ b/tempest/api/object_storage/test_container_quotas.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Cloudwatt
# All Rights Reserved.
#
@@ -15,25 +13,19 @@
# License for the specific language governing permissions and limitations
# under the License.
-import testtools
-
from tempest.api.object_storage import base
from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
-from tempest.test import attr
-from tempest.test import HTTP_SUCCESS
+from tempest import test
CONF = config.CONF
QUOTA_BYTES = 10
QUOTA_COUNT = 3
-SKIP_MSG = "Container quotas middleware not available."
class ContainerQuotasTest(base.BaseObjectTest):
"""Attemps to test the perfect behavior of quotas in a container."""
- container_quotas_available = \
- CONF.object_storage_feature_enabled.container_quotas
def setUp(self):
"""Creates and sets a container with quotas.
@@ -58,8 +50,8 @@
self.delete_containers([self.container_name])
super(ContainerQuotasTest, self).tearDown()
- @testtools.skipIf(not container_quotas_available, SKIP_MSG)
- @attr(type="smoke")
+ @test.requires_ext(extension='container_quotas', service='object')
+ @test.attr(type="smoke")
def test_upload_valid_object(self):
"""Attempts to uploads an object smaller than the bytes quota."""
object_name = data_utils.rand_name(name="TestObject")
@@ -69,14 +61,14 @@
resp, _ = self.object_client.create_object(
self.container_name, object_name, data)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'PUT')
nafter = self._get_bytes_used()
self.assertEqual(nbefore + len(data), nafter)
- @testtools.skipIf(not container_quotas_available, SKIP_MSG)
- @attr(type="smoke")
+ @test.requires_ext(extension='container_quotas', service='object')
+ @test.attr(type="smoke")
def test_upload_large_object(self):
"""Attempts to upload an object lagger than the bytes quota."""
object_name = data_utils.rand_name(name="TestObject")
@@ -91,8 +83,8 @@
nafter = self._get_bytes_used()
self.assertEqual(nbefore, nafter)
- @testtools.skipIf(not container_quotas_available, SKIP_MSG)
- @attr(type="smoke")
+ @test.requires_ext(extension='container_quotas', service='object')
+ @test.attr(type="smoke")
def test_upload_too_many_objects(self):
"""Attempts to upload many objects that exceeds the count limit."""
for _ in range(QUOTA_COUNT):
diff --git a/tempest/api/object_storage/test_container_services.py b/tempest/api/object_storage/test_container_services.py
index 04de072..84cc91e 100644
--- a/tempest/api/object_storage/test_container_services.py
+++ b/tempest/api/object_storage/test_container_services.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -22,15 +20,32 @@
class ContainerTest(base.BaseObjectTest):
- @classmethod
- def setUpClass(cls):
- super(ContainerTest, cls).setUpClass()
- cls.containers = []
+ def setUp(self):
+ super(ContainerTest, self).setUp()
+ self.containers = []
- @classmethod
- def tearDownClass(cls):
- cls.delete_containers(cls.containers)
- super(ContainerTest, cls).tearDownClass()
+ def tearDown(self):
+ self.delete_containers(self.containers)
+ super(ContainerTest, self).tearDown()
+
+ def _create_container(self):
+ # setup container
+ container_name = data_utils.rand_name(name='TestContainer')
+ self.container_client.create_container(container_name)
+ self.containers.append(container_name)
+
+ return container_name
+
+ def _create_object(self, container_name, object_name=None):
+ # setup object
+ if object_name is None:
+ object_name = data_utils.rand_name(name='TestObject')
+ data = data_utils.arbitrary_string()
+ self.object_client.create_object(container_name,
+ object_name,
+ data)
+
+ return object_name
@attr(type='smoke')
def test_create_container(self):
@@ -41,11 +56,97 @@
self.assertHeaders(resp, 'Container', 'PUT')
@attr(type='smoke')
+ def test_create_container_overwrite(self):
+ # overwrite container with the same name
+ container_name = data_utils.rand_name(name='TestContainer')
+ self.container_client.create_container(container_name)
+ self.containers.append(container_name)
+
+ resp, _ = self.container_client.create_container(container_name)
+ self.assertIn(resp['status'], ('202', '201'))
+ self.assertHeaders(resp, 'Container', 'PUT')
+
+ @attr(type='smoke')
+ def test_create_container_with_metadata_key(self):
+ # create container with the blank value of metadata
+ container_name = data_utils.rand_name(name='TestContainer')
+ metadata = {'test-container-meta': ''}
+ resp, _ = self.container_client.create_container(
+ container_name,
+ metadata=metadata)
+ self.containers.append(container_name)
+ self.assertIn(resp['status'], ('201', '202'))
+ self.assertHeaders(resp, 'Container', 'PUT')
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ # if the value of metadata is blank, metadata is not registered
+ # in the server
+ self.assertNotIn('x-container-meta-test-container-meta', resp)
+
+ @attr(type='smoke')
+ def test_create_container_with_metadata_value(self):
+ # create container with metadata value
+ container_name = data_utils.rand_name(name='TestContainer')
+
+ metadata = {'test-container-meta': 'Meta1'}
+ resp, _ = self.container_client.create_container(
+ container_name,
+ metadata=metadata)
+ self.containers.append(container_name)
+ self.assertIn(resp['status'], ('201', '202'))
+ self.assertHeaders(resp, 'Container', 'PUT')
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertIn('x-container-meta-test-container-meta', resp)
+ self.assertEqual(resp['x-container-meta-test-container-meta'],
+ metadata['test-container-meta'])
+
+ @attr(type='smoke')
+ def test_create_container_with_remove_metadata_key(self):
+ # create container with the blank value of remove metadata
+ container_name = data_utils.rand_name(name='TestContainer')
+ metadata_1 = {'test-container-meta': 'Meta1'}
+ self.container_client.create_container(
+ container_name,
+ metadata=metadata_1)
+ self.containers.append(container_name)
+
+ metadata_2 = {'test-container-meta': ''}
+ resp, _ = self.container_client.create_container(
+ container_name,
+ remove_metadata=metadata_2)
+ self.assertIn(resp['status'], ('201', '202'))
+ self.assertHeaders(resp, 'Container', 'PUT')
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertNotIn('x-container-meta-test-container-meta', resp)
+
+ @attr(type='smoke')
+ def test_create_container_with_remove_metadata_value(self):
+ # create container with remove metadata
+ container_name = data_utils.rand_name(name='TestContainer')
+ metadata = {'test-container-meta': 'Meta1'}
+ self.container_client.create_container(container_name,
+ metadata=metadata)
+ self.containers.append(container_name)
+
+ resp, _ = self.container_client.create_container(
+ container_name,
+ remove_metadata=metadata)
+ self.assertIn(resp['status'], ('201', '202'))
+ self.assertHeaders(resp, 'Container', 'PUT')
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertNotIn('x-container-meta-test-container-meta', resp)
+
+ @attr(type='smoke')
def test_delete_container(self):
# create a container
- container_name = data_utils.rand_name(name='TestContainer')
- resp, _ = self.container_client.create_container(container_name)
- self.containers.append(container_name)
+ container_name = self._create_container()
# delete container
resp, _ = self.container_client.delete_container(container_name)
self.assertIn(int(resp['status']), HTTP_SUCCESS)
@@ -54,78 +155,280 @@
self.containers.remove(container_name)
@attr(type='smoke')
- def test_list_container_contents_json(self):
- # add metadata to an object
-
- # create a container
- container_name = data_utils.rand_name(name='TestContainer')
- resp, _ = self.container_client.create_container(container_name)
- self.containers.append(container_name)
- # create object
- object_name = data_utils.rand_name(name='TestObject')
- data = data_utils.arbitrary_string()
- resp, _ = self.object_client.create_object(container_name,
- object_name, data)
- # set object metadata
- meta_key = data_utils.rand_name(name='Meta-Test-')
- meta_value = data_utils.rand_name(name='MetaValue-')
- orig_metadata = {meta_key: meta_value}
- resp, _ = self.object_client.update_object_metadata(container_name,
- object_name,
- orig_metadata)
+ def test_list_container_contents(self):
# get container contents list
+ container_name = self._create_container()
+ object_name = self._create_object(container_name)
+
+ resp, object_list = self.container_client.list_container_contents(
+ container_name)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual(object_name, object_list.strip('\n'))
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_no_object(self):
+ # get empty container contents list
+ container_name = self._create_container()
+
+ resp, object_list = self.container_client.list_container_contents(
+ container_name)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual('', object_list.strip('\n'))
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_delimiter(self):
+ # get container contents list using delimiter param
+ container_name = self._create_container()
+ object_name = data_utils.rand_name(name='TestObject/')
+ self._create_object(container_name, object_name)
+
+ params = {'delimiter': '/'}
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual(object_name.split('/')[0], object_list.strip('/\n'))
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_end_marker(self):
+ # get container contents list using end_marker param
+ container_name = self._create_container()
+ object_name = self._create_object(container_name)
+
+ params = {'end_marker': 'ZzzzObject1234567890'}
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual(object_name, object_list.strip('\n'))
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_format_json(self):
+ # get container contents list using format_json param
+ container_name = self._create_container()
+ self._create_object(container_name)
+
params = {'format': 'json'}
- resp, object_list = \
- self.container_client.\
- list_container_contents(container_name, params=params)
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
self.assertIn(int(resp['status']), HTTP_SUCCESS)
self.assertHeaders(resp, 'Container', 'GET')
self.assertIsNotNone(object_list)
-
- object_names = [obj['name'] for obj in object_list]
- self.assertIn(object_name, object_names)
+ self.assertTrue([c['name'] for c in object_list])
+ self.assertTrue([c['hash'] for c in object_list])
+ self.assertTrue([c['bytes'] for c in object_list])
+ self.assertTrue([c['content_type'] for c in object_list])
+ self.assertTrue([c['last_modified'] for c in object_list])
@attr(type='smoke')
- def test_container_metadata(self):
- # update/retrieve/delete container metadata
+ def test_list_container_contents_with_format_xml(self):
+ # get container contents list using format_xml param
+ container_name = self._create_container()
+ self._create_object(container_name)
- # create a container
- container_name = data_utils.rand_name(name='TestContainer')
- resp, _ = self.container_client.create_container(container_name)
- self.containers.append(container_name)
- # update container metadata
- metadata = {'name': 'Pictures',
- 'description': 'Travel'
- }
- resp, _ = \
- self.container_client.update_container_metadata(container_name,
- metadata=metadata)
+ params = {'format': 'xml'}
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
self.assertIn(int(resp['status']), HTTP_SUCCESS)
- self.assertHeaders(resp, 'Container', 'POST')
+ self.assertHeaders(resp, 'Container', 'GET')
- # list container metadata
+ self.assertIsNotNone(object_list)
+ self.assertEqual(object_list.tag, 'container')
+ self.assertTrue('name' in object_list.keys())
+ self.assertEqual(object_list.find(".//object").tag, 'object')
+ self.assertEqual(object_list.find(".//name").tag, 'name')
+ self.assertEqual(object_list.find(".//hash").tag, 'hash')
+ self.assertEqual(object_list.find(".//bytes").tag, 'bytes')
+ self.assertEqual(object_list.find(".//content_type").tag,
+ 'content_type')
+ self.assertEqual(object_list.find(".//last_modified").tag,
+ 'last_modified')
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_limit(self):
+ # get container contents list using limit param
+ container_name = self._create_container()
+ object_name = self._create_object(container_name)
+
+ params = {'limit': data_utils.rand_int_id(1, 10000)}
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual(object_name, object_list.strip('\n'))
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_marker(self):
+ # get container contents list using marker param
+ container_name = self._create_container()
+ object_name = self._create_object(container_name)
+
+ params = {'marker': 'AaaaObject1234567890'}
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual(object_name, object_list.strip('\n'))
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_path(self):
+ # get container contents list using path param
+ container_name = self._create_container()
+ object_name = data_utils.rand_name(name='Swift/TestObject')
+ self._create_object(container_name, object_name)
+
+ params = {'path': 'Swift'}
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual(object_name, object_list.strip('\n'))
+
+ @attr(type='smoke')
+ def test_list_container_contents_with_prefix(self):
+ # get container contents list using prefix param
+ container_name = self._create_container()
+ object_name = self._create_object(container_name)
+
+ prefix_key = object_name[0:8]
+ params = {'prefix': prefix_key}
+ resp, object_list = self.container_client.list_container_contents(
+ container_name,
+ params=params)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'GET')
+ self.assertEqual(object_name, object_list.strip('\n'))
+
+ @attr(type='smoke')
+ def test_list_container_metadata(self):
+ # List container metadata
+ container_name = self._create_container()
+
+ metadata = {'name': 'Pictures'}
+ self.container_client.update_container_metadata(
+ container_name,
+ metadata=metadata)
+
resp, _ = self.container_client.list_container_metadata(
container_name)
self.assertIn(int(resp['status']), HTTP_SUCCESS)
self.assertHeaders(resp, 'Container', 'HEAD')
-
self.assertIn('x-container-meta-name', resp)
- self.assertIn('x-container-meta-description', resp)
- self.assertEqual(resp['x-container-meta-name'], 'Pictures')
- self.assertEqual(resp['x-container-meta-description'], 'Travel')
+ self.assertEqual(resp['x-container-meta-name'], metadata['name'])
- # delete container metadata
- resp, _ = self.container_client.delete_container_metadata(
+ @attr(type='smoke')
+ def test_list_no_container_metadata(self):
+ # HEAD container without metadata
+ container_name = self._create_container()
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'HEAD')
+ self.assertNotIn('x-container-meta-', str(resp))
+
+ @attr(type='smoke')
+ def test_update_container_metadata_with_create_and_delete_matadata(self):
+ # Send one request of adding and deleting metadata
+ container_name = data_utils.rand_name(name='TestContainer')
+ metadata_1 = {'test-container-meta1': 'Meta1'}
+ self.container_client.create_container(container_name,
+ metadata=metadata_1)
+ self.containers.append(container_name)
+
+ metadata_2 = {'test-container-meta2': 'Meta2'}
+ resp, _ = self.container_client.update_container_metadata(
container_name,
- metadata=metadata.keys())
+ metadata=metadata_2,
+ remove_metadata=metadata_1)
self.assertIn(int(resp['status']), HTTP_SUCCESS)
self.assertHeaders(resp, 'Container', 'POST')
- # check if the metadata are no longer there
- resp, _ = self.container_client.list_container_metadata(container_name)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
- self.assertHeaders(resp, 'Container', 'HEAD')
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertNotIn('x-container-meta-test-container-meta1', resp)
+ self.assertIn('x-container-meta-test-container-meta2', resp)
+ self.assertEqual(resp['x-container-meta-test-container-meta2'],
+ metadata_2['test-container-meta2'])
- self.assertNotIn('x-container-meta-name', resp)
- self.assertNotIn('x-container-meta-description', resp)
+ @attr(type='smoke')
+ def test_update_container_metadata_with_create_metadata(self):
+ # update container metadata using add metadata
+ container_name = self._create_container()
+
+ metadata = {'test-container-meta1': 'Meta1'}
+ resp, _ = self.container_client.update_container_metadata(
+ container_name,
+ metadata=metadata)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'POST')
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertIn('x-container-meta-test-container-meta1', resp)
+ self.assertEqual(resp['x-container-meta-test-container-meta1'],
+ metadata['test-container-meta1'])
+
+ @attr(type='smoke')
+ def test_update_container_metadata_with_delete_metadata(self):
+ # update container metadata using delete metadata
+ container_name = data_utils.rand_name(name='TestContainer')
+ metadata = {'test-container-meta1': 'Meta1'}
+ self.container_client.create_container(container_name,
+ metadata=metadata)
+ self.containers.append(container_name)
+
+ resp, _ = self.container_client.delete_container_metadata(
+ container_name,
+ metadata=metadata)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'POST')
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertNotIn('x-container-meta-test-container-meta1', resp)
+
+ @attr(type='smoke')
+ def test_update_container_metadata_with_create_matadata_key(self):
+ # update container metadata with a blenk value of metadata
+ container_name = self._create_container()
+
+ metadata = {'test-container-meta1': ''}
+ resp, _ = self.container_client.update_container_metadata(
+ container_name,
+ metadata=metadata)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'POST')
+
+ resp, _ = self.container_client.list_container_metadata(
+ container_name)
+ self.assertNotIn('x-container-meta-test-container-meta1', resp)
+
+ @attr(type='smoke')
+ def test_update_container_metadata_with_delete_metadata_key(self):
+ # update container metadata with a blank value of matadata
+ container_name = data_utils.rand_name(name='TestContainer')
+ metadata = {'test-container-meta1': 'Meta1'}
+ self.container_client.create_container(container_name,
+ metadata=metadata)
+ self.containers.append(container_name)
+
+ metadata = {'test-container-meta1': ''}
+ resp, _ = self.container_client.delete_container_metadata(
+ container_name,
+ metadata=metadata)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertHeaders(resp, 'Container', 'POST')
+
+ resp, _ = self.container_client.list_container_metadata(container_name)
+ self.assertNotIn('x-container-meta-test-container-meta1', resp)
diff --git a/tempest/api/object_storage/test_container_staticweb.py b/tempest/api/object_storage/test_container_staticweb.py
index 9f9abd8..197e7fa 100644
--- a/tempest/api/object_storage/test_container_staticweb.py
+++ b/tempest/api/object_storage/test_container_staticweb.py
@@ -56,6 +56,12 @@
self.container_client.update_container_metadata(
self.container_name, metadata=headers)
+ # Maintain original headers, no auth added
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=None
+ )
+
# test GET on http://account_url/container_name
# we should retrieve the self.object_name file
resp, body = self.custom_account_client.request("GET",
@@ -112,6 +118,12 @@
self.container_client.update_container_metadata(
self.container_name, metadata=headers)
+ # Maintain original headers, no auth added
+ self.custom_account_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=None
+ )
+
# test GET on http://account_url/container_name
# we should retrieve a listing of objects
resp, body = self.custom_account_client.request("GET",
@@ -136,6 +148,12 @@
object_name_404,
object_data_404)
+ # Do not set auth in HTTP headers for next request
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=None
+ )
+
# Request non-existing object
resp, body = self.custom_object_client.get_object(self.container_name,
"notexisting")
diff --git a/tempest/api/object_storage/test_container_sync.py b/tempest/api/object_storage/test_container_sync.py
index dcfe219..207fced 100644
--- a/tempest/api/object_storage/test_container_sync.py
+++ b/tempest/api/object_storage/test_container_sync.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,25 +14,42 @@
# under the License.
import time
+import urlparse
from tempest.api.object_storage import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
-from tempest.test import skip_because
+from tempest.test import HTTP_SUCCESS
+
+CONF = config.CONF
+
+
+# This test can be quite long to run due to its
+# dependency on container-sync process running interval.
+# You can obviously reduce the container-sync interval in the
+# container-server configuration.
class ContainerSyncTest(base.BaseObjectTest):
+
@classmethod
def setUpClass(cls):
super(ContainerSyncTest, cls).setUpClass()
cls.containers = []
cls.objects = []
+
+ # Default container-server config only allows localhost
+ cls.local_ip = '127.0.0.1'
+
+ # Must be configure according to container-sync interval
container_sync_timeout = \
- int(cls.config.object_storage.container_sync_timeout)
+ int(CONF.object_storage.container_sync_timeout)
cls.container_sync_interval = \
- int(cls.config.object_storage.container_sync_interval)
+ int(CONF.object_storage.container_sync_interval)
cls.attempts = \
int(container_sync_timeout / cls.container_sync_interval)
+
# define container and object clients
cls.clients = {}
cls.clients[data_utils.rand_name(name='TestContainerSync')] = \
@@ -51,8 +66,7 @@
cls.delete_containers(cls.containers, client[0], client[1])
super(ContainerSyncTest, cls).tearDownClass()
- @skip_because(bug="1093743")
- @attr(type='gate')
+ @attr(type='slow')
def test_container_synchronization(self):
# container to container synchronization
# to allow/accept sync requests to/from other accounts
@@ -62,51 +76,53 @@
cont_client = [self.clients[c][0] for c in cont]
obj_client = [self.clients[c][1] for c in cont]
# tell first container to synchronize to a second
+ client_proxy_ip = \
+ urlparse.urlparse(cont_client[1].base_url).netloc.split(':')[0]
+ client_base_url = \
+ cont_client[1].base_url.replace(client_proxy_ip,
+ self.local_ip)
headers = {'X-Container-Sync-Key': 'sync_key',
'X-Container-Sync-To': "%s/%s" %
- (cont_client[1].base_url, str(cont[1]))}
+ (client_base_url, str(cont[1]))}
resp, body = \
cont_client[0].put(str(cont[0]), body=None, headers=headers)
- self.assertIn(resp['status'], ('202', '201'),
- 'Error installing X-Container-Sync-To '
- 'for the container "%s"' % (cont[0]))
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
# create object in container
object_name = data_utils.rand_name(name='TestSyncObject')
data = object_name[::-1] # data_utils.arbitrary_string()
resp, _ = obj_client[0].create_object(cont[0], object_name, data)
- self.assertEqual(resp['status'], '201',
- 'Error creating the object "%s" in'
- 'the container "%s"'
- % (object_name, cont[0]))
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
self.objects.append(object_name)
# wait until container contents list is not empty
cont_client = [self.clients[c][0] for c in self.containers]
params = {'format': 'json'}
while self.attempts > 0:
- # get first container content
- resp, object_list_0 = \
- cont_client[0].\
- list_container_contents(self.containers[0], params=params)
- self.assertEqual(resp['status'], '200',
- 'Error listing the destination container`s'
- ' "%s" contents' % (self.containers[0]))
- object_list_0 = dict((obj['name'], obj) for obj in object_list_0)
- # get second container content
- resp, object_list_1 = \
- cont_client[1].\
- list_container_contents(self.containers[1], params=params)
- self.assertEqual(resp['status'], '200',
- 'Error listing the destination container`s'
- ' "%s" contents' % (self.containers[1]))
- object_list_1 = dict((obj['name'], obj) for obj in object_list_1)
+ object_lists = []
+ for client_index in (0, 1):
+ resp, object_list = \
+ cont_client[client_index].\
+ list_container_contents(self.containers[client_index],
+ params=params)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ object_lists.append(dict(
+ (obj['name'], obj) for obj in object_list))
# check that containers are not empty and have equal keys()
# or wait for next attempt
- if not object_list_0 or not object_list_1 or \
- set(object_list_0.keys()) != set(object_list_1.keys()):
+ if not object_lists[0] or not object_lists[1] or \
+ set(object_lists[0].keys()) != set(object_lists[1].keys()):
time.sleep(self.container_sync_interval)
self.attempts -= 1
else:
break
- self.assertEqual(object_list_0, object_list_1,
+
+ self.assertEqual(object_lists[0], object_lists[1],
'Different object lists in containers.')
+
+ # Verify object content
+ obj_clients = [(self.clients[c][1], c) for c in self.containers]
+ for obj_client, cont in obj_clients:
+ for obj_name in object_lists[0]:
+ resp, object_content = obj_client.get_object(cont, obj_name)
+ self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertEqual(object_content, obj_name[::-1])
diff --git a/tempest/api/object_storage/test_crossdomain.py b/tempest/api/object_storage/test_crossdomain.py
index 41430c8..4f399b4 100644
--- a/tempest/api/object_storage/test_crossdomain.py
+++ b/tempest/api/object_storage/test_crossdomain.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
@@ -19,27 +17,14 @@
from tempest.api.object_storage import base
from tempest import clients
from tempest.common import custom_matchers
-from tempest import config
-from tempest.test import attr
-from tempest.test import HTTP_SUCCESS
-
-CONF = config.CONF
+from tempest import test
class CrossdomainTest(base.BaseObjectTest):
- crossdomain_available = \
- CONF.object_storage_feature_enabled.crossdomain
@classmethod
def setUpClass(cls):
super(CrossdomainTest, cls).setUpClass()
-
- # skip this test if CORS isn't enabled in the conf file.
- if not cls.crossdomain_available:
- skip_msg = ("%s skipped as Crossdomain middleware not available"
- % cls.__name__)
- raise cls.skipException(skip_msg)
-
# creates a test user. The test user will set its base_url to the Swift
# endpoint and test the healthcheck feature.
cls.data.setup_test_user()
@@ -65,22 +50,22 @@
super(CrossdomainTest, self).setUp()
client = self.os_test_user.account_client
- client._set_auth()
# Turning http://.../v1/foobar into http://.../
- client.base_url = "/".join(client.base_url.split("/")[:-2])
+ client.skip_path()
def tearDown(self):
# clear the base_url for subsequent requests
- self.os_test_user.account_client.base_url = None
+ self.os_test_user.account_client.reset_path()
super(CrossdomainTest, self).tearDown()
- @attr('gate')
+ @test.attr('gate')
+ @test.requires_ext(extension='crossdomain', service='object')
def test_get_crossdomain_policy(self):
resp, body = self.os_test_user.account_client.get("crossdomain.xml",
{})
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertTrue(body.startswith(self.xml_start) and
body.endswith(self.xml_end))
diff --git a/tempest/api/object_storage/test_healthcheck.py b/tempest/api/object_storage/test_healthcheck.py
index 7bbdd1e..35aee2a 100644
--- a/tempest/api/object_storage/test_healthcheck.py
+++ b/tempest/api/object_storage/test_healthcheck.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
@@ -18,7 +16,6 @@
from tempest.api.object_storage import base
-from tempest import clients
from tempest.common import custom_matchers
from tempest.test import attr
from tempest.test import HTTP_SUCCESS
@@ -30,37 +27,15 @@
def setUpClass(cls):
super(HealthcheckTest, cls).setUpClass()
- # creates a test user. The test user will set its base_url to the Swift
- # endpoint and test the healthcheck feature.
- cls.data.setup_test_user()
-
- cls.os_test_user = clients.Manager(
- cls.data.test_user,
- cls.data.test_password,
- cls.data.test_tenant)
-
- @classmethod
- def tearDownClass(cls):
- cls.data.teardown_all()
- super(HealthcheckTest, cls).tearDownClass()
-
def setUp(self):
super(HealthcheckTest, self).setUp()
- client = self.os_test_user.account_client
- client._set_auth()
-
# Turning http://.../v1/foobar into http://.../
- client.base_url = "/".join(client.base_url.split("/")[:-2])
-
- def tearDown(self):
- # clear the base_url for subsequent requests
- self.os_test_user.account_client.base_url = None
- super(HealthcheckTest, self).tearDown()
+ self.account_client.skip_path()
@attr('gate')
def test_get_healthcheck(self):
- resp, _ = self.os_test_user.account_client.get("healthcheck", {})
+ resp, _ = self.account_client.get("healthcheck", {})
# The status is expected to be 200
self.assertIn(int(resp['status']), HTTP_SUCCESS)
diff --git a/tempest/api/object_storage/test_object_expiry.py b/tempest/api/object_storage/test_object_expiry.py
index 4958f70..3aae0a1 100644
--- a/tempest/api/object_storage/test_object_expiry.py
+++ b/tempest/api/object_storage/test_object_expiry.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -21,7 +19,6 @@
from tempest.common.utils import data_utils
from tempest import exceptions
from tempest.test import attr
-from tempest.test import skip_because
class ObjectExpiryTest(base.BaseObjectTest):
@@ -31,48 +28,51 @@
cls.container_name = data_utils.rand_name(name='TestContainer')
cls.container_client.create_container(cls.container_name)
+ def setUp(self):
+ super(ObjectExpiryTest, self).setUp()
+ # create object
+ self.object_name = data_utils.rand_name(name='TestObject')
+ resp, _ = self.object_client.create_object(self.container_name,
+ self.object_name, '')
+
@classmethod
def tearDownClass(cls):
- """The test script fails in tear down class
- as the container contains expired objects (LP bug 1069849).
- But delete action for the expired object is raising
- NotFound exception and also non empty container cannot be deleted.
- """
cls.delete_containers([cls.container_name])
super(ObjectExpiryTest, cls).tearDownClass()
- @skip_because(bug="1069849")
- @attr(type='gate')
- def test_get_object_after_expiry_time(self):
- # TODO(harika-vakadi): similar test case has to be created for
- # "X-Delete-At", after this test case works.
-
- # create object
- object_name = data_utils.rand_name(name='TestObject')
- data = data_utils.arbitrary_string()
- resp, _ = self.object_client.create_object(self.container_name,
- object_name, data)
- # update object metadata with expiry time of 3 seconds
- metadata = {'X-Delete-After': '3'}
+ def _test_object_expiry(self, metadata):
+ # update object metadata
resp, _ = \
self.object_client.update_object_metadata(self.container_name,
- object_name, metadata,
+ self.object_name,
+ metadata,
metadata_prefix='')
+ # verify object metadata
resp, _ = \
self.object_client.list_object_metadata(self.container_name,
- object_name)
+ self.object_name)
self.assertEqual(resp['status'], '200')
self.assertHeaders(resp, 'Object', 'HEAD')
self.assertIn('x-delete-at', resp)
resp, body = self.object_client.get_object(self.container_name,
- object_name)
+ self.object_name)
self.assertEqual(resp['status'], '200')
self.assertHeaders(resp, 'Object', 'GET')
self.assertIn('x-delete-at', resp)
- # check data
- self.assertEqual(body, data)
+
# sleep for over 5 seconds, so that object expires
time.sleep(5)
+
# object should not be there anymore
self.assertRaises(exceptions.NotFound, self.object_client.get_object,
- self.container_name, object_name)
+ self.container_name, self.object_name)
+
+ @attr(type='gate')
+ def test_get_object_after_expiry_time(self):
+ metadata = {'X-Delete-After': '3'}
+ self._test_object_expiry(metadata)
+
+ @attr(type='gate')
+ def test_get_object_at_expiry_time(self):
+ metadata = {'X-Delete-At': str(int(time.time()) + 3)}
+ self._test_object_expiry(metadata)
diff --git a/tempest/api/object_storage/test_object_formpost.py b/tempest/api/object_storage/test_object_formpost.py
index 817c892..6f46ec9 100644
--- a/tempest/api/object_storage/test_object_formpost.py
+++ b/tempest/api/object_storage/test_object_formpost.py
@@ -1,4 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Christian Schwede <christian.schwede@enovance.com>
@@ -117,21 +116,3 @@
self.assertIn(int(resp['status']), HTTP_SUCCESS)
self.assertHeaders(resp, "Object", "GET")
self.assertEqual(body, "hello world")
-
- @attr(type=['gate', 'negative'])
- def test_post_object_using_form_expired(self):
- body, content_type = self.get_multipart_form(expires=1)
- time.sleep(2)
-
- headers = {'Content-Type': content_type,
- 'Content-Length': str(len(body))}
-
- url = "%s/%s/%s" % (self.container_client.base_url,
- self.container_name,
- self.object_name)
-
- # Use a raw request, otherwise authentication headers are used
- resp, body = self.object_client.http_obj.request(url, "POST",
- body, headers=headers)
- self.assertEqual(int(resp['status']), 401)
- self.assertIn('FormPost: Form Expired', body)
diff --git a/tempest/api/object_storage/test_object_formpost_negative.py b/tempest/api/object_storage/test_object_formpost_negative.py
new file mode 100644
index 0000000..e02a058
--- /dev/null
+++ b/tempest/api/object_storage/test_object_formpost_negative.py
@@ -0,0 +1,110 @@
+# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
+# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
+#
+# 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 hashlib
+import hmac
+import time
+import urlparse
+
+from tempest.api.object_storage import base
+from tempest.common.utils import data_utils
+from tempest.test import attr
+
+
+class ObjectFormPostNegativeTest(base.BaseObjectTest):
+
+ @classmethod
+ def setUpClass(cls):
+ super(ObjectFormPostNegativeTest, cls).setUpClass()
+ cls.container_name = data_utils.rand_name(name='TestContainer')
+ cls.object_name = data_utils.rand_name(name='ObjectTemp')
+
+ cls.container_client.create_container(cls.container_name)
+ cls.containers = [cls.container_name]
+
+ cls.key = 'Meta'
+ cls.metadata = {'Temp-URL-Key': cls.key}
+ cls.account_client.create_account_metadata(metadata=cls.metadata)
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.account_client.delete_account_metadata(metadata=cls.metadata)
+ cls.delete_containers(cls.containers)
+ cls.data.teardown_all()
+ super(ObjectFormPostNegativeTest, cls).tearDownClass()
+
+ def get_multipart_form(self, expires=600):
+ path = "%s/%s/%s" % (
+ urlparse.urlparse(self.container_client.base_url).path,
+ self.container_name,
+ self.object_name)
+
+ redirect = ''
+ max_file_size = 104857600
+ max_file_count = 10
+ expires += int(time.time())
+ hmac_body = '%s\n%s\n%s\n%s\n%s' % (path,
+ redirect,
+ max_file_size,
+ max_file_count,
+ expires)
+
+ signature = hmac.new(self.key, hmac_body, hashlib.sha1).hexdigest()
+
+ fields = {'redirect': redirect,
+ 'max_file_size': str(max_file_size),
+ 'max_file_count': str(max_file_count),
+ 'expires': str(expires),
+ 'signature': signature}
+
+ boundary = '--boundary--'
+ data = []
+ for (key, value) in fields.items():
+ data.append('--' + boundary)
+ data.append('Content-Disposition: form-data; name="%s"' % key)
+ data.append('')
+ data.append(value)
+
+ data.append('--' + boundary)
+ data.append('Content-Disposition: form-data; '
+ 'name="file1"; filename="testfile"')
+ data.append('Content-Type: application/octet-stream')
+ data.append('')
+ data.append('hello world')
+
+ data.append('--' + boundary + '--')
+ data.append('')
+
+ body = '\r\n'.join(data)
+ content_type = 'multipart/form-data; boundary=%s' % boundary
+ return body, content_type
+
+ @attr(type=['gate', 'negative'])
+ def test_post_object_using_form_expired(self):
+ body, content_type = self.get_multipart_form(expires=1)
+ time.sleep(2)
+
+ headers = {'Content-Type': content_type,
+ 'Content-Length': str(len(body))}
+
+ url = "%s/%s/%s" % (self.container_client.base_url,
+ self.container_name,
+ self.object_name)
+
+ # Use a raw request, otherwise authentication headers are used
+ resp, body = self.object_client.http_obj.request(url, "POST",
+ body, headers=headers)
+ self.assertEqual(int(resp['status']), 401)
+ self.assertIn('FormPost: Form Expired', body)
diff --git a/tempest/api/object_storage/test_object_services.py b/tempest/api/object_storage/test_object_services.py
index c7fdd0e..6f349b6 100644
--- a/tempest/api/object_storage/test_object_services.py
+++ b/tempest/api/object_storage/test_object_services.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,7 +14,6 @@
# under the License.
import hashlib
-import re
from tempest.api.object_storage import base
from tempest.common import custom_matchers
@@ -33,20 +30,9 @@
cls.container_client.create_container(cls.container_name)
cls.containers = [cls.container_name]
- cls.data.setup_test_user()
- resp, body = cls.token_client.auth(cls.data.test_user,
- cls.data.test_password,
- cls.data.test_tenant)
- cls.new_token = cls.token_client.get_token(cls.data.test_user,
- cls.data.test_password,
- cls.data.test_tenant)
- cls.custom_headers = {'X-Auth-Token': cls.new_token}
-
@classmethod
def tearDownClass(cls):
cls.delete_containers(cls.containers)
- # delete the user setup created
- cls.data.teardown_all()
super(ObjectTest, cls).tearDownClass()
@attr(type='smoke')
@@ -277,23 +263,15 @@
resp, _ = self.object_client.list_object_metadata(
self.container_name, object_name)
- # Check only the existence of common headers with custom matcher
- self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders(
- 'Object', 'HEAD'))
- self.assertIn('x-object-manifest', resp)
-
# Etag value of a large object is enclosed in double-quotations.
- # This is a special case, therefore the formats of response headers
- # are checked without a custom matcher.
+ # After etag quotes are checked they are removed and the response is
+ # checked if all common headers are present and well formatted
self.assertTrue(resp['etag'].startswith('\"'))
self.assertTrue(resp['etag'].endswith('\"'))
- self.assertTrue(resp['etag'].strip('\"').isalnum())
- self.assertTrue(re.match("^\d+\.?\d*\Z", resp['x-timestamp']))
- self.assertNotEqual(len(resp['content-type']), 0)
- self.assertTrue(re.match("^tx[0-9a-f]*-[0-9a-f]*$",
- resp['x-trans-id']))
- self.assertNotEqual(len(resp['date']), 0)
- self.assertEqual(resp['accept-ranges'], 'bytes')
+ resp['etag'] = resp['etag'].strip('"')
+ self.assertHeaders(resp, 'Object', 'HEAD')
+
+ self.assertIn('x-object-manifest', resp)
self.assertEqual(resp['x-object-manifest'],
'%s/%s/' % (self.container_name, object_name))
@@ -379,8 +357,12 @@
self.assertEqual(resp_meta['x-container-read'], '.r:*,.rlistings')
# trying to get object with empty headers as it is public readable
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=None
+ )
resp, body = self.custom_object_client.get_object(
- self.container_name, object_name, metadata={})
+ self.container_name, object_name)
self.assertHeaders(resp, 'Object', 'GET')
self.assertEqual(body, data)
@@ -415,12 +397,14 @@
self.assertEqual(resp['x-container-read'], '.r:*,.rlistings')
# get auth token of alternative user
- token = self.identity_client_alt.get_auth()
- headers = {'X-Auth-Token': token}
+ alt_auth_data = self.identity_client_alt.auth_provider.auth_data
+ self.custom_object_client.auth_provider.set_alt_auth_data(
+ request_part='headers',
+ auth_data=alt_auth_data
+ )
# access object using alternate user creds
resp, body = self.custom_object_client.get_object(
- self.container_name, object_name,
- metadata=headers)
+ self.container_name, object_name)
self.assertHeaders(resp, 'Object', 'GET')
self.assertEqual(body, data)
diff --git a/tempest/api/object_storage/test_object_slo.py b/tempest/api/object_storage/test_object_slo.py
index 997120a..0443a80 100644
--- a/tempest/api/object_storage/test_object_slo.py
+++ b/tempest/api/object_storage/test_object_slo.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NTT Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -16,7 +14,6 @@
import hashlib
import json
-import re
from tempest.api.object_storage import base
from tempest.common import custom_matchers
@@ -97,29 +94,19 @@
return object_name
def _assertHeadersSLO(self, resp, method):
- # Check the existence of common headers with custom matcher
- self.assertThat(resp, custom_matchers.ExistsAllResponseHeaders(
- 'Object', method))
# When sending GET or HEAD requests to SLO the response contains
# 'X-Static-Large-Object' header
if method in ('GET', 'HEAD'):
self.assertIn('x-static-large-object', resp)
+ self.assertEqual(resp['x-static-large-object'], 'True')
- # Check common headers for all HTTP methods
- self.assertTrue(re.match("^tx[0-9a-f]*-[0-9a-f]*$",
- resp['x-trans-id']))
- self.assertTrue(resp['content-length'].isdigit())
- self.assertNotEqual(len(resp['date']), 0)
# Etag value of a large object is enclosed in double-quotations.
+ # After etag quotes are checked they are removed and the response is
+ # checked if all common headers are present and well formatted
self.assertTrue(resp['etag'].startswith('\"'))
self.assertTrue(resp['etag'].endswith('\"'))
- self.assertTrue(resp['etag'].strip('\"').isalnum())
- # Check header formats for a specific method
- if method in ('GET', 'HEAD'):
- self.assertTrue(re.match("^\d+\.?\d*\Z", resp['x-timestamp']))
- self.assertNotEqual(len(resp['content-type']), 0)
- self.assertEqual(resp['accept-ranges'], 'bytes')
- self.assertEqual(resp['x-static-large-object'], 'True')
+ resp['etag'] = resp['etag'].strip('"')
+ self.assertHeaders(resp, 'Object', method)
@test.attr(type='gate')
def test_upload_manifest(self):
diff --git a/tempest/api/object_storage/test_object_temp_url.py b/tempest/api/object_storage/test_object_temp_url.py
index d0e5353..47c270e 100644
--- a/tempest/api/object_storage/test_object_temp_url.py
+++ b/tempest/api/object_storage/test_object_temp_url.py
@@ -1,4 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
@@ -23,28 +22,16 @@
from tempest.api.object_storage import base
from tempest.common.utils import data_utils
from tempest import config
-from tempest import exceptions
-from tempest.test import attr
-from tempest.test import HTTP_SUCCESS
+from tempest import test
CONF = config.CONF
class ObjectTempUrlTest(base.BaseObjectTest):
- tempurl_available = \
- CONF.object_storage_feature_enabled.tempurl
-
@classmethod
def setUpClass(cls):
super(ObjectTempUrlTest, cls).setUpClass()
-
- # skip this test if TempUrl isn't enabled in the conf file.
- if not cls.tempurl_available:
- skip_msg = ("%s skipped as TempUrl middleware not available"
- % cls.__name__)
- raise cls.skipException(skip_msg)
-
# create a container
cls.container_name = data_utils.rand_name(name='TestContainer')
cls.container_client.create_container(cls.container_name)
@@ -108,7 +95,8 @@
return url
- @attr(type='gate')
+ @test.attr(type='gate')
+ @test.requires_ext(extension='tempurl', service='object')
def test_get_object_using_temp_url(self):
expires = self._get_expiry_date()
@@ -119,16 +107,17 @@
# trying to get object using temp url within expiry time
resp, body = self.object_client.get(url)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'GET')
self.assertEqual(body, self.content)
# Testing a HEAD on this Temp URL
resp, body = self.object_client.head(url)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'HEAD')
- @attr(type='gate')
+ @test.attr(type='gate')
+ @test.requires_ext(extension='tempurl', service='object')
def test_get_object_using_temp_url_key_2(self):
key2 = 'Meta2-'
metadata = {'Temp-URL-Key-2': key2}
@@ -149,10 +138,11 @@
self.object_name, "GET",
expires, key2)
resp, body = self.object_client.get(url)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertEqual(body, self.content)
- @attr(type='gate')
+ @test.attr(type='gate')
+ @test.requires_ext(extension='tempurl', service='object')
def test_put_object_using_temp_url(self):
new_data = data_utils.arbitrary_string(
size=len(self.object_name),
@@ -165,12 +155,12 @@
# trying to put random data in the object using temp url
resp, body = self.object_client.put(url, new_data, None)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'PUT')
# Testing a HEAD on this Temp URL
resp, body = self.object_client.head(url)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'HEAD')
# Validate that the content of the object has been modified
@@ -181,7 +171,8 @@
_, body = self.object_client.get(url)
self.assertEqual(body, new_data)
- @attr(type='gate')
+ @test.attr(type='gate')
+ @test.requires_ext(extension='tempurl', service='object')
def test_head_object_using_temp_url(self):
expires = self._get_expiry_date()
@@ -192,20 +183,5 @@
# Testing a HEAD on this Temp URL
resp, body = self.object_client.head(url)
- self.assertIn(int(resp['status']), HTTP_SUCCESS)
+ self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
self.assertHeaders(resp, 'Object', 'HEAD')
-
- @attr(type=['gate', 'negative'])
- def test_get_object_after_expiration_time(self):
-
- expires = self._get_expiry_date(1)
- # get a temp URL for the created object
- url = self._get_temp_url(self.container_name,
- self.object_name, "GET",
- expires, self.key)
-
- # temp URL is valid for 1 seconds, let's wait 2
- time.sleep(2)
-
- self.assertRaises(exceptions.Unauthorized,
- self.object_client.get, url)
diff --git a/tempest/api/object_storage/test_object_temp_url_negative.py b/tempest/api/object_storage/test_object_temp_url_negative.py
new file mode 100644
index 0000000..cf24f66
--- /dev/null
+++ b/tempest/api/object_storage/test_object_temp_url_negative.py
@@ -0,0 +1,107 @@
+# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
+#
+# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
+#
+# 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 hashlib
+import hmac
+import time
+import urlparse
+
+from tempest.api.object_storage import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest import test
+
+
+class ObjectTempUrlNegativeTest(base.BaseObjectTest):
+
+ @classmethod
+ def setUpClass(cls):
+ super(ObjectTempUrlNegativeTest, cls).setUpClass()
+
+ cls.container_name = data_utils.rand_name(name='TestContainer')
+ cls.container_client.create_container(cls.container_name)
+ cls.containers = [cls.container_name]
+
+ # update account metadata
+ cls.key = 'Meta'
+ cls.metadata = {'Temp-URL-Key': cls.key}
+ cls.account_client.create_account_metadata(metadata=cls.metadata)
+ cls.account_client_metadata, _ = \
+ cls.account_client.list_account_metadata()
+
+ @classmethod
+ def tearDownClass(cls):
+ resp, _ = cls.account_client.delete_account_metadata(
+ metadata=cls.metadata)
+
+ cls.delete_containers(cls.containers)
+
+ # delete the user setup created
+ cls.data.teardown_all()
+ super(ObjectTempUrlNegativeTest, cls).tearDownClass()
+
+ def setUp(self):
+ super(ObjectTempUrlNegativeTest, self).setUp()
+ # make sure the metadata has been set
+ self.assertIn('x-account-meta-temp-url-key',
+ self.account_client_metadata)
+
+ self.assertEqual(
+ self.account_client_metadata['x-account-meta-temp-url-key'],
+ self.key)
+
+ # create object
+ self.object_name = data_utils.rand_name(name='ObjectTemp')
+ self.data = data_utils.arbitrary_string(size=len(self.object_name),
+ base_text=self.object_name)
+ self.object_client.create_object(self.container_name,
+ self.object_name, self.data)
+
+ def _get_expiry_date(self, expiration_time=1000):
+ return int(time.time() + expiration_time)
+
+ def _get_temp_url(self, container, object_name, method, expires,
+ key):
+ """Create the temporary URL."""
+
+ path = "%s/%s/%s" % (
+ urlparse.urlparse(self.object_client.base_url).path,
+ container, object_name)
+
+ hmac_body = '%s\n%s\n%s' % (method, expires, path)
+ sig = hmac.new(key, hmac_body, hashlib.sha1).hexdigest()
+
+ url = "%s/%s?temp_url_sig=%s&temp_url_expires=%s" % (container,
+ object_name,
+ sig, expires)
+
+ return url
+
+ @test.attr(type=['gate', 'negative'])
+ @test.requires_ext(extension='tempurl', service='object')
+ def test_get_object_after_expiration_time(self):
+
+ expires = self._get_expiry_date(1)
+ # get a temp URL for the created object
+ url = self._get_temp_url(self.container_name,
+ self.object_name, "GET",
+ expires, self.key)
+
+ # temp URL is valid for 1 seconds, let's wait 2
+ time.sleep(2)
+
+ self.assertRaises(exceptions.Unauthorized,
+ self.object_client.get, url)
diff --git a/tempest/api/object_storage/test_object_version.py b/tempest/api/object_storage/test_object_version.py
index d706eef..75293d2 100644
--- a/tempest/api/object_storage/test_object_version.py
+++ b/tempest/api/object_storage/test_object_version.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/orchestration/base.py b/tempest/api/orchestration/base.py
index b6c03e0..3424082 100644
--- a/tempest/api/orchestration/base.py
+++ b/tempest/api/orchestration/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -14,9 +12,11 @@
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest.openstack.common import log as logging
import tempest.test
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -28,12 +28,10 @@
def setUpClass(cls):
super(BaseOrchestrationTest, cls).setUpClass()
os = clients.OrchestrationManager()
- cls.orchestration_cfg = os.config.orchestration
- cls.compute_cfg = os.config.compute
- if not os.config.service_available.heat:
+ if not CONF.service_available.heat:
raise cls.skipException("Heat support is required")
- cls.build_timeout = cls.orchestration_cfg.build_timeout
- cls.build_interval = cls.orchestration_cfg.build_interval
+ cls.build_timeout = CONF.orchestration.build_timeout
+ cls.build_interval = CONF.orchestration.build_interval
cls.os = os
cls.orchestration_client = os.orchestration_client
@@ -47,7 +45,7 @@
def _get_default_network(cls):
resp, networks = cls.network_client.list_networks()
for net in networks['networks']:
- if net['name'] == cls.compute_cfg.fixed_network_name:
+ if net['name'] == CONF.compute.fixed_network_name:
return net
@classmethod
@@ -60,16 +58,6 @@
return admin_client
@classmethod
- def _get_client_args(cls):
-
- return (
- cls.config,
- cls.config.identity.admin_username,
- cls.config.identity.admin_password,
- cls.config.identity.uri
- )
-
- @classmethod
def create_stack(cls, stack_name, template_data, parameters={}):
resp, body = cls.client.create_stack(
stack_name,
diff --git a/tempest/api/orchestration/stacks/test_limits.py b/tempest/api/orchestration/stacks/test_limits.py
index d294c7a..22f544d 100644
--- a/tempest/api/orchestration/stacks/test_limits.py
+++ b/tempest/api/orchestration/stacks/test_limits.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -16,9 +14,11 @@
from tempest.api.orchestration import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.test import attr
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -34,7 +34,7 @@
@attr(type='gate')
def test_exceed_max_template_size_fails(self):
- fill = 'A' * self.orchestration_cfg.max_template_size
+ fill = 'A' * CONF.orchestration.max_template_size
template = '''
HeatTemplateFormatVersion: '2012-12-12'
Description: '%s'
diff --git a/tempest/api/orchestration/stacks/test_neutron_resources.py b/tempest/api/orchestration/stacks/test_neutron_resources.py
index c86edf0..243c3ce 100644
--- a/tempest/api/orchestration/stacks/test_neutron_resources.py
+++ b/tempest/api/orchestration/stacks/test_neutron_resources.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -18,8 +16,10 @@
from tempest.api.orchestration import base
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -93,16 +93,15 @@
@classmethod
def setUpClass(cls):
super(NeutronResourcesTestJSON, cls).setUpClass()
- if not cls.orchestration_cfg.image_ref:
+ if not CONF.orchestration.image_ref:
raise cls.skipException("No image available to test")
cls.client = cls.orchestration_client
os = clients.Manager()
- cls.network_cfg = os.config.network
- if not cls.config.service_available.neutron:
+ if not CONF.service_available.neutron:
raise cls.skipException("Neutron support is required")
cls.network_client = os.network_client
cls.stack_name = data_utils.rand_name('heat')
- cls.keypair_name = (cls.orchestration_cfg.keypair_name or
+ cls.keypair_name = (CONF.orchestration.keypair_name or
cls._create_keypair()['name'])
cls.external_router_id = cls._get_external_router_id()
@@ -112,8 +111,8 @@
cls.template,
parameters={
'KeyName': cls.keypair_name,
- 'InstanceType': cls.orchestration_cfg.instance_type,
- 'ImageId': cls.orchestration_cfg.image_ref,
+ 'InstanceType': CONF.orchestration.instance_type,
+ 'ImageId': CONF.orchestration.image_ref,
'ExternalRouterId': cls.external_router_id
})
cls.stack_id = cls.stack_identifier.split('/')[1]
diff --git a/tempest/api/orchestration/stacks/test_non_empty_stack.py b/tempest/api/orchestration/stacks/test_non_empty_stack.py
index eead234..11d01f7 100644
--- a/tempest/api/orchestration/stacks/test_non_empty_stack.py
+++ b/tempest/api/orchestration/stacks/test_non_empty_stack.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -112,6 +110,18 @@
self.assertEqual('fluffy', stack['outputs'][0]['output_key'])
@attr(type='gate')
+ def test_suspend_resume_stack(self):
+ """suspend and resume a stack."""
+ resp, suspend_stack = self.client.suspend_stack(self.stack_identifier)
+ self.assertEqual('200', resp['status'])
+ self.client.wait_for_stack_status(self.stack_identifier,
+ 'SUSPEND_COMPLETE')
+ resp, resume_stack = self.client.resume_stack(self.stack_identifier)
+ self.assertEqual('200', resp['status'])
+ self.client.wait_for_stack_status(self.stack_identifier,
+ 'RESUME_COMPLETE')
+
+ @attr(type='gate')
def test_list_resources(self):
"""Getting list of created resources for the stack should be possible.
"""
diff --git a/tempest/api/orchestration/stacks/test_server_cfn_init.py b/tempest/api/orchestration/stacks/test_server_cfn_init.py
index 6fbbb5b..4267c1d 100644
--- a/tempest/api/orchestration/stacks/test_server_cfn_init.py
+++ b/tempest/api/orchestration/stacks/test_server_cfn_init.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -127,13 +125,13 @@
@classmethod
def setUpClass(cls):
super(ServerCfnInitTestJSON, cls).setUpClass()
- if not cls.orchestration_cfg.image_ref:
+ if not CONF.orchestration.image_ref:
raise cls.skipException("No image available to test")
cls.client = cls.orchestration_client
stack_name = data_utils.rand_name('heat')
- if cls.orchestration_cfg.keypair_name:
- keypair_name = cls.orchestration_cfg.keypair_name
+ if CONF.orchestration.keypair_name:
+ keypair_name = CONF.orchestration.keypair_name
else:
cls.keypair = cls._create_keypair()
keypair_name = cls.keypair['name']
@@ -144,8 +142,8 @@
cls.template,
parameters={
'key_name': keypair_name,
- 'flavor': cls.orchestration_cfg.instance_type,
- 'image': cls.orchestration_cfg.image_ref,
+ 'flavor': CONF.orchestration.instance_type,
+ 'image': CONF.orchestration.image_ref,
'network': cls._get_default_network()['id']
})
diff --git a/tempest/api/orchestration/stacks/test_stacks.py b/tempest/api/orchestration/stacks/test_stacks.py
index 0b7883d..fc2dda8 100644
--- a/tempest/api/orchestration/stacks/test_stacks.py
+++ b/tempest/api/orchestration/stacks/test_stacks.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
diff --git a/tempest/api/orchestration/stacks/test_templates.py b/tempest/api/orchestration/stacks/test_templates.py
index 2589632..2da819d 100644
--- a/tempest/api/orchestration/stacks/test_templates.py
+++ b/tempest/api/orchestration/stacks/test_templates.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -12,17 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.
-import logging
-
from tempest.api.orchestration import base
from tempest.common.utils import data_utils
-from tempest import exceptions
from tempest.test import attr
-LOG = logging.getLogger(__name__)
-
-
class TemplateYAMLTestJSON(base.BaseOrchestrationTest):
_interface = 'json'
@@ -61,14 +53,6 @@
self.parameters)
self.assertEqual('200', resp['status'])
- @attr(type=['gate', 'negative'])
- def test_validate_template_url(self):
- """Validating template passing url to it."""
- self.assertRaises(exceptions.BadRequest,
- self.client.validate_template_url,
- template_url=self.invalid_template_url,
- parameters=self.parameters)
-
class TemplateAWSTestJSON(TemplateYAMLTestJSON):
template = """
diff --git a/tempest/api/orchestration/stacks/test_templates_negative.py b/tempest/api/orchestration/stacks/test_templates_negative.py
new file mode 100644
index 0000000..c55f6ee
--- /dev/null
+++ b/tempest/api/orchestration/stacks/test_templates_negative.py
@@ -0,0 +1,62 @@
+# Copyright 2014 NEC Corporation. All rights reserved.
+#
+# 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 tempest.api.orchestration import base
+from tempest import exceptions
+from tempest import test
+
+
+class TemplateYAMLNegativeTestJSON(base.BaseOrchestrationTest):
+ _interface = 'json'
+
+ template = """
+HeatTemplateFormatVersion: '2012-12-12'
+Description: |
+ Template which creates only a new user
+Resources:
+ CfnUser:
+ Type: AWS::IAM::User
+"""
+
+ invalid_template_url = 'http://www.example.com/template.yaml'
+
+ @classmethod
+ def setUpClass(cls):
+ super(TemplateYAMLNegativeTestJSON, cls).setUpClass()
+ cls.client = cls.orchestration_client
+ cls.parameters = {}
+
+ @test.attr(type=['gate', 'negative'])
+ def test_validate_template_url(self):
+ """Validating template passing url to it."""
+ self.assertRaises(exceptions.BadRequest,
+ self.client.validate_template_url,
+ template_url=self.invalid_template_url,
+ parameters=self.parameters)
+
+
+class TemplateAWSNegativeTestJSON(TemplateYAMLNegativeTestJSON):
+ template = """
+{
+ "AWSTemplateFormatVersion" : "2010-09-09",
+ "Description" : "Template which creates only a new user",
+ "Resources" : {
+ "CfnUser" : {
+ "Type" : "AWS::IAM::User"
+ }
+ }
+}
+"""
+
+ invalid_template_url = 'http://www.example.com/template.template'
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/api/telemetry/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/api/telemetry/__init__.py
diff --git a/tempest/api/telemetry/base.py b/tempest/api/telemetry/base.py
new file mode 100644
index 0000000..c4614c6
--- /dev/null
+++ b/tempest/api/telemetry/base.py
@@ -0,0 +1,51 @@
+# 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 tempest.common.utils import data_utils
+from tempest import config
+from tempest import exceptions
+import tempest.test
+
+CONF = config.CONF
+
+
+class BaseTelemetryTest(tempest.test.BaseTestCase):
+
+ """Base test case class for all Telemetry API tests."""
+
+ @classmethod
+ def setUpClass(cls):
+ if not CONF.service_available.ceilometer:
+ raise cls.skipException("Ceilometer support is required")
+ super(BaseTelemetryTest, cls).setUpClass()
+ os = cls.get_client_manager()
+ cls.telemetry_client = os.telemetry_client
+ cls.alarm_ids = []
+
+ @classmethod
+ def create_alarm(cls, **kwargs):
+ resp, body = cls.telemetry_client.create_alarm(
+ name=data_utils.rand_name('telemetry_alarm'),
+ type='threshold', **kwargs)
+ if resp['status'] == '201':
+ cls.alarm_ids.append(body['alarm_id'])
+ return resp, body
+
+ @classmethod
+ def tearDownClass(cls):
+ for alarm_id in cls.alarm_ids:
+ try:
+ cls.telemetry_client.delete_alarm(alarm_id)
+ except exceptions.NotFound:
+ pass
+ cls.clear_isolated_creds()
+ super(BaseTelemetryTest, cls).tearDownClass()
diff --git a/tempest/api/telemetry/test_telemetry_alarming_api.py b/tempest/api/telemetry/test_telemetry_alarming_api.py
new file mode 100644
index 0000000..907d3d0
--- /dev/null
+++ b/tempest/api/telemetry/test_telemetry_alarming_api.py
@@ -0,0 +1,43 @@
+# 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 tempest.api.telemetry import base
+from tempest import exceptions
+from tempest.test import attr
+
+
+class TelemetryAlarmingAPITestJSON(base.BaseTelemetryTest):
+ _interface = 'json'
+
+ @attr(type="gate")
+ def test_alarm_list(self):
+ resp, _ = self.telemetry_client.list_alarms()
+ self.assertEqual(int(resp['status']), 200)
+
+ @attr(type="gate")
+ def test_create_alarm(self):
+ rules = {'meter_name': 'cpu_util',
+ 'comparison_operator': 'gt',
+ 'threshold': 80.0,
+ 'period': 70}
+ resp, body = self.create_alarm(threshold_rule=rules)
+ self.alarm_id = body['alarm_id']
+ self.assertEqual(int(resp['status']), 201)
+ self.assertDictContainsSubset(rules, body['threshold_rule'])
+ resp, body = self.telemetry_client.get_alarm(self.alarm_id)
+ self.assertEqual(int(resp['status']), 200)
+ self.assertDictContainsSubset(rules, body['threshold_rule'])
+ resp, _ = self.telemetry_client.delete_alarm(self.alarm_id)
+ self.assertEqual(int(resp['status']), 204)
+ self.assertRaises(exceptions.NotFound,
+ self.telemetry_client.get_alarm,
+ self.alarm_id)
diff --git a/tempest/api/utils.py b/tempest/api/utils.py
index be6bdba..c62dc8d 100644
--- a/tempest/api/utils.py
+++ b/tempest/api/utils.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/volume/admin/test_multi_backend.py b/tempest/api/volume/admin/test_multi_backend.py
index c563259..b0c878b 100644
--- a/tempest/api/volume/admin/test_multi_backend.py
+++ b/tempest/api/volume/admin/test_multi_backend.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -14,11 +12,12 @@
from tempest.api.volume import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.openstack.common import log as logging
-from tempest.services.volume.json.admin import volume_types_client
-from tempest.services.volume.json import volumes_client
from tempest.test import attr
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -28,29 +27,14 @@
@classmethod
def setUpClass(cls):
super(VolumeMultiBackendTest, cls).setUpClass()
- if not cls.config.volume_feature_enabled.multi_backend:
+ if not CONF.volume_feature_enabled.multi_backend:
cls.tearDownClass()
raise cls.skipException("Cinder multi-backend feature disabled")
- cls.backend1_name = cls.config.volume.backend1_name
- cls.backend2_name = cls.config.volume.backend2_name
+ cls.backend1_name = CONF.volume.backend1_name
+ cls.backend2_name = CONF.volume.backend2_name
- adm_user = cls.config.identity.admin_username
- adm_pass = cls.config.identity.admin_password
- adm_tenant = cls.config.identity.admin_tenant_name
- auth_url = cls.config.identity.uri
-
- cls.volume_client = volumes_client.VolumesClientJSON(cls.config,
- adm_user,
- adm_pass,
- auth_url,
- adm_tenant)
- cls.type_client = volume_types_client.VolumeTypesClientJSON(cls.config,
- adm_user,
- adm_pass,
- auth_url,
- adm_tenant)
-
+ cls.volume_client = cls.os_adm.volumes_client
cls.volume_type_id_list = []
cls.volume_id_list = []
try:
@@ -58,7 +42,7 @@
type1_name = data_utils.rand_name('Type-')
vol1_name = data_utils.rand_name('Volume-')
extra_specs1 = {"volume_backend_name": cls.backend1_name}
- resp, cls.type1 = cls.type_client.create_volume_type(
+ resp, cls.type1 = cls.client.create_volume_type(
type1_name, extra_specs=extra_specs1)
cls.volume_type_id_list.append(cls.type1['id'])
@@ -73,7 +57,7 @@
type2_name = data_utils.rand_name('Type-')
vol2_name = data_utils.rand_name('Volume-')
extra_specs2 = {"volume_backend_name": cls.backend2_name}
- resp, cls.type2 = cls.type_client.create_volume_type(
+ resp, cls.type2 = cls.client.create_volume_type(
type2_name, extra_specs=extra_specs2)
cls.volume_type_id_list.append(cls.type2['id'])
@@ -98,7 +82,7 @@
# volume types deletion
volume_type_id_list = getattr(cls, 'volume_type_id_list', [])
for volume_type_id in volume_type_id_list:
- cls.type_client.delete_volume_type(volume_type_id)
+ cls.client.delete_volume_type(volume_type_id)
super(VolumeMultiBackendTest, cls).tearDownClass()
diff --git a/tempest/api/volume/admin/test_snapshots_actions.py b/tempest/api/volume/admin/test_snapshots_actions.py
index 03fbd33..12fda92 100644
--- a/tempest/api/volume/admin/test_snapshots_actions.py
+++ b/tempest/api/volume/admin/test_snapshots_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD
# All Rights Reserved.
#
@@ -66,6 +64,19 @@
status)
super(SnapshotsActionsTest, self).tearDown()
+ def _create_reset_and_force_delete_temp_snapshot(self, status=None):
+ # Create snapshot, reset snapshot status,
+ # and force delete temp snapshot
+ temp_snapshot = self.create_snapshot(self.volume['id'])
+ if status:
+ resp, body = self.admin_snapshots_client.\
+ reset_snapshot_status(temp_snapshot['id'], status)
+ self.assertEqual(202, resp.status)
+ resp_delete, volume_delete = self.admin_snapshots_client.\
+ force_delete_snapshot(temp_snapshot['id'])
+ self.assertEqual(202, resp_delete.status)
+ self.client.wait_for_resource_deletion(temp_snapshot['id'])
+
def _get_progress_alias(self):
return 'os-extended-snapshot-attributes:progress'
@@ -101,6 +112,26 @@
self.assertEqual(status, snapshot_get['status'])
self.assertEqual(progress, snapshot_get[progress_alias])
+ @attr(type='gate')
+ def test_snapshot_force_delete_when_snapshot_is_creating(self):
+ # test force delete when status of snapshot is creating
+ self._create_reset_and_force_delete_temp_snapshot('creating')
+
+ @attr(type='gate')
+ def test_snapshot_force_delete_when_snapshot_is_deleting(self):
+ # test force delete when status of snapshot is deleting
+ self._create_reset_and_force_delete_temp_snapshot('deleting')
+
+ @attr(type='gate')
+ def test_snapshot_force_delete_when_snapshot_is_error(self):
+ # test force delete when status of snapshot is error
+ self._create_reset_and_force_delete_temp_snapshot('error')
+
+ @attr(type='gate')
+ def test_snapshot_force_delete_when_snapshot_is_error_deleting(self):
+ # test force delete when status of snapshot is error_deleting
+ self._create_reset_and_force_delete_temp_snapshot('error_deleting')
+
class SnapshotsActionsTestXML(SnapshotsActionsTest):
_interface = "xml"
diff --git a/tempest/api/volume/admin/test_volume_hosts.py b/tempest/api/volume/admin/test_volume_hosts.py
index 4f40d4a..5c311e1 100644
--- a/tempest/api/volume/admin/test_volume_hosts.py
+++ b/tempest/api/volume/admin/test_volume_hosts.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/volume/admin/test_volume_types.py b/tempest/api/volume/admin/test_volume_types.py
index 3a92e8d..d481251 100644
--- a/tempest/api/volume/admin/test_volume_types.py
+++ b/tempest/api/volume/admin/test_volume_types.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,27 +15,15 @@
from tempest.api.volume import base
from tempest.common.utils import data_utils
-from tempest.services.volume.json.admin import volume_types_client
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
-class VolumeTypesTest(base.BaseVolumeV1Test):
+
+class VolumeTypesTest(base.BaseVolumeV1AdminTest):
_interface = "json"
- @classmethod
- def setUpClass(cls):
- super(VolumeTypesTest, cls).setUpClass()
- adm_user = cls.config.identity.admin_username
- adm_pass = cls.config.identity.admin_password
- adm_tenant = cls.config.identity.admin_tenant_name
- auth_url = cls.config.identity.uri
-
- cls.client = volume_types_client.VolumeTypesClientJSON(cls.config,
- adm_user,
- adm_pass,
- auth_url,
- adm_tenant)
-
def _delete_volume(self, volume_id):
resp, _ = self.volumes_client.delete_volume(volume_id)
self.assertEqual(202, resp.status)
@@ -60,8 +46,8 @@
volume = {}
vol_name = data_utils.rand_name("volume-")
vol_type_name = data_utils.rand_name("volume-type-")
- proto = self.config.volume.storage_protocol
- vendor = self.config.volume.vendor_name
+ proto = CONF.volume.storage_protocol
+ vendor = CONF.volume.vendor_name
extra_specs = {"storage_protocol": proto,
"vendor_name": vendor}
body = {}
@@ -103,8 +89,8 @@
# Create/get volume type.
body = {}
name = data_utils.rand_name("volume-type-")
- proto = self.config.volume.storage_protocol
- vendor = self.config.volume.vendor_name
+ proto = CONF.volume.storage_protocol
+ vendor = CONF.volume.vendor_name
extra_specs = {"storage_protocol": proto,
"vendor_name": vendor}
resp, body = self.client.create_volume_type(
diff --git a/tempest/api/volume/admin/test_volume_types_extra_specs.py b/tempest/api/volume/admin/test_volume_types_extra_specs.py
index f0fba07..99a0826 100644
--- a/tempest/api/volume/admin/test_volume_types_extra_specs.py
+++ b/tempest/api/volume/admin/test_volume_types_extra_specs.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/volume/admin/test_volume_types_extra_specs_negative.py b/tempest/api/volume/admin/test_volume_types_extra_specs_negative.py
index cf992f2..5a1a2cd 100644
--- a/tempest/api/volume/admin/test_volume_types_extra_specs_negative.py
+++ b/tempest/api/volume/admin/test_volume_types_extra_specs_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/volume/admin/test_volume_types_negative.py b/tempest/api/volume/admin/test_volume_types_negative.py
index 3832048..56ad227 100644
--- a/tempest/api/volume/admin/test_volume_types_negative.py
+++ b/tempest/api/volume/admin/test_volume_types_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/api/volume/admin/test_volumes_actions.py b/tempest/api/volume/admin/test_volumes_actions.py
index 941dc7e..9274fce 100644
--- a/tempest/api/volume/admin/test_volumes_actions.py
+++ b/tempest/api/volume/admin/test_volumes_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD
# All Rights Reserved.
#
diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py
index 9c841cc..de2b240 100644
--- a/tempest/api/volume/base.py
+++ b/tempest/api/volume/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,9 +15,12 @@
from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest.openstack.common import log as logging
import tempest.test
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -29,22 +30,20 @@
@classmethod
def setUpClass(cls):
+ cls.set_network_resources()
super(BaseVolumeTest, cls).setUpClass()
- if not cls.config.service_available.cinder:
+ if not CONF.service_available.cinder:
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
raise cls.skipException(skip_msg)
cls.os = cls.get_client_manager()
- cls.volumes_client = cls.os.volumes_client
- cls.snapshots_client = cls.os.snapshots_client
cls.servers_client = cls.os.servers_client
- cls.volumes_extension_client = cls.os.volumes_extension_client
- cls.image_ref = cls.config.compute.image_ref
- cls.flavor_ref = cls.config.compute.flavor_ref
- cls.build_interval = cls.config.volume.build_interval
- cls.build_timeout = cls.config.volume.build_timeout
+ cls.image_ref = CONF.compute.image_ref
+ cls.flavor_ref = CONF.compute.flavor_ref
+ cls.build_interval = CONF.volume.build_interval
+ cls.build_timeout = CONF.volume.build_timeout
cls.snapshots = []
cls.volumes = []
@@ -113,16 +112,13 @@
class BaseVolumeV1Test(BaseVolumeTest):
@classmethod
def setUpClass(cls):
- if not cls.config.volume_feature_enabled.api_v1:
+ if not CONF.volume_feature_enabled.api_v1:
msg = "Volume API v1 not supported"
raise cls.skipException(msg)
super(BaseVolumeV1Test, cls).setUpClass()
+ cls.snapshots_client = cls.os.snapshots_client
cls.volumes_client = cls.os.volumes_client
- cls.volumes_client.keystone_auth(cls.os.username,
- cls.os.password,
- cls.os.auth_url,
- cls.volumes_client.service,
- cls.os.tenant_name)
+ cls.volumes_extension_client = cls.os.volumes_extension_client
class BaseVolumeV1AdminTest(BaseVolumeV1Test):
@@ -130,14 +126,14 @@
@classmethod
def setUpClass(cls):
super(BaseVolumeV1AdminTest, cls).setUpClass()
- cls.adm_user = cls.config.identity.admin_username
- cls.adm_pass = cls.config.identity.admin_password
- cls.adm_tenant = cls.config.identity.admin_tenant_name
+ cls.adm_user = CONF.identity.admin_username
+ cls.adm_pass = CONF.identity.admin_password
+ cls.adm_tenant = CONF.identity.admin_tenant_name
if not all((cls.adm_user, cls.adm_pass, cls.adm_tenant)):
msg = ("Missing Volume Admin API credentials "
"in configuration.")
raise cls.skipException(msg)
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_admin_creds()
admin_username, admin_tenant_name, admin_password = creds
cls.os_adm = clients.Manager(username=admin_username,
diff --git a/tempest/api/volume/test_extensions.py b/tempest/api/volume/test_extensions.py
index 90988a2..cceffd6 100644
--- a/tempest/api/volume/test_extensions.py
+++ b/tempest/api/volume/test_extensions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
@@ -17,10 +15,17 @@
from tempest.api.volume import base
+from tempest import config
+from tempest.openstack.common import log as logging
from tempest.test import attr
+CONF = config.CONF
-class ExtensionsTestJSON(base.BaseVolumeTest):
+
+LOG = logging.getLogger(__name__)
+
+
+class ExtensionsTestJSON(base.BaseVolumeV1Test):
_interface = 'json'
@attr(type='gate')
@@ -28,9 +33,11 @@
# List of all extensions
resp, extensions = self.volumes_extension_client.list_extensions()
self.assertEqual(200, resp.status)
- if len(self.config.volume_feature_enabled.api_extensions) == 0:
+ if len(CONF.volume_feature_enabled.api_extensions) == 0:
raise self.skipException('There are not any extensions configured')
- ext = self.config.volume_feature_enabled.api_extensions[0]
+ extension_list = [extension.get('alias') for extension in extensions]
+ LOG.debug("Cinder extensions: %s" % ','.join(extension_list))
+ ext = CONF.volume_feature_enabled.api_extensions[0]
if ext == 'all':
self.assertIn('Hosts', map(lambda x: x['name'], extensions))
elif ext:
diff --git a/tempest/api/volume/test_snapshot_metadata.py b/tempest/api/volume/test_snapshot_metadata.py
new file mode 100644
index 0000000..1493b37
--- /dev/null
+++ b/tempest/api/volume/test_snapshot_metadata.py
@@ -0,0 +1,117 @@
+# Copyright 2013 Huawei Technologies Co.,LTD
+# All Rights Reserved.
+#
+# 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 tempest.api.volume import base
+from tempest import test
+
+
+class SnapshotMetadataTest(base.BaseVolumeV1Test):
+ _interface = "json"
+
+ @classmethod
+ def setUpClass(cls):
+ super(SnapshotMetadataTest, cls).setUpClass()
+ cls.client = cls.snapshots_client
+ # Create a volume
+ cls.volume = cls.create_volume()
+ # Create a snapshot
+ cls.snapshot = cls.create_snapshot(volume_id=cls.volume['id'])
+ cls.snapshot_id = cls.snapshot['id']
+
+ def tearDown(self):
+ # Update the metadata to {}
+ self.client.update_snapshot_metadata(self.snapshot_id, {})
+ super(SnapshotMetadataTest, self).tearDown()
+
+ @test.attr(type='gate')
+ def test_create_get_delete_snapshot_metadata(self):
+ # Create metadata for the snapshot
+ metadata = {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3"}
+ expected = {"key2": "value2",
+ "key3": "value3"}
+ resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
+ metadata)
+ self.assertEqual(200, resp.status)
+ # Get the metadata of the snapshot
+ resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(metadata, body)
+ # Delete one item metadata of the snapshot
+ resp, body = self.client.delete_snapshot_metadata_item(
+ self.snapshot_id,
+ "key1")
+ self.assertEqual(200, resp.status)
+ resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
+ self.assertEqual(expected, body)
+
+ @test.attr(type='gate')
+ def test_update_snapshot_metadata(self):
+ # Update metadata for the snapshot
+ metadata = {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3"}
+ update = {"key3": "value3_update",
+ "key4": "value4"}
+ # Create metadata for the snapshot
+ resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
+ metadata)
+ self.assertEqual(200, resp.status)
+ # Get the metadata of the snapshot
+ resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(metadata, body)
+ # Update metadata item
+ resp, body = self.client.update_snapshot_metadata(
+ self.snapshot_id,
+ update)
+ self.assertEqual(200, resp.status)
+ # Get the metadata of the snapshot
+ resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(update, body)
+
+ @test.attr(type='gate')
+ def test_update_snapshot_metadata_item(self):
+ # Update metadata item for the snapshot
+ metadata = {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3"}
+ update_item = {"key3": "value3_update"}
+ expect = {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3_update"}
+ # Create metadata for the snapshot
+ resp, body = self.client.create_snapshot_metadata(self.snapshot_id,
+ metadata)
+ self.assertEqual(200, resp.status)
+ # Get the metadata of the snapshot
+ resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
+ self.assertEqual(metadata, body)
+ # Update metadata item
+ resp, body = self.client.update_snapshot_metadata_item(
+ self.snapshot_id,
+ "key3",
+ update_item)
+ self.assertEqual(200, resp.status)
+ # Get the metadata of the snapshot
+ resp, body = self.client.get_snapshot_metadata(self.snapshot_id)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(expect, body)
+
+
+class SnapshotMetadataTestXML(SnapshotMetadataTest):
+ _interface = "xml"
diff --git a/tempest/api/volume/test_volume_metadata.py b/tempest/api/volume/test_volume_metadata.py
index 0909ade..ec732d1 100644
--- a/tempest/api/volume/test_volume_metadata.py
+++ b/tempest/api/volume/test_volume_metadata.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Huawei Technologies Co.,LTD
# All Rights Reserved.
#
@@ -15,11 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest.api.volume.base import BaseVolumeTest
+from testtools.matchers import ContainsAll
+
+from tempest.api.volume import base
from tempest import test
-class VolumeMetadataTest(BaseVolumeTest):
+class VolumeMetadataTest(base.BaseVolumeV1Test):
_interface = "json"
@classmethod
@@ -51,7 +51,7 @@
# Get the metadata of the volume
resp, body = self.volumes_client.get_volume_metadata(self.volume_id)
self.assertEqual(200, resp.status)
- self.assertEqual(metadata, body)
+ self.assertThat(body.items(), ContainsAll(metadata.items()))
# Delete one item metadata of the volume
rsp, body = self.volumes_client.delete_volume_metadata_item(
self.volume_id,
@@ -78,7 +78,7 @@
# Get the metadata of the volume
resp, body = self.volumes_client.get_volume_metadata(self.volume_id)
self.assertEqual(200, resp.status)
- self.assertEqual(metadata, body)
+ self.assertThat(body.items(), ContainsAll(metadata.items()))
# Update metadata
resp, body = self.volumes_client.update_volume_metadata(
self.volume_id,
@@ -87,7 +87,7 @@
# Get the metadata of the volume
resp, body = self.volumes_client.get_volume_metadata(self.volume_id)
self.assertEqual(200, resp.status)
- self.assertEqual(update, body)
+ self.assertThat(body.items(), ContainsAll(update.items()))
@test.attr(type='gate')
def test_update_volume_metadata_item(self):
@@ -95,9 +95,6 @@
metadata = {"key1": "value1",
"key2": "value2",
"key3": "value3"}
- create_expect = {"key1": "value1",
- "key2": "value2",
- "key3": "value3"}
update_item = {"key3": "value3_update"}
expect = {"key1": "value1",
"key2": "value2",
@@ -107,7 +104,7 @@
self.volume_id,
metadata)
self.assertEqual(200, resp.status)
- self.assertEqual(create_expect, body)
+ self.assertThat(body.items(), ContainsAll(metadata.items()))
# Update metadata item
resp, body = self.volumes_client.update_volume_metadata_item(
self.volume_id,
@@ -117,7 +114,7 @@
# Get the metadata of the volume
resp, body = self.volumes_client.get_volume_metadata(self.volume_id)
self.assertEqual(200, resp.status)
- self.assertEqual(expect, body)
+ self.assertThat(body.items(), ContainsAll(expect.items()))
class VolumeMetadataTestXML(VolumeMetadataTest):
diff --git a/tempest/api/volume/test_volume_transfers.py b/tempest/api/volume/test_volume_transfers.py
index 34eab00..cf4e052 100644
--- a/tempest/api/volume/test_volume_transfers.py
+++ b/tempest/api/volume/test_volume_transfers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,10 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
+from testtools import matchers
+
from tempest.api.volume import base
from tempest import clients
+from tempest import config
from tempest.test import attr
+CONF = config.CONF
+
class VolumesTransfersTest(base.BaseVolumeV1Test):
_interface = "json"
@@ -28,7 +31,7 @@
super(VolumesTransfersTest, cls).setUpClass()
# Add another tenant to test volume-transfer
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
creds = cls.isolated_creds.get_alt_creds()
username, tenant_name, password = creds
cls.os_alt = clients.Manager(username=username,
@@ -57,10 +60,17 @@
cls.alt_client = cls.os_alt.volumes_client
cls.adm_client = cls.os_adm.volumes_client
+ def _delete_volume(self, volume_id):
+ # Delete the specified volume using admin creds
+ resp, _ = self.adm_client.delete_volume(volume_id)
+ self.assertEqual(202, resp.status)
+ self.adm_client.wait_for_resource_deletion(volume_id)
+
@attr(type='gate')
def test_create_get_list_accept_volume_transfer(self):
# Create a volume first
volume = self.create_volume()
+ self.addCleanup(self._delete_volume, volume['id'])
# Create a volume transfer
resp, transfer = self.client.create_volume_transfer(volume['id'])
@@ -79,7 +89,7 @@
# or equal to 1
resp, body = self.client.list_volume_transfers()
self.assertEqual(200, resp.status)
- self.assertGreaterEqual(len(body), 1)
+ self.assertThat(len(body), matchers.GreaterThan(0))
# Accept a volume transfer by alt_tenant
resp, body = self.alt_client.accept_volume_transfer(transfer_id,
@@ -90,6 +100,7 @@
def test_create_list_delete_volume_transfer(self):
# Create a volume first
volume = self.create_volume()
+ self.addCleanup(self._delete_volume, volume['id'])
# Create a volume transfer
resp, body = self.client.create_volume_transfer(volume['id'])
@@ -98,10 +109,14 @@
self.client.wait_for_volume_status(volume['id'],
'awaiting-transfer')
- # List all volume transfers, there's only one in this test
+ # List all volume transfers (looking for the one we created)
resp, body = self.client.list_volume_transfers()
self.assertEqual(200, resp.status)
- self.assertEqual(volume['id'], body[0]['volume_id'])
+ for transfer in body:
+ if volume['id'] == transfer['volume_id']:
+ break
+ else:
+ self.fail('Transfer not found for volume %s' % volume['id'])
# Delete a volume transfer
resp, body = self.client.delete_volume_transfer(transfer_id)
diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py
index 7a7ead6..5924c7e 100644
--- a/tempest/api/volume/test_volumes_actions.py
+++ b/tempest/api/volume/test_volumes_actions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,10 +15,13 @@
from tempest.api.volume import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
from tempest.test import services
from tempest.test import stresstest
+CONF = config.CONF
+
class VolumesActionsTest(base.BaseVolumeV1Test):
_interface = "json"
@@ -100,7 +101,7 @@
image_name = data_utils.rand_name('Image-')
resp, body = self.client.upload_volume(self.volume['id'],
image_name,
- self.config.volume.disk_format)
+ CONF.volume.disk_format)
image_id = body["image_id"]
self.addCleanup(self.image_client.delete_image, image_id)
self.assertEqual(202, resp.status)
diff --git a/tempest/api/volume/test_volumes_get.py b/tempest/api/volume/test_volumes_get.py
index e342563..6d89e5b 100644
--- a/tempest/api/volume/test_volumes_get.py
+++ b/tempest/api/volume/test_volumes_get.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,11 +13,16 @@
# License for the specific language governing permissions and limitations
# under the License.
+from testtools.matchers import ContainsAll
+
from tempest.api.volume import base
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
from tempest.test import services
+CONF = config.CONF
+
class VolumesGetTest(base.BaseVolumeV1Test):
_interface = "json"
@@ -68,16 +71,16 @@
self.assertEqual(200, resp.status)
self.assertEqual(v_name,
fetched_volume['display_name'],
- 'The fetched Volume is different '
+ 'The fetched Volume name is different '
'from the created Volume')
self.assertEqual(volume['id'],
fetched_volume['id'],
- 'The fetched Volume is different '
+ 'The fetched Volume id is different '
'from the created Volume')
- self.assertEqual(metadata,
- fetched_volume['metadata'],
- 'The fetched Volume is different '
- 'from the created Volume')
+ self.assertThat(fetched_volume['metadata'].items(),
+ ContainsAll(metadata.items()),
+ 'The fetched Volume metadata misses data '
+ 'from the created Volume')
# NOTE(jdg): Revert back to strict true/false checking
# after fix for bug #1227837 merges
@@ -104,7 +107,10 @@
self.assertEqual(volume['id'], updated_volume['id'])
self.assertEqual(new_v_name, updated_volume['display_name'])
self.assertEqual(new_desc, updated_volume['display_description'])
- self.assertEqual(metadata, updated_volume['metadata'])
+ self.assertThat(updated_volume['metadata'].items(),
+ ContainsAll(metadata.items()),
+ 'The fetched Volume metadata misses data '
+ 'from the created Volume')
# NOTE(jdg): Revert back to strict true/false checking
# after fix for bug #1227837 merges
@@ -114,18 +120,6 @@
if 'imageRef' not in kwargs:
self.assertEqual(boot_flag, False)
- @attr(type='gate')
- def test_volume_get_metadata_none(self):
- # Create a volume without passing metadata, get details, and delete
-
- # Create a volume without metadata
- volume = self.create_volume(metadata={})
-
- # GET Volume
- resp, fetched_volume = self.client.get_volume(volume['id'])
- self.assertEqual(200, resp.status)
- self.assertEqual(fetched_volume['metadata'], {})
-
@attr(type='smoke')
def test_volume_create_get_update_delete(self):
self._volume_create_get_update_delete()
@@ -133,8 +127,7 @@
@attr(type='smoke')
@services('image')
def test_volume_create_get_update_delete_from_image(self):
- self._volume_create_get_update_delete(imageRef=self.
- config.compute.image_ref)
+ self._volume_create_get_update_delete(imageRef=CONF.compute.image_ref)
@attr(type='gate')
def test_volume_create_get_update_delete_as_clone(self):
diff --git a/tempest/api/volume/test_volumes_list.py b/tempest/api/volume/test_volumes_list.py
index 49a2f74..049544d 100644
--- a/tempest/api/volume/test_volumes_list.py
+++ b/tempest/api/volume/test_volumes_list.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -21,6 +19,7 @@
from tempest.common.utils import data_utils
from tempest.openstack.common import log as logging
from tempest.test import attr
+from testtools.matchers import ContainsAll
LOG = logging.getLogger(__name__)
@@ -110,7 +109,12 @@
for key in params:
msg = "Failed to list volumes %s by %s" % \
('details' if with_detail else '', key)
- self.assertEqual(params[key], volume[key], msg)
+ if key == 'metadata':
+ self.assertThat(volume[key].items(),
+ ContainsAll(params[key].items()),
+ msg)
+ else:
+ self.assertEqual(params[key], volume[key], msg)
@attr(type='smoke')
def test_volume_list(self):
diff --git a/tempest/api/volume/test_volumes_negative.py b/tempest/api/volume/test_volumes_negative.py
index f14cfdc..284c321 100644
--- a/tempest/api/volume/test_volumes_negative.py
+++ b/tempest/api/volume/test_volumes_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -36,14 +34,14 @@
cls.mountpoint = "/dev/vdc"
@attr(type=['negative', 'gate'])
- def test_volume_get_nonexistant_volume_id(self):
- # Should not be able to get a non-existant volume
+ def test_volume_get_nonexistent_volume_id(self):
+ # Should not be able to get a non-existent volume
self.assertRaises(exceptions.NotFound, self.client.get_volume,
str(uuid.uuid4()))
@attr(type=['negative', 'gate'])
- def test_volume_delete_nonexistant_volume_id(self):
- # Should not be able to delete a non-existant Volume
+ def test_volume_delete_nonexistent_volume_id(self):
+ # Should not be able to delete a non-existent Volume
self.assertRaises(exceptions.NotFound, self.client.delete_volume,
str(uuid.uuid4()))
@@ -82,8 +80,8 @@
size='-1', display_name=v_name, metadata=metadata)
@attr(type=['negative', 'gate'])
- def test_create_volume_with_nonexistant_volume_type(self):
- # Should not be able to create volume with non-existant volume type
+ def test_create_volume_with_nonexistent_volume_type(self):
+ # Should not be able to create volume with non-existent volume type
v_name = data_utils.rand_name('Volume-')
metadata = {'Type': 'work'}
self.assertRaises(exceptions.NotFound, self.client.create_volume,
@@ -91,8 +89,8 @@
display_name=v_name, metadata=metadata)
@attr(type=['negative', 'gate'])
- def test_create_volume_with_nonexistant_snapshot_id(self):
- # Should not be able to create volume with non-existant snapshot
+ def test_create_volume_with_nonexistent_snapshot_id(self):
+ # Should not be able to create volume with non-existent snapshot
v_name = data_utils.rand_name('Volume-')
metadata = {'Type': 'work'}
self.assertRaises(exceptions.NotFound, self.client.create_volume,
@@ -100,8 +98,8 @@
display_name=v_name, metadata=metadata)
@attr(type=['negative', 'gate'])
- def test_create_volume_with_nonexistant_source_volid(self):
- # Should not be able to create volume with non-existant source volume
+ def test_create_volume_with_nonexistent_source_volid(self):
+ # Should not be able to create volume with non-existent source volume
v_name = data_utils.rand_name('Volume-')
metadata = {'Type': 'work'}
self.assertRaises(exceptions.NotFound, self.client.create_volume,
@@ -109,7 +107,7 @@
display_name=v_name, metadata=metadata)
@attr(type=['negative', 'gate'])
- def test_update_volume_with_nonexistant_volume_id(self):
+ def test_update_volume_with_nonexistent_volume_id(self):
v_name = data_utils.rand_name('Volume-')
metadata = {'Type': 'work'}
self.assertRaises(exceptions.NotFound, self.client.update_volume,
diff --git a/tempest/api/volume/test_volumes_snapshots.py b/tempest/api/volume/test_volumes_snapshots.py
index 4e57007..487ada6 100644
--- a/tempest/api/volume/test_volumes_snapshots.py
+++ b/tempest/api/volume/test_volumes_snapshots.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
diff --git a/tempest/api/volume/test_volumes_snapshots_negative.py b/tempest/api/volume/test_volumes_snapshots_negative.py
index 0e4f5dc..b24b597 100644
--- a/tempest/api/volume/test_volumes_snapshots_negative.py
+++ b/tempest/api/volume/test_volumes_snapshots_negative.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/api/volume/v2/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/api/volume/v2/__init__.py
diff --git a/tempest/api/volume/v2/test_volumes_list.py b/tempest/api/volume/v2/test_volumes_list.py
new file mode 100644
index 0000000..049544d
--- /dev/null
+++ b/tempest/api/volume/v2/test_volumes_list.py
@@ -0,0 +1,228 @@
+# Copyright 2012 OpenStack Foundation
+# Copyright 2013 IBM Corp.
+# All Rights Reserved.
+#
+# 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 operator
+
+from tempest.api.volume import base
+from tempest.common.utils import data_utils
+from tempest.openstack.common import log as logging
+from tempest.test import attr
+from testtools.matchers import ContainsAll
+
+LOG = logging.getLogger(__name__)
+
+VOLUME_FIELDS = ('id', 'display_name')
+
+
+class VolumesListTest(base.BaseVolumeV1Test):
+
+ """
+ This test creates a number of 1G volumes. To run successfully,
+ ensure that the backing file for the volume group that Nova uses
+ has space for at least 3 1G volumes!
+ If you are running a Devstack environment, ensure that the
+ VOLUME_BACKING_FILE_SIZE is at least 4G in your localrc
+ """
+
+ _interface = 'json'
+
+ def assertVolumesIn(self, fetched_list, expected_list, fields=None):
+ if fields:
+ expected_list = map(operator.itemgetter(*fields), expected_list)
+ fetched_list = map(operator.itemgetter(*fields), fetched_list)
+
+ missing_vols = [v for v in expected_list if v not in fetched_list]
+ if len(missing_vols) == 0:
+ return
+
+ def str_vol(vol):
+ return "%s:%s" % (vol['id'], vol['display_name'])
+
+ raw_msg = "Could not find volumes %s in expected list %s; fetched %s"
+ self.fail(raw_msg % ([str_vol(v) for v in missing_vols],
+ [str_vol(v) for v in expected_list],
+ [str_vol(v) for v in fetched_list]))
+
+ @classmethod
+ def setUpClass(cls):
+ super(VolumesListTest, cls).setUpClass()
+ cls.client = cls.volumes_client
+
+ # Create 3 test volumes
+ cls.volume_list = []
+ cls.volume_id_list = []
+ cls.metadata = {'Type': 'work'}
+ for i in range(3):
+ try:
+ volume = cls.create_volume(metadata=cls.metadata)
+
+ resp, volume = cls.client.get_volume(volume['id'])
+ cls.volume_list.append(volume)
+ cls.volume_id_list.append(volume['id'])
+ except Exception:
+ LOG.exception('Failed to create volume. %d volumes were '
+ 'created' % len(cls.volume_id_list))
+ if cls.volume_list:
+ # We could not create all the volumes, though we were able
+ # to create *some* of the volumes. This is typically
+ # because the backing file size of the volume group is
+ # too small.
+ for volid in cls.volume_id_list:
+ cls.client.delete_volume(volid)
+ cls.client.wait_for_resource_deletion(volid)
+ raise
+
+ @classmethod
+ def tearDownClass(cls):
+ # Delete the created volumes
+ for volid in cls.volume_id_list:
+ resp, _ = cls.client.delete_volume(volid)
+ cls.client.wait_for_resource_deletion(volid)
+ super(VolumesListTest, cls).tearDownClass()
+
+ def _list_by_param_value_and_assert(self, params, with_detail=False):
+ """
+ Perform list or list_details action with given params
+ and validates result.
+ """
+ if with_detail:
+ resp, fetched_vol_list = \
+ self.client.list_volumes_with_detail(params=params)
+ else:
+ resp, fetched_vol_list = self.client.list_volumes(params=params)
+
+ self.assertEqual(200, resp.status)
+ # Validating params of fetched volumes
+ for volume in fetched_vol_list:
+ for key in params:
+ msg = "Failed to list volumes %s by %s" % \
+ ('details' if with_detail else '', key)
+ if key == 'metadata':
+ self.assertThat(volume[key].items(),
+ ContainsAll(params[key].items()),
+ msg)
+ else:
+ self.assertEqual(params[key], volume[key], msg)
+
+ @attr(type='smoke')
+ def test_volume_list(self):
+ # Get a list of Volumes
+ # Fetch all volumes
+ resp, fetched_list = self.client.list_volumes()
+ self.assertEqual(200, resp.status)
+ self.assertVolumesIn(fetched_list, self.volume_list,
+ fields=VOLUME_FIELDS)
+
+ @attr(type='gate')
+ def test_volume_list_with_details(self):
+ # Get a list of Volumes with details
+ # Fetch all Volumes
+ resp, fetched_list = self.client.list_volumes_with_detail()
+ self.assertEqual(200, resp.status)
+ self.assertVolumesIn(fetched_list, self.volume_list)
+
+ @attr(type='gate')
+ def test_volume_list_by_name(self):
+ volume = self.volume_list[data_utils.rand_int_id(0, 2)]
+ params = {'display_name': volume['display_name']}
+ resp, fetched_vol = self.client.list_volumes(params)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(1, len(fetched_vol), str(fetched_vol))
+ self.assertEqual(fetched_vol[0]['display_name'],
+ volume['display_name'])
+
+ @attr(type='gate')
+ def test_volume_list_details_by_name(self):
+ volume = self.volume_list[data_utils.rand_int_id(0, 2)]
+ params = {'display_name': volume['display_name']}
+ resp, fetched_vol = self.client.list_volumes_with_detail(params)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(1, len(fetched_vol), str(fetched_vol))
+ self.assertEqual(fetched_vol[0]['display_name'],
+ volume['display_name'])
+
+ @attr(type='gate')
+ def test_volumes_list_by_status(self):
+ params = {'status': 'available'}
+ resp, fetched_list = self.client.list_volumes(params)
+ self.assertEqual(200, resp.status)
+ for volume in fetched_list:
+ self.assertEqual('available', volume['status'])
+ self.assertVolumesIn(fetched_list, self.volume_list,
+ fields=VOLUME_FIELDS)
+
+ @attr(type='gate')
+ def test_volumes_list_details_by_status(self):
+ params = {'status': 'available'}
+ resp, fetched_list = self.client.list_volumes_with_detail(params)
+ self.assertEqual(200, resp.status)
+ for volume in fetched_list:
+ self.assertEqual('available', volume['status'])
+ self.assertVolumesIn(fetched_list, self.volume_list)
+
+ @attr(type='gate')
+ def test_volumes_list_by_availability_zone(self):
+ volume = self.volume_list[data_utils.rand_int_id(0, 2)]
+ zone = volume['availability_zone']
+ params = {'availability_zone': zone}
+ resp, fetched_list = self.client.list_volumes(params)
+ self.assertEqual(200, resp.status)
+ for volume in fetched_list:
+ self.assertEqual(zone, volume['availability_zone'])
+ self.assertVolumesIn(fetched_list, self.volume_list,
+ fields=VOLUME_FIELDS)
+
+ @attr(type='gate')
+ def test_volumes_list_details_by_availability_zone(self):
+ volume = self.volume_list[data_utils.rand_int_id(0, 2)]
+ zone = volume['availability_zone']
+ params = {'availability_zone': zone}
+ resp, fetched_list = self.client.list_volumes_with_detail(params)
+ self.assertEqual(200, resp.status)
+ for volume in fetched_list:
+ self.assertEqual(zone, volume['availability_zone'])
+ self.assertVolumesIn(fetched_list, self.volume_list)
+
+ @attr(type='gate')
+ def test_volume_list_with_param_metadata(self):
+ # Test to list volumes when metadata param is given
+ params = {'metadata': self.metadata}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_volume_list_with_detail_param_metadata(self):
+ # Test to list volumes details when metadata param is given
+ params = {'metadata': self.metadata}
+ self._list_by_param_value_and_assert(params, with_detail=True)
+
+ @attr(type='gate')
+ def test_volume_list_param_display_name_and_status(self):
+ # Test to list volume when display name and status param is given
+ volume = self.volume_list[data_utils.rand_int_id(0, 2)]
+ params = {'display_name': volume['display_name'],
+ 'status': 'available'}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_volume_list_with_detail_param_display_name_and_status(self):
+ # Test to list volume when name and status param is given
+ volume = self.volume_list[data_utils.rand_int_id(0, 2)]
+ params = {'display_name': volume['display_name'],
+ 'status': 'available'}
+ self._list_by_param_value_and_assert(params, with_detail=True)
+
+
+class VolumeListTestXML(VolumesListTest):
+ _interface = 'xml'
diff --git a/tempest/auth.py b/tempest/auth.py
new file mode 100644
index 0000000..582cfdd
--- /dev/null
+++ b/tempest/auth.py
@@ -0,0 +1,396 @@
+# Copyright 2014 Hewlett-Packard Development Company, L.P.
+# All Rights Reserved.
+#
+# 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 copy
+import exceptions
+import re
+import urlparse
+
+from datetime import datetime
+from tempest import config
+from tempest.services.identity.json import identity_client as json_id
+from tempest.services.identity.v3.json import identity_client as json_v3id
+from tempest.services.identity.v3.xml import identity_client as xml_v3id
+from tempest.services.identity.xml import identity_client as xml_id
+
+from tempest.openstack.common import log as logging
+
+CONF = config.CONF
+LOG = logging.getLogger(__name__)
+
+
+class AuthProvider(object):
+ """
+ Provide authentication
+ """
+
+ def __init__(self, credentials, client_type='tempest',
+ interface=None):
+ """
+ :param credentials: credentials for authentication
+ :param client_type: 'tempest' or 'official'
+ :param interface: 'json' or 'xml'. Applicable for tempest client only
+ """
+ if self.check_credentials(credentials):
+ self.credentials = credentials
+ else:
+ raise TypeError("Invalid credentials")
+ self.credentials = credentials
+ self.client_type = client_type
+ self.interface = interface
+ if self.client_type == 'tempest' and self.interface is None:
+ self.interface = 'json'
+ self.cache = None
+ self.alt_auth_data = None
+ self.alt_part = None
+
+ def __str__(self):
+ return "Creds :{creds}, client type: {client_type}, interface: " \
+ "{interface}, cached auth data: {cache}".format(
+ creds=self.credentials, client_type=self.client_type,
+ interface=self.interface, cache=self.cache
+ )
+
+ def _decorate_request(self, filters, method, url, headers=None, body=None,
+ auth_data=None):
+ """
+ Decorate request with authentication data
+ """
+ raise NotImplementedError
+
+ def _get_auth(self):
+ raise NotImplementedError
+
+ @classmethod
+ def check_credentials(cls, credentials):
+ """
+ Verify credentials are valid. Subclasses can do a better check.
+ """
+ return isinstance(credentials, dict)
+
+ @property
+ def auth_data(self):
+ if self.cache is None or self.is_expired(self.cache):
+ self.cache = self._get_auth()
+ return self.cache
+
+ @auth_data.deleter
+ def auth_data(self):
+ self.clear_auth()
+
+ def clear_auth(self):
+ """
+ Can be called to clear the access cache so that next request
+ will fetch a new token and base_url.
+ """
+ self.cache = None
+
+ def is_expired(self, auth_data):
+ raise NotImplementedError
+
+ def auth_request(self, method, url, headers=None, body=None, filters=None):
+ """
+ Obtains auth data and decorates a request with that.
+ :param method: HTTP method of the request
+ :param url: relative URL of the request (path)
+ :param headers: HTTP headers of the request
+ :param body: HTTP body in case of POST / PUT
+ :param filters: select a base URL out of the catalog
+ :returns a Tuple (url, headers, body)
+ """
+ orig_req = dict(url=url, headers=headers, body=body)
+
+ auth_url, auth_headers, auth_body = self._decorate_request(
+ filters, method, url, headers, body)
+ auth_req = dict(url=auth_url, headers=auth_headers, body=auth_body)
+
+ # Overwrite part if the request if it has been requested
+ if self.alt_part is not None:
+ if self.alt_auth_data is not None:
+ alt_url, alt_headers, alt_body = self._decorate_request(
+ filters, method, url, headers, body,
+ auth_data=self.alt_auth_data)
+ alt_auth_req = dict(url=alt_url, headers=alt_headers,
+ body=alt_body)
+ auth_req[self.alt_part] = alt_auth_req[self.alt_part]
+
+ else:
+ # If alt auth data is None, skip auth in the requested part
+ auth_req[self.alt_part] = orig_req[self.alt_part]
+
+ # Next auth request will be normal, unless otherwise requested
+ self.reset_alt_auth_data()
+
+ return auth_req['url'], auth_req['headers'], auth_req['body']
+
+ def reset_alt_auth_data(self):
+ """
+ Configure auth provider to provide valid authentication data
+ """
+ self.alt_part = None
+ self.alt_auth_data = None
+
+ def set_alt_auth_data(self, request_part, auth_data):
+ """
+ Configure auth provider to provide alt authentication data
+ on a part of the *next* auth_request. If credentials are None,
+ set invalid data.
+ :param request_part: request part to contain invalid auth: url,
+ headers, body
+ :param auth_data: alternative auth_data from which to get the
+ invalid data to be injected
+ """
+ self.alt_part = request_part
+ self.alt_auth_data = auth_data
+
+ def base_url(self, filters, auth_data=None):
+ """
+ Extracts the base_url based on provided filters
+ """
+ raise NotImplementedError
+
+
+class KeystoneAuthProvider(AuthProvider):
+
+ def __init__(self, credentials, client_type='tempest', interface=None):
+ super(KeystoneAuthProvider, self).__init__(credentials, client_type,
+ interface)
+ self.auth_client = self._auth_client()
+
+ def _decorate_request(self, filters, method, url, headers=None, body=None,
+ auth_data=None):
+ if auth_data is None:
+ auth_data = self.auth_data
+ token, _ = auth_data
+ base_url = self.base_url(filters=filters, auth_data=auth_data)
+ # build authenticated request
+ # returns new request, it does not touch the original values
+ _headers = copy.deepcopy(headers)
+ _headers['X-Auth-Token'] = token
+ if url is None or url == "":
+ _url = base_url
+ else:
+ # Join base URL and url, and remove multiple contiguous slashes
+ _url = "/".join([base_url, url])
+ parts = [x for x in urlparse.urlparse(_url)]
+ parts[2] = re.sub("/{2,}", "/", parts[2])
+ _url = urlparse.urlunparse(parts)
+ # no change to method or body
+ return _url, _headers, body
+
+ def _auth_client(self):
+ raise NotImplementedError
+
+ def _auth_params(self):
+ raise NotImplementedError
+
+ def _get_auth(self):
+ # Bypasses the cache
+ if self.client_type == 'tempest':
+ auth_func = getattr(self.auth_client, 'get_token')
+ auth_params = self._auth_params()
+
+ # returns token, auth_data
+ token, auth_data = auth_func(**auth_params)
+ return token, auth_data
+ else:
+ raise NotImplementedError
+
+ def get_token(self):
+ return self.auth_data[0]
+
+
+class KeystoneV2AuthProvider(KeystoneAuthProvider):
+
+ EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
+
+ @classmethod
+ def check_credentials(cls, credentials, scoped=True):
+ # tenant_name is optional if not scoped
+ valid = super(KeystoneV2AuthProvider, cls).check_credentials(
+ credentials) and 'username' in credentials and \
+ 'password' in credentials
+ if scoped:
+ valid = valid and 'tenant_name' in credentials
+ return valid
+
+ def _auth_client(self):
+ if self.client_type == 'tempest':
+ if self.interface == 'json':
+ return json_id.TokenClientJSON()
+ else:
+ return xml_id.TokenClientXML()
+ else:
+ raise NotImplementedError
+
+ def _auth_params(self):
+ if self.client_type == 'tempest':
+ return dict(
+ user=self.credentials['username'],
+ password=self.credentials['password'],
+ tenant=self.credentials.get('tenant_name', None),
+ auth_data=True)
+ else:
+ raise NotImplementedError
+
+ def base_url(self, filters, auth_data=None):
+ """
+ Filters can be:
+ - service: compute, image, etc
+ - region: the service region
+ - endpoint_type: adminURL, publicURL, internalURL
+ - api_version: replace catalog version with this
+ - skip_path: take just the base URL
+ """
+ if auth_data is None:
+ auth_data = self.auth_data
+ token, _auth_data = auth_data
+ service = filters.get('service')
+ region = filters.get('region')
+ endpoint_type = filters.get('endpoint_type', 'publicURL')
+
+ if service is None:
+ raise exceptions.EndpointNotFound("No service provided")
+
+ _base_url = None
+ for ep in _auth_data['serviceCatalog']:
+ if ep["type"] == service:
+ for _ep in ep['endpoints']:
+ if region is not None and _ep['region'] == region:
+ _base_url = _ep.get(endpoint_type)
+ if not _base_url:
+ # No region matching, use the first
+ _base_url = ep['endpoints'][0].get(endpoint_type)
+ break
+ if _base_url is None:
+ raise exceptions.EndpointNotFound(service)
+
+ parts = urlparse.urlparse(_base_url)
+ if filters.get('api_version', None) is not None:
+ path = "/" + filters['api_version']
+ noversion_path = "/".join(parts.path.split("/")[2:])
+ if noversion_path != "":
+ path += "/" + noversion_path
+ _base_url = _base_url.replace(parts.path, path)
+ if filters.get('skip_path', None) is not None:
+ _base_url = _base_url.replace(parts.path, "/")
+
+ return _base_url
+
+ def is_expired(self, auth_data):
+ _, access = auth_data
+ expiry = datetime.strptime(access['token']['expires'],
+ self.EXPIRY_DATE_FORMAT)
+ return expiry <= datetime.now()
+
+
+class KeystoneV3AuthProvider(KeystoneAuthProvider):
+
+ EXPIRY_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
+
+ @classmethod
+ def check_credentials(cls, credentials, scoped=True):
+ # tenant_name is optional if not scoped
+ valid = super(KeystoneV3AuthProvider, cls).check_credentials(
+ credentials) and 'username' in credentials and \
+ 'password' in credentials and 'domain_name' in credentials
+ if scoped:
+ valid = valid and 'tenant_name' in credentials
+ return valid
+
+ def _auth_client(self):
+ if self.client_type == 'tempest':
+ if self.interface == 'json':
+ return json_v3id.V3TokenClientJSON()
+ else:
+ return xml_v3id.V3TokenClientXML()
+ else:
+ raise NotImplementedError
+
+ def _auth_params(self):
+ if self.client_type == 'tempest':
+ return dict(
+ user=self.credentials['username'],
+ password=self.credentials['password'],
+ tenant=self.credentials.get('tenant_name', None),
+ domain=self.credentials['domain_name'],
+ auth_data=True)
+ else:
+ raise NotImplementedError
+
+ def base_url(self, filters, auth_data=None):
+ """
+ Filters can be:
+ - service: compute, image, etc
+ - region: the service region
+ - endpoint_type: adminURL, publicURL, internalURL
+ - api_version: replace catalog version with this
+ - skip_path: take just the base URL
+ """
+ if auth_data is None:
+ auth_data = self.auth_data
+ token, _auth_data = auth_data
+ service = filters.get('service')
+ region = filters.get('region')
+ endpoint_type = filters.get('endpoint_type', 'public')
+
+ if service is None:
+ raise exceptions.EndpointNotFound("No service provided")
+
+ if 'URL' in endpoint_type:
+ endpoint_type = endpoint_type.replace('URL', '')
+ _base_url = None
+ catalog = _auth_data['catalog']
+ # Select entries with matching service type
+ service_catalog = [ep for ep in catalog if ep['type'] == service]
+ if len(service_catalog) > 0:
+ service_catalog = service_catalog[0]['endpoints']
+ else:
+ # No matching service
+ raise exceptions.EndpointNotFound(service)
+ # Filter by endpoint type (interface)
+ filtered_catalog = [ep for ep in service_catalog if
+ ep['interface'] == endpoint_type]
+ if len(filtered_catalog) == 0:
+ # No matching type, keep all and try matching by region at least
+ filtered_catalog = service_catalog
+ # Filter by region
+ filtered_catalog = [ep for ep in filtered_catalog if
+ ep['region'] == region]
+ if len(filtered_catalog) == 0:
+ # No matching region, take the first endpoint
+ filtered_catalog = [filtered_catalog[0]]
+ # There should be only one match. If not take the first.
+ _base_url = filtered_catalog[0].get('url', None)
+ if _base_url is None:
+ raise exceptions.EndpointNotFound(service)
+
+ parts = urlparse.urlparse(_base_url)
+ if filters.get('api_version', None) is not None:
+ path = "/" + filters['api_version']
+ noversion_path = "/".join(parts.path.split("/")[2:])
+ if noversion_path != "":
+ path += noversion_path
+ _base_url = _base_url.replace(parts.path, path)
+ if filters.get('skip_path', None) is not None:
+ _base_url = _base_url.replace(parts.path, "/")
+
+ return _base_url
+
+ def is_expired(self, auth_data):
+ _, access = auth_data
+ expiry = datetime.strptime(access['expires_at'],
+ self.EXPIRY_DATE_FORMAT)
+ return expiry <= datetime.now()
diff --git a/tempest/cli/__init__.py b/tempest/cli/__init__.py
index 547d0d0..a5e0447 100644
--- a/tempest/cli/__init__.py
+++ b/tempest/cli/__init__.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,31 +17,15 @@
import shlex
import subprocess
-from oslo.config import cfg
-
import tempest.cli.output_parser
+from tempest import config
from tempest.openstack.common import log as logging
import tempest.test
LOG = logging.getLogger(__name__)
-cli_opts = [
- cfg.BoolOpt('enabled',
- default=True,
- help="enable cli tests"),
- cfg.StrOpt('cli_dir',
- default='/usr/local/bin',
- help="directory where python client binaries are located"),
- cfg.IntOpt('timeout',
- default=15,
- help="Number of seconds to wait on a CLI timeout"),
-]
-
-CONF = cfg.CONF
-cli_group = cfg.OptGroup(name='cli', title="cli Configuration Options")
-CONF.register_group(cli_group)
-CONF.register_opts(cli_opts, group=cli_group)
+CONF = config.CONF
class ClientTestBase(tempest.test.BaseTestCase):
@@ -52,7 +34,6 @@
if not CONF.cli.enabled:
msg = "cli testing disabled"
raise cls.skipException(msg)
- cls.identity = cls.config.identity
super(ClientTestBase, cls).setUpClass()
def __init__(self, *args, **kwargs):
@@ -108,10 +89,10 @@
# TODO(jogo) make admin=False work
creds = ('--os-username %s --os-tenant-name %s --os-password %s '
'--os-auth-url %s ' %
- (self.identity.admin_username,
- self.identity.admin_tenant_name,
- self.identity.admin_password,
- self.identity.uri))
+ (CONF.identity.admin_username,
+ CONF.identity.admin_tenant_name,
+ CONF.identity.admin_password,
+ CONF.identity.uri))
flags = creds + ' ' + flags
return self.cmd(cmd, action, flags, params, fail_ok)
diff --git a/tempest/cli/output_parser.py b/tempest/cli/output_parser.py
index bb3368f..4edcd47 100644
--- a/tempest/cli/output_parser.py
+++ b/tempest/cli/output_parser.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/cli/simple_read_only/heat_templates/heat_minimal_hot.yaml b/tempest/cli/simple_read_only/heat_templates/heat_minimal_hot.yaml
index 6d89b7b..4657bfc 100644
--- a/tempest/cli/simple_read_only/heat_templates/heat_minimal_hot.yaml
+++ b/tempest/cli/simple_read_only/heat_templates/heat_minimal_hot.yaml
@@ -3,10 +3,10 @@
parameters:
instance_image:
description: Glance image name
- type: String
+ type: string
instance_type:
description: Nova instance type
- type: String
+ type: string
default: m1.small
constraints:
- allowed_values: [m1.small, m1.medium, m1.large]
diff --git a/tempest/cli/simple_read_only/test_ceilometer.py b/tempest/cli/simple_read_only/test_ceilometer.py
index 8bdd633..0b6ae22 100644
--- a/tempest/cli/simple_read_only/test_ceilometer.py
+++ b/tempest/cli/simple_read_only/test_ceilometer.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,17 +13,16 @@
# License for the specific language governing permissions and limitations
# under the License.
-from oslo.config import cfg
-
-import tempest.cli
+from tempest import cli
+from tempest import config
from tempest.openstack.common import log as logging
-CONF = cfg.CONF
+CONF = config.CONF
LOG = logging.getLogger(__name__)
-class SimpleReadOnlyCeilometerClientTest(tempest.cli.ClientTestBase):
+class SimpleReadOnlyCeilometerClientTest(cli.ClientTestBase):
"""Basic, read-only tests for Ceilometer CLI client.
Checks return values and output of read-only commands.
@@ -36,7 +33,7 @@
@classmethod
def setUpClass(cls):
if (not CONF.service_available.ceilometer):
- msg = ("Skiping all Ceilometer cli tests because it is"
+ msg = ("Skipping all Ceilometer cli tests because it is "
"not available")
raise cls.skipException(msg)
super(SimpleReadOnlyCeilometerClientTest, cls).setUpClass()
diff --git a/tempest/cli/simple_read_only/test_cinder.py b/tempest/cli/simple_read_only/test_cinder.py
index 25157a4..afbd732 100644
--- a/tempest/cli/simple_read_only/test_cinder.py
+++ b/tempest/cli/simple_read_only/test_cinder.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,7 +18,9 @@
import subprocess
import tempest.cli
+from tempest import config
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -32,6 +32,13 @@
their own. They only verify the structure of output if present.
"""
+ @classmethod
+ def setUpClass(cls):
+ if not CONF.service_available.cinder:
+ msg = ("%s skipped as Cinder is not available" % cls.__name__)
+ raise cls.skipException(msg)
+ super(SimpleReadOnlyCinderClientTest, cls).setUpClass()
+
def test_cinder_fake_action(self):
self.assertRaises(subprocess.CalledProcessError,
self.cinder,
@@ -49,6 +56,12 @@
def test_cinder_volumes_list(self):
self.cinder('list')
+ self.cinder('list', params='--all-tenants 1')
+ self.cinder('list', params='--all-tenants 0')
+ self.assertRaises(subprocess.CalledProcessError,
+ self.cinder,
+ 'list',
+ params='--all-tenants bad')
def test_cinder_quota_class_show(self):
"""This CLI can accept and string as param."""
@@ -59,14 +72,14 @@
def test_cinder_quota_defaults(self):
"""This CLI can accept and string as param."""
roles = self.parser.listing(self.cinder('quota-defaults',
- params=self.identity.
+ params=CONF.identity.
admin_tenant_name))
self.assertTableStruct(roles, ['Property', 'Value'])
def test_cinder_quota_show(self):
"""This CLI can accept and string as param."""
roles = self.parser.listing(self.cinder('quota-show',
- params=self.identity.
+ params=CONF.identity.
admin_tenant_name))
self.assertTableStruct(roles, ['Property', 'Value'])
@@ -132,7 +145,7 @@
self.cinder('list', flags='--retries 3')
def test_cinder_region_list(self):
- region = self.config.volume.region
+ region = CONF.volume.region
if not region:
- region = self.config.identity.region
+ region = CONF.identity.region
self.cinder('list', flags='--os-region-name ' + region)
diff --git a/tempest/cli/simple_read_only/test_glance.py b/tempest/cli/simple_read_only/test_glance.py
index a5a229c..9869483 100644
--- a/tempest/cli/simple_read_only/test_glance.py
+++ b/tempest/cli/simple_read_only/test_glance.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,13 +16,11 @@
import re
import subprocess
-from oslo.config import cfg
-
import tempest.cli
+from tempest import config
from tempest.openstack.common import log as logging
-CONF = cfg.CONF
-
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -37,6 +33,13 @@
their own. They only verify the structure of output if present.
"""
+ @classmethod
+ def setUpClass(cls):
+ if not CONF.service_available.glance:
+ msg = ("%s skipped as Glance is not available" % cls.__name__)
+ raise cls.skipException(msg)
+ super(SimpleReadOnlyGlanceClientTest, cls).setUpClass()
+
def test_glance_fake_action(self):
self.assertRaises(subprocess.CalledProcessError,
self.glance,
@@ -50,7 +53,7 @@
'Size', 'Status'])
def test_glance_member_list(self):
- tenant_name = '--tenant-id %s' % self.identity.admin_tenant_name
+ tenant_name = '--tenant-id %s' % CONF.identity.admin_tenant_name
out = self.glance('member-list',
params=tenant_name)
endpoints = self.parser.listing(out)
diff --git a/tempest/cli/simple_read_only/test_heat.py b/tempest/cli/simple_read_only/test_heat.py
index e2fefe8..cf4580c 100644
--- a/tempest/cli/simple_read_only/test_heat.py
+++ b/tempest/cli/simple_read_only/test_heat.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -16,12 +14,11 @@
import os
import yaml
-from oslo.config import cfg
-
import tempest.cli
+from tempest import config
from tempest.openstack.common import log as logging
-CONF = cfg.CONF
+CONF = config.CONF
LOG = logging.getLogger(__name__)
diff --git a/tempest/cli/simple_read_only/test_keystone.py b/tempest/cli/simple_read_only/test_keystone.py
index a7e7147..1efbede 100644
--- a/tempest/cli/simple_read_only/test_keystone.py
+++ b/tempest/cli/simple_read_only/test_keystone.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,12 +16,11 @@
import re
import subprocess
-from oslo.config import cfg
-
import tempest.cli
+from tempest import config
from tempest.openstack.common import log as logging
-CONF = cfg.CONF
+CONF = config.CONF
LOG = logging.getLogger(__name__)
diff --git a/tempest/cli/simple_read_only/test_neutron.py b/tempest/cli/simple_read_only/test_neutron.py
index 61ffc25..cd81378 100644
--- a/tempest/cli/simple_read_only/test_neutron.py
+++ b/tempest/cli/simple_read_only/test_neutron.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,18 +16,17 @@
import re
import subprocess
-from oslo.config import cfg
-
-import tempest.cli
+from tempest import cli
+from tempest import config
from tempest.openstack.common import log as logging
from tempest import test
-CONF = cfg.CONF
+CONF = config.CONF
LOG = logging.getLogger(__name__)
-class SimpleReadOnlyNeutronClientTest(tempest.cli.ClientTestBase):
+class SimpleReadOnlyNeutronClientTest(cli.ClientTestBase):
"""Basic, read-only tests for Neutron CLI client.
Checks return values and output of read-only commands.
@@ -40,7 +37,7 @@
@classmethod
def setUpClass(cls):
if (not CONF.service_available.neutron):
- msg = "Skiping all Neutron cli tests because it is not available"
+ msg = "Skipping all Neutron cli tests because it is not available"
raise cls.skipException(msg)
super(SimpleReadOnlyNeutronClientTest, cls).setUpClass()
@@ -60,17 +57,20 @@
self.assertTableStruct(ext, ['alias', 'name'])
@test.attr(type='smoke')
+ @test.requires_ext(extension='dhcp_agent_scheduler', service='network')
def test_neutron_dhcp_agent_list_hosting_net(self):
self.neutron('dhcp-agent-list-hosting-net',
params=CONF.compute.fixed_network_name)
@test.attr(type='smoke')
+ @test.requires_ext(extension='agent', service='network')
def test_neutron_agent_list(self):
agents = self.parser.listing(self.neutron('agent-list'))
field_names = ['id', 'agent_type', 'host', 'alive', 'admin_state_up']
self.assertTableStruct(agents, field_names)
@test.attr(type='smoke')
+ @test.requires_ext(extension='router', service='network')
def test_neutron_floatingip_list(self):
self.neutron('floatingip-list')
@@ -86,10 +86,11 @@
def test_neutron_meter_label_rule_list(self):
self.neutron('meter-label-rule-list')
+ @test.requires_ext(extension='lbaas_agent_scheduler', service='network')
def _test_neutron_lbaas_command(self, command):
try:
self.neutron(command)
- except tempest.cli.CommandFailed as e:
+ except cli.CommandFailed as e:
if '404 Not Found' not in e.stderr:
self.fail('%s: Unexpected failure.' % command)
@@ -110,6 +111,7 @@
self._test_neutron_lbaas_command('lb-vip-list')
@test.attr(type='smoke')
+ @test.requires_ext(extension='external-net', service='network')
def test_neutron_net_external_list(self):
self.neutron('net-external-list')
@@ -118,19 +120,23 @@
self.neutron('port-list')
@test.attr(type='smoke')
+ @test.requires_ext(extension='quotas', service='network')
def test_neutron_quota_list(self):
self.neutron('quota-list')
@test.attr(type='smoke')
+ @test.requires_ext(extension='router', service='network')
def test_neutron_router_list(self):
self.neutron('router-list')
@test.attr(type='smoke')
+ @test.requires_ext(extension='security-group', service='network')
def test_neutron_security_group_list(self):
security_grp = self.parser.listing(self.neutron('security-group-list'))
self.assertTableStruct(security_grp, ['id', 'name', 'description'])
@test.attr(type='smoke')
+ @test.requires_ext(extension='security-group', service='network')
def test_neutron_security_group_rule_list(self):
self.neutron('security-group-rule-list')
@@ -156,7 +162,7 @@
'router-show', 'agent-update', 'help'))
self.assertFalse(wanted_commands - commands)
- # Optional arguments:
+ # Optional arguments:
@test.attr(type='smoke')
def test_neutron_version(self):
diff --git a/tempest/cli/simple_read_only/test_nova.py b/tempest/cli/simple_read_only/test_nova.py
index 1aa8f2c..b0264d0 100644
--- a/tempest/cli/simple_read_only/test_nova.py
+++ b/tempest/cli/simple_read_only/test_nova.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,15 +15,14 @@
import subprocess
-from oslo.config import cfg
import testtools
import tempest.cli
+from tempest import config
from tempest.openstack.common import log as logging
import tempest.test
-CONF = cfg.CONF
-
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -44,6 +41,13 @@
"""
+ @classmethod
+ def setUpClass(cls):
+ if not CONF.service_available.nova:
+ msg = ("%s skipped as Nova is not available" % cls.__name__)
+ raise cls.skipException(msg)
+ super(SimpleReadOnlyNovaClientTest, cls).setUpClass()
+
def test_admin_fake_action(self):
self.assertRaises(subprocess.CalledProcessError,
self.nova,
diff --git a/tempest/cli/simple_read_only/test_nova_manage.py b/tempest/cli/simple_read_only/test_nova_manage.py
index 524db5d..13a1589 100644
--- a/tempest/cli/simple_read_only/test_nova_manage.py
+++ b/tempest/cli/simple_read_only/test_nova_manage.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,9 +16,11 @@
import subprocess
import tempest.cli
+from tempest import config
from tempest.openstack.common import log as logging
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -36,6 +36,13 @@
"""
+ @classmethod
+ def setUpClass(cls):
+ if not CONF.service_available.nova:
+ msg = ("%s skipped as Nova is not available" % cls.__name__)
+ raise cls.skipException(msg)
+ super(SimpleReadOnlyNovaManageTest, cls).setUpClass()
+
def test_admin_fake_action(self):
self.assertRaises(subprocess.CalledProcessError,
self.nova_manage,
diff --git a/tempest/clients.py b/tempest/clients.py
index 83b72c6..9c1a0f1 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,9 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
+from tempest import auth
+from tempest.common.rest_client import NegativeRestClient
from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
+from tempest.services.baremetal.v1.client_json import BaremetalClientJSON
from tempest.services import botoclients
from tempest.services.compute.json.aggregates_client import \
AggregatesClientJSON
@@ -62,6 +63,8 @@
from tempest.services.compute.v3.json.hosts_client import HostsV3ClientJSON
from tempest.services.compute.v3.json.hypervisor_client import \
HypervisorV3ClientJSON
+from tempest.services.compute.v3.json.instance_usage_audit_log_client import \
+ InstanceUsagesAuditLogV3ClientJSON
from tempest.services.compute.v3.json.interfaces_client import \
InterfacesV3ClientJSON
from tempest.services.compute.v3.json.keypairs_client import \
@@ -74,28 +77,8 @@
ServicesV3ClientJSON
from tempest.services.compute.v3.json.tenant_usages_client import \
TenantUsagesV3ClientJSON
-from tempest.services.compute.v3.xml.aggregates_client import \
- AggregatesV3ClientXML
-from tempest.services.compute.v3.xml.availability_zone_client import \
- AvailabilityZoneV3ClientXML
-from tempest.services.compute.v3.xml.certificates_client import \
- CertificatesV3ClientXML
-from tempest.services.compute.v3.xml.extensions_client import \
- ExtensionsV3ClientXML
-from tempest.services.compute.v3.xml.flavors_client import FlavorsV3ClientXML
-from tempest.services.compute.v3.xml.hosts_client import HostsV3ClientXML
-from tempest.services.compute.v3.xml.hypervisor_client import \
- HypervisorV3ClientXML
-from tempest.services.compute.v3.xml.interfaces_client import \
- InterfacesV3ClientXML
-from tempest.services.compute.v3.xml.keypairs_client import KeyPairsV3ClientXML
-from tempest.services.compute.v3.xml.quotas_client import \
- QuotasV3ClientXML
-from tempest.services.compute.v3.xml.servers_client import ServersV3ClientXML
-from tempest.services.compute.v3.xml.services_client import \
- ServicesV3ClientXML
-from tempest.services.compute.v3.xml.tenant_usages_client import \
- TenantUsagesV3ClientXML
+from tempest.services.compute.v3.json.version_client import \
+ VersionV3ClientJSON
from tempest.services.compute.xml.aggregates_client import AggregatesClientXML
from tempest.services.compute.xml.availability_zone_client import \
AvailabilityZoneClientXML
@@ -161,6 +144,10 @@
ObjectClientCustomizedHeader
from tempest.services.orchestration.json.orchestration_client import \
OrchestrationClient
+from tempest.services.telemetry.json.telemetry_client import \
+ TelemetryClientJSON
+from tempest.services.telemetry.xml.telemetry_client import \
+ TelemetryClientXML
from tempest.services.volume.json.admin.volume_hosts_client import \
VolumeHostsClientJSON
from tempest.services.volume.json.admin.volume_types_client import \
@@ -189,7 +176,7 @@
"""
def __init__(self, username=None, password=None, tenant_name=None,
- interface='json'):
+ interface='json', service=None):
"""
We allow overriding of the credentials used within the various
client classes managed by the Manager object. Left as None, the
@@ -199,176 +186,208 @@
:param password: Override of the password
:param tenant_name: Override of the tenant name
"""
- self.config = CONF
- # If no creds are provided, we fall back on the defaults
- # in the config file for the Compute API.
- self.username = username or CONF.identity.username
- self.password = password or CONF.identity.password
- self.tenant_name = tenant_name or CONF.identity.tenant_name
-
- if None in (self.username, self.password, self.tenant_name):
- msg = ("Missing required credentials. "
- "username: %(u)s, password: %(p)s, "
- "tenant_name: %(t)s" %
- {'u': username, 'p': password, 't': tenant_name})
- raise exceptions.InvalidConfiguration(msg)
-
- self.auth_url = CONF.identity.uri
- self.auth_url_v3 = CONF.identity.uri_v3
-
- client_args = (CONF, self.username, self.password,
- self.auth_url, self.tenant_name)
-
- if self.auth_url_v3:
- auth_version = 'v3'
- client_args_v3_auth = (CONF, self.username,
- self.password, self.auth_url_v3,
- self.tenant_name, auth_version)
+ self.interface = interface
+ self.auth_version = CONF.identity.auth_version
+ # FIXME(andreaf) Change Manager __init__ to accept a credentials dict
+ if username is None or password is None:
+ # Tenant None is a valid use case
+ self.credentials = self.get_default_credentials()
else:
- client_args_v3_auth = None
+ self.credentials = dict(username=username, password=password,
+ tenant_name=tenant_name)
+ if self.auth_version == 'v3':
+ self.credentials['domain_name'] = 'Default'
+ # Setup an auth provider
+ auth_provider = self.get_auth_provider(self.credentials)
- self.servers_client_v3_auth = None
-
- if interface == 'xml':
- self.certificates_client = CertificatesClientXML(*client_args)
- self.certificates_v3_client = CertificatesV3ClientXML(*client_args)
- self.servers_client = ServersClientXML(*client_args)
- self.servers_v3_client = ServersV3ClientXML(*client_args)
- self.limits_client = LimitsClientXML(*client_args)
- self.images_client = ImagesClientXML(*client_args)
- self.keypairs_v3_client = KeyPairsV3ClientXML(*client_args)
- self.keypairs_client = KeyPairsClientXML(*client_args)
- self.keypairs_v3_client = KeyPairsV3ClientXML(*client_args)
- self.quotas_client = QuotasClientXML(*client_args)
- self.quotas_v3_client = QuotasV3ClientXML(*client_args)
- self.flavors_client = FlavorsClientXML(*client_args)
- self.flavors_v3_client = FlavorsV3ClientXML(*client_args)
- self.extensions_v3_client = ExtensionsV3ClientXML(*client_args)
- self.extensions_client = ExtensionsClientXML(*client_args)
+ if self.interface == 'xml':
+ self.certificates_client = CertificatesClientXML(
+ auth_provider)
+ self.servers_client = ServersClientXML(auth_provider)
+ self.limits_client = LimitsClientXML(auth_provider)
+ self.images_client = ImagesClientXML(auth_provider)
+ self.keypairs_client = KeyPairsClientXML(auth_provider)
+ self.quotas_client = QuotasClientXML(auth_provider)
+ self.flavors_client = FlavorsClientXML(auth_provider)
+ self.extensions_client = ExtensionsClientXML(auth_provider)
self.volumes_extensions_client = VolumesExtensionsClientXML(
- *client_args)
- self.floating_ips_client = FloatingIPsClientXML(*client_args)
- self.snapshots_client = SnapshotsClientXML(*client_args)
- self.volumes_client = VolumesClientXML(*client_args)
- self.volume_types_client = VolumeTypesClientXML(*client_args)
- self.identity_client = IdentityClientXML(*client_args)
- self.identity_v3_client = IdentityV3ClientXML(*client_args)
- self.token_client = TokenClientXML(CONF)
+ auth_provider)
+ self.floating_ips_client = FloatingIPsClientXML(
+ auth_provider)
+ self.snapshots_client = SnapshotsClientXML(auth_provider)
+ self.volumes_client = VolumesClientXML(auth_provider)
+ self.volume_types_client = VolumeTypesClientXML(
+ auth_provider)
+ self.identity_client = IdentityClientXML(auth_provider)
+ self.identity_v3_client = IdentityV3ClientXML(
+ auth_provider)
self.security_groups_client = SecurityGroupsClientXML(
- *client_args)
- self.interfaces_v3_client = InterfacesV3ClientXML(*client_args)
- self.interfaces_client = InterfacesClientXML(*client_args)
- self.endpoints_client = EndPointClientXML(*client_args)
- self.fixed_ips_client = FixedIPsClientXML(*client_args)
- self.availability_zone_v3_client = AvailabilityZoneV3ClientXML(
- *client_args)
+ auth_provider)
+ self.interfaces_client = InterfacesClientXML(auth_provider)
+ self.endpoints_client = EndPointClientXML(auth_provider)
+ self.fixed_ips_client = FixedIPsClientXML(auth_provider)
self.availability_zone_client = AvailabilityZoneClientXML(
- *client_args)
- self.services_v3_client = ServicesV3ClientXML(*client_args)
- self.service_client = ServiceClientXML(*client_args)
- self.aggregates_v3_client = AggregatesV3ClientXML(*client_args)
- self.aggregates_client = AggregatesClientXML(*client_args)
- self.services_client = ServicesClientXML(*client_args)
- self.tenant_usages_v3_client = TenantUsagesV3ClientXML(
- *client_args)
- self.tenant_usages_client = TenantUsagesClientXML(*client_args)
- self.policy_client = PolicyClientXML(*client_args)
- self.hosts_client = HostsClientXML(*client_args)
- self.hypervisor_v3_client = HypervisorV3ClientXML(*client_args)
- self.hypervisor_client = HypervisorClientXML(*client_args)
- self.token_v3_client = V3TokenClientXML(*client_args)
- self.network_client = NetworkClientXML(*client_args)
- self.credentials_client = CredentialsClientXML(*client_args)
+ auth_provider)
+ self.service_client = ServiceClientXML(auth_provider)
+ self.aggregates_client = AggregatesClientXML(auth_provider)
+ self.services_client = ServicesClientXML(auth_provider)
+ self.tenant_usages_client = TenantUsagesClientXML(
+ auth_provider)
+ self.policy_client = PolicyClientXML(auth_provider)
+ self.hosts_client = HostsClientXML(auth_provider)
+ self.hypervisor_client = HypervisorClientXML(auth_provider)
+ self.network_client = NetworkClientXML(auth_provider)
+ self.credentials_client = CredentialsClientXML(
+ auth_provider)
self.instance_usages_audit_log_client = \
- InstanceUsagesAuditLogClientXML(*client_args)
- self.volume_hosts_client = VolumeHostsClientXML(*client_args)
+ InstanceUsagesAuditLogClientXML(auth_provider)
+ self.volume_hosts_client = VolumeHostsClientXML(
+ auth_provider)
self.volumes_extension_client = VolumeExtensionClientXML(
- *client_args)
- self.hosts_v3_client = HostsV3ClientXML(*client_args)
+ auth_provider)
+ if CONF.service_available.ceilometer:
+ self.telemetry_client = TelemetryClientXML(
+ auth_provider)
+ self.token_client = TokenClientXML()
+ self.token_v3_client = V3TokenClientXML()
- if client_args_v3_auth:
- self.servers_client_v3_auth = ServersClientXML(
- *client_args_v3_auth)
-
- elif interface == 'json':
- self.certificates_client = CertificatesClientJSON(*client_args)
+ elif self.interface == 'json':
+ self.certificates_client = CertificatesClientJSON(
+ auth_provider)
self.certificates_v3_client = CertificatesV3ClientJSON(
- *client_args)
- self.servers_client = ServersClientJSON(*client_args)
- self.servers_v3_client = ServersV3ClientJSON(*client_args)
- self.limits_client = LimitsClientJSON(*client_args)
- self.images_client = ImagesClientJSON(*client_args)
- self.keypairs_v3_client = KeyPairsV3ClientJSON(*client_args)
- self.keypairs_client = KeyPairsClientJSON(*client_args)
- self.keypairs_v3_client = KeyPairsV3ClientJSON(*client_args)
- self.quotas_client = QuotasClientJSON(*client_args)
- self.quotas_v3_client = QuotasV3ClientJSON(*client_args)
- self.flavors_client = FlavorsClientJSON(*client_args)
- self.flavors_v3_client = FlavorsV3ClientJSON(*client_args)
- self.extensions_v3_client = ExtensionsV3ClientJSON(*client_args)
- self.extensions_client = ExtensionsClientJSON(*client_args)
+ auth_provider)
+ self.baremetal_client = BaremetalClientJSON(auth_provider)
+ self.servers_client = ServersClientJSON(auth_provider)
+ self.servers_v3_client = ServersV3ClientJSON(auth_provider)
+ self.limits_client = LimitsClientJSON(auth_provider)
+ self.images_client = ImagesClientJSON(auth_provider)
+ self.keypairs_v3_client = KeyPairsV3ClientJSON(
+ auth_provider)
+ self.keypairs_client = KeyPairsClientJSON(auth_provider)
+ self.keypairs_v3_client = KeyPairsV3ClientJSON(
+ auth_provider)
+ self.quotas_client = QuotasClientJSON(auth_provider)
+ self.quotas_v3_client = QuotasV3ClientJSON(auth_provider)
+ self.flavors_client = FlavorsClientJSON(auth_provider)
+ self.flavors_v3_client = FlavorsV3ClientJSON(auth_provider)
+ self.extensions_v3_client = ExtensionsV3ClientJSON(
+ auth_provider)
+ self.extensions_client = ExtensionsClientJSON(
+ auth_provider)
self.volumes_extensions_client = VolumesExtensionsClientJSON(
- *client_args)
- self.floating_ips_client = FloatingIPsClientJSON(*client_args)
- self.snapshots_client = SnapshotsClientJSON(*client_args)
- self.volumes_client = VolumesClientJSON(*client_args)
- self.volume_types_client = VolumeTypesClientJSON(*client_args)
- self.identity_client = IdentityClientJSON(*client_args)
- self.identity_v3_client = IdentityV3ClientJSON(*client_args)
- self.token_client = TokenClientJSON(CONF)
+ auth_provider)
+ self.floating_ips_client = FloatingIPsClientJSON(
+ auth_provider)
+ self.snapshots_client = SnapshotsClientJSON(auth_provider)
+ self.volumes_client = VolumesClientJSON(auth_provider)
+ self.volume_types_client = VolumeTypesClientJSON(
+ auth_provider)
+ self.identity_client = IdentityClientJSON(auth_provider)
+ self.identity_v3_client = IdentityV3ClientJSON(
+ auth_provider)
self.security_groups_client = SecurityGroupsClientJSON(
- *client_args)
- self.interfaces_v3_client = InterfacesV3ClientJSON(*client_args)
- self.interfaces_client = InterfacesClientJSON(*client_args)
- self.endpoints_client = EndPointClientJSON(*client_args)
- self.fixed_ips_client = FixedIPsClientJSON(*client_args)
+ auth_provider)
+ self.interfaces_v3_client = InterfacesV3ClientJSON(
+ auth_provider)
+ self.interfaces_client = InterfacesClientJSON(
+ auth_provider)
+ self.endpoints_client = EndPointClientJSON(auth_provider)
+ self.fixed_ips_client = FixedIPsClientJSON(auth_provider)
self.availability_zone_v3_client = AvailabilityZoneV3ClientJSON(
- *client_args)
+ auth_provider)
self.availability_zone_client = AvailabilityZoneClientJSON(
- *client_args)
- self.services_v3_client = ServicesV3ClientJSON(*client_args)
- self.service_client = ServiceClientJSON(*client_args)
- self.aggregates_v3_client = AggregatesV3ClientJSON(*client_args)
- self.aggregates_client = AggregatesClientJSON(*client_args)
- self.services_client = ServicesClientJSON(*client_args)
+ auth_provider)
+ self.services_v3_client = ServicesV3ClientJSON(
+ auth_provider)
+ self.service_client = ServiceClientJSON(auth_provider)
+ self.aggregates_v3_client = AggregatesV3ClientJSON(
+ auth_provider)
+ self.aggregates_client = AggregatesClientJSON(
+ auth_provider)
+ self.services_client = ServicesClientJSON(auth_provider)
self.tenant_usages_v3_client = TenantUsagesV3ClientJSON(
- *client_args)
- self.tenant_usages_client = TenantUsagesClientJSON(*client_args)
- self.policy_client = PolicyClientJSON(*client_args)
- self.hosts_client = HostsClientJSON(*client_args)
- self.hypervisor_v3_client = HypervisorV3ClientJSON(*client_args)
- self.hypervisor_client = HypervisorClientJSON(*client_args)
- self.token_v3_client = V3TokenClientJSON(*client_args)
- self.network_client = NetworkClientJSON(*client_args)
- self.credentials_client = CredentialsClientJSON(*client_args)
+ auth_provider)
+ self.tenant_usages_client = TenantUsagesClientJSON(
+ auth_provider)
+ self.version_v3_client = VersionV3ClientJSON(auth_provider)
+ self.policy_client = PolicyClientJSON(auth_provider)
+ self.hosts_client = HostsClientJSON(auth_provider)
+ self.hypervisor_v3_client = HypervisorV3ClientJSON(
+ auth_provider)
+ self.hypervisor_client = HypervisorClientJSON(
+ auth_provider)
+ self.network_client = NetworkClientJSON(auth_provider)
+ self.credentials_client = CredentialsClientJSON(
+ auth_provider)
self.instance_usages_audit_log_client = \
- InstanceUsagesAuditLogClientJSON(*client_args)
- self.volume_hosts_client = VolumeHostsClientJSON(*client_args)
+ InstanceUsagesAuditLogClientJSON(auth_provider)
+ self.instance_usages_audit_log_v3_client = \
+ InstanceUsagesAuditLogV3ClientJSON(auth_provider)
+ self.volume_hosts_client = VolumeHostsClientJSON(
+ auth_provider)
self.volumes_extension_client = VolumeExtensionClientJSON(
- *client_args)
- self.hosts_v3_client = HostsV3ClientJSON(*client_args)
+ auth_provider)
+ self.hosts_v3_client = HostsV3ClientJSON(auth_provider)
+ if CONF.service_available.ceilometer:
+ self.telemetry_client = TelemetryClientJSON(
+ auth_provider)
+ self.token_client = TokenClientJSON()
+ self.token_v3_client = V3TokenClientJSON()
+ self.negative_client = NegativeRestClient(auth_provider)
+ self.negative_client.service = service
- if client_args_v3_auth:
- self.servers_client_v3_auth = ServersClientJSON(
- *client_args_v3_auth)
else:
msg = "Unsupported interface type `%s'" % interface
raise exceptions.InvalidConfiguration(msg)
+ # TODO(andreaf) EC2 client still do their auth, v2 only
+ ec2_client_args = (self.credentials.get('username'),
+ self.credentials.get('password'),
+ CONF.identity.uri,
+ self.credentials.get('tenant_name'))
+
# common clients
- self.account_client = AccountClient(*client_args)
+ self.account_client = AccountClient(auth_provider)
if CONF.service_available.glance:
- self.image_client = ImageClientJSON(*client_args)
- self.image_client_v2 = ImageClientV2JSON(*client_args)
- self.container_client = ContainerClient(*client_args)
- self.object_client = ObjectClient(*client_args)
- self.orchestration_client = OrchestrationClient(*client_args)
- self.ec2api_client = botoclients.APIClientEC2(*client_args)
- self.s3_client = botoclients.ObjectClientS3(*client_args)
- self.custom_object_client = ObjectClientCustomizedHeader(*client_args)
+ self.image_client = ImageClientJSON(auth_provider)
+ self.image_client_v2 = ImageClientV2JSON(auth_provider)
+ self.container_client = ContainerClient(auth_provider)
+ self.object_client = ObjectClient(auth_provider)
+ self.orchestration_client = OrchestrationClient(
+ auth_provider)
+ self.ec2api_client = botoclients.APIClientEC2(*ec2_client_args)
+ self.s3_client = botoclients.ObjectClientS3(*ec2_client_args)
+ self.custom_object_client = ObjectClientCustomizedHeader(
+ auth_provider)
self.custom_account_client = \
- AccountClientCustomizedHeader(*client_args)
- self.data_processing_client = DataProcessingClient(*client_args)
+ AccountClientCustomizedHeader(auth_provider)
+ self.data_processing_client = DataProcessingClient(
+ auth_provider)
+
+ @classmethod
+ def get_auth_provider_class(cls, auth_version):
+ if auth_version == 'v2':
+ return auth.KeystoneV2AuthProvider
+ else:
+ return auth.KeystoneV3AuthProvider
+
+ def get_default_credentials(self):
+ return dict(
+ username=CONF.identity.username,
+ password=CONF.identity.password,
+ tenant_name=CONF.identity.tenant_name
+ )
+
+ def get_auth_provider(self, credentials=None):
+ auth_params = dict(client_type='tempest',
+ interface=self.interface)
+ auth_provider_class = self.get_auth_provider_class(self.auth_version)
+ # If invalid / incomplete credentials are provided, use default ones
+ if credentials is None or \
+ not auth_provider_class.check_credentials(credentials):
+ credentials = self.credentials
+ auth_params['credentials'] = credentials
+ return auth_provider_class(**auth_params)
class AltManager(Manager):
@@ -378,11 +397,12 @@
managed client objects
"""
- def __init__(self, interface='json'):
+ def __init__(self, interface='json', service=None):
super(AltManager, self).__init__(CONF.identity.alt_username,
CONF.identity.alt_password,
CONF.identity.alt_tenant_name,
- interface=interface)
+ interface=interface,
+ service=service)
class AdminManager(Manager):
@@ -392,11 +412,12 @@
managed client objects
"""
- def __init__(self, interface='json'):
+ def __init__(self, interface='json', service=None):
super(AdminManager, self).__init__(CONF.identity.admin_username,
CONF.identity.admin_password,
CONF.identity.admin_tenant_name,
- interface=interface)
+ interface=interface,
+ service=service)
class ComputeAdminManager(Manager):
@@ -406,12 +427,13 @@
managed client objects
"""
- def __init__(self, interface='json'):
+ def __init__(self, interface='json', service=None):
base = super(ComputeAdminManager, self)
base.__init__(CONF.compute_admin.username,
CONF.compute_admin.password,
CONF.compute_admin.tenant_name,
- interface=interface)
+ interface=interface,
+ service=service)
class OrchestrationManager(Manager):
@@ -419,9 +441,10 @@
Manager object that uses the admin credentials for its
so that heat templates can create users
"""
- def __init__(self, interface='json'):
+ def __init__(self, interface='json', service=None):
base = super(OrchestrationManager, self)
base.__init__(CONF.identity.admin_username,
CONF.identity.admin_password,
- CONF.identity.tenant_name,
- interface=interface)
+ CONF.identity.admin_tenant_name,
+ interface=interface,
+ service=service)
diff --git a/tempest/common/commands.py b/tempest/common/commands.py
index 4fc85b6..6405eaa 100644
--- a/tempest/common/commands.py
+++ b/tempest/common/commands.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -31,7 +29,8 @@
subprocess_args = {'stdout': subprocess.PIPE,
'stderr': subprocess.STDOUT}
try:
- proc = subprocess.Popen(['/usr/bin/sudo'] + args, **subprocess_args)
+ proc = subprocess.Popen(['/usr/bin/sudo', '-n'] + args,
+ **subprocess_args)
return proc.communicate()[0]
if proc.returncode != 0:
LOG.error(cmd + "returned with: " +
diff --git a/tempest/common/custom_matchers.py b/tempest/common/custom_matchers.py
index 307d5db..4a7921f 100644
--- a/tempest/common/custom_matchers.py
+++ b/tempest/common/custom_matchers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NTT Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -125,7 +123,7 @@
elif key == 'content-type' and not value:
return InvalidFormat(key, value)
elif key == 'x-trans-id' and \
- not re.match("^tx[0-9a-f]*-[0-9a-f]*$", value):
+ not re.match("^tx[0-9a-f]{21}-[0-9a-f]{10}.*", value):
return InvalidFormat(key, value)
elif key == 'date' and not value:
return InvalidFormat(key, value)
@@ -133,6 +131,8 @@
return InvalidFormat(key, value)
elif key == 'etag' and not value.isalnum():
return InvalidFormat(key, value)
+ elif key == 'transfer-encoding' and not value == 'chunked':
+ return InvalidFormat(key, value)
return None
diff --git a/tempest/common/debug.py b/tempest/common/debug.py
index f132f6a..8325d4d 100644
--- a/tempest/common/debug.py
+++ b/tempest/common/debug.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/common/generate_json.py b/tempest/common/generate_json.py
new file mode 100644
index 0000000..c8e86dc
--- /dev/null
+++ b/tempest/common/generate_json.py
@@ -0,0 +1,265 @@
+# Copyright 2014 Red Hat, Inc. & Deutsche Telekom AG
+# All Rights Reserved.
+#
+# 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 copy
+import jsonschema
+
+from tempest.openstack.common import log as logging
+
+LOG = logging.getLogger(__name__)
+
+
+def generate_valid(schema):
+ """
+ Create a valid dictionary based on the types in a json schema.
+ """
+ LOG.debug("generate_valid: %s" % schema)
+ schema_type = schema["type"]
+ if isinstance(schema_type, list):
+ # Just choose the first one since all are valid.
+ schema_type = schema_type[0]
+ return type_map_valid[schema_type](schema)
+
+
+def generate_valid_string(schema):
+ size = schema.get("minLength", 0)
+ # TODO(dkr mko): handle format and pattern
+ return "x" * size
+
+
+def generate_valid_integer(schema):
+ # TODO(dkr mko): handle multipleOf
+ if "minimum" in schema:
+ minimum = schema["minimum"]
+ if "exclusiveMinimum" not in schema:
+ return minimum
+ else:
+ return minimum + 1
+ if "maximum" in schema:
+ maximum = schema["maximum"]
+ if "exclusiveMaximum" not in schema:
+ return maximum
+ else:
+ return maximum - 1
+ return 0
+
+
+def generate_valid_object(schema):
+ obj = {}
+ for k, v in schema["properties"].iteritems():
+ obj[k] = generate_valid(v)
+ return obj
+
+
+def generate_invalid(schema):
+ """
+ Generate an invalid json dictionary based on a schema.
+ Only one value is mis-generated for each dictionary created.
+
+ Any generator must return a list of tuples or a single tuple.
+ The values of this tuple are:
+ result[0]: Name of the test
+ result[1]: json schema for the test
+ result[2]: expected result of the test (can be None)
+ """
+ LOG.debug("generate_invalid: %s" % schema)
+ schema_type = schema["type"]
+ if isinstance(schema_type, list):
+ if "integer" in schema_type:
+ schema_type = "integer"
+ else:
+ raise Exception("non-integer list types not supported")
+ result = []
+ for generator in type_map_invalid[schema_type]:
+ ret = generator(schema)
+ if ret is not None:
+ if isinstance(ret, list):
+ result.extend(ret)
+ elif isinstance(ret, tuple):
+ result.append(ret)
+ else:
+ raise Exception("generator (%s) returns invalid result"
+ % generator)
+ LOG.debug("result: %s" % result)
+ return result
+
+
+def _check_for_expected_result(name, schema):
+ expected_result = None
+ if "results" in schema:
+ if name in schema["results"]:
+ expected_result = schema["results"][name]
+ return expected_result
+
+
+def generator(fn):
+ """
+ Decorator for simple generators that simply return one value
+ """
+ def wrapped(schema):
+ result = fn(schema)
+ if result is not None:
+ expected_result = _check_for_expected_result(fn.__name__, schema)
+ return (fn.__name__, result, expected_result)
+ return
+ return wrapped
+
+
+@generator
+def gen_int(_):
+ return 4
+
+
+@generator
+def gen_string(_):
+ return "XXXXXX"
+
+
+def gen_none(schema):
+ # Note(mkoderer): it's not using the decorator otherwise it'd be filtered
+ expected_result = _check_for_expected_result('gen_none', schema)
+ return ('gen_none', None, expected_result)
+
+
+@generator
+def gen_str_min_length(schema):
+ min_length = schema.get("minLength", 0)
+ if min_length > 0:
+ return "x" * (min_length - 1)
+
+
+@generator
+def gen_str_max_length(schema):
+ max_length = schema.get("maxLength", -1)
+ if max_length > -1:
+ return "x" * (max_length + 1)
+
+
+@generator
+def gen_int_min(schema):
+ if "minimum" in schema:
+ minimum = schema["minimum"]
+ if "exclusiveMinimum" not in schema:
+ minimum -= 1
+ return minimum
+
+
+@generator
+def gen_int_max(schema):
+ if "maximum" in schema:
+ maximum = schema["maximum"]
+ if "exclusiveMaximum" not in schema:
+ maximum += 1
+ return maximum
+
+
+def gen_obj_remove_attr(schema):
+ invalids = []
+ valid = generate_valid(schema)
+ required = schema.get("required", [])
+ for r in required:
+ new_valid = copy.deepcopy(valid)
+ del new_valid[r]
+ invalids.append(("gen_obj_remove_attr", new_valid, None))
+ return invalids
+
+
+@generator
+def gen_obj_add_attr(schema):
+ valid = generate_valid(schema)
+ if not schema.get("additionalProperties", True):
+ new_valid = copy.deepcopy(valid)
+ new_valid["$$$$$$$$$$"] = "xxx"
+ return new_valid
+
+
+def gen_inv_prop_obj(schema):
+ LOG.debug("generate_invalid_object: %s" % schema)
+ valid = generate_valid(schema)
+ invalids = []
+ properties = schema["properties"]
+
+ for k, v in properties.iteritems():
+ for invalid in generate_invalid(v):
+ LOG.debug(v)
+ new_valid = copy.deepcopy(valid)
+ new_valid[k] = invalid[1]
+ name = "prop_%s_%s" % (k, invalid[0])
+ invalids.append((name, new_valid, invalid[2]))
+
+ LOG.debug("generate_invalid_object return: %s" % invalids)
+ return invalids
+
+
+type_map_valid = {
+ "string": generate_valid_string,
+ "integer": generate_valid_integer,
+ "object": generate_valid_object
+}
+
+type_map_invalid = {
+ "string": [
+ gen_int,
+ gen_none,
+ gen_str_min_length,
+ gen_str_max_length],
+ "integer": [
+ gen_string,
+ gen_none,
+ gen_int_min,
+ gen_int_max],
+ "object": [
+ gen_obj_remove_attr,
+ gen_obj_add_attr,
+ gen_inv_prop_obj]
+}
+
+schema = {
+ "type": "object",
+ "properties": {
+ "name": {"type": "string"},
+ "http-method": {
+ "enum": ["GET", "PUT", "HEAD",
+ "POST", "PATCH", "DELETE", 'COPY']
+ },
+ "url": {"type": "string"},
+ "json-schema": jsonschema._utils.load_schema("draft4"),
+ "resources": {
+ "type": "array",
+ "items": {
+ "oneOf": [
+ {"type": "string"},
+ {
+ "type": "object",
+ "properties": {
+ "name": {"type": "string"},
+ "expected_result": {"type": "integer"}
+ }
+ }
+ ]
+ }
+ },
+ "results": {
+ "type": "object",
+ "properties": {}
+ }
+ },
+ "required": ["name", "http-method", "url"],
+ "additionalProperties": False,
+}
+
+
+def validate_negative_test_schema(nts):
+ jsonschema.validate(nts, schema)
diff --git a/tempest/common/generate_sample_tempest.py b/tempest/common/generate_sample_tempest.py
index 6097aa8..e1213db 100644
--- a/tempest/common/generate_sample_tempest.py
+++ b/tempest/common/generate_sample_tempest.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
diff --git a/tempest/common/glance_http.py b/tempest/common/glance_http.py
index e72cd9e..4503f13 100644
--- a/tempest/common/glance_http.py
+++ b/tempest/common/glance_http.py
@@ -45,8 +45,10 @@
class HTTPClient(object):
- def __init__(self, endpoint, **kwargs):
- self.endpoint = endpoint
+ def __init__(self, auth_provider, filters, **kwargs):
+ self.auth_provider = auth_provider
+ self.filters = filters
+ self.endpoint = auth_provider.base_url(filters)
endpoint_parts = self.parse_endpoint(self.endpoint)
self.endpoint_scheme = endpoint_parts.scheme
self.endpoint_hostname = endpoint_parts.hostname
@@ -57,8 +59,6 @@
self.connection_kwargs = self.get_connection_kwargs(
self.endpoint_scheme, **kwargs)
- self.auth_token = kwargs.get('token')
-
@staticmethod
def parse_endpoint(endpoint):
return urlparse.urlparse(endpoint)
@@ -100,15 +100,15 @@
# Copy the kwargs so we can reuse the original in case of redirects
kwargs['headers'] = copy.deepcopy(kwargs.get('headers', {}))
kwargs['headers'].setdefault('User-Agent', USER_AGENT)
- if self.auth_token:
- kwargs['headers'].setdefault('X-Auth-Token', self.auth_token)
self._log_request(method, url, kwargs['headers'])
conn = self.get_connection()
try:
- conn_url = posixpath.normpath('%s/%s' % (self.endpoint_path, url))
+ url_parts = self.parse_endpoint(url)
+ conn_url = posixpath.normpath(url_parts.path)
+ LOG.debug('Actual Path: {path}'.format(path=conn_url))
if kwargs['headers'].get('Transfer-Encoding') == 'chunked':
conn.putrequest(method, conn_url)
for header, value in kwargs['headers'].items():
@@ -198,7 +198,13 @@
# We use 'Transfer-Encoding: chunked' because
# body size may not always be known in advance.
kwargs['headers']['Transfer-Encoding'] = 'chunked'
- return self._http_request(url, method, **kwargs)
+
+ # Decorate the request with auth
+ req_url, kwargs['headers'], kwargs['body'] = \
+ self.auth_provider.auth_request(
+ method=method, url=url, headers=kwargs['headers'],
+ body=kwargs.get('body', None), filters=self.filters)
+ return self._http_request(req_url, method, **kwargs)
class OpenSSLConnectionDelegator(object):
@@ -218,6 +224,8 @@
return getattr(self.connection, name)
def makefile(self, *args, **kwargs):
+ # Ensure the socket is closed when this file is closed
+ kwargs['close'] = True
return socket._fileobject(self.connection, *args, **kwargs)
@@ -345,6 +353,15 @@
self.sock = OpenSSLConnectionDelegator(self.context, sock)
self.sock.connect((self.host, self.port))
+ def close(self):
+ if self.sock:
+ # Remove the reference to the socket but don't close it yet.
+ # Response close will close both socket and associated
+ # file. Closing socket too soon will cause response
+ # reads to fail with socket IO error 'Bad file descriptor'.
+ self.sock = None
+ httplib.HTTPSConnection.close(self)
+
class ResponseBodyIterator(object):
"""A class that acts as an iterator over an HTTP response."""
diff --git a/tempest/common/http.py b/tempest/common/http.py
index b70502c..b3793bc 100644
--- a/tempest/common/http.py
+++ b/tempest/common/http.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# Copyright 2013 Citrix Systems, Inc.
# All Rights Reserved.
diff --git a/tempest/common/isolated_creds.py b/tempest/common/isolated_creds.py
index da60318..ac8b14f 100644
--- a/tempest/common/isolated_creds.py
+++ b/tempest/common/isolated_creds.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -32,12 +30,12 @@
class IsolatedCreds(object):
def __init__(self, name, tempest_client=True, interface='json',
- password='pass'):
+ password='pass', network_resources=None):
+ self.network_resources = network_resources
self.isolated_creds = {}
self.isolated_net_resources = {}
self.ports = []
self.name = name
- self.config = CONF
self.tempest_client = tempest_client
self.interface = interface
self.password = password
@@ -147,18 +145,28 @@
else:
self.identity_admin_client.tenants.delete(tenant)
- def _create_creds(self, suffix=None, admin=False):
- data_utils.rand_name_root = data_utils.rand_name(self.name)
- if suffix:
- data_utils.rand_name_root += suffix
- tenant_name = data_utils.rand_name_root + "-tenant"
+ def _create_creds(self, suffix="", admin=False):
+ """Create random credentials under the following schema.
+
+ If the name contains a '.' is the full class path of something, and
+ we don't really care. If it isn't, it's probably a meaningful name,
+ so use it.
+
+ For logging purposes, -user and -tenant are long and redundant,
+ don't use them. The user# will be sufficient to figure it out.
+ """
+ if '.' in self.name:
+ root = ""
+ else:
+ root = self.name
+
+ tenant_name = data_utils.rand_name(root) + suffix
tenant_desc = tenant_name + "-desc"
tenant = self._create_tenant(name=tenant_name,
description=tenant_desc)
- if suffix:
- data_utils.rand_name_root += suffix
- username = data_utils.rand_name_root + "-user"
- email = data_utils.rand_name_root + "@example.com"
+
+ username = data_utils.rand_name(root) + suffix
+ email = data_utils.rand_name(root) + suffix + "@example.com"
user = self._create_user(username, self.password,
tenant, email)
if admin:
@@ -198,15 +206,33 @@
network = None
subnet = None
router = None
+ # Make sure settings
+ if self.network_resources:
+ if self.network_resources['router']:
+ if (not self.network_resources['subnet'] or
+ not self.network_resources['network']):
+ raise exceptions.InvalidConfiguration(
+ 'A router requires a subnet and network')
+ elif self.network_resources['subnet']:
+ if not self.network_resources['network']:
+ raise exceptions.InvalidConfiguration(
+ 'A subnet requires a network')
+ elif self.network_resources['dhcp']:
+ raise exceptions.InvalidConfiguration('DHCP requires a subnet')
+
data_utils.rand_name_root = data_utils.rand_name(self.name)
- network_name = data_utils.rand_name_root + "-network"
- network = self._create_network(network_name, tenant_id)
+ if not self.network_resources or self.network_resources['network']:
+ network_name = data_utils.rand_name_root + "-network"
+ network = self._create_network(network_name, tenant_id)
try:
- subnet_name = data_utils.rand_name_root + "-subnet"
- subnet = self._create_subnet(subnet_name, tenant_id, network['id'])
- router_name = data_utils.rand_name_root + "-router"
- router = self._create_router(router_name, tenant_id)
- self._add_router_interface(router['id'], subnet['id'])
+ if not self.network_resources or self.network_resources['subnet']:
+ subnet_name = data_utils.rand_name_root + "-subnet"
+ subnet = self._create_subnet(subnet_name, tenant_id,
+ network['id'])
+ if not self.network_resources or self.network_resources['router']:
+ router_name = data_utils.rand_name_root + "-router"
+ router = self._create_router(router_name, tenant_id)
+ self._add_router_interface(router['id'], subnet['id'])
except Exception:
if router:
self._clear_isolated_router(router['id'], router['name'])
@@ -220,7 +246,7 @@
def _create_network(self, name, tenant_id):
if self.tempest_client:
resp, resp_body = self.network_admin_client.create_network(
- name, tenant_id=tenant_id)
+ name=name, tenant_id=tenant_id)
else:
body = {'network': {'tenant_id': tenant_id, 'name': name}}
resp_body = self.network_admin_client.create_network(body)
@@ -230,14 +256,28 @@
if not self.tempest_client:
body = {'subnet': {'name': subnet_name, 'tenant_id': tenant_id,
'network_id': network_id, 'ip_version': 4}}
+ if self.network_resources:
+ body['enable_dhcp'] = self.network_resources['dhcp']
base_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
mask_bits = CONF.network.tenant_network_mask_bits
for subnet_cidr in base_cidr.subnet(mask_bits):
try:
if self.tempest_client:
- resp, resp_body = self.network_admin_client.create_subnet(
- network_id, str(subnet_cidr), name=subnet_name,
- tenant_id=tenant_id)
+ if self.network_resources:
+ resp, resp_body = self.network_admin_client.\
+ create_subnet(
+ network_id=network_id, cidr=str(subnet_cidr),
+ name=subnet_name,
+ tenant_id=tenant_id,
+ enable_dhcp=self.network_resources['dhcp'],
+ ip_version=4)
+ else:
+ resp, resp_body = self.network_admin_client.\
+ create_subnet(network_id=network_id,
+ cidr=str(subnet_cidr),
+ name=subnet_name,
+ tenant_id=tenant_id,
+ ip_version=4)
else:
body['subnet']['cidr'] = str(subnet_cidr)
resp_body = self.network_admin_client.create_subnet(body)
@@ -431,26 +471,34 @@
net_client = self.network_admin_client
for cred in self.isolated_net_resources:
network, subnet, router = self.isolated_net_resources.get(cred)
- try:
- if self.tempest_client:
- net_client.remove_router_interface_with_subnet_id(
- router['id'], subnet['id'])
- else:
- body = {'subnet_id': subnet['id']}
- net_client.remove_interface_router(router['id'], body)
- except exceptions.NotFound:
- LOG.warn('router with name: %s not found for delete' %
- router['name'])
- pass
- self._clear_isolated_router(router['id'], router['name'])
- # TODO(mlavalle) This method call will be removed once patch
- # https://review.openstack.org/#/c/46563/ merges in Neutron
- self._cleanup_ports(network['id'])
- self._clear_isolated_subnet(subnet['id'], subnet['name'])
- self._clear_isolated_network(network['id'], network['name'])
- LOG.info("Cleared isolated network resources: \n"
- + " network: %s, subnet: %s, router: %s"
- % (network['name'], subnet['name'], router['name']))
+ LOG.debug("Clearing network: %(network)s, "
+ "subnet: %(subnet)s, router: %(router)s",
+ {'network': network, 'subnet': subnet, 'router': router})
+ if (not self.network_resources or
+ self.network_resources.get('router')):
+ try:
+ if self.tempest_client:
+ net_client.remove_router_interface_with_subnet_id(
+ router['id'], subnet['id'])
+ else:
+ body = {'subnet_id': subnet['id']}
+ net_client.remove_interface_router(router['id'], body)
+ except exceptions.NotFound:
+ LOG.warn('router with name: %s not found for delete' %
+ router['name'])
+ pass
+ self._clear_isolated_router(router['id'], router['name'])
+ if (not self.network_resources or
+ self.network_resources.get('network')):
+ # TODO(mlavalle) This method call will be removed once patch
+ # https://review.openstack.org/#/c/46563/ merges in Neutron
+ self._cleanup_ports(network['id'])
+ if (not self.network_resources or
+ self.network_resources.get('subnet')):
+ self._clear_isolated_subnet(subnet['id'], subnet['name'])
+ if (not self.network_resources or
+ self.network_resources.get('network')):
+ self._clear_isolated_network(network['id'], network['name'])
def clear_isolated_creds(self):
if not self.isolated_creds:
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index 9aca2ff..212d41d 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -24,10 +22,13 @@
import time
from tempest.common import http
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
# redrive rate limited calls at most twice
MAX_RECURSION_DEPTH = 2
TOKEN_CHARS_RE = re.compile('^[-A-Za-z0-9+/=]*$')
@@ -37,37 +38,38 @@
class RestClient(object):
+
TYPE = "json"
+
+ # This is used by _parse_resp method
+ # Redefine it for purposes of your xml service client
+ # List should contain top-xml_tag-names of data, which is like list/array
+ # For example, in keystone it is users, roles, tenants and services
+ # All of it has children with same tag-names
+ list_tags = []
+
+ # This is used by _parse_resp method too
+ # Used for selection of dict-like xmls,
+ # like metadata for Vms in nova, and volumes in cinder
+ dict_tags = ["metadata", ]
+
LOG = logging.getLogger(__name__)
- def __init__(self, config, user, password, auth_url, tenant_name=None,
- auth_version='v2'):
- self.config = config
- self.user = user
- self.password = password
- self.auth_url = auth_url
- self.tenant_name = tenant_name
- self.auth_version = auth_version
+ def __init__(self, auth_provider):
+ self.auth_provider = auth_provider
- self.service = None
- self.token = None
- self.base_url = None
- self.region = {}
- for cfgname in dir(self.config):
- # Find all config.FOO.catalog_type and assume FOO is a service.
- cfg = getattr(self.config, cfgname)
- catalog_type = getattr(cfg, 'catalog_type', None)
- if not catalog_type:
- continue
- service_region = getattr(cfg, 'region', None)
- if not service_region:
- service_region = self.config.identity.region
- self.region[catalog_type] = service_region
self.endpoint_url = 'publicURL'
+ self.service = None
+ # The version of the API this client implements
+ self.api_version = None
+ self._skip_path = False
+ # NOTE(vponomaryov): self.headers is deprecated now.
+ # should be removed after excluding it from all use places.
+ # Insted of this should be used 'get_headers' method
self.headers = {'Content-Type': 'application/%s' % self.TYPE,
'Accept': 'application/%s' % self.TYPE}
- self.build_interval = config.compute.build_interval
- self.build_timeout = config.compute.build_timeout
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
self.general_header_lc = set(('cache-control', 'connection',
'date', 'pragma', 'trailer',
'transfer-encoding', 'via',
@@ -76,213 +78,93 @@
'location', 'proxy-authenticate',
'retry-after', 'server',
'vary', 'www-authenticate'))
- dscv = self.config.identity.disable_ssl_certificate_validation
+ dscv = CONF.identity.disable_ssl_certificate_validation
self.http_obj = http.ClosingHttp(
disable_ssl_certificate_validation=dscv)
+ def _get_type(self):
+ return self.TYPE
+
+ def get_headers(self, accept_type=None, send_type=None):
+ # This method should be used instead of
+ # deprecated 'self.headers'
+ if accept_type is None:
+ accept_type = self._get_type()
+ if send_type is None:
+ send_type = self._get_type()
+ return {'Content-Type': 'application/%s' % send_type,
+ 'Accept': 'application/%s' % accept_type}
+
def __str__(self):
STRING_LIMIT = 80
- str_format = ("config:%s, user:%s, password:%s, "
- "auth_url:%s, tenant_name:%s, auth_version:%s, "
- "service:%s, base_url:%s, region:%s, "
- "endpoint_url:%s, build_interval:%s, build_timeout:%s"
+ str_format = ("config:%s, service:%s, base_url:%s, "
+ "filters: %s, build_interval:%s, build_timeout:%s"
"\ntoken:%s..., \nheaders:%s...")
- return str_format % (self.config, self.user, self.password,
- self.auth_url, self.tenant_name,
- self.auth_version, self.service,
- self.base_url, self.region, self.endpoint_url,
- self.build_interval, self.build_timeout,
+ return str_format % (CONF, self.service, self.base_url,
+ self.filters, self.build_interval,
+ self.build_timeout,
str(self.token)[0:STRING_LIMIT],
- str(self.headers)[0:STRING_LIMIT])
+ str(self.get_headers())[0:STRING_LIMIT])
- def _set_auth(self):
+ def _get_region(self, service):
"""
- Sets the token and base_url used in requests based on the strategy type
+ Returns the region for a specific service
"""
+ service_region = None
+ for cfgname in dir(CONF._config):
+ # Find all config.FOO.catalog_type and assume FOO is a service.
+ cfg = getattr(CONF, cfgname)
+ catalog_type = getattr(cfg, 'catalog_type', None)
+ if catalog_type == service:
+ service_region = getattr(cfg, 'region', None)
+ if not service_region:
+ service_region = CONF.identity.region
+ return service_region
- if self.auth_version == 'v3':
- auth_func = self.identity_auth_v3
- else:
- auth_func = self.keystone_auth
+ @property
+ def user(self):
+ return self.auth_provider.credentials.get('username', None)
- self.token, self.base_url = (
- auth_func(self.user, self.password, self.auth_url,
- self.service, self.tenant_name))
+ @property
+ def tenant_name(self):
+ return self.auth_provider.credentials.get('tenant_name', None)
- def clear_auth(self):
+ @property
+ def password(self):
+ return self.auth_provider.credentials.get('password', None)
+
+ @property
+ def base_url(self):
+ return self.auth_provider.base_url(filters=self.filters)
+
+ @property
+ def token(self):
+ return self.auth_provider.get_token()
+
+ @property
+ def filters(self):
+ _filters = dict(
+ service=self.service,
+ endpoint_type=self.endpoint_url,
+ region=self._get_region(self.service)
+ )
+ if self.api_version is not None:
+ _filters['api_version'] = self.api_version
+ if self._skip_path:
+ _filters['skip_path'] = self._skip_path
+ return _filters
+
+ def skip_path(self):
"""
- Can be called to clear the token and base_url so that the next request
- will fetch a new token and base_url.
+ When set, ignore the path part of the base URL from the catalog
"""
+ self._skip_path = True
- self.token = None
- self.base_url = None
-
- def get_auth(self):
- """Returns the token of the current request or sets the token if
- none.
+ def reset_path(self):
"""
-
- if not self.token:
- self._set_auth()
-
- return self.token
-
- def basic_auth(self, user, password, auth_url):
+ When reset, use the base URL from the catalog as-is
"""
- Provides authentication for the target API.
- """
-
- params = {}
- params['headers'] = {'User-Agent': 'Test-Client', 'X-Auth-User': user,
- 'X-Auth-Key': password}
-
- resp, body = self.http_obj.request(auth_url, 'GET', **params)
- try:
- return resp['x-auth-token'], resp['x-server-management-url']
- except Exception:
- raise
-
- def keystone_auth(self, user, password, auth_url, service, tenant_name):
- """
- Provides authentication via Keystone using v2 identity API.
- """
-
- # Normalize URI to ensure /tokens is in it.
- if 'tokens' not in auth_url:
- auth_url = auth_url.rstrip('/') + '/tokens'
-
- creds = {
- 'auth': {
- 'passwordCredentials': {
- 'username': user,
- 'password': password,
- },
- 'tenantName': tenant_name,
- }
- }
-
- headers = {'Content-Type': 'application/json'}
- body = json.dumps(creds)
- self._log_request('POST', auth_url, headers, body)
- resp, resp_body = self.http_obj.request(auth_url, 'POST',
- headers=headers, body=body)
- self._log_response(resp, resp_body)
-
- if resp.status == 200:
- try:
- auth_data = json.loads(resp_body)['access']
- token = auth_data['token']['id']
- except Exception as e:
- print("Failed to obtain token for user: %s" % e)
- raise
-
- mgmt_url = None
- for ep in auth_data['serviceCatalog']:
- if ep["type"] == service:
- for _ep in ep['endpoints']:
- if service in self.region and \
- _ep['region'] == self.region[service]:
- mgmt_url = _ep[self.endpoint_url]
- if not mgmt_url:
- mgmt_url = ep['endpoints'][0][self.endpoint_url]
- break
-
- if mgmt_url is None:
- raise exceptions.EndpointNotFound(service)
-
- return token, mgmt_url
-
- elif resp.status == 401:
- raise exceptions.AuthenticationFailure(user=user,
- password=password,
- tenant=tenant_name)
- raise exceptions.IdentityError('Unexpected status code {0}'.format(
- resp.status))
-
- def identity_auth_v3(self, user, password, auth_url, service,
- project_name, domain_id='default'):
- """Provides authentication using Identity API v3."""
-
- req_url = auth_url.rstrip('/') + '/auth/tokens'
-
- creds = {
- "auth": {
- "identity": {
- "methods": ["password"],
- "password": {
- "user": {
- "name": user, "password": password,
- "domain": {"id": domain_id}
- }
- }
- },
- "scope": {
- "project": {
- "domain": {"id": domain_id},
- "name": project_name
- }
- }
- }
- }
-
- headers = {'Content-Type': 'application/json'}
- body = json.dumps(creds)
- resp, body = self.http_obj.request(req_url, 'POST',
- headers=headers, body=body)
-
- if resp.status == 201:
- try:
- token = resp['x-subject-token']
- except Exception:
- self.LOG.exception("Failed to obtain token using V3"
- " authentication (auth URL is '%s')" %
- req_url)
- raise
-
- catalog = json.loads(body)['token']['catalog']
-
- mgmt_url = None
- for service_info in catalog:
- if service_info['type'] != service:
- continue # this isn't the entry for us.
-
- endpoints = service_info['endpoints']
-
- # Look for an endpoint in the region if configured.
- if service in self.region:
- region = self.region[service]
-
- for ep in endpoints:
- if ep['region'] != region:
- continue
-
- mgmt_url = ep['url']
- # FIXME(blk-u): this isn't handling endpoint type
- # (public, internal, admin).
- break
-
- if not mgmt_url:
- # Didn't find endpoint for region, use the first.
-
- ep = endpoints[0]
- mgmt_url = ep['url']
- # FIXME(blk-u): this isn't handling endpoint type
- # (public, internal, admin).
-
- break
-
- return token, mgmt_url
-
- elif resp.status == 401:
- raise exceptions.AuthenticationFailure(user=user,
- password=password)
- else:
- self.LOG.error("Failed to obtain token using V3 authentication"
- " (auth URL is '%s'), the response status is %s" %
- (req_url, resp.status))
- raise exceptions.AuthenticationFailure(user=user,
- password=password)
+ self._skip_path = False
def expected_success(self, expected_code, read_code):
assert_msg = ("This function only allowed to use for HTTP status"
@@ -298,19 +180,19 @@
details = pattern.format(read_code, expected_code)
raise exceptions.InvalidHttpSuccessCode(details)
- def post(self, url, body, headers):
+ def post(self, url, body, headers=None):
return self.request('POST', url, headers, body)
def get(self, url, headers=None):
return self.request('GET', url, headers)
- def delete(self, url, headers=None):
- return self.request('DELETE', url, headers)
+ def delete(self, url, headers=None, body=None):
+ return self.request('DELETE', url, headers, body)
- def patch(self, url, body, headers):
+ def patch(self, url, body, headers=None):
return self.request('PATCH', url, headers, body)
- def put(self, url, body, headers):
+ def put(self, url, body, headers=None):
return self.request('PUT', url, headers, body)
def head(self, url, headers=None):
@@ -366,7 +248,48 @@
hashlib.md5(str_body).hexdigest())
def _parse_resp(self, body):
- return json.loads(body)
+ if self._get_type() is "json":
+ body = json.loads(body)
+
+ # We assume, that if the first value of the deserialized body's
+ # item set is a dict or a list, that we just return the first value
+ # of deserialized body.
+ # Essentially "cutting out" the first placeholder element in a body
+ # that looks like this:
+ #
+ # {
+ # "users": [
+ # ...
+ # ]
+ # }
+ try:
+ # Ensure there are not more than one top-level keys
+ if len(body.keys()) > 1:
+ return body
+ # Just return the "wrapped" element
+ first_key, first_item = body.items()[0]
+ if isinstance(first_item, (dict, list)):
+ return first_item
+ except (ValueError, IndexError):
+ pass
+ return body
+ elif self._get_type() is "xml":
+ element = etree.fromstring(body)
+ if any(s in element.tag for s in self.dict_tags):
+ # Parse dictionary-like xmls (metadata, etc)
+ dictionary = {}
+ for el in element.getchildren():
+ dictionary[u"%s" % el.get("key")] = u"%s" % el.text
+ return dictionary
+ if any(s in element.tag for s in self.list_tags):
+ # Parse list-like xmls (users, roles, etc)
+ array = []
+ for child in element.getchildren():
+ array.append(xml_to_json(child))
+ return array
+
+ # Parse one-item-like xmls (user, role, etc)
+ return xml_to_json(element)
def response_checker(self, method, url, headers, body, resp, resp_body):
if (resp.status in set((204, 205, 304)) or resp.status < 200 or
@@ -396,28 +319,29 @@
if not resp_body and resp.status >= 400:
self.LOG.warning("status >= 400 response with empty body")
- def _request(self, method, url,
- headers=None, body=None):
+ def _request(self, method, url, headers=None, body=None):
"""A simple HTTP request interface."""
-
- req_url = "%s/%s" % (self.base_url, url)
- self._log_request(method, req_url, headers, body)
- resp, resp_body = self.http_obj.request(req_url, method,
- headers=headers, body=body)
+ # Authenticate the request with the auth provider
+ req_url, req_headers, req_body = self.auth_provider.auth_request(
+ method, url, headers, body, self.filters)
+ self._log_request(method, req_url, req_headers, req_body)
+ # Do the actual request
+ resp, resp_body = self.http_obj.request(
+ req_url, method, headers=req_headers, body=req_body)
self._log_response(resp, resp_body)
- self.response_checker(method, url, headers, body, resp, resp_body)
+ # Verify HTTP response codes
+ self.response_checker(method, url, req_headers, req_body, resp,
+ resp_body)
return resp, resp_body
- def request(self, method, url,
- headers=None, body=None):
+ def request(self, method, url, headers=None, body=None):
retry = 0
- if (self.token is None) or (self.base_url is None):
- self._set_auth()
if headers is None:
- headers = {}
- headers['X-Auth-Token'] = self.token
+ # NOTE(vponomaryov): if some client do not need headers,
+ # it should explicitly pass empty dict
+ headers = self.get_headers()
resp, resp_body = self._request(method, url,
headers=headers, body=body)
@@ -458,18 +382,17 @@
if resp.status < 400:
return
- JSON_ENC = ['application/json; charset=UTF-8', 'application/json',
- 'application/json; charset=utf-8']
+ JSON_ENC = ['application/json', 'application/json; charset=utf-8']
# NOTE(mtreinish): This is for compatibility with Glance and swift
# APIs. These are the return content types that Glance api v1
# (and occasionally swift) are using.
- TXT_ENC = ['text/plain', 'text/plain; charset=UTF-8',
- 'text/html; charset=UTF-8', 'text/plain; charset=utf-8']
- XML_ENC = ['application/xml', 'application/xml; charset=UTF-8']
+ TXT_ENC = ['text/plain', 'text/html', 'text/html; charset=utf-8',
+ 'text/plain; charset=utf-8']
+ XML_ENC = ['application/xml', 'application/xml; charset=utf-8']
- if ctype in JSON_ENC or ctype in XML_ENC:
+ if ctype.lower() in JSON_ENC or ctype.lower() in XML_ENC:
parse_resp = True
- elif ctype in TXT_ENC:
+ elif ctype.lower() in TXT_ENC:
parse_resp = False
else:
raise exceptions.RestClientException(str(resp.status))
@@ -538,10 +461,13 @@
if (not isinstance(resp_body, collections.Mapping) or
'retry-after' not in resp):
return True
- over_limit = resp_body.get('overLimit', None)
- if not over_limit:
- return True
- return 'exceed' in over_limit.get('message', 'blabla')
+ if self._get_type() is "json":
+ over_limit = resp_body.get('overLimit', None)
+ if not over_limit:
+ return True
+ return 'exceed' in over_limit.get('message', 'blabla')
+ elif self._get_type() is "xml":
+ return 'exceed' in resp_body.get('message', 'blabla')
def wait_for_resource_deletion(self, id):
"""Waits for a resource to be deleted."""
@@ -563,6 +489,11 @@
class RestClientXML(RestClient):
+
+ # NOTE(vponomaryov): This is deprecated class
+ # and should be removed after excluding it
+ # from all service clients
+
TYPE = "xml"
def _parse_resp(self, body):
@@ -573,3 +504,33 @@
'retry-after' not in resp):
return True
return 'exceed' in resp_body.get('message', 'blabla')
+
+
+class NegativeRestClient(RestClient):
+ """
+ Version of RestClient that does not raise exceptions.
+ """
+ def _error_checker(self, method, url,
+ headers, body, resp, resp_body):
+ pass
+
+ def send_request(self, method, url_template, resources, body=None):
+ url = url_template % tuple(resources)
+ if method == "GET":
+ resp, body = self.get(url)
+ elif method == "POST":
+ resp, body = self.post(url, body)
+ elif method == "PUT":
+ resp, body = self.put(url, body)
+ elif method == "PATCH":
+ resp, body = self.patch(url, body)
+ elif method == "HEAD":
+ resp, body = self.head(url)
+ elif method == "DELETE":
+ resp, body = self.delete(url)
+ elif method == "COPY":
+ resp, body = self.copy(url)
+ else:
+ assert False
+
+ return resp, body
diff --git a/tempest/common/ssh.py b/tempest/common/ssh.py
index bca2f9e..c772ce9 100644
--- a/tempest/common/ssh.py
+++ b/tempest/common/ssh.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -51,7 +49,7 @@
self.channel_timeout = float(channel_timeout)
self.buf_size = 1024
- def _get_ssh_connection(self, sleep=1.5, backoff=1.01):
+ def _get_ssh_connection(self, sleep=1.5, backoff=1):
"""Returns an ssh connection to the specified host."""
bsleep = sleep
ssh = paramiko.SSHClient()
@@ -78,37 +76,25 @@
self.username, self.host)
return ssh
except (socket.error,
- paramiko.SSHException):
- attempts += 1
- time.sleep(bsleep)
- bsleep *= backoff
- if not self._is_timed_out(_start_time):
- continue
- else:
+ paramiko.SSHException) as e:
+ if self._is_timed_out(_start_time):
LOG.exception("Failed to establish authenticated ssh"
" connection to %s@%s after %d attempts",
self.username, self.host, attempts)
raise exceptions.SSHTimeout(host=self.host,
user=self.username,
password=self.password)
+ bsleep += backoff
+ attempts += 1
+ LOG.warning("Failed to establish authenticated ssh"
+ " connection to %s@%s (%s). Number attempts: %s."
+ " Retry after %d seconds.",
+ self.username, self.host, e, attempts, bsleep)
+ time.sleep(bsleep)
def _is_timed_out(self, start_time):
return (time.time() - self.timeout) > start_time
- def connect_until_closed(self):
- """Connect to the server and wait until connection is lost."""
- try:
- ssh = self._get_ssh_connection()
- _transport = ssh.get_transport()
- _start_time = time.time()
- _timed_out = self._is_timed_out(_start_time)
- while _transport.is_active() and not _timed_out:
- time.sleep(5)
- _timed_out = self._is_timed_out(_start_time)
- ssh.close()
- except (EOFError, paramiko.AuthenticationException, socket.error):
- return
-
def exec_command(self, cmd):
"""
Execute the specified command on the server.
@@ -140,7 +126,7 @@
raise exceptions.TimeoutException(
"Command: '{0}' executed on host '{1}'.".format(
cmd, self.host))
- if not ready[0]: # If there is nothing to read.
+ if not ready[0]: # If there is nothing to read.
continue
out_chunk = err_chunk = None
if channel.recv_ready():
diff --git a/tempest/common/tempest_fixtures.py b/tempest/common/tempest_fixtures.py
index 73c02e8..b33f354 100644
--- a/tempest/common/tempest_fixtures.py
+++ b/tempest/common/tempest_fixtures.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
diff --git a/tempest/common/utils/__init__.py b/tempest/common/utils/__init__.py
index 38f3d38..04d898d 100644
--- a/tempest/common/utils/__init__.py
+++ b/tempest/common/utils/__init__.py
@@ -1,4 +1,3 @@
-LAST_REBOOT_TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
PING_IPV4_COMMAND = 'ping -c 3 '
PING_IPV6_COMMAND = 'ping6 -c 3 '
PING_PACKET_LOSS_REGEX = '(\d{1,3})\.?\d*\% packet loss'
diff --git a/tempest/common/utils/data_utils.py b/tempest/common/utils/data_utils.py
index 4f93e1c..cd32720 100644
--- a/tempest/common/utils/data_utils.py
+++ b/tempest/common/utils/data_utils.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -32,14 +30,33 @@
return uuid.uuid4().hex
-def rand_name(name='test'):
- return name + "-tempest-" + str(random.randint(1, 0x7fffffff))
+def rand_name(name=''):
+ randbits = str(random.randint(1, 0x7fffffff))
+ if name:
+ return name + '-' + randbits
+ else:
+ return randbits
def rand_int_id(start=0, end=0x7fffffff):
return random.randint(start, end)
+def rand_mac_address():
+ """Generate an Ethernet MAC address."""
+ # NOTE(vish): We would prefer to use 0xfe here to ensure that linux
+ # bridge mac addresses don't change, but it appears to
+ # conflict with libvirt, so we use the next highest octet
+ # that has the unicast and locally administered bits set
+ # properly: 0xfa.
+ # Discussion: https://bugs.launchpad.net/nova/+bug/921838
+ mac = [0xfa, 0x16, 0x3e,
+ random.randint(0x00, 0xff),
+ random.randint(0x00, 0xff),
+ random.randint(0x00, 0xff)]
+ return ':'.join(["%02x" % x for x in mac])
+
+
def build_url(host, port, api_version=None, path=None,
params=None, use_ssl=False):
"""Build the request URL from given host, port, path and parameters."""
diff --git a/tempest/common/utils/file_utils.py b/tempest/common/utils/file_utils.py
index b111e84..43083f4 100644
--- a/tempest/common/utils/file_utils.py
+++ b/tempest/common/utils/file_utils.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py
index fa59e14..bb2fcfb 100644
--- a/tempest/common/utils/linux/remote_client.py
+++ b/tempest/common/utils/linux/remote_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# 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
@@ -16,7 +14,6 @@
import time
from tempest.common.ssh import Client
-from tempest.common import utils
from tempest import config
from tempest.exceptions import ServerUnreachable
@@ -78,11 +75,10 @@
return output
def get_boot_time(self):
- cmd = 'date -d "`cut -f1 -d. /proc/uptime` seconds ago" \
- "+%Y-%m-%d %H:%M:%S"'
- boot_time_string = self.ssh_client.exec_command(cmd)
- boot_time_string = boot_time_string.replace('\n', '')
- return time.strptime(boot_time_string, utils.LAST_REBOOT_TIME_FORMAT)
+ cmd = 'cut -f1 -d. /proc/uptime'
+ boot_secs = self.ssh_client.exec_command(cmd)
+ boot_time = time.time() - int(boot_secs)
+ return time.localtime(boot_time)
def write_to_console(self, message):
message = re.sub("([$\\`])", "\\\\\\\\\\1", message)
diff --git a/tempest/common/utils/misc.py b/tempest/common/utils/misc.py
index 1099ff5..a0b0c0a 100644
--- a/tempest/common/utils/misc.py
+++ b/tempest/common/utils/misc.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/common/utils/test_utils.py b/tempest/common/utils/test_utils.py
new file mode 100644
index 0000000..eca716e
--- /dev/null
+++ b/tempest/common/utils/test_utils.py
@@ -0,0 +1,134 @@
+# Copyright 2013 Hewlett-Packard, Ltd.
+#
+# 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 tempest.common.utils import misc
+from tempest import config
+from tempest.scenario import manager
+
+import json
+import re
+import string
+import unicodedata
+
+CONF = config.CONF
+
+
+@misc.singleton
+class ImageUtils(object):
+
+ default_ssh_user = 'root'
+
+ def __init__(self):
+ # Load configuration items
+ self.ssh_users = json.loads(CONF.input_scenario.ssh_user_regex)
+ self.non_ssh_image_pattern = \
+ CONF.input_scenario.non_ssh_image_regex
+ # Setup clients
+ ocm = manager.OfficialClientManager(CONF.identity.username,
+ CONF.identity.password,
+ CONF.identity.tenant_name)
+ self.client = ocm.compute_client
+
+ def ssh_user(self, image_id):
+ _image = self.client.images.get(image_id)
+ for regex, user in self.ssh_users:
+ # First match wins
+ if re.match(regex, _image.name) is not None:
+ return user
+ else:
+ return self.default_ssh_user
+
+ def _is_sshable_image(self, image):
+ return not re.search(pattern=self.non_ssh_image_pattern,
+ string=str(image.name))
+
+ def is_sshable_image(self, image_id):
+ _image = self.client.images.get(image_id)
+ return self._is_sshable_image(_image)
+
+ def _is_flavor_enough(self, flavor, image):
+ return image.minDisk <= flavor.disk
+
+ def is_flavor_enough(self, flavor_id, image_id):
+ _image = self.client.images.get(image_id)
+ _flavor = self.client.flavors.get(flavor_id)
+ return self._is_flavor_enough(_flavor, _image)
+
+
+@misc.singleton
+class InputScenarioUtils(object):
+
+ """
+ Example usage:
+
+ import testscenarios
+ (...)
+ load_tests = testscenarios.load_tests_apply_scenarios
+
+
+ class TestInputScenario(manager.OfficialClientTest):
+
+ scenario_utils = test_utils.InputScenarioUtils()
+ scenario_flavor = scenario_utils.scenario_flavors
+ scenario_image = scenario_utils.scenario_images
+ scenarios = testscenarios.multiply_scenarios(scenario_image,
+ scenario_flavor)
+
+ def test_create_server_metadata(self):
+ name = rand_name('instance')
+ _ = self.compute_client.servers.create(name=name,
+ flavor=self.flavor_ref,
+ image=self.image_ref)
+ """
+ validchars = "-_.{ascii}{digit}".format(ascii=string.ascii_letters,
+ digit=string.digits)
+
+ def __init__(self):
+ ocm = manager.OfficialClientManager(CONF.identity.username,
+ CONF.identity.password,
+ CONF.identity.tenant_name)
+ self.client = ocm.compute_client
+ self.image_pattern = CONF.input_scenario.image_regex
+ self.flavor_pattern = CONF.input_scenario.flavor_regex
+
+ def _normalize_name(self, name):
+ nname = unicodedata.normalize('NFKD', name).encode('ASCII', 'ignore')
+ nname = ''.join(c for c in nname if c in self.validchars)
+ return nname
+
+ @property
+ def scenario_images(self):
+ """
+ :return: a scenario with name and uuid of images
+ """
+ if not hasattr(self, '_scenario_images'):
+ images = self.client.images.list(detailed=False)
+ self._scenario_images = [
+ (self._normalize_name(i.name), dict(image_ref=i.id))
+ for i in images if re.search(self.image_pattern, str(i.name))
+ ]
+ return self._scenario_images
+
+ @property
+ def scenario_flavors(self):
+ """
+ :return: a scenario with name and uuid of flavors
+ """
+ if not hasattr(self, '_scenario_flavors'):
+ flavors = self.client.flavors.list(detailed=False)
+ self._scenario_flavors = [
+ (self._normalize_name(f.name), dict(flavor_ref=f.id))
+ for f in flavors if re.search(self.flavor_pattern, str(f.name))
+ ]
+ return self._scenario_flavors
diff --git a/tempest/common/waiters.py b/tempest/common/waiters.py
index ce620a8..dbeba8f 100644
--- a/tempest/common/waiters.py
+++ b/tempest/common/waiters.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
diff --git a/tempest/config.py b/tempest/config.py
index d42edc9..d24ab34 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -45,6 +43,10 @@
help="Full URI of the OpenStack Identity API (Keystone), v2"),
cfg.StrOpt('uri_v3',
help='Full URI of the OpenStack Identity API (Keystone), v3'),
+ cfg.StrOpt('auth_version',
+ default='v2',
+ help="Identity API version to be used for authentication "
+ "for API tests."),
cfg.StrOpt('region',
default='RegionOne',
help="The identity region name to use. Also used as the other "
@@ -78,7 +80,7 @@
secret=True),
cfg.StrOpt('admin_username',
default='admin',
- help="Administrative Username to use for"
+ help="Administrative Username to use for "
"Keystone API requests."),
cfg.StrOpt('admin_tenant_name',
default='admin',
@@ -90,6 +92,16 @@
secret=True),
]
+identity_feature_group = cfg.OptGroup(name='identity-feature-enabled',
+ title='Enabled Identity Features')
+
+IdentityFeatureGroup = [
+ cfg.BoolOpt('trust',
+ default=True,
+ help='Does the identity service have delegation and '
+ 'impersonation enabled')
+]
+
compute_group = cfg.OptGroup(name='compute',
title='Compute Service Options')
@@ -139,7 +151,7 @@
default='root',
help="User name used to authenticate to an instance."),
cfg.IntOpt('ping_timeout',
- default=60,
+ default=120,
help="Timeout in seconds to wait for ping to "
"succeed."),
cfg.IntOpt('ssh_timeout',
@@ -398,11 +410,11 @@
"one is used."),
cfg.IntOpt('container_sync_timeout',
default=120,
- help="Number of seconds to time on waiting for a container"
+ help="Number of seconds to time on waiting for a container "
"to container synchronization complete."),
cfg.IntOpt('container_sync_interval',
default=5,
- help="Number of seconds to wait while looping to check the"
+ help="Number of seconds to wait while looping to check the "
"status of a container to container synchronization"),
cfg.StrOpt('operator_role',
default='Member',
@@ -415,19 +427,11 @@
title='Enabled object-storage features')
ObjectStoreFeaturesGroup = [
- cfg.BoolOpt('container_quotas',
- default=True,
- help="Set to True if the Container Quota middleware "
- "is enabled"),
- cfg.BoolOpt('accounts_quotas',
- default=True,
- help="Set to True if the Account Quota middleware is enabled"),
- cfg.BoolOpt('crossdomain',
- default=True,
- help="Set to True if the Crossdomain middleware is enabled"),
- cfg.BoolOpt('tempurl',
- default=True,
- help="Set to True if the TempURL middleware is enabled"),
+ cfg.ListOpt('discoverable_apis',
+ default=['all'],
+ help="A list of the enabled optional discoverable apis. "
+ "A single entry, all, indicates that all of these "
+ "features are expected to be enabled"),
]
@@ -582,7 +586,12 @@
help='time (in seconds) between log file error checks.'),
cfg.IntOpt('default_thread_number_per_action',
default=4,
- help='The number of threads created while stress test.')
+ help='The number of threads created while stress test.'),
+ cfg.BoolOpt('leave_dirty_stack',
+ default=False,
+ help='Prevent the cleaning (tearDownClass()) between'
+ ' each stress test run if an exception occurs'
+ ' during this run.')
]
@@ -644,6 +653,9 @@
cfg.BoolOpt('savanna',
default=False,
help="Whether or not Savanna is expected to be available"),
+ cfg.BoolOpt('ironic',
+ default=False,
+ help="Whether or not Ironic is expected to be available"),
]
debug_group = cfg.OptGroup(name="debug",
@@ -655,6 +667,51 @@
help="Enable diagnostic commands"),
]
+input_scenario_group = cfg.OptGroup(name="input-scenario",
+ title="Filters and values for"
+ " input scenarios")
+
+InputScenarioGroup = [
+ cfg.StrOpt('image_regex',
+ default='^cirros-0.3.1-x86_64-uec$',
+ help="Matching images become parameters for scenario tests"),
+ cfg.StrOpt('flavor_regex',
+ default='^m1.nano$',
+ help="Matching flavors become parameters for scenario tests"),
+ cfg.StrOpt('non_ssh_image_regex',
+ default='^.*[Ww]in.*$',
+ help="SSH verification in tests is skipped"
+ "for matching images"),
+ cfg.StrOpt('ssh_user_regex',
+ default="[[\"^.*[Cc]irros.*$\", \"root\"]]",
+ help="List of user mapped to regex "
+ "to matching image names."),
+]
+
+
+baremetal_group = cfg.OptGroup(name='baremetal',
+ title='Baremetal provisioning service options')
+
+BaremetalGroup = [
+ cfg.StrOpt('catalog_type',
+ default='baremetal',
+ help="Catalog type of the baremetal provisioning service."),
+]
+
+cli_group = cfg.OptGroup(name='cli', title="cli Configuration Options")
+
+CLIGroup = [
+ cfg.BoolOpt('enabled',
+ default=True,
+ help="enable cli tests"),
+ cfg.StrOpt('cli_dir',
+ default='/usr/local/bin',
+ help="directory where python client binaries are located"),
+ cfg.IntOpt('timeout',
+ default=15,
+ help="Number of seconds to wait on a CLI timeout"),
+]
+
# this should never be called outside of this class
class TempestConfigPrivate(object):
@@ -679,9 +736,7 @@
path = os.path.join(conf_dir, conf_file)
- if not (os.path.isfile(path) or
- 'TEMPEST_CONFIG_DIR' in os.environ or
- 'TEMPEST_CONFIG' in os.environ):
+ if not os.path.isfile(path):
path = failsafe_path
# only parse the config file if we expect one to exist. This is needed
@@ -698,6 +753,8 @@
register_opt_group(cfg.CONF, compute_features_group,
ComputeFeaturesGroup)
register_opt_group(cfg.CONF, identity_group, IdentityGroup)
+ register_opt_group(cfg.CONF, identity_feature_group,
+ IdentityFeatureGroup)
register_opt_group(cfg.CONF, image_group, ImageGroup)
register_opt_group(cfg.CONF, image_feature_group, ImageFeaturesGroup)
register_opt_group(cfg.CONF, network_group, NetworkGroup)
@@ -721,10 +778,14 @@
register_opt_group(cfg.CONF, service_available_group,
ServiceAvailableGroup)
register_opt_group(cfg.CONF, debug_group, DebugGroup)
+ register_opt_group(cfg.CONF, baremetal_group, BaremetalGroup)
+ register_opt_group(cfg.CONF, input_scenario_group, InputScenarioGroup)
+ register_opt_group(cfg.CONF, cli_group, CLIGroup)
self.compute = cfg.CONF.compute
self.compute_feature_enabled = cfg.CONF['compute-feature-enabled']
self.identity = cfg.CONF.identity
- self.images = cfg.CONF.image
+ self.identity_feature_enabled = cfg.CONF['identity-feature-enabled']
+ self.image = cfg.CONF.image
self.image_feature_enabled = cfg.CONF['image-feature-enabled']
self.network = cfg.CONF.network
self.network_feature_enabled = cfg.CONF['network-feature-enabled']
@@ -743,6 +804,9 @@
self.scenario = cfg.CONF.scenario
self.service_available = cfg.CONF.service_available
self.debug = cfg.CONF.debug
+ self.baremetal = cfg.CONF.baremetal
+ self.input_scenario = cfg.CONF['input-scenario']
+ self.cli = cfg.CONF.cli
if not self.compute_admin.username:
self.compute_admin.username = self.identity.admin_username
self.compute_admin.password = self.identity.admin_password
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index 0bab9c7..3b3f3eb 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -125,8 +123,7 @@
class RateLimitExceeded(TempestException):
- message = ("Rate limit exceeded.\nMessage: %(message)s\n"
- "Details: %(details)s")
+ message = "Rate limit exceeded"
class OverLimit(TempestException):
@@ -164,10 +161,6 @@
message = "The server is not reachable via the configured network"
-class SQLException(TempestException):
- message = "SQL error: %(message)s"
-
-
class TearDownException(TempestException):
message = "%(num)d cleanUp operation failed"
diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py
index 2adc98e..2e499a2 100644
--- a/tempest/hacking/checks.py
+++ b/tempest/hacking/checks.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/manager.py b/tempest/manager.py
index 42b8c8f..93ff10f 100644
--- a/tempest/manager.py
+++ b/tempest/manager.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest import config
from tempest import exceptions
@@ -29,7 +26,6 @@
"""
def __init__(self):
- self.config = config.CONF
self.client_attr_names = []
# we do this everywhere, have it be part of the super class
diff --git a/tempest/openstack/common/fixture/mockpatch.py b/tempest/openstack/common/fixture/mockpatch.py
index 858e77c..d7dcc11 100644
--- a/tempest/openstack/common/fixture/mockpatch.py
+++ b/tempest/openstack/common/fixture/mockpatch.py
@@ -22,14 +22,15 @@
class PatchObject(fixtures.Fixture):
"""Deal with code around mock."""
- def __init__(self, obj, attr, **kwargs):
+ def __init__(self, obj, attr, new=mock.DEFAULT, **kwargs):
self.obj = obj
self.attr = attr
self.kwargs = kwargs
+ self.new = new
def setUp(self):
super(PatchObject, self).setUp()
- _p = mock.patch.object(self.obj, self.attr, **self.kwargs)
+ _p = mock.patch.object(self.obj, self.attr, self.new, **self.kwargs)
self.mock = _p.start()
self.addCleanup(_p.stop)
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 409fcc2..0fc304a 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -24,7 +22,7 @@
import cinderclient.client
import glanceclient
import heatclient.client
-import keystoneclient.apiclient.exceptions
+import keystoneclient.exceptions
import keystoneclient.v2_0.client
import netaddr
from neutronclient.common import exceptions as exc
@@ -37,11 +35,13 @@
from tempest.common import isolated_creds
from tempest.common.utils import data_utils
from tempest.common.utils.linux.remote_client import RemoteClient
+from tempest import config
from tempest import exceptions
import tempest.manager
from tempest.openstack.common import log
import tempest.test
+CONF = config.CONF
LOG = log.getLogger(__name__)
@@ -91,14 +91,14 @@
# each user that operations need to be performed for.
self._validate_credentials(username, password, tenant_name)
- auth_url = self.config.identity.uri
- dscv = self.config.identity.disable_ssl_certificate_validation
- region = self.config.identity.region
+ auth_url = CONF.identity.uri
+ dscv = CONF.identity.disable_ssl_certificate_validation
+ region = CONF.identity.region
client_args = (username, password, tenant_name, auth_url)
# Create our default Nova client to use in testing
- service_type = self.config.compute.catalog_type
+ service_type = CONF.compute.catalog_type
return novaclient.client.Client(self.NOVACLIENT_VERSION,
*client_args,
service_type=service_type,
@@ -109,17 +109,17 @@
def _get_image_client(self):
token = self.identity_client.auth_token
- region = self.config.identity.region
+ region = CONF.identity.region
endpoint = self.identity_client.service_catalog.url_for(
attr='region', filter_value=region,
- service_type='image', endpoint_type='publicURL')
- dscv = self.config.identity.disable_ssl_certificate_validation
+ service_type=CONF.image.catalog_type, endpoint_type='publicURL')
+ dscv = CONF.identity.disable_ssl_certificate_validation
return glanceclient.Client('1', endpoint=endpoint, token=token,
insecure=dscv)
def _get_volume_client(self, username, password, tenant_name):
- auth_url = self.config.identity.uri
- region = self.config.identity.region
+ auth_url = CONF.identity.uri
+ region = CONF.identity.region
return cinderclient.client.Client(self.CINDERCLIENT_VERSION,
username,
password,
@@ -129,23 +129,24 @@
http_log_debug=True)
def _get_object_storage_client(self, username, password, tenant_name):
- auth_url = self.config.identity.uri
- # add current tenant to Member group.
+ auth_url = CONF.identity.uri
+ # add current tenant to swift operator role group.
keystone_admin = self._get_identity_client(
- self.config.identity.admin_username,
- self.config.identity.admin_password,
- self.config.identity.admin_tenant_name)
+ CONF.identity.admin_username,
+ CONF.identity.admin_password,
+ CONF.identity.admin_tenant_name)
- # enable test user to operate swift by adding Member role to him.
+ # enable test user to operate swift by adding operator role to him.
roles = keystone_admin.roles.list()
- member_role = [role for role in roles if role.name == 'Member'][0]
+ operator_role = CONF.object_storage.operator_role
+ member_role = [role for role in roles if role.name == operator_role][0]
# NOTE(maurosr): This is surrounded in the try-except block cause
# neutron tests doesn't have tenant isolation.
try:
keystone_admin.roles.add_user_role(self.identity_client.user_id,
member_role.id,
self.identity_client.tenant_id)
- except keystoneclient.apiclient.exceptions.Conflict:
+ except keystoneclient.exceptions.Conflict:
pass
return swiftclient.Connection(auth_url, username, password,
@@ -155,22 +156,23 @@
def _get_orchestration_client(self, username=None, password=None,
tenant_name=None):
if not username:
- username = self.config.identity.admin_username
+ username = CONF.identity.admin_username
if not password:
- password = self.config.identity.admin_password
+ password = CONF.identity.admin_password
if not tenant_name:
- tenant_name = self.config.identity.tenant_name
+ tenant_name = CONF.identity.tenant_name
self._validate_credentials(username, password, tenant_name)
keystone = self._get_identity_client(username, password, tenant_name)
- region = self.config.identity.region
+ region = CONF.identity.region
token = keystone.auth_token
+ service_type = CONF.orchestration.catalog_type
try:
endpoint = keystone.service_catalog.url_for(
attr='region',
filter_value=region,
- service_type='orchestration',
+ service_type=service_type,
endpoint_type='publicURL')
except keystoneclient.exceptions.EndpointNotFound:
return None
@@ -186,8 +188,8 @@
# of the identity service, so use admin credentials by default.
self._validate_credentials(username, password, tenant_name)
- auth_url = self.config.identity.uri
- dscv = self.config.identity.disable_ssl_certificate_validation
+ auth_url = CONF.identity.uri
+ dscv = CONF.identity.disable_ssl_certificate_validation
return keystoneclient.v2_0.client.Client(username=username,
password=password,
@@ -202,14 +204,14 @@
# preferable to authenticating as a specific user because
# working with certain resources (public routers and networks)
# often requires admin privileges anyway.
- username = self.config.identity.admin_username
- password = self.config.identity.admin_password
- tenant_name = self.config.identity.admin_tenant_name
+ username = CONF.identity.admin_username
+ password = CONF.identity.admin_password
+ tenant_name = CONF.identity.admin_tenant_name
self._validate_credentials(username, password, tenant_name)
- auth_url = self.config.identity.uri
- dscv = self.config.identity.disable_ssl_certificate_validation
+ auth_url = CONF.identity.uri
+ dscv = CONF.identity.disable_ssl_certificate_validation
return neutronclient.v2_0.client.Client(username=username,
password=password,
@@ -235,7 +237,8 @@
def setUpClass(cls):
super(OfficialClientTest, cls).setUpClass()
cls.isolated_creds = isolated_creds.IsolatedCreds(
- __name__, tempest_client=False)
+ cls.__name__, tempest_client=False,
+ network_resources=cls.network_resources)
username, password, tenant_name = cls.credentials()
@@ -252,12 +255,12 @@
@classmethod
def _get_credentials(cls, get_creds, prefix):
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
username, tenant_name, password = get_creds()
else:
- username = getattr(cls.config.identity, prefix + 'username')
- password = getattr(cls.config.identity, prefix + 'password')
- tenant_name = getattr(cls.config.identity, prefix + 'tenant_name')
+ username = getattr(CONF.identity, prefix + 'username')
+ password = getattr(CONF.identity, prefix + 'password')
+ tenant_name = getattr(CONF.identity, prefix + 'tenant_name')
return username, password, tenant_name
@classmethod
@@ -395,7 +398,8 @@
if new_status.lower() == error_status.lower():
message = ("%s failed to get to expected status. "
"In %s state.") % (thing, new_status)
- raise exceptions.BuildErrorException(message)
+ raise exceptions.BuildErrorException(message,
+ server_id=thing_id)
elif new_status == expected_status and expected_status is not None:
return True # All good.
LOG.debug("Waiting for %s to get to %s status. "
@@ -403,8 +407,8 @@
thing, log_status, new_status)
if not tempest.test.call_until_true(
check_status,
- self.config.compute.build_timeout,
- self.config.compute.build_interval):
+ CONF.compute.build_timeout,
+ CONF.compute.build_interval):
message = ("Timed out waiting for thing %s "
"to become %s") % (thing_id, log_status)
raise exceptions.TimeoutException(message)
@@ -454,9 +458,9 @@
if name is None:
name = data_utils.rand_name('scenario-server-')
if image is None:
- image = self.config.compute.image_ref
+ image = CONF.compute.image_ref
if flavor is None:
- flavor = self.config.compute.flavor_ref
+ flavor = CONF.compute.flavor_ref
LOG.debug("Creating a server (name: %s, image: %s, flavor: %s)",
name, image, flavor)
server = client.servers.create(name, image, flavor, **create_kwargs)
@@ -519,14 +523,21 @@
if isinstance(server_or_ip, basestring):
ip = server_or_ip
else:
- network_name_for_ssh = self.config.compute.network_for_ssh
+ network_name_for_ssh = CONF.compute.network_for_ssh
ip = server_or_ip.networks[network_name_for_ssh][0]
if username is None:
- username = self.config.scenario.ssh_user
+ username = CONF.scenario.ssh_user
if private_key is None:
private_key = self.keypair.private_key
return RemoteClient(ip, username, pkey=private_key)
+ def _log_console_output(self, servers=None):
+ if not servers:
+ servers = self.compute_client.servers.list()
+ for server in servers:
+ LOG.debug('Console output for %s', server.id)
+ LOG.debug(server.get_console_output())
+
class NetworkScenarioTest(OfficialClientTest):
"""
@@ -535,7 +546,7 @@
@classmethod
def check_preconditions(cls):
- if (cls.config.service_available.neutron):
+ if (CONF.service_available.neutron):
cls.enabled = True
# verify that neutron_available is telling the truth
try:
@@ -551,13 +562,13 @@
@classmethod
def setUpClass(cls):
super(NetworkScenarioTest, cls).setUpClass()
- if cls.config.compute.allow_tenant_isolation:
+ if CONF.compute.allow_tenant_isolation:
cls.tenant_id = cls.isolated_creds.get_primary_tenant().id
else:
cls.tenant_id = cls.manager._get_identity_client(
- cls.config.identity.username,
- cls.config.identity.password,
- cls.config.identity.tenant_name).tenant_id
+ CONF.identity.username,
+ CONF.identity.password,
+ CONF.identity.tenant_name).tenant_id
def _create_network(self, tenant_id, namestart='network-smoke-'):
name = data_utils.rand_name(namestart)
@@ -612,12 +623,12 @@
Create a subnet for the given network within the cidr block
configured for tenant networks.
"""
- cfg = self.config.network
- tenant_cidr = netaddr.IPNetwork(cfg.tenant_network_cidr)
+ tenant_cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
result = None
# Repeatedly attempt subnet creation with sequential cidr
# blocks until an unallocated block is found.
- for subnet_cidr in tenant_cidr.subnet(cfg.tenant_network_mask_bits):
+ for subnet_cidr in tenant_cidr.subnet(
+ CONF.network.tenant_network_mask_bits):
body = dict(
subnet=dict(
ip_version=4,
@@ -660,13 +671,17 @@
"Unable to determine which port to target.")
return ports[0]['id']
- def _create_floating_ip(self, server, external_network_id):
- port_id = self._get_server_port_id(server)
+ def _create_floating_ip(self, thing, external_network_id,
+ port_filters=None):
+ if port_filters is None:
+ port_id = self._get_server_port_id(thing)
+ else:
+ port_id = port_filters
body = dict(
floatingip=dict(
floating_network_id=external_network_id,
port_id=port_id,
- tenant_id=server.tenant_id,
+ tenant_id=thing.tenant_id,
)
)
result = self.network_client.create_floatingip(body=body)
@@ -701,7 +716,59 @@
return (proc.returncode == 0) == should_succeed
return tempest.test.call_until_true(
- ping, self.config.compute.ping_timeout, 1)
+ ping, CONF.compute.ping_timeout, 1)
+
+ def _create_pool(self, lb_method, protocol, subnet_id):
+ """Wrapper utility that returns a test pool."""
+ name = data_utils.rand_name('pool-')
+ body = {
+ "pool": {
+ "protocol": protocol,
+ "name": name,
+ "subnet_id": subnet_id,
+ "lb_method": lb_method
+ }
+ }
+ resp = self.network_client.create_pool(body=body)
+ pool = net_common.DeletablePool(client=self.network_client,
+ **resp['pool'])
+ self.assertEqual(pool['name'], name)
+ self.set_resource(name, pool)
+ return pool
+
+ def _create_member(self, address, protocol_port, pool_id):
+ """Wrapper utility that returns a test member."""
+ body = {
+ "member": {
+ "protocol_port": protocol_port,
+ "pool_id": pool_id,
+ "address": address
+ }
+ }
+ resp = self.network_client.create_member(body)
+ member = net_common.DeletableMember(client=self.network_client,
+ **resp['member'])
+ self.set_resource(data_utils.rand_name('member-'), member)
+ return member
+
+ def _create_vip(self, protocol, protocol_port, subnet_id, pool_id):
+ """Wrapper utility that returns a test vip."""
+ name = data_utils.rand_name('vip-')
+ body = {
+ "vip": {
+ "protocol": protocol,
+ "name": name,
+ "subnet_id": subnet_id,
+ "pool_id": pool_id,
+ "protocol_port": protocol_port
+ }
+ }
+ resp = self.network_client.create_vip(body)
+ vip = net_common.DeletableVip(client=self.network_client,
+ **resp['vip'])
+ self.assertEqual(vip['name'], name)
+ self.set_resource(name, vip)
+ return vip
def _check_vm_connectivity(self, ip_address,
username=None,
@@ -897,7 +964,7 @@
return rules
def _ssh_to_server(self, server, private_key):
- ssh_login = self.config.compute.image_ssh_user
+ ssh_login = CONF.compute.image_ssh_user
return self.get_remote_client(server,
username=ssh_login,
private_key=private_key)
@@ -923,8 +990,8 @@
network has, a tenant router will be created and returned that
routes traffic to the public network.
"""
- router_id = self.config.network.public_router_id
- network_id = self.config.network.public_network_id
+ router_id = CONF.network.public_router_id
+ network_id = CONF.network.public_network_id
if router_id:
result = self.network_client.show_router(router_id)
return net_common.AttributeDict(**result['router'])
@@ -977,14 +1044,14 @@
@classmethod
def setUpClass(cls):
super(OrchestrationScenarioTest, cls).setUpClass()
- if not cls.config.service_available.heat:
+ if not CONF.service_available.heat:
raise cls.skipException("Heat support is required")
@classmethod
def credentials(cls):
- username = cls.config.identity.admin_username
- password = cls.config.identity.admin_password
- tenant_name = cls.config.identity.tenant_name
+ username = CONF.identity.admin_username
+ password = CONF.identity.admin_password
+ tenant_name = CONF.identity.tenant_name
return username, password, tenant_name
def _load_template(self, base_file, file_name):
@@ -1001,5 +1068,5 @@
def _get_default_network(cls):
networks = cls.network_client.list_networks()
for net in networks['networks']:
- if net['name'] == cls.config.compute.fixed_network_name:
+ if net['name'] == CONF.compute.fixed_network_name:
return net
diff --git a/tempest/scenario/orchestration/test_autoscaling.py b/tempest/scenario/orchestration/test_autoscaling.py
index 90ef3a0..cd7a2b2 100644
--- a/tempest/scenario/orchestration/test_autoscaling.py
+++ b/tempest/scenario/orchestration/test_autoscaling.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -15,25 +13,28 @@
import heatclient.exc as heat_exceptions
import time
+from tempest import config
from tempest.scenario import manager
from tempest.test import attr
from tempest.test import call_until_true
from tempest.test import services
from tempest.test import skip_because
+CONF = config.CONF
+
class AutoScalingTest(manager.OrchestrationScenarioTest):
def setUp(self):
super(AutoScalingTest, self).setUp()
- if not self.config.orchestration.image_ref:
+ if not CONF.orchestration.image_ref:
raise self.skipException("No image available to test")
self.client = self.orchestration_client
def assign_keypair(self):
self.stack_name = self._stack_rand_name()
- if self.config.orchestration.keypair_name:
- self.keypair_name = self.config.orchestration.keypair_name
+ if CONF.orchestration.keypair_name:
+ self.keypair_name = CONF.orchestration.keypair_name
else:
self.keypair = self.create_keypair()
self.keypair_name = self.keypair.id
@@ -42,8 +43,8 @@
net = self._get_default_network()
self.parameters = {
'KeyName': self.keypair_name,
- 'InstanceType': self.config.orchestration.instance_type,
- 'ImageId': self.config.orchestration.image_ref,
+ 'InstanceType': CONF.orchestration.instance_type,
+ 'ImageId': CONF.orchestration.image_ref,
'StackStart': str(time.time()),
'Subnet': net['subnets'][0]
}
@@ -60,7 +61,7 @@
# if a keypair was set, do not delete the stack on exit to allow
# for manual post-mortums
- if not self.config.orchestration.keypair_name:
+ if not CONF.orchestration.keypair_name:
self.set_resource('stack', self.stack)
@skip_because(bug="1257575")
@@ -72,7 +73,7 @@
self.launch_stack()
sid = self.stack_identifier
- timeout = self.config.orchestration.build_timeout
+ timeout = CONF.orchestration.build_timeout
interval = 10
self.assertEqual('CREATE', self.stack.action)
diff --git a/tempest/scenario/test_aggregates_basic_ops.py b/tempest/scenario/test_aggregates_basic_ops.py
new file mode 100644
index 0000000..f2b681e
--- /dev/null
+++ b/tempest/scenario/test_aggregates_basic_ops.py
@@ -0,0 +1,133 @@
+# Copyright 2013 IBM Corp.
+# All Rights Reserved.
+#
+# 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 tempest.common import tempest_fixtures as fixtures
+from tempest.common.utils.data_utils import rand_name
+from tempest.openstack.common import log as logging
+from tempest.scenario import manager
+from tempest import test
+
+
+LOG = logging.getLogger(__name__)
+
+
+class TestAggregatesBasicOps(manager.OfficialClientTest):
+ """
+ Creates an aggregate within an availability zone
+ Adds a host to the aggregate
+ Checks aggregate details
+ Updates aggregate's name
+ Removes host from aggregate
+ Deletes aggregate
+ """
+ @classmethod
+ def credentials(cls):
+ return cls.admin_credentials()
+
+ def _create_aggregate(self, **kwargs):
+ aggregate = self.compute_client.aggregates.create(**kwargs)
+ aggregate_name = kwargs['name']
+ availability_zone = kwargs['availability_zone']
+ self.assertEqual(aggregate.name, aggregate_name)
+ self.assertEqual(aggregate.availability_zone, availability_zone)
+ self.set_resource(aggregate.id, aggregate)
+ LOG.debug("Aggregate %s created." % (aggregate.name))
+ return aggregate
+
+ def _delete_aggregate(self, aggregate):
+ self.compute_client.aggregates.delete(aggregate.id)
+ self.remove_resource(aggregate.id)
+ LOG.debug("Aggregate %s deleted. " % (aggregate.name))
+
+ def _get_host_name(self):
+ hosts = self.compute_client.hosts.list()
+ self.assertTrue(len(hosts) >= 1)
+ hostname = hosts[0].host_name
+ return hostname
+
+ def _add_host(self, aggregate_name, host):
+ aggregate = self.compute_client.aggregates.add_host(aggregate_name,
+ host)
+ self.assertIn(host, aggregate.hosts)
+ LOG.debug("Host %s added to Aggregate %s." % (host, aggregate.name))
+
+ def _remove_host(self, aggregate_name, host):
+ aggregate = self.compute_client.aggregates.remove_host(aggregate_name,
+ host)
+ self.assertNotIn(host, aggregate.hosts)
+ LOG.debug("Host %s removed to Aggregate %s." % (host, aggregate.name))
+
+ def _check_aggregate_details(self, aggregate, aggregate_name, azone,
+ hosts, metadata):
+ aggregate = self.compute_client.aggregates.get(aggregate.id)
+ self.assertEqual(aggregate_name, aggregate.name)
+ self.assertEqual(azone, aggregate.availability_zone)
+ self.assertEqual(aggregate.hosts, hosts)
+ for meta_key in metadata.keys():
+ self.assertIn(meta_key, aggregate.metadata)
+ self.assertEqual(metadata[meta_key], aggregate.metadata[meta_key])
+ LOG.debug("Aggregate %s details match." % aggregate.name)
+
+ def _set_aggregate_metadata(self, aggregate, meta):
+ aggregate = self.compute_client.aggregates.set_metadata(aggregate.id,
+ meta)
+
+ for key, value in meta.items():
+ self.assertEqual(meta[key], aggregate.metadata[key])
+ LOG.debug("Aggregate %s metadata updated successfully." %
+ aggregate.name)
+
+ def _update_aggregate(self, aggregate, aggregate_name,
+ availability_zone):
+ values = {}
+ if aggregate_name:
+ values.update({'name': aggregate_name})
+ if availability_zone:
+ values.update({'availability_zone': availability_zone})
+ if values.keys():
+ aggregate = self.compute_client.aggregates.update(aggregate.id,
+ values)
+ for key, values in values.items():
+ self.assertEqual(getattr(aggregate, key), values)
+ return aggregate
+
+ @test.services('compute')
+ def test_aggregate_basic_ops(self):
+ self.useFixture(fixtures.LockFixture('availability_zone'))
+ az = 'foo_zone'
+ aggregate_name = rand_name('aggregate-scenario')
+ aggregate = self._create_aggregate(name=aggregate_name,
+ availability_zone=az)
+
+ metadata = {'meta_key': 'meta_value'}
+ self._set_aggregate_metadata(aggregate, metadata)
+
+ host = self._get_host_name()
+ self._add_host(aggregate, host)
+ self._check_aggregate_details(aggregate, aggregate_name, az, [host],
+ metadata)
+
+ aggregate_name = rand_name('renamed-aggregate-scenario')
+ aggregate = self._update_aggregate(aggregate, aggregate_name, None)
+
+ additional_metadata = {'foo': 'bar'}
+ self._set_aggregate_metadata(aggregate, additional_metadata)
+
+ metadata.update(additional_metadata)
+ self._check_aggregate_details(aggregate, aggregate.name, az, [host],
+ metadata)
+
+ self._remove_host(aggregate, host)
+ self._delete_aggregate(aggregate)
diff --git a/tempest/scenario/test_cross_tenant_connectivity.py b/tempest/scenario/test_cross_tenant_connectivity.py
index faba987..edcf091 100644
--- a/tempest/scenario/test_cross_tenant_connectivity.py
+++ b/tempest/scenario/test_cross_tenant_connectivity.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
#
@@ -17,6 +15,7 @@
from tempest.common import debug
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.scenario import manager
@@ -25,6 +24,8 @@
from tempest.test import call_until_true
from tempest.test import services
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -133,8 +134,8 @@
msg = 'No alt_tenant defined'
cls.enabled = False
raise cls.skipException(msg)
- cfg = cls.config.network
- if not (cfg.tenant_networks_reachable or cfg.public_network_id):
+ if not (CONF.network.tenant_networks_reachable or
+ CONF.network.public_network_id):
msg = ('Either tenant_networks_reachable must be "true", or '
'public_network_id must be defined.')
cls.enabled = False
@@ -168,7 +169,7 @@
)
for tenant in [cls.demo_tenant, cls.alt_tenant]:
cls.tenants[tenant.tenant_id] = tenant
- if not cls.config.network.public_router_id:
+ if not CONF.network.public_router_id:
cls.floating_ip_access = True
else:
cls.floating_ip_access = False
@@ -279,7 +280,7 @@
self._assign_floating_ips(server)
def _assign_floating_ips(self, server):
- public_network_id = self.config.network.public_network_id
+ public_network_id = CONF.network.public_network_id
floating_ip = self._create_floating_ip(server, public_network_id)
self.floating_ips.setdefault(server, floating_ip)
@@ -355,7 +356,7 @@
return should_succeed
return call_until_true(ping_remote,
- self.config.compute.ping_timeout,
+ CONF.compute.ping_timeout,
1)
def _check_connectivity(self, access_point, ip, should_succeed=True):
@@ -473,17 +474,21 @@
@attr(type='smoke')
@services('compute', 'network')
def test_cross_tenant_traffic(self):
- for tenant_id in self.tenants.keys():
- self._deploy_tenant(tenant_id)
- self._verify_network_details(self.tenants[tenant_id])
- self._verify_mac_addr(self.tenants[tenant_id])
+ try:
+ for tenant_id in self.tenants.keys():
+ self._deploy_tenant(tenant_id)
+ self._verify_network_details(self.tenants[tenant_id])
+ self._verify_mac_addr(self.tenants[tenant_id])
- # in-tenant check
- self._test_in_tenant_block(self.demo_tenant)
- self._test_in_tenant_allow(self.demo_tenant)
+ # in-tenant check
+ self._test_in_tenant_block(self.demo_tenant)
+ self._test_in_tenant_allow(self.demo_tenant)
- # cross tenant check
- source_tenant = self.demo_tenant
- dest_tenant = self.alt_tenant
- self._test_cross_tenant_block(source_tenant, dest_tenant)
- self._test_cross_tenant_allow(source_tenant, dest_tenant)
+ # cross tenant check
+ source_tenant = self.demo_tenant
+ dest_tenant = self.alt_tenant
+ self._test_cross_tenant_block(source_tenant, dest_tenant)
+ self._test_cross_tenant_allow(source_tenant, dest_tenant)
+ except Exception:
+ self._log_console_output(servers=self.servers)
+ raise
diff --git a/tempest/scenario/test_dashboard_basic_ops.py b/tempest/scenario/test_dashboard_basic_ops.py
index 1081a3e..19996e5 100644
--- a/tempest/scenario/test_dashboard_basic_ops.py
+++ b/tempest/scenario/test_dashboard_basic_ops.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -19,9 +17,12 @@
from lxml import html
+from tempest import config
from tempest.scenario import manager
from tempest.test import services
+CONF = config.CONF
+
class TestDashboardBasicOps(manager.OfficialClientTest):
@@ -34,18 +35,19 @@
@classmethod
def setUpClass(cls):
+ cls.set_network_resources()
super(TestDashboardBasicOps, cls).setUpClass()
- if not cls.config.service_available.horizon:
+ if not CONF.service_available.horizon:
raise cls.skipException("Horizon support is required")
def check_login_page(self):
- response = urllib2.urlopen(self.config.dashboard.dashboard_url)
+ response = urllib2.urlopen(CONF.dashboard.dashboard_url)
self.assertIn("<h3>Log In</h3>", response.read())
def user_login(self):
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
- response = self.opener.open(self.config.dashboard.dashboard_url).read()
+ response = self.opener.open(CONF.dashboard.dashboard_url).read()
# Grab the CSRF token and default region
csrf_token = html.fromstring(response).xpath(
@@ -54,17 +56,17 @@
'//input[@name="region"]/@value')[0]
# Prepare login form request
- req = urllib2.Request(self.config.dashboard.login_url)
+ req = urllib2.Request(CONF.dashboard.login_url)
req.add_header('Content-type', 'application/x-www-form-urlencoded')
- req.add_header('Referer', self.config.dashboard.dashboard_url)
- params = {'username': self.config.identity.username,
- 'password': self.config.identity.password,
+ req.add_header('Referer', CONF.dashboard.dashboard_url)
+ params = {'username': CONF.identity.username,
+ 'password': CONF.identity.password,
'region': region,
'csrfmiddlewaretoken': csrf_token}
self.opener.open(req, urllib.urlencode(params))
def check_home_page(self):
- response = self.opener.open(self.config.dashboard.dashboard_url)
+ response = self.opener.open(CONF.dashboard.dashboard_url)
self.assertIn('Overview', response.read())
@services('dashboard')
diff --git a/tempest/scenario/test_large_ops.py b/tempest/scenario/test_large_ops.py
index 7f8d3e4..e8030c9 100644
--- a/tempest/scenario/test_large_ops.py
+++ b/tempest/scenario/test_large_ops.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -16,10 +14,13 @@
# under the License.
from tempest.common.utils import data_utils
+from tempest import config
from tempest.openstack.common import log as logging
from tempest.scenario import manager
from tempest.test import services
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -36,6 +37,11 @@
"""
+ @classmethod
+ def setUpClass(cls):
+ cls.set_network_resources()
+ super(TestLargeOpsScenario, cls).setUpClass()
+
def _wait_for_server_status(self, status):
for server in self.servers:
self.status_timeout(
@@ -64,12 +70,9 @@
return image.id
def glance_image_create(self):
- aki_img_path = self.config.scenario.img_dir + "/" + \
- self.config.scenario.aki_img_file
- ari_img_path = self.config.scenario.img_dir + "/" + \
- self.config.scenario.ari_img_file
- ami_img_path = self.config.scenario.img_dir + "/" + \
- self.config.scenario.ami_img_file
+ aki_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.aki_img_file
+ ari_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.ari_img_file
+ ami_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.ami_img_file
LOG.debug("paths: ami: %s, ari: %s, aki: %s"
% (ami_img_path, ari_img_path, aki_img_path))
kernel_id = self._image_create('scenario-aki', 'aki', aki_img_path)
@@ -84,12 +87,12 @@
def nova_boot(self):
name = data_utils.rand_name('scenario-server-')
client = self.compute_client
- flavor_id = self.config.compute.flavor_ref
+ flavor_id = CONF.compute.flavor_ref
secgroup = self._create_security_group_nova()
self.servers = client.servers.create(
name=name, image=self.image,
flavor=flavor_id,
- min_count=self.config.scenario.large_ops_number,
+ min_count=CONF.scenario.large_ops_number,
security_groups=[secgroup.name])
# needed because of bug 1199788
self.servers = [x for x in client.servers.list() if name in x.name]
@@ -99,7 +102,7 @@
@services('compute', 'image')
def test_large_ops_scenario(self):
- if self.config.scenario.large_ops_number < 1:
+ if CONF.scenario.large_ops_number < 1:
return
self.glance_image_create()
self.nova_boot()
diff --git a/tempest/scenario/test_load_balancer_basic.py b/tempest/scenario/test_load_balancer_basic.py
new file mode 100644
index 0000000..68f6e62
--- /dev/null
+++ b/tempest/scenario/test_load_balancer_basic.py
@@ -0,0 +1,240 @@
+# Copyright 2014 Mirantis.inc
+# All Rights Reserved.
+#
+# 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 time
+import urllib
+
+from tempest.api.network import common as net_common
+from tempest.common import ssh
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import exceptions
+from tempest.scenario import manager
+from tempest import test
+
+config = config.CONF
+
+
+class TestLoadBalancerBasic(manager.NetworkScenarioTest):
+
+ """
+ This test checks basic load balancing.
+
+ The following is the scenario outline:
+ 1. Create an instance
+ 2. SSH to the instance and start two servers
+ 3. Create a load balancer with two members and with ROUND_ROBIN algorithm
+ associate the VIP with a floating ip
+ 4. Send 10 requests to the floating ip and check that they are shared
+ between the two servers and that both of them get equal portions
+ of the requests
+ """
+
+ @classmethod
+ def check_preconditions(cls):
+ super(TestLoadBalancerBasic, cls).check_preconditions()
+ cfg = config.network
+ if not test.is_extension_enabled('lbaas', 'network'):
+ msg = 'LBaaS Extension is not enabled'
+ cls.enabled = False
+ raise cls.skipException(msg)
+ if not (cfg.tenant_networks_reachable or cfg.public_network_id):
+ msg = ('Either tenant_networks_reachable must be "true", or '
+ 'public_network_id must be defined.')
+ cls.enabled = False
+ raise cls.skipException(msg)
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestLoadBalancerBasic, cls).setUpClass()
+ cls.check_preconditions()
+ cls.security_groups = {}
+ cls.networks = []
+ cls.subnets = []
+ cls.servers_keypairs = {}
+ cls.pools = []
+ cls.members = []
+ cls.vips = []
+ cls.floating_ips = {}
+ cls.port1 = 80
+ cls.port2 = 88
+
+ def _create_security_groups(self):
+ self.security_groups[self.tenant_id] =\
+ self._create_security_group_neutron(tenant_id=self.tenant_id)
+
+ def _create_server(self):
+ tenant_id = self.tenant_id
+ name = data_utils.rand_name("smoke_server-")
+ keypair = self.create_keypair(name='keypair-%s' % name)
+ security_groups = [self.security_groups[tenant_id].name]
+ nets = self.network_client.list_networks()
+ for net in nets['networks']:
+ if net['tenant_id'] == self.tenant_id:
+ self.networks.append(net)
+ create_kwargs = {
+ 'nics': [
+ {'net-id': net['id']},
+ ],
+ 'key_name': keypair.name,
+ 'security_groups': security_groups,
+ }
+ server = self.create_server(name=name,
+ create_kwargs=create_kwargs)
+ self.servers_keypairs[server] = keypair
+ break
+ self.assertTrue(self.servers_keypairs)
+
+ def _start_servers(self):
+ """
+ 1. SSH to the instance
+ 2. Start two servers listening on ports 80 and 88 respectively
+ """
+ for server in self.servers_keypairs.keys():
+ ssh_login = config.compute.image_ssh_user
+ private_key = self.servers_keypairs[server].private_key
+ network_name = self.networks[0]['name']
+
+ ip_address = server.networks[network_name][0]
+ ssh_client = ssh.Client(ip_address, ssh_login,
+ pkey=private_key,
+ timeout=100)
+ start_server = "while true; do echo -e 'HTTP/1.0 200 OK\r\n\r\n" \
+ "%(server)s' | sudo nc -l -p %(port)s ; done &"
+ cmd = start_server % {'server': 'server1',
+ 'port': self.port1}
+ ssh_client.exec_command(cmd)
+ cmd = start_server % {'server': 'server2',
+ 'port': self.port2}
+ ssh_client.exec_command(cmd)
+
+ def _check_connection(self, check_ip):
+ def try_connect(ip):
+ try:
+ urllib.urlopen("http://{0}/".format(ip))
+ return True
+ except IOError:
+ return False
+ timeout = config.compute.ping_timeout
+ timer = 0
+ while not try_connect(check_ip):
+ time.sleep(1)
+ timer += 1
+ if timer >= timeout:
+ message = "Timed out trying to connect to %s" % check_ip
+ raise exceptions.TimeoutException(message)
+
+ def _create_pool(self):
+ """Create a pool with ROUND_ROBIN algorithm."""
+ subnets = self.network_client.list_subnets()
+ for subnet in subnets['subnets']:
+ if subnet['tenant_id'] == self.tenant_id:
+ self.subnets.append(subnet)
+ pool = super(TestLoadBalancerBasic, self)._create_pool(
+ 'ROUND_ROBIN',
+ 'HTTP',
+ subnet['id'])
+ self.pools.append(pool)
+ break
+ self.assertTrue(self.pools)
+
+ def _create_members(self, network_name, server_ids):
+ """
+ Create two members.
+
+ In case there is only one server, create both members with the same ip
+ but with different ports to listen on.
+ """
+ servers = self.compute_client.servers.list()
+ for server in servers:
+ if server.id in server_ids:
+ ip = server.networks[network_name][0]
+ pool_id = self.pools[0]['id']
+ if len(set(server_ids)) == 1 or len(servers) == 1:
+ member1 = self._create_member(ip, self.port1, pool_id)
+ member2 = self._create_member(ip, self.port2, pool_id)
+ self.members.extend([member1, member2])
+ else:
+ member = self._create_member(ip, self.port1, pool_id)
+ self.members.append(member)
+ self.assertTrue(self.members)
+
+ def _assign_floating_ip_to_vip(self, vip):
+ public_network_id = config.network.public_network_id
+ port_id = vip['port_id']
+ floating_ip = self._create_floating_ip(vip,
+ public_network_id,
+ port_filters=port_id)
+ self.floating_ips.setdefault(vip['id'], [])
+ self.floating_ips[vip['id']].append(floating_ip)
+
+ def _create_load_balancer(self):
+ self._create_pool()
+ self._create_members(self.networks[0]['name'],
+ [self.servers_keypairs.keys()[0].id])
+ subnet_id = self.subnets[0]['id']
+ pool_id = self.pools[0]['id']
+ vip = super(TestLoadBalancerBasic, self)._create_vip('HTTP', 80,
+ subnet_id,
+ pool_id)
+ self.vips.append(vip)
+ self._status_timeout(NeutronRetriever(self.network_client,
+ self.network_client.vip_path,
+ net_common.DeletableVip),
+ self.vips[0]['id'],
+ expected_status='ACTIVE')
+ self._assign_floating_ip_to_vip(self.vips[0])
+
+ def _check_load_balancing(self):
+ """
+ 1. Send 10 requests on the floating ip associated with the VIP
+ 2. Check that the requests are shared between
+ the two servers and that both of them get equal portions
+ of the requests
+ """
+
+ vip = self.vips[0]
+ floating_ip_vip = self.floating_ips[
+ vip['id']][0]['floating_ip_address']
+ self._check_connection(floating_ip_vip)
+ resp = []
+ for count in range(10):
+ resp.append(
+ urllib.urlopen(
+ "http://{0}/".format(floating_ip_vip)).read())
+ self.assertEqual(set(["server1\n", "server2\n"]), set(resp))
+ self.assertEqual(5, resp.count("server1\n"))
+ self.assertEqual(5, resp.count("server2\n"))
+
+ @test.skip_because(bug="1277381")
+ @test.attr(type='smoke')
+ @test.services('compute', 'network')
+ def test_load_balancer_basic(self):
+ self._create_security_groups()
+ self._create_server()
+ self._start_servers()
+ self._create_load_balancer()
+ self._check_load_balancing()
+
+
+class NeutronRetriever(object):
+ def __init__(self, network_client, path, resource):
+ self.network_client = network_client
+ self.path = path
+ self.resource = resource
+
+ def get(self, thing_id):
+ obj = self.network_client.get(self.path % thing_id)
+ return self.resource(client=self.network_client, **obj.values()[0])
diff --git a/tempest/scenario/test_minimum_basic.py b/tempest/scenario/test_minimum_basic.py
index 8a51cd1..846e0cc 100644
--- a/tempest/scenario/test_minimum_basic.py
+++ b/tempest/scenario/test_minimum_basic.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -16,10 +14,12 @@
# under the License.
from tempest.common.utils import data_utils
+from tempest import config
from tempest.openstack.common import log as logging
from tempest.scenario import manager
from tempest.test import services
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -65,12 +65,9 @@
return image.id
def glance_image_create(self):
- aki_img_path = self.config.scenario.img_dir + "/" + \
- self.config.scenario.aki_img_file
- ari_img_path = self.config.scenario.img_dir + "/" + \
- self.config.scenario.ari_img_file
- ami_img_path = self.config.scenario.img_dir + "/" + \
- self.config.scenario.ami_img_file
+ aki_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.aki_img_file
+ ari_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.ari_img_file
+ ami_img_path = CONF.scenario.img_dir + "/" + CONF.scenario.ami_img_file
LOG.debug("paths: ami: %s, ari: %s, aki: %s"
% (ami_img_path, ari_img_path, aki_img_path))
kernel_id = self._image_create('scenario-aki', 'aki', aki_img_path)
@@ -131,7 +128,12 @@
self.server.add_floating_ip(self.floating_ip)
def ssh_to_server(self):
- self.linux_client = self.get_remote_client(self.floating_ip.ip)
+ try:
+ self.linux_client = self.get_remote_client(self.floating_ip.ip)
+ except Exception:
+ LOG.exception('ssh to server failed')
+ self._log_console_output()
+ raise
def check_partitions(self):
partitions = self.linux_client.get_partitions()
@@ -156,6 +158,7 @@
self.cinder_list()
self.cinder_show()
self.nova_volume_attach()
+ self.addCleanup(self.nova_volume_detach)
self.cinder_show()
self.nova_reboot()
@@ -164,5 +167,3 @@
self._create_loginable_secgroup_rule_nova()
self.ssh_to_server()
self.check_partitions()
-
- self.nova_volume_detach()
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index 3618a14..0c0234f 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
@@ -19,57 +17,14 @@
from tempest.common import debug
from tempest.common.utils import data_utils
from tempest import config
-from tempest.openstack.common import jsonutils
from tempest.openstack.common import log as logging
from tempest.scenario import manager
-
-import tempest.test
-from tempest.test import attr
-from tempest.test import services
+from tempest import test
CONF = config.CONF
LOG = logging.getLogger(__name__)
-class FloatingIPCheckTracker(object):
- """
- Checking VM connectivity through floating IP addresses is bound to fail
- if the floating IP has not actually been associated with the VM yet.
- This helper class facilitates checking for floating IP assignments on
- VMs. It only checks for a given IP address once.
- """
-
- def __init__(self, compute_client, floating_ip_map):
- self.compute_client = compute_client
- self.unchecked = floating_ip_map.copy()
-
- def run_checks(self):
- """Check for any remaining unverified floating IPs
-
- Gets VM details from nova and checks for floating IPs
- within the returned information. Returns true when all
- checks are complete and is suitable for use with
- tempest.test.call_until_true()
- """
- to_delete = []
- loggable_map = {}
- for check_addr, server in self.unchecked.iteritems():
- serverdata = self.compute_client.servers.get(server.id)
- ip_addr = [addr for sublist in serverdata.networks.values() for
- addr in sublist]
- if check_addr.floating_ip_address in ip_addr:
- to_delete.append(check_addr)
- else:
- loggable_map[server.id] = check_addr
-
- for to_del in to_delete:
- del self.unchecked[to_del]
-
- LOG.debug('Unchecked floating IPs: %s',
- jsonutils.dumps(loggable_map))
- return len(self.unchecked) == 0
-
-
class TestNetworkBasicOps(manager.NetworkScenarioTest):
"""
@@ -146,8 +101,8 @@
@classmethod
def check_preconditions(cls):
super(TestNetworkBasicOps, cls).check_preconditions()
- cfg = cls.config.network
- if not (cfg.tenant_networks_reachable or cfg.public_network_id):
+ if not (CONF.network.tenant_networks_reachable
+ or CONF.network.public_network_id):
msg = ('Either tenant_networks_reachable must be "true", or '
'public_network_id must be defined.')
cls.enabled = False
@@ -156,6 +111,10 @@
@classmethod
def setUpClass(cls):
super(TestNetworkBasicOps, cls).setUpClass()
+ for ext in ['router', 'security-group']:
+ if not test.is_extension_enabled(ext, 'network'):
+ msg = "%s extension not enabled." % ext
+ raise cls.skipException(msg)
cls.check_preconditions()
# TODO(mnewby) Consider looking up entities as needed instead
# of storing them as collections on the class.
@@ -229,30 +188,22 @@
key.private_key)
except Exception:
LOG.exception('Tenant connectivity check failed')
+ self._log_console_output(servers=self.servers.keys())
debug.log_ip_ns()
raise
- def _wait_for_floating_ip_association(self):
- ip_tracker = FloatingIPCheckTracker(self.compute_client,
- self.floating_ips)
-
- self.assertTrue(
- tempest.test.call_until_true(
- ip_tracker.run_checks, CONF.compute.build_timeout,
- CONF.compute.build_interval),
- "Timed out while waiting for the floating IP assignments "
- "to propagate")
-
def _create_and_associate_floating_ips(self):
public_network_id = CONF.network.public_network_id
for server in self.servers.keys():
floating_ip = self._create_floating_ip(server, public_network_id)
self.floating_ips[floating_ip] = server
- def _check_public_network_connectivity(self, should_connect=True):
+ def _check_public_network_connectivity(self, should_connect=True,
+ msg=None):
# The target login is assumed to have been configured for
# key-based authentication by cloud-init.
ssh_login = CONF.compute.image_ssh_user
+ LOG.debug('checking network connections')
try:
for floating_ip, server in self.floating_ips.iteritems():
ip_address = floating_ip.floating_ip_address
@@ -264,7 +215,11 @@
private_key,
should_connect=should_connect)
except Exception:
- LOG.exception('Public network connectivity check failed')
+ ex_msg = 'Public network connectivity check failed'
+ if msg:
+ ex_msg += ": " + msg
+ LOG.exception(ex_msg)
+ self._log_console_output(servers=self.servers.keys())
debug.log_ip_ns()
raise
@@ -282,19 +237,21 @@
self._associate_floating_ip(floating_ip, server)
self.floating_ips[floating_ip] = server
- @attr(type='smoke')
- @services('compute', 'network')
+ @test.attr(type='smoke')
+ @test.services('compute', 'network')
def test_network_basic_ops(self):
self._create_security_groups()
self._create_networks()
self._check_networks()
self._create_servers()
self._create_and_associate_floating_ips()
- self._wait_for_floating_ip_association()
self._check_tenant_network_connectivity()
self._check_public_network_connectivity(should_connect=True)
self._disassociate_floating_ips()
- self._check_public_network_connectivity(should_connect=False)
+ self._check_public_network_connectivity(should_connect=False,
+ msg="after disassociate "
+ "floating ip")
self._reassociate_floating_ips()
- self._wait_for_floating_ip_association()
- self._check_public_network_connectivity(should_connect=True)
+ self._check_public_network_connectivity(should_connect=True,
+ msg="after re-associate "
+ "floating ip")
diff --git a/tempest/scenario/test_network_quotas.py b/tempest/scenario/test_network_quotas.py
deleted file mode 100644
index cb7aa0b..0000000
--- a/tempest/scenario/test_network_quotas.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 Hewlett-Packard Development Company, L.P.
-# All Rights Reserved.
-#
-# 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 neutronclient.common import exceptions as exc
-
-from tempest.scenario.manager import NetworkScenarioTest
-from tempest.test import services
-
-
-class TestNetworkQuotaBasic(NetworkScenarioTest):
- """
- This test suite contains tests that each loop trying to grab a
- particular resource until a quota limit is hit.
- For sanity, there is a maximum number of iterations - if this is hit
- the test fails. Covers network, subnet, port.
- """
-
- @classmethod
- def check_preconditions(cls):
- super(TestNetworkQuotaBasic, cls).check_preconditions()
-
- @classmethod
- def setUpClass(cls):
- super(TestNetworkQuotaBasic, cls).setUpClass()
- cls.check_preconditions()
- cls.networks = []
- cls.subnets = []
- cls.ports = []
-
- @services('network')
- def test_create_network_until_quota_hit(self):
- hit_limit = False
- networknum = self._get_tenant_own_network_num(self.tenant_id)
- max = self._show_quota_network(self.tenant_id) - networknum
- for n in xrange(max):
- try:
- self.networks.append(
- self._create_network(self.tenant_id,
- namestart='network-quotatest-'))
- except exc.NeutronClientException as e:
- if (e.status_code != 409):
- raise
- hit_limit = True
- break
- self.assertFalse(hit_limit, "Failed: Hit quota limit !")
-
- try:
- self.networks.append(
- self._create_network(self.tenant_id,
- namestart='network-quotatest-'))
- except exc.NeutronClientException as e:
- if (e.status_code != 409):
- raise
- hit_limit = True
- self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")
-
- @services('network')
- def test_create_subnet_until_quota_hit(self):
- if not self.networks:
- self.networks.append(
- self._create_network(self.tenant_id,
- namestart='network-quotatest-'))
- hit_limit = False
- subnetnum = self._get_tenant_own_subnet_num(self.tenant_id)
- max = self._show_quota_subnet(self.tenant_id) - subnetnum
- for n in xrange(max):
- try:
- self.subnets.append(
- self._create_subnet(self.networks[0],
- namestart='subnet-quotatest-'))
- except exc.NeutronClientException as e:
- if (e.status_code != 409):
- raise
- hit_limit = True
- break
- self.assertFalse(hit_limit, "Failed: Hit quota limit !")
-
- try:
- self.subnets.append(
- self._create_subnet(self.networks[0],
- namestart='subnet-quotatest-'))
- except exc.NeutronClientException as e:
- if (e.status_code != 409):
- raise
- hit_limit = True
- self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")
-
- @services('network')
- def test_create_ports_until_quota_hit(self):
- if not self.networks:
- self.networks.append(
- self._create_network(self.tenant_id,
- namestart='network-quotatest-'))
- hit_limit = False
- portnum = self._get_tenant_own_port_num(self.tenant_id)
- max = self._show_quota_port(self.tenant_id) - portnum
- for n in xrange(max):
- try:
- self.ports.append(
- self._create_port(self.networks[0],
- namestart='port-quotatest-'))
- except exc.NeutronClientException as e:
- if (e.status_code != 409):
- raise
- hit_limit = True
- break
- self.assertFalse(hit_limit, "Failed: Hit quota limit !")
-
- try:
- self.ports.append(
- self._create_port(self.networks[0],
- namestart='port-quotatest-'))
- except exc.NeutronClientException as e:
- if (e.status_code != 409):
- raise
- hit_limit = True
- self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")
diff --git a/tempest/scenario/test_server_advanced_ops.py b/tempest/scenario/test_server_advanced_ops.py
index 112c8a2..9626157 100644
--- a/tempest/scenario/test_server_advanced_ops.py
+++ b/tempest/scenario/test_server_advanced_ops.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,10 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
+from tempest import config
from tempest.openstack.common import log as logging
from tempest.scenario import manager
from tempest.test import services
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -33,15 +34,16 @@
@classmethod
def setUpClass(cls):
+ cls.set_network_resources()
super(TestServerAdvancedOps, cls).setUpClass()
- if not cls.config.compute_feature_enabled.resize:
+ if not CONF.compute_feature_enabled.resize:
msg = "Skipping test - resize not available on this host"
raise cls.skipException(msg)
- resize_flavor = cls.config.compute.flavor_ref_alt
+ resize_flavor = CONF.compute.flavor_ref_alt
- if resize_flavor == cls.config.compute.flavor_ref:
+ if resize_flavor == CONF.compute.flavor_ref:
msg = "Skipping test - flavor_ref and flavor_ref_alt are identical"
raise cls.skipException(msg)
@@ -50,7 +52,7 @@
# We create an instance for use in this test
instance = self.create_server()
instance_id = instance.id
- resize_flavor = self.config.compute.flavor_ref_alt
+ resize_flavor = CONF.compute.flavor_ref_alt
LOG.debug("Resizing instance %s from flavor %s to flavor %s",
instance.id, instance.flavor, resize_flavor)
instance.resize(resize_flavor)
diff --git a/tempest/scenario/test_server_basic_ops.py b/tempest/scenario/test_server_basic_ops.py
index 1e1a310..73ff6b4 100644
--- a/tempest/scenario/test_server_basic_ops.py
+++ b/tempest/scenario/test_server_basic_ops.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,12 +14,24 @@
# under the License.
from tempest.common.utils import data_utils
+from tempest.common.utils import test_utils
+from tempest import config
from tempest.openstack.common import log as logging
from tempest.scenario import manager
from tempest.test import services
+import testscenarios
+
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
+# NOTE(andreaf) - nose does not honour the load_tests protocol
+# however it's test discovery regex will match anything
+# which includes _tests. So nose would require some further
+# investigation to be supported with this
+load_tests = testscenarios.load_tests_apply_scenarios
+
class TestServerBasicOps(manager.OfficialClientTest):
@@ -37,6 +47,37 @@
* Terminate the instance
"""
+ scenario_utils = test_utils.InputScenarioUtils()
+ scenario_flavor = scenario_utils.scenario_flavors
+ scenario_image = scenario_utils.scenario_images
+
+ scenarios = testscenarios.multiply_scenarios(scenario_image,
+ scenario_flavor)
+
+ def setUp(self):
+ super(TestServerBasicOps, self).setUp()
+ # Setup image and flavor the test instance
+ # Support both configured and injected values
+ if not hasattr(self, 'image_ref'):
+ self.image_ref = CONF.compute.image_ref
+ if not hasattr(self, 'flavor_ref'):
+ self.flavor_ref = CONF.compute.flavor_ref
+ self.image_utils = test_utils.ImageUtils()
+ if not self.image_utils.is_flavor_enough(self.flavor_ref,
+ self.image_ref):
+ raise self.skipException(
+ '{image} does not fit in {flavor}'.format(
+ image=self.image_ref, flavor=self.flavor_ref
+ )
+ )
+ self.run_ssh = CONF.compute.run_ssh and \
+ self.image_utils.is_sshable_image(self.image_ref)
+ self.ssh_user = self.image_utils.ssh_user(self.image_ref)
+ LOG.debug('Starting test for i:{image}, f:{flavor}. '
+ 'Run ssh: {ssh}, user: {ssh_user}'.format(
+ image=self.image_ref, flavor=self.flavor_ref,
+ ssh=self.run_ssh, ssh_user=self.ssh_user))
+
def add_keypair(self):
self.keypair = self.create_keypair()
@@ -53,10 +94,13 @@
self._create_loginable_secgroup_rule_nova(secgroup_id=self.secgroup.id)
def boot_instance(self):
+ # Create server with image and flavor from input scenario
create_kwargs = {
'key_name': self.keypair.id
}
- instance = self.create_server(create_kwargs=create_kwargs)
+ instance = self.create_server(image=self.image_ref,
+ flavor=self.flavor_ref,
+ create_kwargs=create_kwargs)
self.set_resource('instance', instance)
def pause_server(self):
@@ -100,6 +144,24 @@
instance.delete()
self.remove_resource('instance')
+ def verify_ssh(self):
+ if self.run_ssh:
+ # Obtain a floating IP
+ floating_ip = self.compute_client.floating_ips.create()
+ # Attach a floating IP
+ instance = self.get_resource('instance')
+ instance.add_floating_ip(floating_ip)
+ # Check ssh
+ try:
+ self.get_remote_client(
+ server_or_ip=floating_ip.ip,
+ username=self.image_utils.ssh_user(self.image_ref),
+ private_key=self.keypair.private)
+ except Exception:
+ LOG.exception('ssh to server failed')
+ self._log_console_output()
+ raise
+
@services('compute', 'network')
def test_server_basicops(self):
self.add_keypair()
@@ -109,4 +171,5 @@
self.unpause_server()
self.suspend_server()
self.resume_server()
+ self.verify_ssh()
self.terminate_instance()
diff --git a/tempest/scenario/test_snapshot_pattern.py b/tempest/scenario/test_snapshot_pattern.py
index 00139f0..2bb3d84 100644
--- a/tempest/scenario/test_snapshot_pattern.py
+++ b/tempest/scenario/test_snapshot_pattern.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -15,9 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
+from tempest import config
+from tempest.openstack.common import log
from tempest.scenario import manager
from tempest.test import services
+CONF = config.CONF
+
+LOG = log.getLogger(__name__)
+
class TestSnapshotPattern(manager.OfficialClientTest):
"""
@@ -40,7 +44,11 @@
self.keypair = self.create_keypair()
def _ssh_to_server(self, server_or_ip):
- linux_client = self.get_remote_client(server_or_ip)
+ try:
+ linux_client = self.get_remote_client(server_or_ip)
+ except Exception:
+ LOG.exception()
+ self._log_console_output()
return linux_client.ssh_client
def _write_timestamp(self, server_or_ip):
@@ -68,8 +76,8 @@
self._create_loginable_secgroup_rule_nova()
# boot a instance and create a timestamp file in it
- server = self._boot_image(self.config.compute.image_ref)
- if self.config.compute.use_floatingip_for_ssh:
+ server = self._boot_image(CONF.compute.image_ref)
+ if CONF.compute.use_floatingip_for_ssh:
fip_for_server = self._create_floating_ip()
self._set_floating_ip_to_server(server, fip_for_server)
self._write_timestamp(fip_for_server.ip)
@@ -83,7 +91,7 @@
server_from_snapshot = self._boot_image(snapshot_image.id)
# check the existence of the timestamp file in the second instance
- if self.config.compute.use_floatingip_for_ssh:
+ if CONF.compute.use_floatingip_for_ssh:
fip_for_snapshot = self._create_floating_ip()
self._set_floating_ip_to_server(server_from_snapshot,
fip_for_snapshot)
diff --git a/tempest/scenario/test_stamp_pattern.py b/tempest/scenario/test_stamp_pattern.py
index 5eac55c..8d043ae 100644
--- a/tempest/scenario/test_stamp_pattern.py
+++ b/tempest/scenario/test_stamp_pattern.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -20,11 +18,14 @@
from cinderclient import exceptions as cinder_exceptions
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.scenario import manager
import tempest.test
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -115,7 +116,6 @@
def _wait_for_volume_availible_on_the_system(self, server_or_ip):
ssh = self.get_remote_client(server_or_ip)
- conf = self.config
def _func():
part = ssh.get_partitions()
@@ -123,8 +123,8 @@
return 'vdb' in part
if not tempest.test.call_until_true(_func,
- conf.compute.build_timeout,
- conf.compute.build_interval):
+ CONF.compute.build_timeout,
+ CONF.compute.build_interval):
raise exceptions.TimeoutException
def _create_timestamp(self, server_or_ip):
@@ -150,10 +150,10 @@
# boot an instance and create a timestamp file in it
volume = self._create_volume()
- server = self._boot_image(self.config.compute.image_ref)
+ server = self._boot_image(CONF.compute.image_ref)
# create and add floating IP to server1
- if self.config.compute.use_floatingip_for_ssh:
+ if CONF.compute.use_floatingip_for_ssh:
floating_ip_for_server = self._create_floating_ip()
self._add_floating_ip(server, floating_ip_for_server)
ip_for_server = floating_ip_for_server.ip
@@ -179,7 +179,7 @@
server_from_snapshot = self._boot_image(snapshot_image.id)
# create and add floating IP to server_from_snapshot
- if self.config.compute.use_floatingip_for_ssh:
+ if CONF.compute.use_floatingip_for_ssh:
floating_ip_for_snapshot = self._create_floating_ip()
self._add_floating_ip(server_from_snapshot,
floating_ip_for_snapshot)
diff --git a/tempest/scenario/test_swift_basic_ops.py b/tempest/scenario/test_swift_basic_ops.py
index 6763503..60df606 100644
--- a/tempest/scenario/test_swift_basic_ops.py
+++ b/tempest/scenario/test_swift_basic_ops.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
@@ -17,10 +15,13 @@
from tempest.common.utils.data_utils import rand_name
+from tempest import config
from tempest.openstack.common import log as logging
from tempest.scenario import manager
from tempest.test import services
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -39,8 +40,9 @@
@classmethod
def setUpClass(cls):
+ cls.set_network_resources()
super(TestSwiftBasicOps, cls).setUpClass()
- if not cls.config.service_available.swift:
+ if not CONF.service_available.swift:
skip_msg = ("%s skipped as swift is not available" %
cls.__name__)
raise cls.skipException(skip_msg)
@@ -91,7 +93,7 @@
for obj in not_present_obj:
self.assertNotIn(obj, object_list)
- @services('object')
+ @services('object_storage')
def test_swift_basic_ops(self):
self._get_swift_stat()
container_name = self._create_container()
diff --git a/tempest/scenario/test_volume_boot_pattern.py b/tempest/scenario/test_volume_boot_pattern.py
index fa9a228..7b002eb 100644
--- a/tempest/scenario/test_volume_boot_pattern.py
+++ b/tempest/scenario/test_volume_boot_pattern.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -13,9 +11,15 @@
# under the License.
from tempest.common.utils import data_utils
+from tempest import config
+from tempest.openstack.common import log
from tempest.scenario import manager
from tempest.test import services
+CONF = config.CONF
+
+LOG = log.getLogger(__name__)
+
class TestVolumeBootPattern(manager.OfficialClientTest):
@@ -33,7 +37,7 @@
"""
def _create_volume_from_image(self):
- img_uuid = self.config.compute.image_ref
+ img_uuid = CONF.compute.image_ref
vol_name = data_utils.rand_name('volume-origin')
return self.create_volume(name=vol_name, imageRef=img_uuid)
@@ -86,18 +90,24 @@
'available')
def _ssh_to_server(self, server, keypair):
- if self.config.compute.use_floatingip_for_ssh:
+ if CONF.compute.use_floatingip_for_ssh:
floating_ip = self.compute_client.floating_ips.create()
fip_name = data_utils.rand_name('scenario-fip')
self.set_resource(fip_name, floating_ip)
server.add_floating_ip(floating_ip)
ip = floating_ip.ip
else:
- network_name_for_ssh = self.config.compute.network_for_ssh
+ network_name_for_ssh = CONF.compute.network_for_ssh
ip = server.networks[network_name_for_ssh][0]
- client = self.get_remote_client(ip,
- private_key=keypair.private_key)
+ try:
+ client = self.get_remote_client(
+ ip,
+ private_key=keypair.private_key)
+ except Exception:
+ LOG.exception('ssh to server failed')
+ self._log_console_output()
+ raise
return client.ssh_client
def _get_content(self, ssh_client):
diff --git a/tempest/services/__init__.py b/tempest/services/__init__.py
index e210926..e7bec60 100644
--- a/tempest/services/__init__.py
+++ b/tempest/services/__init__.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/baremetal/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/services/baremetal/__init__.py
diff --git a/tempest/services/baremetal/base.py b/tempest/services/baremetal/base.py
new file mode 100644
index 0000000..6e86466
--- /dev/null
+++ b/tempest/services/baremetal/base.py
@@ -0,0 +1,197 @@
+# 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 functools
+import json
+
+import six
+
+from tempest.common import rest_client
+from tempest import config
+
+CONF = config.CONF
+
+
+def handle_errors(f):
+ """A decorator that allows to ignore certain types of errors."""
+
+ @functools.wraps(f)
+ def wrapper(*args, **kwargs):
+ param_name = 'ignore_errors'
+ ignored_errors = kwargs.get(param_name, tuple())
+
+ if param_name in kwargs:
+ del kwargs[param_name]
+
+ try:
+ return f(*args, **kwargs)
+ except ignored_errors:
+ # Silently ignore errors
+ pass
+
+ return wrapper
+
+
+class BaremetalClient(rest_client.RestClient):
+ """
+ Base Tempest REST client for Ironic API.
+
+ """
+
+ def __init__(self, auth_provider):
+ super(BaremetalClient, self).__init__(auth_provider)
+ self.service = CONF.baremetal.catalog_type
+ self.uri_prefix = ''
+
+ def serialize(self, object_type, object_dict):
+ """Serialize an Ironic object."""
+
+ raise NotImplementedError
+
+ def deserialize(self, object_str):
+ """Deserialize an Ironic object."""
+
+ raise NotImplementedError
+
+ def _get_uri(self, resource_name, uuid=None, permanent=False):
+ """
+ Get URI for a specific resource or object.
+
+ :param resource_name: The name of the REST resource, e.g., 'nodes'.
+ :param uuid: The unique identifier of an object in UUID format.
+ :return: Relative URI for the resource or object.
+
+ """
+ prefix = self.uri_prefix if not permanent else ''
+
+ return '{pref}/{res}{uuid}'.format(pref=prefix,
+ res=resource_name,
+ uuid='/%s' % uuid if uuid else '')
+
+ def _make_patch(self, allowed_attributes, **kw):
+ """
+ Create a JSON patch according to RFC 6902.
+
+ :param allowed_attributes: An iterable object that contains a set of
+ allowed attributes for an object.
+ :param **kw: Attributes and new values for them.
+ :return: A JSON path that sets values of the specified attributes to
+ the new ones.
+
+ """
+ def get_change(kw, path='/'):
+ for name, value in six.iteritems(kw):
+ if isinstance(value, dict):
+ for ch in get_change(value, path + '%s/' % name):
+ yield ch
+ else:
+ yield {'path': path + name,
+ 'value': value,
+ 'op': 'replace'}
+
+ patch = [ch for ch in get_change(kw)
+ if ch['path'].lstrip('/') in allowed_attributes]
+
+ return patch
+
+ def _list_request(self, resource, permanent=False):
+ """
+ Get the list of objects of the specified type.
+
+ :param resource: The name of the REST resource, e.g., 'nodes'.
+ :return: A tuple with the server response and deserialized JSON list
+ of objects
+
+ """
+ uri = self._get_uri(resource, permanent=permanent)
+
+ resp, body = self.get(uri, self.headers)
+
+ return resp, self.deserialize(body)
+
+ def _show_request(self, resource, uuid, permanent=False):
+ """
+ Gets a specific object of the specified type.
+
+ :param uuid: Unique identifier of the object in UUID format.
+ :return: Serialized object as a dictionary.
+
+ """
+ uri = self._get_uri(resource, uuid=uuid, permanent=permanent)
+ resp, body = self.get(uri, self.headers)
+
+ return resp, self.deserialize(body)
+
+ def _create_request(self, resource, object_type, object_dict):
+ """
+ Create an object of the specified type.
+
+ :param resource: The name of the REST resource, e.g., 'nodes'.
+ :param object_dict: A Python dict that represents an object of the
+ specified type.
+ :return: A tuple with the server response and the deserialized created
+ object.
+
+ """
+ body = self.serialize(object_type, object_dict)
+ uri = self._get_uri(resource)
+
+ resp, body = self.post(uri, headers=self.headers, body=body)
+
+ return resp, self.deserialize(body)
+
+ def _delete_request(self, resource, uuid):
+ """
+ Delete specified object.
+
+ :param resource: The name of the REST resource, e.g., 'nodes'.
+ :param uuid: The unique identifier of an object in UUID format.
+ :return: A tuple with the server response and the response body.
+
+ """
+ uri = self._get_uri(resource, uuid)
+
+ resp, body = self.delete(uri, self.headers)
+ return resp, body
+
+ def _patch_request(self, resource, uuid, patch_object):
+ """
+ Update specified object with JSON-patch.
+
+ :param resource: The name of the REST resource, e.g., 'nodes'.
+ :param uuid: The unique identifier of an object in UUID format.
+ :return: A tuple with the server response and the serialized patched
+ object.
+
+ """
+ uri = self._get_uri(resource, uuid)
+ patch_body = json.dumps(patch_object)
+
+ resp, body = self.patch(uri, headers=self.headers, body=patch_body)
+ return resp, self.deserialize(body)
+
+ @handle_errors
+ def get_api_description(self):
+ """Retrieves all versions of the Ironic API."""
+
+ return self._list_request('', permanent=True)
+
+ @handle_errors
+ def get_version_description(self, version='v1'):
+ """
+ Retrieves the desctription of the API.
+
+ :param version: The version of the API. Default: 'v1'.
+ :return: Serialized description of API resources.
+
+ """
+ return self._list_request(version, permanent=True)
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/baremetal/v1/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/services/baremetal/v1/__init__.py
diff --git a/tempest/services/baremetal/v1/base_v1.py b/tempest/services/baremetal/v1/base_v1.py
new file mode 100644
index 0000000..3f4c509
--- /dev/null
+++ b/tempest/services/baremetal/v1/base_v1.py
@@ -0,0 +1,206 @@
+# 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 tempest.services.baremetal import base
+
+
+class BaremetalClientV1(base.BaremetalClient):
+ """
+ Base Tempest REST client for Ironic API v1.
+
+ Specific implementations must implement serialize and deserialize
+ methods in order to send requests to Ironic.
+
+ """
+ def __init__(self, auth_provider):
+ super(BaremetalClientV1, self).__init__(auth_provider)
+ self.version = '1'
+ self.uri_prefix = 'v%s' % self.version
+
+ @base.handle_errors
+ def list_nodes(self):
+ """List all existing nodes."""
+ return self._list_request('nodes')
+
+ @base.handle_errors
+ def list_chassis(self):
+ """List all existing chassis."""
+ return self._list_request('chassis')
+
+ @base.handle_errors
+ def list_ports(self):
+ """List all existing ports."""
+ return self._list_request('ports')
+
+ @base.handle_errors
+ def show_node(self, uuid):
+ """
+ Gets a specific node.
+
+ :param uuid: Unique identifier of the node in UUID format.
+ :return: Serialized node as a dictionary.
+
+ """
+ return self._show_request('nodes', uuid)
+
+ @base.handle_errors
+ def show_chassis(self, uuid):
+ """
+ Gets a specific chassis.
+
+ :param uuid: Unique identifier of the chassis in UUID format.
+ :return: Serialized chassis as a dictionary.
+
+ """
+ return self._show_request('chassis', uuid)
+
+ @base.handle_errors
+ def show_port(self, uuid):
+ """
+ Gets a specific port.
+
+ :param uuid: Unique identifier of the port in UUID format.
+ :return: Serialized port as a dictionary.
+
+ """
+ return self._show_request('ports', uuid)
+
+ @base.handle_errors
+ def create_node(self, chassis_id, **kwargs):
+ """
+ Create a baremetal node with the specified parameters.
+
+ :param cpu_arch: CPU architecture of the node. Default: x86_64.
+ :param cpu_num: Number of CPUs. Default: 8.
+ :param storage: Disk size. Default: 1024.
+ :param memory: Available RAM. Default: 4096.
+ :param driver: Driver name. Default: "fake"
+ :return: A tuple with the server response and the created node.
+
+ """
+ node = {'chassis_uuid': chassis_id,
+ 'properties': {'cpu_arch': kwargs.get('cpu_arch', 'x86_64'),
+ 'cpu_num': kwargs.get('cpu_num', 8),
+ 'storage': kwargs.get('storage', 1024),
+ 'memory': kwargs.get('memory', 4096)},
+ 'driver': kwargs.get('driver', 'fake')}
+
+ return self._create_request('nodes', 'node', node)
+
+ @base.handle_errors
+ def create_chassis(self, **kwargs):
+ """
+ Create a chassis with the specified parameters.
+
+ :param description: The description of the chassis.
+ Default: test-chassis
+ :return: A tuple with the server response and the created chassis.
+
+ """
+ chassis = {'description': kwargs.get('description', 'test-chassis')}
+
+ return self._create_request('chassis', 'chassis', chassis)
+
+ @base.handle_errors
+ def create_port(self, node_id, **kwargs):
+ """
+ Create a port with the specified parameters.
+
+ :param node_id: The ID of the node which owns the port.
+ :param address: MAC address of the port. Default: 01:23:45:67:89:0A.
+ :return: A tuple with the server response and the created port.
+
+ """
+ port = {'address': kwargs.get('address', '01:23:45:67:89:0A'),
+ 'node_uuid': node_id}
+
+ return self._create_request('ports', 'port', port)
+
+ @base.handle_errors
+ def delete_node(self, uuid):
+ """
+ Deletes a node having the specified UUID.
+
+ :param uuid: The unique identifier of the node.
+ :return: A tuple with the server response and the response body.
+
+ """
+ return self._delete_request('nodes', uuid)
+
+ @base.handle_errors
+ def delete_chassis(self, uuid):
+ """
+ Deletes a chassis having the specified UUID.
+
+ :param uuid: The unique identifier of the chassis.
+ :return: A tuple with the server response and the response body.
+
+ """
+ return self._delete_request('chassis', uuid)
+
+ @base.handle_errors
+ def delete_port(self, uuid):
+ """
+ Deletes a port having the specified UUID.
+
+ :param uuid: The unique identifier of the port.
+ :return: A tuple with the server response and the response body.
+
+ """
+ return self._delete_request('ports', uuid)
+
+ @base.handle_errors
+ def update_node(self, uuid, **kwargs):
+ """
+ Update the specified node.
+
+ :param uuid: The unique identifier of the node.
+ :return: A tuple with the server response and the updated node.
+
+ """
+ node_attributes = ('properties/cpu_arch',
+ 'properties/cpu_num',
+ 'properties/storage',
+ 'properties/memory',
+ 'driver')
+
+ patch = self._make_patch(node_attributes, **kwargs)
+
+ return self._patch_request('nodes', uuid, patch)
+
+ @base.handle_errors
+ def update_chassis(self, uuid, **kwargs):
+ """
+ Update the specified chassis.
+
+ :param uuid: The unique identifier of the chassis.
+ :return: A tuple with the server response and the updated chassis.
+
+ """
+ chassis_attributes = ('description',)
+ patch = self._make_patch(chassis_attributes, **kwargs)
+
+ return self._patch_request('chassis', uuid, patch)
+
+ @base.handle_errors
+ def update_port(self, uuid, **kwargs):
+ """
+ Update the specified port.
+
+ :param uuid: The unique identifier of the port.
+ :return: A tuple with the server response and the updated port.
+
+ """
+ port_attributes = ('address',)
+ patch = self._make_patch(port_attributes, **kwargs)
+
+ return self._patch_request('ports', uuid, patch)
diff --git a/tempest/services/baremetal/v1/client_json.py b/tempest/services/baremetal/v1/client_json.py
new file mode 100644
index 0000000..c9dc874
--- /dev/null
+++ b/tempest/services/baremetal/v1/client_json.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.
+
+import json
+
+from tempest.services.baremetal.v1 import base_v1
+
+
+class BaremetalClientJSON(base_v1.BaremetalClientV1):
+ """Tempest REST client for Ironic JSON API v1."""
+
+ def __init__(self, auth_provider):
+ super(BaremetalClientJSON, self).__init__(auth_provider)
+
+ self.serialize = lambda obj_type, obj_body: json.dumps(obj_body)
+ self.deserialize = json.loads
diff --git a/tempest/services/botoclients.py b/tempest/services/botoclients.py
index 0b4b3b9..03e87b1 100644
--- a/tempest/services/botoclients.py
+++ b/tempest/services/botoclients.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,25 +18,27 @@
import types
import urlparse
+from tempest import config
from tempest import exceptions
import boto
import boto.ec2
import boto.s3.connection
+CONF = config.CONF
+
class BotoClientBase(object):
ALLOWED_METHODS = set()
- def __init__(self, config,
- username=None, password=None,
+ def __init__(self, username=None, password=None,
auth_url=None, tenant_name=None,
*args, **kwargs):
- self.connection_timeout = str(config.boto.http_socket_timeout)
- self.num_retries = str(config.boto.num_retries)
- self.build_timeout = config.boto.build_timeout
+ self.connection_timeout = str(CONF.boto.http_socket_timeout)
+ self.num_retries = str(CONF.boto.num_retries)
+ self.build_timeout = CONF.boto.build_timeout
self.ks_cred = {"username": username,
"password": password,
"auth_url": auth_url,
@@ -105,15 +105,15 @@
def connect_method(self, *args, **kwargs):
return boto.connect_ec2(*args, **kwargs)
- def __init__(self, config, *args, **kwargs):
- super(APIClientEC2, self).__init__(config, *args, **kwargs)
- aws_access = config.boto.aws_access
- aws_secret = config.boto.aws_secret
- purl = urlparse.urlparse(config.boto.ec2_url)
+ def __init__(self, *args, **kwargs):
+ super(APIClientEC2, self).__init__(*args, **kwargs)
+ aws_access = CONF.boto.aws_access
+ aws_secret = CONF.boto.aws_secret
+ purl = urlparse.urlparse(CONF.boto.ec2_url)
- region_name = config.compute.region
+ region_name = CONF.compute.region
if not region_name:
- region_name = config.identity.region
+ region_name = CONF.identity.region
region = boto.ec2.regioninfo.RegionInfo(name=region_name,
endpoint=purl.hostname)
port = purl.port
@@ -196,11 +196,11 @@
def connect_method(self, *args, **kwargs):
return boto.connect_s3(*args, **kwargs)
- def __init__(self, config, *args, **kwargs):
- super(ObjectClientS3, self).__init__(config, *args, **kwargs)
- aws_access = config.boto.aws_access
- aws_secret = config.boto.aws_secret
- purl = urlparse.urlparse(config.boto.s3_url)
+ def __init__(self, *args, **kwargs):
+ super(ObjectClientS3, self).__init__(*args, **kwargs)
+ aws_access = CONF.boto.aws_access
+ aws_secret = CONF.boto.aws_secret
+ purl = urlparse.urlparse(CONF.boto.s3_url)
port = purl.port
if port is None:
if purl.scheme is not "https":
diff --git a/tempest/services/compute/json/aggregates_client.py b/tempest/services/compute/json/aggregates_client.py
index b7c6bf1..aa52081 100644
--- a/tempest/services/compute/json/aggregates_client.py
+++ b/tempest/services/compute/json/aggregates_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -18,15 +16,17 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class AggregatesClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AggregatesClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(AggregatesClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_aggregates(self):
"""Get aggregate list."""
@@ -40,13 +40,9 @@
body = json.loads(body)
return resp, body['aggregate']
- def create_aggregate(self, name, availability_zone=None):
+ def create_aggregate(self, **kwargs):
"""Creates a new aggregate."""
- post_body = {
- 'name': name,
- 'availability_zone': availability_zone,
- }
- post_body = json.dumps({'aggregate': post_body})
+ post_body = json.dumps({'aggregate': kwargs})
resp, body = self.post('os-aggregates', post_body, self.headers)
body = json.loads(body)
diff --git a/tempest/services/compute/json/availability_zone_client.py b/tempest/services/compute/json/availability_zone_client.py
index b11871b..ea4e95e 100644
--- a/tempest/services/compute/json/availability_zone_client.py
+++ b/tempest/services/compute/json/availability_zone_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -18,15 +16,17 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class AvailabilityZoneClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AvailabilityZoneClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(AvailabilityZoneClientJSON, self).__init__(
+ auth_provider)
+ self.service = CONF.compute.catalog_type
def get_availability_zone_list(self):
resp, body = self.get('os-availability-zone')
diff --git a/tempest/services/compute/json/certificates_client.py b/tempest/services/compute/json/certificates_client.py
index 9fdce17..b7135f6 100644
--- a/tempest/services/compute/json/certificates_client.py
+++ b/tempest/services/compute/json/certificates_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -18,15 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class CertificatesClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(CertificatesClientJSON, self).__init__(config, username,
- password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(CertificatesClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_certificate(self, id):
url = "os-certificates/%s" % (id)
diff --git a/tempest/services/compute/json/extensions_client.py b/tempest/services/compute/json/extensions_client.py
index ad5354c..f7e2737 100644
--- a/tempest/services/compute/json/extensions_client.py
+++ b/tempest/services/compute/json/extensions_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,20 +16,22 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class ExtensionsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ExtensionsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(ExtensionsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_extensions(self):
url = 'extensions'
resp, body = self.get(url)
body = json.loads(body)
- return resp, body
+ return resp, body['extensions']
def is_enabled(self, extension):
_, extensions = self.list_extensions()
diff --git a/tempest/services/compute/json/fixed_ips_client.py b/tempest/services/compute/json/fixed_ips_client.py
index 4ef7c4c..144b7dc 100644
--- a/tempest/services/compute/json/fixed_ips_client.py
+++ b/tempest/services/compute/json/fixed_ips_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -18,14 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class FixedIPsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FixedIPsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(FixedIPsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_fixed_ip_details(self, fixed_ip):
url = "os-fixed-ips/%s" % (fixed_ip)
diff --git a/tempest/services/compute/json/flavors_client.py b/tempest/services/compute/json/flavors_client.py
index 00d6f8a..96ab6d7 100644
--- a/tempest/services/compute/json/flavors_client.py
+++ b/tempest/services/compute/json/flavors_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,14 +17,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class FlavorsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FlavorsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(FlavorsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_flavors(self, params=None):
url = 'flavors'
diff --git a/tempest/services/compute/json/floating_ips_client.py b/tempest/services/compute/json/floating_ips_client.py
index 8349263..2bf5241 100644
--- a/tempest/services/compute/json/floating_ips_client.py
+++ b/tempest/services/compute/json/floating_ips_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,14 +17,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class FloatingIPsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FloatingIPsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(FloatingIPsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_floating_ips(self, params=None):
"""Returns a list of all floating IPs filtered by any parameters."""
diff --git a/tempest/services/compute/json/hosts_client.py b/tempest/services/compute/json/hosts_client.py
index f51879d..aa63927 100644
--- a/tempest/services/compute/json/hosts_client.py
+++ b/tempest/services/compute/json/hosts_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -18,14 +16,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class HostsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HostsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(HostsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_hosts(self, params=None):
"""Lists all hosts."""
diff --git a/tempest/services/compute/json/hypervisor_client.py b/tempest/services/compute/json/hypervisor_client.py
index fba5acb..74844dc 100644
--- a/tempest/services/compute/json/hypervisor_client.py
+++ b/tempest/services/compute/json/hypervisor_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation.
# All Rights Reserved.
#
@@ -18,15 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class HypervisorClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HypervisorClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(HypervisorClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_hypervisor_list(self):
"""List hypervisors information."""
diff --git a/tempest/services/compute/json/images_client.py b/tempest/services/compute/json/images_client.py
index c05571a..7324d84 100644
--- a/tempest/services/compute/json/images_client.py
+++ b/tempest/services/compute/json/images_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,17 +18,19 @@
from tempest.common.rest_client import RestClient
from tempest.common import waiters
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class ImagesClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ImagesClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
- self.build_interval = self.config.compute.build_interval
- self.build_timeout = self.config.compute.build_timeout
+ def __init__(self, auth_provider):
+ super(ImagesClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
def create_image(self, server_id, name, meta=None):
"""Creates an image of the original server."""
diff --git a/tempest/services/compute/json/instance_usage_audit_log_client.py b/tempest/services/compute/json/instance_usage_audit_log_client.py
index 07ce1bb..27930f2 100644
--- a/tempest/services/compute/json/instance_usage_audit_log_client.py
+++ b/tempest/services/compute/json/instance_usage_audit_log_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -18,14 +16,17 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class InstanceUsagesAuditLogClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
+ def __init__(self, auth_provider):
super(InstanceUsagesAuditLogClientJSON, self).__init__(
- config, username, password, auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ auth_provider)
+ self.service = CONF.compute.catalog_type
def list_instance_usage_audit_logs(self):
url = 'os-instance_usage_audit_log'
diff --git a/tempest/services/compute/json/interfaces_client.py b/tempest/services/compute/json/interfaces_client.py
index 06e6476..d9a2030 100644
--- a/tempest/services/compute/json/interfaces_client.py
+++ b/tempest/services/compute/json/interfaces_client.py
@@ -17,15 +17,17 @@
import time
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class InterfacesClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(InterfacesClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(InterfacesClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_interfaces(self, server):
resp, body = self.get('servers/%s/os-interface' % server)
@@ -36,11 +38,12 @@
fixed_ip=None):
post_body = dict(interfaceAttachment=dict())
if port_id:
- post_body['port_id'] = port_id
+ post_body['interfaceAttachment']['port_id'] = port_id
if network_id:
- post_body['net_id'] = network_id
+ post_body['interfaceAttachment']['net_id'] = network_id
if fixed_ip:
- post_body['fixed_ips'] = [dict(ip_address=fixed_ip)]
+ fip = dict(ip_address=fixed_ip)
+ post_body['interfaceAttachment']['fixed_ips'] = [fip]
post_body = json.dumps(post_body)
resp, body = self.post('servers/%s/os-interface' % server,
headers=self.headers,
diff --git a/tempest/services/compute/json/keypairs_client.py b/tempest/services/compute/json/keypairs_client.py
index 5e1900c..3e2d4a7 100644
--- a/tempest/services/compute/json/keypairs_client.py
+++ b/tempest/services/compute/json/keypairs_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,14 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class KeyPairsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(KeyPairsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(KeyPairsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_keypairs(self):
resp, body = self.get("os-keypairs")
diff --git a/tempest/services/compute/json/limits_client.py b/tempest/services/compute/json/limits_client.py
index 3e53e3e..765ba79 100644
--- a/tempest/services/compute/json/limits_client.py
+++ b/tempest/services/compute/json/limits_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,15 +14,18 @@
# under the License.
import json
+
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class LimitsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(LimitsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(LimitsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_absolute_limits(self):
resp, body = self.get("limits")
diff --git a/tempest/services/compute/json/quotas_client.py b/tempest/services/compute/json/quotas_client.py
index a910dec..2007d4e 100644
--- a/tempest/services/compute/json/quotas_client.py
+++ b/tempest/services/compute/json/quotas_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 NTT Data
# All Rights Reserved.
#
@@ -18,14 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class QuotasClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(QuotasClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(QuotasClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_quota_set(self, tenant_id):
"""List the quota set for a tenant."""
diff --git a/tempest/services/compute/json/security_groups_client.py b/tempest/services/compute/json/security_groups_client.py
index 361ec36..edaf4a3 100644
--- a/tempest/services/compute/json/security_groups_client.py
+++ b/tempest/services/compute/json/security_groups_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,16 +17,17 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class SecurityGroupsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(SecurityGroupsClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(SecurityGroupsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_security_groups(self, params=None):
"""List all security groups for a user."""
diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py
index eb1a0c3..371a59c 100644
--- a/tempest/services/compute/json/servers_client.py
+++ b/tempest/services/compute/json/servers_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
@@ -22,17 +20,18 @@
from tempest.common.rest_client import RestClient
from tempest.common import waiters
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class ServersClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None,
- auth_version='v2'):
- super(ServersClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name,
- auth_version=auth_version)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(ServersClientJSON, self).__init__(auth_provider)
+
+ self.service = CONF.compute.catalog_type
def create_server(self, name, image_ref, flavor_ref, **kwargs):
"""
@@ -397,9 +396,9 @@
'os-virtual-interfaces']))
return resp, json.loads(body)
- def rescue_server(self, server_id, adminPass=None):
+ def rescue_server(self, server_id, **kwargs):
"""Rescue the provided server."""
- return self.action(server_id, 'rescue', None, adminPass=adminPass)
+ return self.action(server_id, 'rescue', None, **kwargs)
def unrescue_server(self, server_id):
"""Unrescue the provided server."""
diff --git a/tempest/services/compute/json/services_client.py b/tempest/services/compute/json/services_client.py
index 4db7596..4abee47 100644
--- a/tempest/services/compute/json/services_client.py
+++ b/tempest/services/compute/json/services_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -20,14 +18,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class ServicesClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ServicesClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(ServicesClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_services(self, params=None):
url = 'os-services'
diff --git a/tempest/services/compute/json/tenant_usages_client.py b/tempest/services/compute/json/tenant_usages_client.py
index 4dd6964..b14fa9b 100644
--- a/tempest/services/compute/json/tenant_usages_client.py
+++ b/tempest/services/compute/json/tenant_usages_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -19,14 +17,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class TenantUsagesClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(TenantUsagesClientJSON, self).__init__(
- config, username, password, auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(TenantUsagesClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_tenant_usages(self, params=None):
url = 'os-simple-tenant-usage'
diff --git a/tempest/services/compute/json/volumes_extensions_client.py b/tempest/services/compute/json/volumes_extensions_client.py
index d9906fd..ba7b5df 100644
--- a/tempest/services/compute/json/volumes_extensions_client.py
+++ b/tempest/services/compute/json/volumes_extensions_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,18 +18,20 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class VolumesExtensionsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumesExtensionsClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_type
- self.build_interval = self.config.volume.build_interval
- self.build_timeout = self.config.volume.build_timeout
+ def __init__(self, auth_provider):
+ super(VolumesExtensionsClientJSON, self).__init__(
+ auth_provider)
+ self.service = CONF.compute.catalog_type
+ self.build_interval = CONF.volume.build_interval
+ self.build_timeout = CONF.volume.build_timeout
def list_volumes(self, params=None):
"""List all the volumes created."""
diff --git a/tempest/services/compute/v3/json/aggregates_client.py b/tempest/services/compute/v3/json/aggregates_client.py
index 8ca2770..6bc758c 100644
--- a/tempest/services/compute/v3/json/aggregates_client.py
+++ b/tempest/services/compute/v3/json/aggregates_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -18,16 +16,17 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class AggregatesV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AggregatesV3ClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(AggregatesV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_aggregates(self):
"""Get aggregate list."""
@@ -41,13 +40,9 @@
body = json.loads(body)
return resp, body['aggregate']
- def create_aggregate(self, name, availability_zone=None):
+ def create_aggregate(self, **kwargs):
"""Creates a new aggregate."""
- post_body = {
- 'name': name,
- 'availability_zone': availability_zone,
- }
- post_body = json.dumps({'aggregate': post_body})
+ post_body = json.dumps({'aggregate': kwargs})
resp, body = self.post('os-aggregates', post_body, self.headers)
body = json.loads(body)
diff --git a/tempest/services/compute/v3/json/availability_zone_client.py b/tempest/services/compute/v3/json/availability_zone_client.py
index 9a3fe8b..4a6db55 100644
--- a/tempest/services/compute/v3/json/availability_zone_client.py
+++ b/tempest/services/compute/v3/json/availability_zone_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -18,15 +16,17 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class AvailabilityZoneV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AvailabilityZoneV3ClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(AvailabilityZoneV3ClientJSON, self).__init__(
+ auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def get_availability_zone_list(self):
resp, body = self.get('os-availability-zone')
diff --git a/tempest/services/compute/v3/json/certificates_client.py b/tempest/services/compute/v3/json/certificates_client.py
index bf0152b..0c9f9ac 100644
--- a/tempest/services/compute/v3/json/certificates_client.py
+++ b/tempest/services/compute/v3/json/certificates_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -18,15 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class CertificatesV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(CertificatesV3ClientJSON, self).__init__(config, username,
- password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(CertificatesV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def get_certificate(self, id):
url = "os-certificates/%s" % (id)
diff --git a/tempest/services/compute/v3/json/extensions_client.py b/tempest/services/compute/v3/json/extensions_client.py
index 6e0dc9d..54f0aba 100644
--- a/tempest/services/compute/v3/json/extensions_client.py
+++ b/tempest/services/compute/v3/json/extensions_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,21 +16,22 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class ExtensionsV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ExtensionsV3ClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(ExtensionsV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_extensions(self):
url = 'extensions'
resp, body = self.get(url)
body = json.loads(body)
- return resp, body
+ return resp, body['extensions']
def is_enabled(self, extension):
_, extensions = self.list_extensions()
diff --git a/tempest/services/compute/v3/json/flavors_client.py b/tempest/services/compute/v3/json/flavors_client.py
index e99ac91..df3d0c1 100644
--- a/tempest/services/compute/v3/json/flavors_client.py
+++ b/tempest/services/compute/v3/json/flavors_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,14 +17,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class FlavorsV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FlavorsV3ClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(FlavorsV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_flavors(self, params=None):
url = 'flavors'
@@ -61,11 +61,11 @@
'id': flavor_id,
}
if kwargs.get('ephemeral'):
- post_body['OS-FLV-EXT-DATA:ephemeral'] = kwargs.get('ephemeral')
+ post_body['ephemeral'] = kwargs.get('ephemeral')
if kwargs.get('swap'):
post_body['swap'] = kwargs.get('swap')
if kwargs.get('rxtx'):
- post_body['rxtx_factor'] = kwargs.get('rxtx')
+ post_body['os-flavor-rxtx:rxtx_factor'] = kwargs.get('rxtx')
if kwargs.get('is_public'):
post_body['flavor-access:is_public'] = kwargs.get('is_public')
post_body = json.dumps({'flavor': post_body})
diff --git a/tempest/services/compute/v3/json/hosts_client.py b/tempest/services/compute/v3/json/hosts_client.py
index 85cc34f..e33dd5f 100644
--- a/tempest/services/compute/v3/json/hosts_client.py
+++ b/tempest/services/compute/v3/json/hosts_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -18,14 +16,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class HostsV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HostsV3ClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(HostsV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_hosts(self, params=None):
"""Lists all hosts."""
diff --git a/tempest/services/compute/v3/json/hypervisor_client.py b/tempest/services/compute/v3/json/hypervisor_client.py
index fa1255a..e07a1fb 100644
--- a/tempest/services/compute/v3/json/hypervisor_client.py
+++ b/tempest/services/compute/v3/json/hypervisor_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation.
# All Rights Reserved.
#
@@ -18,15 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class HypervisorV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HypervisorV3ClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(HypervisorV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def get_hypervisor_list(self):
"""List hypervisors information."""
diff --git a/tempest/services/compute/v3/json/instance_usage_audit_log_client.py b/tempest/services/compute/v3/json/instance_usage_audit_log_client.py
index 07ce1bb..3a6ac5f 100644
--- a/tempest/services/compute/v3/json/instance_usage_audit_log_client.py
+++ b/tempest/services/compute/v3/json/instance_usage_audit_log_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -18,23 +16,23 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
-class InstanceUsagesAuditLogClientJSON(RestClient):
+class InstanceUsagesAuditLogV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(InstanceUsagesAuditLogClientJSON, self).__init__(
- config, username, password, auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(InstanceUsagesAuditLogV3ClientJSON, self).__init__(
+ auth_provider)
+ self.service = CONF.compute.catalog_v3_type
- def list_instance_usage_audit_logs(self):
- url = 'os-instance_usage_audit_log'
- resp, body = self.get(url)
- body = json.loads(body)
- return resp, body["instance_usage_audit_logs"]
-
- def get_instance_usage_audit_log(self, time_before):
- url = 'os-instance_usage_audit_log/%s' % time_before
+ def list_instance_usage_audit_logs(self, time_before=None):
+ if time_before:
+ url = 'os-instance-usage-audit-log?before=%s' % time_before
+ else:
+ url = 'os-instance-usage-audit-log'
resp, body = self.get(url)
body = json.loads(body)
return resp, body["instance_usage_audit_log"]
diff --git a/tempest/services/compute/v3/json/interfaces_client.py b/tempest/services/compute/v3/json/interfaces_client.py
index 7fb0fa9..053b9af 100644
--- a/tempest/services/compute/v3/json/interfaces_client.py
+++ b/tempest/services/compute/v3/json/interfaces_client.py
@@ -17,16 +17,17 @@
import time
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class InterfacesV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(InterfacesV3ClientJSON, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(InterfacesV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_interfaces(self, server):
resp, body = self.get('servers/%s/os-attach-interfaces' % server)
@@ -35,14 +36,14 @@
def create_interface(self, server, port_id=None, network_id=None,
fixed_ip=None):
- post_body = dict(interface_attachment=dict())
+ post_body = dict()
if port_id:
post_body['port_id'] = port_id
if network_id:
post_body['net_id'] = network_id
if fixed_ip:
post_body['fixed_ips'] = [dict(ip_address=fixed_ip)]
- post_body = json.dumps(post_body)
+ post_body = json.dumps({'interface_attachment': post_body})
resp, body = self.post('servers/%s/os-attach-interfaces' % server,
headers=self.headers,
body=post_body)
diff --git a/tempest/services/compute/v3/json/keypairs_client.py b/tempest/services/compute/v3/json/keypairs_client.py
index 500aa0e..05dbe25 100644
--- a/tempest/services/compute/v3/json/keypairs_client.py
+++ b/tempest/services/compute/v3/json/keypairs_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,14 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class KeyPairsV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(KeyPairsV3ClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(KeyPairsV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_keypairs(self):
resp, body = self.get("keypairs")
diff --git a/tempest/services/compute/v3/json/limits_client.py b/tempest/services/compute/v3/json/limits_client.py
deleted file mode 100644
index 3e53e3e..0000000
--- a/tempest/services/compute/v3/json/limits_client.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# 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 json
-from tempest.common.rest_client import RestClient
-
-
-class LimitsClientJSON(RestClient):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(LimitsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
-
- def get_absolute_limits(self):
- resp, body = self.get("limits")
- body = json.loads(body)
- return resp, body['limits']['absolute']
-
- def get_specific_absolute_limit(self, absolute_limit):
- resp, body = self.get("limits")
- body = json.loads(body)
- if absolute_limit not in body['limits']['absolute']:
- return None
- else:
- return body['limits']['absolute'][absolute_limit]
diff --git a/tempest/services/compute/v3/json/quotas_client.py b/tempest/services/compute/v3/json/quotas_client.py
index cae2332..1ec8651 100644
--- a/tempest/services/compute/v3/json/quotas_client.py
+++ b/tempest/services/compute/v3/json/quotas_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 NTT Data
# All Rights Reserved.
#
@@ -18,14 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class QuotasV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(QuotasV3ClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(QuotasV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def get_quota_set(self, tenant_id):
"""List the quota set for a tenant."""
diff --git a/tempest/services/compute/v3/json/servers_client.py b/tempest/services/compute/v3/json/servers_client.py
index da31036..11538f5 100644
--- a/tempest/services/compute/v3/json/servers_client.py
+++ b/tempest/services/compute/v3/json/servers_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# Copyright 2013 IBM Corp
@@ -23,17 +21,17 @@
from tempest.common.rest_client import RestClient
from tempest.common import waiters
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class ServersV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url,
- tenant_name=None, auth_version='v2'):
- super(ServersV3ClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name,
- auth_version=auth_version)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(ServersV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def create_server(self, name, image_ref, flavor_ref, **kwargs):
"""
@@ -45,8 +43,6 @@
admin_password: Sets the initial root password.
key_name: Key name of keypair that was created earlier.
meta: A dictionary of values to be used as metadata.
- personality: A list of dictionaries for files to be injected into
- the server.
security_groups: A list of security group dicts.
networks: A list of network dicts with UUID and fixed_ip.
user_data: User data for instance.
@@ -64,7 +60,7 @@
'flavor_ref': flavor_ref
}
- for option in ['personality', 'admin_password', 'key_name', 'networks',
+ for option in ['admin_password', 'key_name', 'networks',
('os-security-groups:security_groups',
'security_groups'),
('os-user-data:user_data', 'user_data'),
@@ -77,7 +73,7 @@
('metadata', 'meta'),
('os-disk-config:disk_config', 'disk_config'),
('os-multiple-create:return_reservation_id',
- 'return_reservation_id')]:
+ 'return_reservation_id')]:
if isinstance(option, tuple):
post_param = option[0]
key = option[1]
@@ -103,7 +99,6 @@
Updates the properties of an existing server.
server_id: The id of an existing server.
name: The name of the server.
- personality: A list of files to be injected into the server.
access_ip_v4: The IPv4 access address for the server.
access_ip_v6: The IPv6 access address for the server.
"""
@@ -163,10 +158,12 @@
body = json.loads(body)
return resp, body
- def wait_for_server_status(self, server_id, status, extra_timeout=0):
+ def wait_for_server_status(self, server_id, status, extra_timeout=0,
+ raise_on_error=True):
"""Waits for a server to reach a given status."""
return waiters.wait_for_server_status(self, server_id, status,
- extra_timeout=extra_timeout)
+ extra_timeout=extra_timeout,
+ raise_on_error=raise_on_error)
def wait_for_server_termination(self, server_id, ignore_error=False):
"""Waits for server to reach termination."""
@@ -346,19 +343,19 @@
return self.action(server_id, 'unlock', None, **kwargs)
def suspend_server(self, server_id, **kwargs):
- """Suspends the provded server."""
+ """Suspends the provided server."""
return self.action(server_id, 'suspend', None, **kwargs)
def resume_server(self, server_id, **kwargs):
- """Un-suspends the provded server."""
+ """Un-suspends the provided server."""
return self.action(server_id, 'resume', None, **kwargs)
def pause_server(self, server_id, **kwargs):
- """Pauses the provded server."""
+ """Pauses the provided server."""
return self.action(server_id, 'pause', None, **kwargs)
def unpause_server(self, server_id, **kwargs):
- """Un-pauses the provded server."""
+ """Un-pauses the provided server."""
return self.action(server_id, 'unpause', None, **kwargs)
def reset_state(self, server_id, state='error'):
@@ -377,10 +374,9 @@
return self.action(server_id, 'get_console_output', 'output',
length=length)
- def rescue_server(self, server_id, admin_password=None):
+ def rescue_server(self, server_id, **kwargs):
"""Rescue the provided server."""
- return self.action(server_id, 'rescue', None,
- admin_password=admin_password)
+ return self.action(server_id, 'rescue', None, **kwargs)
def unrescue_server(self, server_id):
"""Unrescue the provided server."""
diff --git a/tempest/services/compute/v3/json/services_client.py b/tempest/services/compute/v3/json/services_client.py
index 41564e5..1082ea9 100644
--- a/tempest/services/compute/v3/json/services_client.py
+++ b/tempest/services/compute/v3/json/services_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -20,14 +18,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class ServicesV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ServicesV3ClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(ServicesV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_services(self, params=None):
url = 'os-services'
diff --git a/tempest/services/compute/v3/json/tenant_usages_client.py b/tempest/services/compute/v3/json/tenant_usages_client.py
index 298f363..6d59e20 100644
--- a/tempest/services/compute/v3/json/tenant_usages_client.py
+++ b/tempest/services/compute/v3/json/tenant_usages_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -19,14 +17,16 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class TenantUsagesV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(TenantUsagesV3ClientJSON, self).__init__(
- config, username, password, auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
+ def __init__(self, auth_provider):
+ super(TenantUsagesV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
def list_tenant_usages(self, params=None):
url = 'os-simple-tenant-usage'
diff --git a/tempest/services/compute/v3/json/version_client.py b/tempest/services/compute/v3/json/version_client.py
new file mode 100644
index 0000000..b560c58
--- /dev/null
+++ b/tempest/services/compute/v3/json/version_client.py
@@ -0,0 +1,33 @@
+# Copyright 2014 NEC Corporation.
+# All Rights Reserved.
+#
+# 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 json
+
+from tempest.common import rest_client
+from tempest import config
+
+CONF = config.CONF
+
+
+class VersionV3ClientJSON(rest_client.RestClient):
+
+ def __init__(self, auth_provider):
+ super(VersionV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_v3_type
+
+ def get_version(self):
+ resp, body = self.get('')
+ body = json.loads(body)
+ return resp, body['version']
diff --git a/tempest/services/compute/v3/xml/aggregates_client.py b/tempest/services/compute/v3/xml/aggregates_client.py
deleted file mode 100644
index 7563fd6..0000000
--- a/tempest/services/compute/v3/xml/aggregates_client.py
+++ /dev/null
@@ -1,130 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 NEC Corporation.
-# All Rights Reserved.
-#
-# 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 lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest import exceptions
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import Text
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class AggregatesV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AggregatesV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _format_aggregate(self, g):
- agg = xml_to_json(g)
- aggregate = {}
- for key, value in agg.items():
- if key == 'hosts':
- aggregate['hosts'] = []
- for k, v in value.items():
- aggregate['hosts'].append(v)
- elif key == 'availability_zone':
- aggregate[key] = None if value == 'None' else value
- else:
- aggregate[key] = value
- return aggregate
-
- def _parse_array(self, node):
- return [self._format_aggregate(x) for x in node]
-
- def list_aggregates(self):
- """Get aggregate list."""
- resp, body = self.get("os-aggregates", self.headers)
- aggregates = self._parse_array(etree.fromstring(body))
- return resp, aggregates
-
- def get_aggregate(self, aggregate_id):
- """Get details of the given aggregate."""
- resp, body = self.get("os-aggregates/%s" % str(aggregate_id),
- self.headers)
- aggregate = self._format_aggregate(etree.fromstring(body))
- return resp, aggregate
-
- def create_aggregate(self, name, availability_zone=None):
- """Creates a new aggregate."""
- post_body = Element("aggregate",
- name=name,
- availability_zone=availability_zone)
- resp, body = self.post('os-aggregates',
- str(Document(post_body)),
- self.headers)
- aggregate = self._format_aggregate(etree.fromstring(body))
- return resp, aggregate
-
- def update_aggregate(self, aggregate_id, name, availability_zone=None):
- """Update a aggregate."""
- put_body = Element("aggregate",
- name=name,
- availability_zone=availability_zone)
- resp, body = self.put('os-aggregates/%s' % str(aggregate_id),
- str(Document(put_body)),
- self.headers)
- aggregate = self._format_aggregate(etree.fromstring(body))
- return resp, aggregate
-
- def delete_aggregate(self, aggregate_id):
- """Deletes the given aggregate."""
- return self.delete("os-aggregates/%s" % str(aggregate_id),
- self.headers)
-
- def is_resource_deleted(self, id):
- try:
- self.get_aggregate(id)
- except exceptions.NotFound:
- return True
- return False
-
- def add_host(self, aggregate_id, host):
- """Adds a host to the given aggregate."""
- post_body = Element("add_host", host=host)
- resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
- str(Document(post_body)),
- self.headers)
- aggregate = self._format_aggregate(etree.fromstring(body))
- return resp, aggregate
-
- def remove_host(self, aggregate_id, host):
- """Removes a host from the given aggregate."""
- post_body = Element("remove_host", host=host)
- resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
- str(Document(post_body)),
- self.headers)
- aggregate = self._format_aggregate(etree.fromstring(body))
- return resp, aggregate
-
- def set_metadata(self, aggregate_id, meta):
- """Replaces the aggregate's existing metadata with new metadata."""
- post_body = Element("set_metadata")
- metadata = Element("metadata")
- post_body.append(metadata)
- for k, v in meta.items():
- meta = Element(k)
- meta.append(Text(v))
- metadata.append(meta)
- resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
- str(Document(post_body)),
- self.headers)
- aggregate = self._format_aggregate(etree.fromstring(body))
- return resp, aggregate
diff --git a/tempest/services/compute/v3/xml/availability_zone_client.py b/tempest/services/compute/v3/xml/availability_zone_client.py
deleted file mode 100644
index 35fb2b1..0000000
--- a/tempest/services/compute/v3/xml/availability_zone_client.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 NEC Corporation
-# All Rights Reserved.
-#
-# 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 lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class AvailabilityZoneV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AvailabilityZoneV3ClientXML, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _parse_array(self, node):
- return [xml_to_json(x) for x in node]
-
- def get_availability_zone_list(self):
- resp, body = self.get('os-availability-zone', self.headers)
- availability_zone = self._parse_array(etree.fromstring(body))
- return resp, availability_zone
-
- def get_availability_zone_list_detail(self):
- resp, body = self.get('os-availability-zone/detail', self.headers)
- availability_zone = self._parse_array(etree.fromstring(body))
- return resp, availability_zone
diff --git a/tempest/services/compute/v3/xml/certificates_client.py b/tempest/services/compute/v3/xml/certificates_client.py
deleted file mode 100644
index 99dc337..0000000
--- a/tempest/services/compute/v3/xml/certificates_client.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 IBM Corp
-# All Rights Reserved.
-#
-# 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 tempest.common.rest_client import RestClientXML
-
-
-class CertificatesV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(CertificatesV3ClientXML, self).__init__(config, username,
- password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def get_certificate(self, id):
- url = "os-certificates/%s" % (id)
- resp, body = self.get(url, self.headers)
- body = self._parse_resp(body)
- return resp, body
-
- def create_certificate(self):
- """create certificates."""
- url = "os-certificates"
- resp, body = self.post(url, None, self.headers)
- body = self._parse_resp(body)
- return resp, body
diff --git a/tempest/services/compute/v3/xml/extensions_client.py b/tempest/services/compute/v3/xml/extensions_client.py
deleted file mode 100644
index 8f97692..0000000
--- a/tempest/services/compute/v3/xml/extensions_client.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# 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 lxml import etree
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class ExtensionsV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ExtensionsV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _parse_array(self, node):
- array = []
- for child in node:
- array.append(xml_to_json(child))
- return array
-
- def list_extensions(self):
- url = 'extensions'
- resp, body = self.get(url, self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, {'extensions': body}
-
- def is_enabled(self, extension):
- _, extensions = self.list_extensions()
- exts = extensions['extensions']
- return any([e for e in exts if e['name'] == extension])
-
- def get_extension(self, extension_alias):
- resp, body = self.get('extensions/%s' % extension_alias, self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
diff --git a/tempest/services/compute/v3/xml/flavors_client.py b/tempest/services/compute/v3/xml/flavors_client.py
deleted file mode 100644
index 04c21b4..0000000
--- a/tempest/services/compute/v3/xml/flavors_client.py
+++ /dev/null
@@ -1,212 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack Foundation
-# All Rights Reserved.
-#
-# 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 urllib
-
-from lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import Text
-from tempest.services.compute.xml.common import xml_to_json
-from tempest.services.compute.xml.common import XMLNS_V3
-
-XMLNS_OS_FLV_ACCESS = \
- "http://docs.openstack.org/compute/core/flavor-access/api/v3"
-
-
-class FlavorsV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FlavorsV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _format_flavor(self, f):
- flavor = {'links': []}
- for k, v in f.items():
- if k == 'id':
- flavor['id'] = v
- continue
-
- if k == 'link':
- flavor['links'].append(v)
- continue
-
- if k == '{%s}is_public' % XMLNS_OS_FLV_ACCESS:
- k = 'flavor-access:is_public'
- v = True if v == 'True' else False
-
- if k == 'extra_specs':
- k = 'flavor-extra-specs:extra_specs'
- flavor[k] = dict(v)
- continue
-
- try:
- v = int(v)
- except ValueError:
- try:
- v = float(v)
- except ValueError:
- pass
-
- flavor[k] = v
-
- return flavor
-
- def _parse_array(self, node):
- return [self._format_flavor(xml_to_json(x)) for x in node]
-
- def _list_flavors(self, url, params):
- if params:
- url += "?%s" % urllib.urlencode(params)
-
- resp, body = self.get(url, self.headers)
- flavors = self._parse_array(etree.fromstring(body))
- return resp, flavors
-
- def list_flavors(self, params=None):
- url = 'flavors'
- return self._list_flavors(url, params)
-
- def list_flavors_with_detail(self, params=None):
- url = 'flavors/detail'
- return self._list_flavors(url, params)
-
- def get_flavor_details(self, flavor_id):
- resp, body = self.get("flavors/%s" % str(flavor_id), self.headers)
- body = xml_to_json(etree.fromstring(body))
- flavor = self._format_flavor(body)
- return resp, flavor
-
- def create_flavor(self, name, ram, vcpus, disk, flavor_id, **kwargs):
- """Creates a new flavor or instance type."""
- flavor = Element("flavor",
- xmlns=XMLNS_V3,
- ram=ram,
- vcpus=vcpus,
- disk=disk,
- id=flavor_id,
- name=name)
- if kwargs.get('rxtx'):
- flavor.add_attr('rxtx_factor', kwargs.get('rxtx'))
- if kwargs.get('swap'):
- flavor.add_attr('swap', kwargs.get('swap'))
- if kwargs.get('ephemeral'):
- flavor.add_attr('ephemeral', kwargs.get('ephemeral'))
- if kwargs.get('is_public'):
- flavor.add_attr('flavor-access:is_public',
- kwargs.get('is_public'))
- flavor.add_attr('xmlns:flavor-access', XMLNS_OS_FLV_ACCESS)
- resp, body = self.post('flavors', str(Document(flavor)), self.headers)
- body = xml_to_json(etree.fromstring(body))
- flavor = self._format_flavor(body)
- return resp, flavor
-
- def delete_flavor(self, flavor_id):
- """Deletes the given flavor."""
- return self.delete("flavors/%s" % str(flavor_id), self.headers)
-
- def is_resource_deleted(self, id):
- # Did not use get_flavor_details(id) for verification as it gives
- # 200 ok even for deleted id. LP #981263
- # we can remove the loop here and use get by ID when bug gets sortedout
- resp, flavors = self.list_flavors_with_detail()
- for flavor in flavors:
- if flavor['id'] == id:
- return False
- return True
-
- def set_flavor_extra_spec(self, flavor_id, specs):
- """Sets extra Specs to the mentioned flavor."""
- extra_specs = Element("extra_specs")
- for key in specs.keys():
- extra_specs.add_attr(key, specs[key])
- resp, body = self.post('flavors/%s/flavor-extra-specs' % flavor_id,
- str(Document(extra_specs)), self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def get_flavor_extra_spec(self, flavor_id):
- """Gets extra Specs of the mentioned flavor."""
- resp, body = self.get('flavors/%s/flavor-extra-specs' % flavor_id,
- self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def get_flavor_extra_spec_with_key(self, flavor_id, key):
- """Gets extra Specs key-value of the mentioned flavor and key."""
- resp, xml_body = self.get('flavors/%s/flavor-extra-specs/%s' %
- (str(flavor_id), key), self.headers)
- body = {}
- element = etree.fromstring(xml_body)
- key = element.get('key')
- body[key] = xml_to_json(element)
- return resp, body
-
- def update_flavor_extra_spec(self, flavor_id, key, **kwargs):
- """Update extra Specs details of the mentioned flavor and key."""
- doc = Document()
- for (k, v) in kwargs.items():
- element = Element(k)
- doc.append(element)
- value = Text(v)
- element.append(value)
-
- resp, body = self.put('flavors/%s/flavor-extra-specs/%s' %
- (flavor_id, key),
- str(doc), self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, {key: body}
-
- def unset_flavor_extra_spec(self, flavor_id, key):
- """Unsets an extra spec based on the mentioned flavor and key."""
- return self.delete('flavors/%s/flavor-extra-specs/%s' %
- (str(flavor_id), key))
-
- def _parse_array_access(self, node):
- return [xml_to_json(x) for x in node]
-
- def list_flavor_access(self, flavor_id):
- """Gets flavor access information given the flavor id."""
- resp, body = self.get('flavors/%s/flavor-access' % str(flavor_id),
- self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
-
- def add_flavor_access(self, flavor_id, tenant_id):
- """Add flavor access for the specified tenant."""
- doc = Document()
- server = Element("add_tenant_access")
- doc.append(server)
- server.add_attr("tenant_id", tenant_id)
- resp, body = self.post('flavors/%s/action' % str(flavor_id),
- str(doc), self.headers)
- body = self._parse_array_access(etree.fromstring(body))
- return resp, body
-
- def remove_flavor_access(self, flavor_id, tenant_id):
- """Remove flavor access from the specified tenant."""
- doc = Document()
- server = Element("remove_tenant_access")
- doc.append(server)
- server.add_attr("tenant_id", tenant_id)
- resp, body = self.post('flavors/%s/action' % str(flavor_id),
- str(doc), self.headers)
- body = self._parse_array_access(etree.fromstring(body))
- return resp, body
diff --git a/tempest/services/compute/v3/xml/hosts_client.py b/tempest/services/compute/v3/xml/hosts_client.py
deleted file mode 100644
index 82fb076..0000000
--- a/tempest/services/compute/v3/xml/hosts_client.py
+++ /dev/null
@@ -1,92 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2013 IBM Corp.
-#
-# 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 urllib
-
-from lxml import etree
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class HostsV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HostsV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def list_hosts(self, params=None):
- """Lists all hosts."""
-
- url = 'os-hosts'
- if params:
- url += '?%s' % urllib.urlencode(params)
-
- resp, body = self.get(url, self.headers)
- node = etree.fromstring(body)
- body = [xml_to_json(x) for x in node.getchildren()]
- return resp, body
-
- def show_host_detail(self, hostname):
- """Show detail information for the host."""
-
- resp, body = self.get("os-hosts/%s" % str(hostname), self.headers)
- node = etree.fromstring(body)
- body = [xml_to_json(node)]
- return resp, body
-
- def update_host(self, hostname, **kwargs):
- """Update a host."""
-
- request_body = Element("host")
- if kwargs:
- for k, v in kwargs.iteritems():
- request_body.append(Element(k, v))
- resp, body = self.put("os-hosts/%s" % str(hostname),
- str(Document(request_body)),
- self.headers)
- node = etree.fromstring(body)
- body = [xml_to_json(x) for x in node.getchildren()]
- return resp, body
-
- def startup_host(self, hostname):
- """Startup a host."""
-
- resp, body = self.get("os-hosts/%s/startup" % str(hostname),
- self.headers)
- node = etree.fromstring(body)
- body = [xml_to_json(x) for x in node.getchildren()]
- return resp, body
-
- def shutdown_host(self, hostname):
- """Shutdown a host."""
-
- resp, body = self.get("os-hosts/%s/shutdown" % str(hostname),
- self.headers)
- node = etree.fromstring(body)
- body = [xml_to_json(x) for x in node.getchildren()]
- return resp, body
-
- def reboot_host(self, hostname):
- """Reboot a host."""
-
- resp, body = self.get("os-hosts/%s/reboot" % str(hostname),
- self.headers)
- node = etree.fromstring(body)
- body = [xml_to_json(x) for x in node.getchildren()]
- return resp, body
diff --git a/tempest/services/compute/v3/xml/hypervisor_client.py b/tempest/services/compute/v3/xml/hypervisor_client.py
deleted file mode 100644
index ce0207d..0000000
--- a/tempest/services/compute/v3/xml/hypervisor_client.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 IBM Corporation
-# All Rights Reserved.
-#
-# 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 lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class HypervisorV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HypervisorV3ClientXML, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _parse_array(self, node):
- return [xml_to_json(x) for x in node]
-
- def get_hypervisor_list(self):
- """List hypervisors information."""
- resp, body = self.get('os-hypervisors', self.headers)
- hypervisors = self._parse_array(etree.fromstring(body))
- return resp, hypervisors
-
- def get_hypervisor_list_details(self):
- """Show detailed hypervisors information."""
- resp, body = self.get('os-hypervisors/detail', self.headers)
- hypervisors = self._parse_array(etree.fromstring(body))
- return resp, hypervisors
-
- def get_hypervisor_show_details(self, hyper_id):
- """Display the details of the specified hypervisor."""
- resp, body = self.get('os-hypervisors/%s' % hyper_id,
- self.headers)
- hypervisor = xml_to_json(etree.fromstring(body))
- return resp, hypervisor
-
- def get_hypervisor_servers(self, hyper_name):
- """List instances belonging to the specified hypervisor."""
- resp, body = self.get('os-hypervisors/%s/servers' % hyper_name,
- self.headers)
- hypervisors = self._parse_array(etree.fromstring(body))
- return resp, hypervisors
-
- def get_hypervisor_stats(self):
- """Get hypervisor statistics over all compute nodes."""
- resp, body = self.get('os-hypervisors/statistics', self.headers)
- stats = xml_to_json(etree.fromstring(body))
- return resp, stats
-
- def get_hypervisor_uptime(self, hyper_id):
- """Display the uptime of the specified hypervisor."""
- resp, body = self.get('os-hypervisors/%s/uptime' % hyper_id,
- self.headers)
- uptime = xml_to_json(etree.fromstring(body))
- return resp, uptime
-
- def search_hypervisor(self, hyper_name):
- """Search specified hypervisor."""
- resp, body = self.get('os-hypervisors/search?query=%s' % hyper_name,
- self.headers)
- hypervisors = self._parse_array(etree.fromstring(body))
- return resp, hypervisors
diff --git a/tempest/services/compute/v3/xml/instance_usage_audit_log_client.py b/tempest/services/compute/v3/xml/instance_usage_audit_log_client.py
deleted file mode 100644
index 175997b..0000000
--- a/tempest/services/compute/v3/xml/instance_usage_audit_log_client.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 IBM Corporation
-# All Rights Reserved.
-#
-# 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 lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class InstanceUsagesAuditLogClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(InstanceUsagesAuditLogClientXML, self).__init__(
- config, username, password, auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
-
- def list_instance_usage_audit_logs(self):
- url = 'os-instance_usage_audit_log'
- resp, body = self.get(url, self.headers)
- instance_usage_audit_logs = xml_to_json(etree.fromstring(body))
- return resp, instance_usage_audit_logs
-
- def get_instance_usage_audit_log(self, time_before):
- url = 'os-instance_usage_audit_log/%s' % time_before
- resp, body = self.get(url, self.headers)
- instance_usage_audit_log = xml_to_json(etree.fromstring(body))
- return resp, instance_usage_audit_log
diff --git a/tempest/services/compute/v3/xml/interfaces_client.py b/tempest/services/compute/v3/xml/interfaces_client.py
deleted file mode 100644
index 870c130..0000000
--- a/tempest/services/compute/v3/xml/interfaces_client.py
+++ /dev/null
@@ -1,108 +0,0 @@
-# Copyright 2013 IBM Corp.
-# All Rights Reserved.
-#
-# 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 time
-
-from lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest import exceptions
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import Text
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class InterfacesV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(InterfacesV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _process_xml_interface(self, node):
- iface = xml_to_json(node)
- # NOTE(danms): if multiple addresses per interface is ever required,
- # xml_to_json will need to be fixed or replaced in this case
- iface['fixed_ips'] = [dict(iface['fixed_ips']['fixed_ip'].items())]
- return iface
-
- def list_interfaces(self, server):
- resp, body = self.get('servers/%s/os-attach-interfaces' % server,
- self.headers)
- node = etree.fromstring(body)
- interfaces = [self._process_xml_interface(x)
- for x in node.getchildren()]
- return resp, interfaces
-
- def create_interface(self, server, port_id=None, network_id=None,
- fixed_ip=None):
- doc = Document()
- iface = Element('interface_attachment')
- if port_id:
- _port_id = Element('port_id')
- _port_id.append(Text(port_id))
- iface.append(_port_id)
- if network_id:
- _network_id = Element('net_id')
- _network_id.append(Text(network_id))
- iface.append(_network_id)
- if fixed_ip:
- _fixed_ips = Element('fixed_ips')
- _fixed_ip = Element('fixed_ip')
- _ip_address = Element('ip_address')
- _ip_address.append(Text(fixed_ip))
- _fixed_ip.append(_ip_address)
- _fixed_ips.append(_fixed_ip)
- iface.append(_fixed_ips)
- doc.append(iface)
- resp, body = self.post('servers/%s/os-attach-interfaces' % server,
- headers=self.headers,
- body=str(doc))
- body = self._process_xml_interface(etree.fromstring(body))
- return resp, body
-
- def show_interface(self, server, port_id):
- resp, body =\
- self.get('servers/%s/os-attach-interfaces/%s' % (server, port_id),
- self.headers)
- body = self._process_xml_interface(etree.fromstring(body))
- return resp, body
-
- def delete_interface(self, server, port_id):
- resp, body =\
- self.delete('servers/%s/os-attach-interfaces/%s' % (server,
- port_id))
- return resp, body
-
- def wait_for_interface_status(self, server, port_id, status):
- """Waits for a interface to reach a given status."""
- resp, body = self.show_interface(server, port_id)
- interface_status = body['port_state']
- start = int(time.time())
-
- while(interface_status != status):
- time.sleep(self.build_interval)
- resp, body = self.show_interface(server, port_id)
- interface_status = body['port_state']
-
- timed_out = int(time.time()) - start >= self.build_timeout
-
- if interface_status != status and timed_out:
- message = ('Interface %s failed to reach %s status within '
- 'the required time (%s s).' %
- (port_id, status, self.build_timeout))
- raise exceptions.TimeoutException(message)
- return resp, body
diff --git a/tempest/services/compute/v3/xml/keypairs_client.py b/tempest/services/compute/v3/xml/keypairs_client.py
deleted file mode 100644
index d87daff..0000000
--- a/tempest/services/compute/v3/xml/keypairs_client.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2012 IBM Corp.
-# All Rights Reserved.
-#
-# 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 lxml import etree
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import Text
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class KeyPairsV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(KeyPairsV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def list_keypairs(self):
- resp, body = self.get("keypairs", self.headers)
- node = etree.fromstring(body)
- body = [{'keypair': xml_to_json(x)} for x in node.getchildren()]
- return resp, body
-
- def get_keypair(self, key_name):
- resp, body = self.get("keypairs/%s" % str(key_name), self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def create_keypair(self, name, pub_key=None):
- doc = Document()
-
- keypair_element = Element("keypair")
-
- if pub_key:
- public_key_element = Element("public_key")
- public_key_text = Text(pub_key)
- public_key_element.append(public_key_text)
- keypair_element.append(public_key_element)
-
- name_element = Element("name")
- name_text = Text(name)
- name_element.append(name_text)
- keypair_element.append(name_element)
-
- doc.append(keypair_element)
-
- resp, body = self.post("keypairs",
- headers=self.headers, body=str(doc))
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def delete_keypair(self, key_name):
- return self.delete("keypairs/%s" % str(key_name))
diff --git a/tempest/services/compute/v3/xml/limits_client.py b/tempest/services/compute/v3/xml/limits_client.py
deleted file mode 100644
index 704de52..0000000
--- a/tempest/services/compute/v3/xml/limits_client.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2012 IBM Corp.
-# All Rights Reserved.
-#
-# 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 lxml import objectify
-
-from tempest.common.rest_client import RestClientXML
-
-NS = "{http://docs.openstack.org/common/api/v1.0}"
-
-
-class LimitsClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(LimitsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
-
- def get_absolute_limits(self):
- resp, body = self.get("limits", self.headers)
- body = objectify.fromstring(body)
- lim = NS + 'absolute'
- ret = {}
-
- for el in body[lim].iterchildren():
- attributes = el.attrib
- ret[attributes['name']] = attributes['value']
- return resp, ret
-
- def get_specific_absolute_limit(self, absolute_limit):
- resp, body = self.get("limits", self.headers)
- body = objectify.fromstring(body)
- lim = NS + 'absolute'
- ret = {}
-
- for el in body[lim].iterchildren():
- attributes = el.attrib
- ret[attributes['name']] = attributes['value']
- if absolute_limit not in ret:
- return None
- else:
- return ret[absolute_limit]
diff --git a/tempest/services/compute/v3/xml/quotas_client.py b/tempest/services/compute/v3/xml/quotas_client.py
deleted file mode 100644
index 7ef2274..0000000
--- a/tempest/services/compute/v3/xml/quotas_client.py
+++ /dev/null
@@ -1,113 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2012 NTT Data
-# All Rights Reserved.
-#
-# 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 lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import xml_to_json
-from tempest.services.compute.xml.common import XMLNS_V3
-
-
-class QuotasV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(QuotasV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _format_quota(self, q):
- quota = {}
- for k, v in q.items():
- try:
- v = int(v)
- except ValueError:
- pass
-
- quota[k] = v
-
- return quota
-
- def _parse_array(self, node):
- return [self._format_quota(xml_to_json(x)) for x in node]
-
- def get_quota_set(self, tenant_id):
- """List the quota set for a tenant."""
-
- url = 'os-quota-sets/%s' % str(tenant_id)
- resp, body = self.get(url, self.headers)
- body = xml_to_json(etree.fromstring(body))
- body = self._format_quota(body)
- return resp, body
-
- def get_default_quota_set(self, tenant_id):
- """List the default quota set for a tenant."""
-
- url = 'os-quota-sets/%s/defaults' % str(tenant_id)
- resp, body = self.get(url, self.headers)
- body = xml_to_json(etree.fromstring(body))
- body = self._format_quota(body)
- return resp, body
-
- def update_quota_set(self, tenant_id, force=None,
- metadata_items=None, ram=None, floating_ips=None,
- fixed_ips=None, key_pairs=None, instances=None,
- security_group_rules=None, cores=None,
- security_groups=None):
- """
- Updates the tenant's quota limits for one or more resources
- """
- post_body = Element("quota_set",
- xmlns=XMLNS_V3)
-
- if force is not None:
- post_body.add_attr('force', force)
-
- if metadata_items is not None:
- post_body.add_attr('metadata_items', metadata_items)
-
- if ram is not None:
- post_body.add_attr('ram', ram)
-
- if floating_ips is not None:
- post_body.add_attr('floating_ips', floating_ips)
-
- if fixed_ips is not None:
- post_body.add_attr('fixed_ips', fixed_ips)
-
- if key_pairs is not None:
- post_body.add_attr('key_pairs', key_pairs)
-
- if instances is not None:
- post_body.add_attr('instances', instances)
-
- if security_group_rules is not None:
- post_body.add_attr('security_group_rules', security_group_rules)
-
- if cores is not None:
- post_body.add_attr('cores', cores)
-
- if security_groups is not None:
- post_body.add_attr('security_groups', security_groups)
-
- resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
- str(Document(post_body)),
- self.headers)
- body = xml_to_json(etree.fromstring(body))
- body = self._format_quota(body)
- return resp, body
diff --git a/tempest/services/compute/v3/xml/servers_client.py b/tempest/services/compute/v3/xml/servers_client.py
deleted file mode 100644
index a5cc291..0000000
--- a/tempest/services/compute/v3/xml/servers_client.py
+++ /dev/null
@@ -1,670 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2012 IBM Corp.
-# Copyright 2013 Hewlett-Packard Development Company, L.P.
-# All Rights Reserved.
-#
-# 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 time
-import urllib
-
-from lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest.common import waiters
-from tempest import exceptions
-from tempest.openstack.common import log as logging
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import Text
-from tempest.services.compute.xml.common import xml_to_json
-from tempest.services.compute.xml.common import XMLNS_V3
-
-
-LOG = logging.getLogger(__name__)
-
-
-def _translate_ip_xml_json(ip):
- """
- Convert the address version to int.
- """
- ip = dict(ip)
- version = ip.get('version')
- if version:
- ip['version'] = int(version)
- if ip.get('type'):
- ip['type'] = ip.get('type')
- if ip.get('mac_addr'):
- ip['mac_addr'] = ip.get('mac_addr')
- return ip
-
-
-def _translate_network_xml_to_json(network):
- return [_translate_ip_xml_json(ip.attrib)
- for ip in network.findall('{%s}ip' % XMLNS_V3)]
-
-
-def _translate_addresses_xml_to_json(xml_addresses):
- return dict((network.attrib['id'], _translate_network_xml_to_json(network))
- for network in xml_addresses.findall('{%s}network' % XMLNS_V3))
-
-
-def _translate_server_xml_to_json(xml_dom):
- """Convert server XML to server JSON.
-
- The addresses collection does not convert well by the dumb xml_to_json.
- This method does some pre and post-processing to deal with that.
-
- Translate XML addresses subtree to JSON.
-
- Having xml_doc similar to
- <api:server xmlns:api="http://docs.openstack.org/compute/api/v3">
- <api:addresses>
- <api:network id="foo_novanetwork">
- <api:ip version="4" addr="192.168.0.4"/>
- </api:network>
- <api:network id="bar_novanetwork">
- <api:ip version="4" addr="10.1.0.4"/>
- <api:ip version="6" addr="2001:0:0:1:2:3:4:5"/>
- </api:network>
- </api:addresses>
- </api:server>
-
- the _translate_server_xml_to_json(etree.fromstring(xml_doc)) should produce
- something like
-
- {'addresses': {'bar_novanetwork': [{'addr': '10.1.0.4', 'version': 4},
- {'addr': '2001:0:0:1:2:3:4:5',
- 'version': 6}],
- 'foo_novanetwork': [{'addr': '192.168.0.4', 'version': 4}]}}
- """
- nsmap = {'api': XMLNS_V3}
- addresses = xml_dom.xpath('/api:server/api:addresses', namespaces=nsmap)
- if addresses:
- if len(addresses) > 1:
- raise ValueError('Expected only single `addresses` element.')
- json_addresses = _translate_addresses_xml_to_json(addresses[0])
- json = xml_to_json(xml_dom)
- json['addresses'] = json_addresses
- else:
- json = xml_to_json(xml_dom)
- disk_config = ('{http://docs.openstack.org'
- '/compute/ext/disk_config/api/v3}disk_config')
- terminated_at = ('{http://docs.openstack.org/'
- 'compute/ext/os-server-usage/api/v3}terminated_at')
- launched_at = ('{http://docs.openstack.org'
- '/compute/ext/os-server-usage/api/v3}launched_at')
- power_state = ('{http://docs.openstack.org'
- '/compute/ext/extended_status/api/v3}power_state')
- availability_zone = ('{http://docs.openstack.org'
- '/compute/ext/extended_availability_zone/api/v3}'
- 'availability_zone')
- vm_state = ('{http://docs.openstack.org'
- '/compute/ext/extended_status/api/v3}vm_state')
- task_state = ('{http://docs.openstack.org'
- '/compute/ext/extended_status/api/v3}task_state')
- access_ip_v4 = ('{http://docs.openstack.org/compute/ext/'
- 'os-access-ips/api/v3}access_ip_v4')
- access_ip_v6 = ('{http://docs.openstack.org/compute/ext/'
- 'os-access-ips/api/v3}access_ip_v6')
- if disk_config in json:
- json['os-disk-config:disk_config'] = json.pop(disk_config)
- if terminated_at in json:
- json['os-server-usage:terminated_at'] = json.pop(terminated_at)
- if launched_at in json:
- json['os-server-usage:launched_at'] = json.pop(launched_at)
- if power_state in json:
- json['os-extended-status:power_state'] = json.pop(power_state)
- if availability_zone in json:
- json['os-extended-availability-zone:availability_zone'] = json.pop(
- availability_zone)
- if vm_state in json:
- json['os-extended-status:vm_state'] = json.pop(vm_state)
- if task_state in json:
- json['os-extended-status:task_state'] = json.pop(task_state)
- if access_ip_v4 in json:
- json['os-access-ips:access_ip_v4'] = json.pop(access_ip_v4)
- if access_ip_v6 in json:
- json['os-access-ips:access_ip_v6'] = json.pop(access_ip_v6)
- return json
-
-
-class ServersV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url,
- tenant_name=None, auth_version='v2'):
- super(ServersV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name,
- auth_version=auth_version)
- self.service = self.config.compute.catalog_v3_type
-
- def _parse_key_value(self, node):
- """Parse <foo key='key'>value</foo> data into {'key': 'value'}."""
- data = {}
- for node in node.getchildren():
- data[node.get('key')] = node.text
- return data
-
- def _parse_links(self, node, json):
- del json['link']
- json['links'] = []
- for linknode in node.findall('{http://www.w3.org/2005/Atom}link'):
- json['links'].append(xml_to_json(linknode))
-
- def _parse_server(self, body):
- json = _translate_server_xml_to_json(body)
-
- if 'metadata' in json and json['metadata']:
- # NOTE(danms): if there was metadata, we need to re-parse
- # that as a special type
- metadata_tag = body.find('{%s}metadata' % XMLNS_V3)
- json["metadata"] = self._parse_key_value(metadata_tag)
- if 'link' in json:
- self._parse_links(body, json)
- for sub in ['image', 'flavor']:
- if sub in json and 'link' in json[sub]:
- self._parse_links(body, json[sub])
- return json
-
- def _parse_xml_virtual_interfaces(self, xml_dom):
- """
- Return server's virtual interfaces XML as JSON.
- """
- data = {"virtual_interfaces": []}
- for iface in xml_dom.getchildren():
- data["virtual_interfaces"].append(
- {"id": iface.get("id"),
- "mac_address": iface.get("mac_address")})
- return data
-
- def get_server(self, server_id):
- """Returns the details of an existing server."""
- resp, body = self.get("servers/%s" % str(server_id), self.headers)
- server = self._parse_server(etree.fromstring(body))
- return resp, server
-
- def lock_server(self, server_id, **kwargs):
- """Locks the given server."""
- return self.action(server_id, 'lock', None, **kwargs)
-
- def unlock_server(self, server_id, **kwargs):
- """Unlocks the given server."""
- return self.action(server_id, 'unlock', None, **kwargs)
-
- def suspend_server(self, server_id, **kwargs):
- """Suspends the provided server."""
- return self.action(server_id, 'suspend', None, **kwargs)
-
- def resume_server(self, server_id, **kwargs):
- """Un-suspends the provided server."""
- return self.action(server_id, 'resume', None, **kwargs)
-
- def pause_server(self, server_id, **kwargs):
- """Pauses the provided server."""
- return self.action(server_id, 'pause', None, **kwargs)
-
- def unpause_server(self, server_id, **kwargs):
- """Un-pauses the provided server."""
- return self.action(server_id, 'unpause', None, **kwargs)
-
- def reset_state(self, server_id, state='error'):
- """Resets the state of a server to active/error."""
- return self.action(server_id, 'reset_state', None, state=state)
-
- def shelve_server(self, server_id, **kwargs):
- """Shelves the provided server."""
- return self.action(server_id, 'shelve', None, **kwargs)
-
- def unshelve_server(self, server_id, **kwargs):
- """Un-shelves the provided server."""
- return self.action(server_id, 'unshelve', None, **kwargs)
-
- def delete_server(self, server_id):
- """Deletes the given server."""
- return self.delete("servers/%s" % str(server_id))
-
- def _parse_array(self, node):
- array = []
- for child in node.getchildren():
- array.append(xml_to_json(child))
- return array
-
- def list_servers(self, params=None):
- url = 'servers'
- if params:
- url += '?%s' % urllib.urlencode(params)
-
- resp, body = self.get(url, self.headers)
- servers = self._parse_array(etree.fromstring(body))
- return resp, {"servers": servers}
-
- def list_servers_with_detail(self, params=None):
- url = 'servers/detail'
- if params:
- url += '?%s' % urllib.urlencode(params)
-
- resp, body = self.get(url, self.headers)
- servers = self._parse_array(etree.fromstring(body))
- return resp, {"servers": servers}
-
- def update_server(self, server_id, name=None, meta=None, access_ip_v4=None,
- access_ip_v6=None, disk_config=None):
- doc = Document()
- server = Element("server")
- doc.append(server)
-
- if name is not None:
- server.add_attr("name", name)
- if access_ip_v4 or access_ip_v6:
- server.add_attr('xmlns:os-access-ips',
- "http://docs.openstack.org/compute/ext/"
- "os-access-ips/api/v3")
- if access_ip_v4 is not None:
- server.add_attr("os-access-ips:access_ip_v4", access_ip_v4)
- if access_ip_v6 is not None:
- server.add_attr("os-access-ips:access_ip_v6", access_ip_v6)
- if disk_config is not None:
- server.add_attr('xmlns:os-disk-config', "http://docs.openstack.org"
- "/compute/ext/disk_config/api/v3")
- server.add_attr("os-disk-config:disk_config", disk_config)
- if meta is not None:
- metadata = Element("metadata")
- server.append(metadata)
- for k, v in meta:
- meta = Element("meta", key=k)
- meta.append(Text(v))
- metadata.append(meta)
-
- resp, body = self.put('servers/%s' % str(server_id),
- str(doc), self.headers)
- return resp, xml_to_json(etree.fromstring(body))
-
- def create_server(self, name, image_ref, flavor_ref, **kwargs):
- """
- Creates an instance of a server.
- name (Required): The name of the server.
- image_ref (Required): Reference to the image used to build the server.
- flavor_ref (Required): The flavor used to build the server.
- Following optional keyword arguments are accepted:
- admin_password: Sets the initial root password.
- key_name: Key name of keypair that was created earlier.
- meta: A dictionary of values to be used as metadata.
- personality: A list of dictionaries for files to be injected into
- the server.
- security_groups: A list of security group dicts.
- networks: A list of network dicts with UUID and fixed_ip.
- user_data: User data for instance.
- availability_zone: Availability zone in which to launch instance.
- access_ip_v4: The IPv4 access address for the server.
- access_ip_v6: The IPv6 access address for the server.
- min_count: Count of minimum number of instances to launch.
- max_count: Count of maximum number of instances to launch.
- disk_config: Determines if user or admin controls disk configuration.
- return_reservation_id: Enable/Disable the return of reservation id.
- """
- server = Element("server",
- xmlns=XMLNS_V3,
- flavor_ref=flavor_ref,
- image_ref=image_ref,
- name=name)
- attrs = ["admin_password", "key_name",
- ('os-access-ips:access_ip_v4',
- 'access_ip_v4',
- 'xmlns:os-access-ips',
- "http://docs.openstack.org/compute/ext/"
- "os-access-ips/api/v3"),
- ('os-access-ips:access_ip_v6',
- 'access_ip_v6',
- 'xmlns:os-access-ips',
- "http://docs.openstack.org/compute/ext/"
- "os-access-ips/api/v3"),
- ("os-user-data:user_data",
- 'user_data',
- 'xmlns:os-user-data',
- "http://docs.openstack.org/compute/ext/userdata/api/v3"),
- ("os-availability-zone:availability_zone",
- 'availability_zone',
- 'xmlns:os-availability-zone',
- "http://docs.openstack.org/compute/ext/"
- "availabilityzone/api/v3"),
- ("os-multiple-create:min_count",
- 'min_count',
- 'xmlns:os-multiple-create',
- "http://docs.openstack.org/compute/ext/"
- "multiplecreate/api/v3"),
- ("os-multiple-create:max_count",
- 'max_count',
- 'xmlns:os-multiple-create',
- "http://docs.openstack.org/compute/ext/"
- "multiplecreate/api/v3"),
- ("os-multiple-create:return_reservation_id",
- "return_reservation_id",
- 'xmlns:os-multiple-create',
- "http://docs.openstack.org/compute/ext/"
- "multiplecreate/api/v3"),
- ("os-disk-config:disk_config",
- "disk_config",
- "xmlns:os-disk-config",
- "http://docs.openstack.org/"
- "compute/ext/disk_config/api/v3")]
-
- for attr in attrs:
- if isinstance(attr, tuple):
- post_param = attr[0]
- key = attr[1]
- value = kwargs.get(key)
- if value is not None:
- server.add_attr(attr[2], attr[3])
- server.add_attr(post_param, value)
- else:
- post_param = attr
- key = attr
- value = kwargs.get(key)
- if value is not None:
- server.add_attr(post_param, value)
-
- if 'security_groups' in kwargs:
- server.add_attr("xmlns:os-security-groups",
- "http://docs.openstack.org/compute/ext/"
- "securitygroups/api/v3")
- secgroups = Element("os-security-groups:security_groups")
- server.append(secgroups)
- for secgroup in kwargs['security_groups']:
- s = Element("security_group", name=secgroup['name'])
- secgroups.append(s)
-
- if 'networks' in kwargs:
- networks = Element("networks")
- server.append(networks)
- for network in kwargs['networks']:
- s = Element("network", uuid=network['uuid'],
- fixed_ip=network['fixed_ip'])
- networks.append(s)
-
- if 'meta' in kwargs:
- metadata = Element("metadata")
- server.append(metadata)
- for k, v in kwargs['meta'].items():
- meta = Element("meta", key=k)
- meta.append(Text(v))
- metadata.append(meta)
-
- if 'personality' in kwargs:
- personality = Element('personality')
- server.append(personality)
- for k in kwargs['personality']:
- temp = Element('file', path=k['path'])
- temp.append(Text(k['contents']))
- personality.append(temp)
-
- resp, body = self.post('servers', str(Document(server)), self.headers)
- server = self._parse_server(etree.fromstring(body))
- return resp, server
-
- def wait_for_server_status(self, server_id, status, extra_timeout=0):
- """Waits for a server to reach a given status."""
- return waiters.wait_for_server_status(self, server_id, status,
- extra_timeout=extra_timeout)
-
- def wait_for_server_termination(self, server_id, ignore_error=False):
- """Waits for server to reach termination."""
- start_time = int(time.time())
- while True:
- try:
- resp, body = self.get_server(server_id)
- except exceptions.NotFound:
- return
-
- server_status = body['status']
- if server_status == 'ERROR' and not ignore_error:
- raise exceptions.BuildErrorException
-
- if int(time.time()) - start_time >= self.build_timeout:
- raise exceptions.TimeoutException
-
- time.sleep(self.build_interval)
-
- def _parse_network(self, node):
- addrs = []
- for child in node.getchildren():
- addrs.append({'version': int(child.get('version')),
- 'addr': child.get('addr')})
- return {node.get('id'): addrs}
-
- def list_addresses(self, server_id):
- """Lists all addresses for a server."""
- resp, body = self.get("servers/%s/ips" % str(server_id), self.headers)
-
- networks = {}
- xml_list = etree.fromstring(body)
- for child in xml_list.getchildren():
- network = self._parse_network(child)
- networks.update(**network)
-
- return resp, networks
-
- def list_addresses_by_network(self, server_id, network_id):
- """Lists all addresses of a specific network type for a server."""
- resp, body = self.get("servers/%s/ips/%s" % (str(server_id),
- network_id),
- self.headers)
- network = self._parse_network(etree.fromstring(body))
-
- return resp, network
-
- def action(self, server_id, action_name, response_key, **kwargs):
- if 'xmlns' not in kwargs:
- kwargs['xmlns'] = XMLNS_V3
- doc = Document((Element(action_name, **kwargs)))
- resp, body = self.post("servers/%s/action" % server_id,
- str(doc), self.headers)
- if response_key is not None:
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def create_backup(self, server_id, backup_type, rotation, name):
- """Backup a server instance."""
- return self.action(server_id, "create_backup", None,
- backup_type=backup_type,
- rotation=rotation,
- name=name)
-
- def change_password(self, server_id, password):
- return self.action(server_id, "change_password", None,
- admin_password=password)
-
- def reboot(self, server_id, reboot_type):
- return self.action(server_id, "reboot", None, type=reboot_type)
-
- def rebuild(self, server_id, image_ref, **kwargs):
- kwargs['image_ref'] = image_ref
- if 'disk_config' in kwargs:
- kwargs['os-disk-config:disk_config'] = kwargs['disk_config']
- del kwargs['disk_config']
- kwargs['xmlns:os-disk-config'] = "http://docs.openstack.org/"\
- "compute/ext/disk_config/api/v3"
- kwargs['xmlns:atom'] = "http://www.w3.org/2005/Atom"
- if 'xmlns' not in kwargs:
- kwargs['xmlns'] = XMLNS_V3
-
- attrs = kwargs.copy()
- if 'metadata' in attrs:
- del attrs['metadata']
- rebuild = Element("rebuild",
- **attrs)
-
- if 'metadata' in kwargs:
- metadata = Element("metadata")
- rebuild.append(metadata)
- for k, v in kwargs['metadata'].items():
- meta = Element("meta", key=k)
- meta.append(Text(v))
- metadata.append(meta)
-
- resp, body = self.post('servers/%s/action' % server_id,
- str(Document(rebuild)), self.headers)
- server = self._parse_server(etree.fromstring(body))
- return resp, server
-
- def resize(self, server_id, flavor_ref, **kwargs):
- if 'disk_config' in kwargs:
- kwargs['os-disk-config:disk_config'] = kwargs['disk_config']
- del kwargs['disk_config']
- kwargs['xmlns:os-disk-config'] = "http://docs.openstack.org/"\
- "compute/ext/disk_config/api/v3"
- kwargs['xmlns:atom'] = "http://www.w3.org/2005/Atom"
- kwargs['flavor_ref'] = flavor_ref
- return self.action(server_id, 'resize', None, **kwargs)
-
- def confirm_resize(self, server_id, **kwargs):
- return self.action(server_id, 'confirm_resize', None, **kwargs)
-
- def revert_resize(self, server_id, **kwargs):
- return self.action(server_id, 'revert_resize', None, **kwargs)
-
- def stop(self, server_id, **kwargs):
- return self.action(server_id, 'stop', None, **kwargs)
-
- def start(self, server_id, **kwargs):
- return self.action(server_id, 'start', None, **kwargs)
-
- def create_image(self, server_id, name, meta=None):
- """Creates an image of the original server."""
- post_body = Element('create_image', name=name)
-
- if meta:
- metadata = Element('metadata')
- post_body.append(metadata)
- for k, v in meta.items():
- data = Element('meta', key=k)
- data.append(Text(v))
- metadata.append(data)
- resp, body = self.post('servers/%s/action' % str(server_id),
- str(Document(post_body)), self.headers)
- return resp, body
-
- def live_migrate_server(self, server_id, dest_host, use_block_migration):
- """This should be called with administrator privileges ."""
-
- req_body = Element("migrate_live",
- xmlns=XMLNS_V3,
- disk_over_commit=False,
- block_migration=use_block_migration,
- host=dest_host)
-
- resp, body = self.post("servers/%s/action" % str(server_id),
- str(Document(req_body)), self.headers)
- return resp, body
-
- def list_server_metadata(self, server_id):
- resp, body = self.get("servers/%s/metadata" % str(server_id),
- self.headers)
- body = self._parse_key_value(etree.fromstring(body))
- return resp, body
-
- def set_server_metadata(self, server_id, meta, no_metadata_field=False):
- doc = Document()
- if not no_metadata_field:
- metadata = Element("metadata")
- doc.append(metadata)
- for k, v in meta.items():
- meta_element = Element("meta", key=k)
- meta_element.append(Text(v))
- metadata.append(meta_element)
- resp, body = self.put('servers/%s/metadata' % str(server_id),
- str(doc), self.headers)
- return resp, xml_to_json(etree.fromstring(body))
-
- def update_server_metadata(self, server_id, meta):
- doc = Document()
- metadata = Element("metadata")
- doc.append(metadata)
- for k, v in meta.items():
- meta_element = Element("meta", key=k)
- meta_element.append(Text(v))
- metadata.append(meta_element)
- resp, body = self.post("/servers/%s/metadata" % str(server_id),
- str(doc), headers=self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def get_server_metadata_item(self, server_id, key):
- resp, body = self.get("servers/%s/metadata/%s" % (str(server_id), key),
- headers=self.headers)
- return resp, dict([(etree.fromstring(body).attrib['key'],
- xml_to_json(etree.fromstring(body)))])
-
- def set_server_metadata_item(self, server_id, key, meta):
- doc = Document()
- for k, v in meta.items():
- meta_element = Element("meta", key=k)
- meta_element.append(Text(v))
- doc.append(meta_element)
- resp, body = self.put('servers/%s/metadata/%s' % (str(server_id), key),
- str(doc), self.headers)
- return resp, xml_to_json(etree.fromstring(body))
-
- def delete_server_metadata_item(self, server_id, key):
- resp, body = self.delete("servers/%s/metadata/%s" %
- (str(server_id), key))
- return resp, body
-
- def get_console_output(self, server_id, length):
- return self.action(server_id, 'get_console_output', 'output',
- length=length)
-
- def rescue_server(self, server_id, admin_password=None):
- """Rescue the provided server."""
- return self.action(server_id, 'rescue', None,
- admin_password=admin_password)
-
- def unrescue_server(self, server_id):
- """Unrescue the provided server."""
- return self.action(server_id, 'unrescue', None)
-
- def attach_volume(self, server_id, volume_id, device='/dev/vdz'):
- return self.action(server_id, "attach", None, volume_id=volume_id,
- device=device)
-
- def detach_volume(self, server_id, volume_id):
- return self.action(server_id, "detach", None, volume_id=volume_id)
-
- def get_server_diagnostics(self, server_id):
- """Get the usage data for a server."""
- resp, body = self.get("servers/%s/os-server-diagnostics" % server_id,
- self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def list_instance_actions(self, server_id):
- """List the provided server action."""
- resp, body = self.get("servers/%s/os-instance-actions" % server_id,
- self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
-
- def get_instance_action(self, server_id, request_id):
- """Returns the action details of the provided server."""
- resp, body = self.get("servers/%s/os-instance-actions/%s" %
- (server_id, request_id), self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def force_delete_server(self, server_id, **kwargs):
- """Force delete a server."""
- return self.action(server_id, 'force_delete', None, **kwargs)
-
- def restore_soft_deleted_server(self, server_id, **kwargs):
- """Restore a soft-deleted server."""
- return self.action(server_id, 'restore', None, **kwargs)
diff --git a/tempest/services/compute/v3/xml/services_client.py b/tempest/services/compute/v3/xml/services_client.py
deleted file mode 100644
index 855641b..0000000
--- a/tempest/services/compute/v3/xml/services_client.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 NEC Corporation
-# Copyright 2013 IBM Corp.
-# All Rights Reserved.
-#
-# 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 urllib
-
-from lxml import etree
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class ServicesV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ServicesV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def list_services(self, params=None):
- url = 'os-services'
- if params:
- url += '?%s' % urllib.urlencode(params)
-
- resp, body = self.get(url, self.headers)
- node = etree.fromstring(body)
- body = [xml_to_json(x) for x in node.getchildren()]
- return resp, body
-
- def enable_service(self, host_name, binary):
- """
- Enable service on a host
- host_name: Name of host
- binary: Service binary
- """
- post_body = Element("service")
- post_body.add_attr('binary', binary)
- post_body.add_attr('host', host_name)
-
- resp, body = self.put('os-services/enable', str(Document(post_body)),
- self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
-
- def disable_service(self, host_name, binary):
- """
- Disable service on a host
- host_name: Name of host
- binary: Service binary
- """
- post_body = Element("service")
- post_body.add_attr('binary', binary)
- post_body.add_attr('host', host_name)
-
- resp, body = self.put('os-services/disable', str(Document(post_body)),
- self.headers)
- body = xml_to_json(etree.fromstring(body))
- return resp, body
diff --git a/tempest/services/compute/v3/xml/tenant_usages_client.py b/tempest/services/compute/v3/xml/tenant_usages_client.py
deleted file mode 100644
index 790bd5c..0000000
--- a/tempest/services/compute/v3/xml/tenant_usages_client.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2013 NEC Corporation
-# All Rights Reserved.
-#
-# 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 urllib
-
-from lxml import etree
-
-from tempest.common.rest_client import RestClientXML
-from tempest.services.compute.xml.common import xml_to_json
-
-
-class TenantUsagesV3ClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(TenantUsagesV3ClientXML, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_v3_type
-
- def _parse_array(self, node):
- json = xml_to_json(node)
- return json
-
- def list_tenant_usages(self, params=None):
- url = 'os-simple-tenant-usage'
- if params:
- url += '?%s' % urllib.urlencode(params)
-
- resp, body = self.get(url, self.headers)
- tenant_usage = self._parse_array(etree.fromstring(body))
- return resp, tenant_usage['tenant_usage']
-
- def get_tenant_usage(self, tenant_id, params=None):
- url = 'os-simple-tenant-usage/%s' % tenant_id
- if params:
- url += '?%s' % urllib.urlencode(params)
-
- resp, body = self.get(url, self.headers)
- tenant_usage = self._parse_array(etree.fromstring(body))
- return resp, tenant_usage
diff --git a/tempest/services/compute/xml/aggregates_client.py b/tempest/services/compute/xml/aggregates_client.py
index 5faaff5..ba08f58 100644
--- a/tempest/services/compute/xml/aggregates_client.py
+++ b/tempest/services/compute/xml/aggregates_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation.
# All Rights Reserved.
#
@@ -18,19 +16,21 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class AggregatesClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AggregatesClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(AggregatesClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _format_aggregate(self, g):
agg = xml_to_json(g)
diff --git a/tempest/services/compute/xml/availability_zone_client.py b/tempest/services/compute/xml/availability_zone_client.py
index ae93774..38280b5 100644
--- a/tempest/services/compute/xml/availability_zone_client.py
+++ b/tempest/services/compute/xml/availability_zone_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -18,16 +16,18 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class AvailabilityZoneClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AvailabilityZoneClientXML, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(AvailabilityZoneClientXML, self).__init__(
+ auth_provider)
+ self.service = CONF.compute.catalog_type
def _parse_array(self, node):
return [xml_to_json(x) for x in node]
diff --git a/tempest/services/compute/xml/certificates_client.py b/tempest/services/compute/xml/certificates_client.py
index 7523352..aad20a4 100644
--- a/tempest/services/compute/xml/certificates_client.py
+++ b/tempest/services/compute/xml/certificates_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -17,14 +15,16 @@
from tempest.common.rest_client import RestClientXML
+from tempest import config
+
+CONF = config.CONF
class CertificatesClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(CertificatesClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(CertificatesClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_certificate(self, id):
url = "os-certificates/%s" % (id)
diff --git a/tempest/services/compute/xml/common.py b/tempest/services/compute/xml/common.py
index d2a18a1..4def19f 100644
--- a/tempest/services/compute/xml/common.py
+++ b/tempest/services/compute/xml/common.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -114,19 +112,35 @@
others, it requires a little hand-editing of the result.
"""
json = {}
+ bool_flag = False
+ int_flag = False
+ long_flag = False
for attr in node.keys():
if not attr.startswith("xmlns"):
json[attr] = node.get(attr)
+ if json[attr] == 'bool':
+ bool_flag = True
+ elif json[attr] == 'int':
+ int_flag = True
+ elif json[attr] == 'long':
+ long_flag = True
if not node.getchildren():
- return node.text or json
+ if bool_flag:
+ return node.text == 'True'
+ elif int_flag:
+ return int(node.text)
+ elif long_flag:
+ return long(node.text)
+ else:
+ return node.text or json
for child in node.getchildren():
tag = child.tag
if tag.startswith("{"):
ns, tag = tag.split("}", 1)
if plurals is not None and tag in plurals:
- json[tag] = parse_array(child)
+ json[tag] = parse_array(child, plurals)
else:
- json[tag] = xml_to_json(child)
+ json[tag] = xml_to_json(child, plurals)
return json
diff --git a/tempest/services/compute/xml/extensions_client.py b/tempest/services/compute/xml/extensions_client.py
index b17fc4f..9753ca8 100644
--- a/tempest/services/compute/xml/extensions_client.py
+++ b/tempest/services/compute/xml/extensions_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,16 +14,19 @@
# under the License.
from lxml import etree
+
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class ExtensionsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ExtensionsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(ExtensionsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _parse_array(self, node):
array = []
@@ -37,7 +38,7 @@
url = 'extensions'
resp, body = self.get(url, self.headers)
body = self._parse_array(etree.fromstring(body))
- return resp, {'extensions': body}
+ return resp, body
def is_enabled(self, extension):
_, extensions = self.list_extensions()
diff --git a/tempest/services/compute/xml/fixed_ips_client.py b/tempest/services/compute/xml/fixed_ips_client.py
index bf2de38..599e168 100644
--- a/tempest/services/compute/xml/fixed_ips_client.py
+++ b/tempest/services/compute/xml/fixed_ips_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
@@ -17,17 +15,19 @@
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
+CONF = config.CONF
+
class FixedIPsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FixedIPsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(FixedIPsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_fixed_ip_details(self, fixed_ip):
url = "os-fixed-ips/%s" % (fixed_ip)
diff --git a/tempest/services/compute/xml/flavors_client.py b/tempest/services/compute/xml/flavors_client.py
index a1c74d9..fb16d20 100644
--- a/tempest/services/compute/xml/flavors_client.py
+++ b/tempest/services/compute/xml/flavors_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,12 +18,14 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
XMLNS_OS_FLV_EXT_DATA = \
"http://docs.openstack.org/compute/ext/flavor_extra_data/api/v1.1"
@@ -35,10 +35,9 @@
class FlavorsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FlavorsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(FlavorsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _format_flavor(self, f):
flavor = {'links': []}
diff --git a/tempest/services/compute/xml/floating_ips_client.py b/tempest/services/compute/xml/floating_ips_client.py
index 2fffaa2..0119d8a 100644
--- a/tempest/services/compute/xml/floating_ips_client.py
+++ b/tempest/services/compute/xml/floating_ips_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -19,18 +17,20 @@
import urllib
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class FloatingIPsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(FloatingIPsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(FloatingIPsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _parse_array(self, node):
array = []
diff --git a/tempest/services/compute/xml/hosts_client.py b/tempest/services/compute/xml/hosts_client.py
index 519798e..daa83c9 100644
--- a/tempest/services/compute/xml/hosts_client.py
+++ b/tempest/services/compute/xml/hosts_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -18,17 +16,19 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class HostsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HostsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(HostsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_hosts(self, params=None):
"""Lists all hosts."""
diff --git a/tempest/services/compute/xml/hypervisor_client.py b/tempest/services/compute/xml/hypervisor_client.py
index c10fed9..5abaad8 100644
--- a/tempest/services/compute/xml/hypervisor_client.py
+++ b/tempest/services/compute/xml/hypervisor_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -18,16 +16,17 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class HypervisorClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(HypervisorClientXML, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(HypervisorClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _parse_array(self, node):
return [xml_to_json(x) for x in node]
diff --git a/tempest/services/compute/xml/images_client.py b/tempest/services/compute/xml/images_client.py
index 20fcc9b..d90a7d8 100644
--- a/tempest/services/compute/xml/images_client.py
+++ b/tempest/services/compute/xml/images_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -21,6 +19,7 @@
from tempest.common.rest_client import RestClientXML
from tempest.common import waiters
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
@@ -28,15 +27,16 @@
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
+
class ImagesClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ImagesClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
- self.build_interval = self.config.compute.build_interval
- self.build_timeout = self.config.compute.build_timeout
+ def __init__(self, auth_provider):
+ super(ImagesClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
def _parse_server(self, node):
data = xml_to_json(node)
diff --git a/tempest/services/compute/xml/instance_usage_audit_log_client.py b/tempest/services/compute/xml/instance_usage_audit_log_client.py
index 175997b..562774b 100644
--- a/tempest/services/compute/xml/instance_usage_audit_log_client.py
+++ b/tempest/services/compute/xml/instance_usage_audit_log_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corporation
# All Rights Reserved.
#
@@ -18,15 +16,18 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class InstanceUsagesAuditLogClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
+ def __init__(self, auth_provider):
super(InstanceUsagesAuditLogClientXML, self).__init__(
- config, username, password, auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ auth_provider)
+ self.service = CONF.compute.catalog_type
def list_instance_usage_audit_logs(self):
url = 'os-instance_usage_audit_log'
diff --git a/tempest/services/compute/xml/interfaces_client.py b/tempest/services/compute/xml/interfaces_client.py
index a84e0bd..4194d7d 100644
--- a/tempest/services/compute/xml/interfaces_client.py
+++ b/tempest/services/compute/xml/interfaces_client.py
@@ -18,19 +18,21 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class InterfacesClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(InterfacesClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(InterfacesClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _process_xml_interface(self, node):
iface = xml_to_json(node)
diff --git a/tempest/services/compute/xml/keypairs_client.py b/tempest/services/compute/xml/keypairs_client.py
index 0157245..92fade4 100644
--- a/tempest/services/compute/xml/keypairs_client.py
+++ b/tempest/services/compute/xml/keypairs_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -17,19 +15,22 @@
from lxml import etree
+
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class KeyPairsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(KeyPairsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(KeyPairsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_keypairs(self):
resp, body = self.get("os-keypairs", self.headers)
diff --git a/tempest/services/compute/xml/limits_client.py b/tempest/services/compute/xml/limits_client.py
index 704de52..2a8fbec 100644
--- a/tempest/services/compute/xml/limits_client.py
+++ b/tempest/services/compute/xml/limits_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -18,16 +16,18 @@
from lxml import objectify
from tempest.common.rest_client import RestClientXML
+from tempest import config
+
+CONF = config.CONF
NS = "{http://docs.openstack.org/common/api/v1.0}"
class LimitsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(LimitsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(LimitsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def get_absolute_limits(self):
resp, body = self.get("limits", self.headers)
diff --git a/tempest/services/compute/xml/quotas_client.py b/tempest/services/compute/xml/quotas_client.py
index ef5362c..f1041f0 100644
--- a/tempest/services/compute/xml/quotas_client.py
+++ b/tempest/services/compute/xml/quotas_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 NTT Data
# All Rights Reserved.
#
@@ -18,18 +16,20 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
+
class QuotasClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(QuotasClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(QuotasClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _format_quota(self, q):
quota = {}
diff --git a/tempest/services/compute/xml/security_groups_client.py b/tempest/services/compute/xml/security_groups_client.py
index aebeb4d..83072be 100644
--- a/tempest/services/compute/xml/security_groups_client.py
+++ b/tempest/services/compute/xml/security_groups_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -19,6 +17,7 @@
import urllib
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
@@ -26,14 +25,14 @@
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
+
class SecurityGroupsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(SecurityGroupsClientXML, self).__init__(
- config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(SecurityGroupsClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _parse_array(self, node):
array = []
diff --git a/tempest/services/compute/xml/servers_client.py b/tempest/services/compute/xml/servers_client.py
index 68f6cf0..37980c9 100644
--- a/tempest/services/compute/xml/servers_client.py
+++ b/tempest/services/compute/xml/servers_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# All Rights Reserved.
@@ -23,6 +21,7 @@
from tempest.common.rest_client import RestClientXML
from tempest.common import waiters
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.services.compute.xml.common import Document
@@ -31,6 +30,7 @@
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -141,12 +141,9 @@
class ServersClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None,
- auth_version='v2'):
- super(ServersClientXML, self).__init__(config, username, password,
- auth_url, tenant_name,
- auth_version=auth_version)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(ServersClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _parse_key_value(self, node):
"""Parse <foo key='key'>value</foo> data into {'key': 'value'}."""
@@ -381,7 +378,7 @@
server_status = body['status']
if server_status == 'ERROR' and not ignore_error:
- raise exceptions.BuildErrorException
+ raise exceptions.BuildErrorException(server_id=server_id)
if int(time.time()) - start_time >= self.build_timeout:
raise exceptions.TimeoutException
@@ -595,9 +592,9 @@
virt_int = self._parse_xml_virtual_interfaces(etree.fromstring(body))
return resp, virt_int
- def rescue_server(self, server_id, adminPass=None):
+ def rescue_server(self, server_id, **kwargs):
"""Rescue the provided server."""
- return self.action(server_id, 'rescue', None, adminPass=adminPass)
+ return self.action(server_id, 'rescue', None, **kwargs)
def unrescue_server(self, server_id):
"""Unrescue the provided server."""
diff --git a/tempest/services/compute/xml/services_client.py b/tempest/services/compute/xml/services_client.py
index ac304e2..c28dc12 100644
--- a/tempest/services/compute/xml/services_client.py
+++ b/tempest/services/compute/xml/services_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# Copyright 2013 IBM Corp.
# All Rights Reserved.
@@ -19,18 +17,21 @@
import urllib
from lxml import etree
+
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class ServicesClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ServicesClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(ServicesClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def list_services(self, params=None):
url = 'os-services'
diff --git a/tempest/services/compute/xml/tenant_usages_client.py b/tempest/services/compute/xml/tenant_usages_client.py
index cb92324..93eeb00 100644
--- a/tempest/services/compute/xml/tenant_usages_client.py
+++ b/tempest/services/compute/xml/tenant_usages_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 NEC Corporation
# All Rights Reserved.
#
@@ -20,16 +18,17 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class TenantUsagesClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(TenantUsagesClientXML, self).__init__(config, username,
- password, auth_url,
- tenant_name)
- self.service = self.config.compute.catalog_type
+ def __init__(self, auth_provider):
+ super(TenantUsagesClientXML, self).__init__(auth_provider)
+ self.service = CONF.compute.catalog_type
def _parse_array(self, node):
json = xml_to_json(node)
diff --git a/tempest/services/compute/xml/volumes_extensions_client.py b/tempest/services/compute/xml/volumes_extensions_client.py
index 4cdc4f0..941cd69 100644
--- a/tempest/services/compute/xml/volumes_extensions_client.py
+++ b/tempest/services/compute/xml/volumes_extensions_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -21,6 +19,7 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
@@ -28,16 +27,17 @@
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
+
class VolumesExtensionsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumesExtensionsClientXML, self).__init__(config,
- username, password,
- auth_url, tenant_name)
- self.service = self.config.compute.catalog_type
- self.build_interval = self.config.compute.build_interval
- self.build_timeout = self.config.compute.build_timeout
+ def __init__(self, auth_provider):
+ super(VolumesExtensionsClientXML, self).__init__(
+ auth_provider)
+ self.service = CONF.compute.catalog_type
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
def _parse_volume(self, body):
vol = dict((attr, body.get(attr)) for attr in body.keys())
diff --git a/tempest/services/data_processing/v1_1/client.py b/tempest/services/data_processing/v1_1/client.py
index bd147e8..e96b44b 100644
--- a/tempest/services/data_processing/v1_1/client.py
+++ b/tempest/services/data_processing/v1_1/client.py
@@ -16,13 +16,15 @@
import json
from tempest.common import rest_client
+from tempest import config
+
+CONF = config.CONF
class DataProcessingClient(rest_client.RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(DataProcessingClient, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.data_processing.catalog_type
+ def __init__(self, auth_provider):
+ super(DataProcessingClient, self).__init__(auth_provider)
+ self.service = CONF.data_processing.catalog_type
@classmethod
def _request_and_parse(cls, req_fun, uri, res_name, *args, **kwargs):
@@ -75,3 +77,17 @@
uri = "node-group-templates/%s" % tmpl_id
return self.delete(uri)
+
+ def list_plugins(self):
+ """List all enabled plugins."""
+
+ uri = 'plugins'
+ return self._request_and_parse(self.get, uri, 'plugins')
+
+ def get_plugin(self, plugin_name, plugin_version=None):
+ """Returns the details of a single plugin."""
+
+ uri = "plugins/%s" % plugin_name
+ if plugin_version:
+ uri += '/%s' % plugin_version
+ return self._request_and_parse(self.get, uri, 'plugin')
diff --git a/tempest/services/identity/json/identity_client.py b/tempest/services/identity/json/identity_client.py
index 94045b8..349a9e9 100644
--- a/tempest/services/identity/json/identity_client.py
+++ b/tempest/services/identity/json/identity_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# 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
@@ -14,19 +12,23 @@
import json
-from tempest.common import http
-from tempest.common.rest_client import RestClient
+from tempest.common import rest_client
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
-class IdentityClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(IdentityClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+class IdentityClientJSON(rest_client.RestClient):
+
+ def __init__(self, auth_provider):
+ super(IdentityClientJSON, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
+ # Needed for xml service client
+ self.list_tags = ["roles", "tenants", "users", "services"]
+
def has_admin_extensions(self):
"""
Returns True if the KSADM Admin Extensions are supported
@@ -44,9 +46,8 @@
'name': name,
}
post_body = json.dumps({'role': post_body})
- resp, body = self.post('OS-KSADM/roles', post_body, self.headers)
- body = json.loads(body)
- return resp, body['role']
+ resp, body = self.post('OS-KSADM/roles', post_body)
+ return resp, self._parse_resp(body)
def create_tenant(self, name, **kwargs):
"""
@@ -61,30 +62,24 @@
'enabled': kwargs.get('enabled', True),
}
post_body = json.dumps({'tenant': post_body})
- resp, body = self.post('tenants', post_body, self.headers)
- body = json.loads(body)
- return resp, body['tenant']
+ resp, body = self.post('tenants', post_body)
+ return resp, self._parse_resp(body)
def delete_role(self, role_id):
"""Delete a role."""
- resp, body = self.delete('OS-KSADM/roles/%s' % str(role_id))
- return resp, body
+ return self.delete('OS-KSADM/roles/%s' % str(role_id))
def list_user_roles(self, tenant_id, user_id):
"""Returns a list of roles assigned to a user for a tenant."""
url = '/tenants/%s/users/%s/roles' % (tenant_id, user_id)
resp, body = self.get(url)
- body = json.loads(body)
- return resp, body['roles']
+ return resp, self._parse_resp(body)
def assign_user_role(self, tenant_id, user_id, role_id):
"""Add roles to a user on a tenant."""
- post_body = json.dumps({})
resp, body = self.put('/tenants/%s/users/%s/roles/OS-KSADM/%s' %
- (tenant_id, user_id, role_id), post_body,
- self.headers)
- body = json.loads(body)
- return resp, body['role']
+ (tenant_id, user_id, role_id), "")
+ return resp, self._parse_resp(body)
def remove_user_role(self, tenant_id, user_id, role_id):
"""Removes a role assignment for a user on a tenant."""
@@ -93,20 +88,17 @@
def delete_tenant(self, tenant_id):
"""Delete a tenant."""
- resp, body = self.delete('tenants/%s' % str(tenant_id))
- return resp, body
+ return self.delete('tenants/%s' % str(tenant_id))
def get_tenant(self, tenant_id):
"""Get tenant details."""
resp, body = self.get('tenants/%s' % str(tenant_id))
- body = json.loads(body)
- return resp, body['tenant']
+ return resp, self._parse_resp(body)
def list_roles(self):
"""Returns roles."""
resp, body = self.get('OS-KSADM/roles')
- body = json.loads(body)
- return resp, body['roles']
+ return resp, self._parse_resp(body)
def list_tenants(self):
"""Returns tenants."""
@@ -134,10 +126,8 @@
'enabled': en,
}
post_body = json.dumps({'tenant': post_body})
- resp, body = self.post('tenants/%s' % tenant_id, post_body,
- self.headers)
- body = json.loads(body)
- return resp, body['tenant']
+ resp, body = self.post('tenants/%s' % tenant_id, post_body)
+ return resp, self._parse_resp(body)
def create_user(self, name, password, tenant_id, email, **kwargs):
"""Create a user."""
@@ -150,34 +140,28 @@
if kwargs.get('enabled') is not None:
post_body['enabled'] = kwargs.get('enabled')
post_body = json.dumps({'user': post_body})
- resp, body = self.post('users', post_body, self.headers)
- body = json.loads(body)
- return resp, body['user']
+ resp, body = self.post('users', post_body)
+ return resp, self._parse_resp(body)
def update_user(self, user_id, **kwargs):
"""Updates a user."""
put_body = json.dumps({'user': kwargs})
- resp, body = self.put('users/%s' % user_id, put_body,
- self.headers)
- body = json.loads(body)
- return resp, body['user']
+ resp, body = self.put('users/%s' % user_id, put_body)
+ return resp, self._parse_resp(body)
def get_user(self, user_id):
"""GET a user."""
resp, body = self.get("users/%s" % user_id)
- body = json.loads(body)
- return resp, body['user']
+ return resp, self._parse_resp(body)
def delete_user(self, user_id):
"""Delete a user."""
- resp, body = self.delete("users/%s" % user_id)
- return resp, body
+ return self.delete("users/%s" % user_id)
def get_users(self):
"""Get the list of users."""
resp, body = self.get("users")
- body = json.loads(body)
- return resp, body['users']
+ return resp, self._parse_resp(body)
def enable_disable_user(self, user_id, enabled):
"""Enables or disables a user."""
@@ -185,21 +169,17 @@
'enabled': enabled
}
put_body = json.dumps({'user': put_body})
- resp, body = self.put('users/%s/enabled' % user_id,
- put_body, self.headers)
- body = json.loads(body)
- return resp, body
+ resp, body = self.put('users/%s/enabled' % user_id, put_body)
+ return resp, self._parse_resp(body)
def delete_token(self, token_id):
"""Delete a token."""
- resp, body = self.delete("tokens/%s" % token_id)
- return resp, body
+ return self.delete("tokens/%s" % token_id)
def list_users_for_tenant(self, tenant_id):
"""List users for a Tenant."""
resp, body = self.get('/tenants/%s/users' % tenant_id)
- body = json.loads(body)
- return resp, body['users']
+ return resp, self._parse_resp(body)
def get_user_by_username(self, tenant_id, username):
resp, users = self.list_users_for_tenant(tenant_id)
@@ -216,22 +196,19 @@
'description': kwargs.get('description')
}
post_body = json.dumps({'OS-KSADM:service': post_body})
- resp, body = self.post('/OS-KSADM/services', post_body, self.headers)
- body = json.loads(body)
- return resp, body['OS-KSADM:service']
+ resp, body = self.post('/OS-KSADM/services', post_body)
+ return resp, self._parse_resp(body)
def get_service(self, service_id):
"""Get Service."""
url = '/OS-KSADM/services/%s' % service_id
resp, body = self.get(url)
- body = json.loads(body)
- return resp, body['OS-KSADM:service']
+ return resp, self._parse_resp(body)
def list_services(self):
"""List Service - Returns Services."""
resp, body = self.get('/OS-KSADM/services/')
- body = json.loads(body)
- return resp, body['OS-KSADM:services']
+ return resp, self._parse_resp(body)
def delete_service(self, service_id):
"""Delete Service."""
@@ -239,18 +216,17 @@
return self.delete(url)
-class TokenClientJSON(RestClient):
+class TokenClientJSON(IdentityClientJSON):
- def __init__(self, config):
- auth_url = config.identity.uri
+ def __init__(self):
+ super(TokenClientJSON, self).__init__(None)
+ auth_url = CONF.identity.uri
- # TODO(jaypipes) Why is this all repeated code in here?
# Normalize URI to ensure /tokens is in it.
if 'tokens' not in auth_url:
auth_url = auth_url.rstrip('/') + '/tokens'
self.auth_url = auth_url
- self.config = config
def auth(self, user, password, tenant):
creds = {
@@ -262,34 +238,41 @@
'tenantName': tenant,
}
}
- headers = {'Content-Type': 'application/json'}
body = json.dumps(creds)
- resp, body = self.post(self.auth_url, headers=headers, body=body)
- return resp, body
+ resp, body = self.post(self.auth_url, body=body)
+
+ return resp, body['access']
def request(self, method, url, headers=None, body=None):
"""A simple HTTP request interface."""
- dscv = self.config.identity.disable_ssl_certificate_validation
- self.http_obj = http.ClosingHttp(
- disable_ssl_certificate_validation=dscv)
if headers is None:
- headers = {}
-
+ # Always accept 'json', for TokenClientXML too.
+ # Because XML response is not easily
+ # converted to the corresponding JSON one
+ headers = self.get_headers(accept_type="json")
self._log_request(method, url, headers, body)
resp, resp_body = self.http_obj.request(url, method,
headers=headers, body=body)
self._log_response(resp, resp_body)
- if resp.status in (401, 403):
+ if resp.status in [401, 403]:
resp_body = json.loads(resp_body)
raise exceptions.Unauthorized(resp_body['error']['message'])
+ elif resp.status not in [200, 201]:
+ raise exceptions.IdentityError(
+ 'Unexpected status code {0}'.format(resp.status))
+ if isinstance(resp_body, str):
+ resp_body = json.loads(resp_body)
return resp, resp_body
- def get_token(self, user, password, tenant):
+ def get_token(self, user, password, tenant, auth_data=False):
+ """
+ Returns (token id, token data) for supplied credentials
+ """
resp, body = self.auth(user, password, tenant)
- if resp['status'] != '202':
- body = json.loads(body)
- access = body['access']
- token = access['token']
- return token['id']
+
+ if auth_data:
+ return body['token']['id'], body
+ else:
+ return body['token']['id']
diff --git a/tempest/services/identity/v3/json/credentials_client.py b/tempest/services/identity/v3/json/credentials_client.py
index c3f788a..a0fbb76 100644
--- a/tempest/services/identity/v3/json/credentials_client.py
+++ b/tempest/services/identity/v3/json/credentials_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,27 +14,20 @@
# under the License.
import json
-from urlparse import urlparse
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class CredentialsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(CredentialsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(CredentialsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
-
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(CredentialsClientJSON, self).request(method, url,
- headers=headers,
- body=body)
+ self.api_version = "v3"
def create_credential(self, access_key, secret_key, user_id, project_id):
"""Creates a credential."""
diff --git a/tempest/services/identity/v3/json/endpoints_client.py b/tempest/services/identity/v3/json/endpoints_client.py
index cf26d0a..1b78115 100644
--- a/tempest/services/identity/v3/json/endpoints_client.py
+++ b/tempest/services/identity/v3/json/endpoints_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,28 +14,20 @@
# under the License.
import json
-import urlparse
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class EndPointClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(EndPointClientJSON, self).__init__(config,
- username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(EndPointClientJSON, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
-
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(
- urlparse.urlparse(self.base_url).path, "/v3")
- return super(EndPointClientJSON, self).request(method, url,
- headers=headers,
- body=body)
+ self.api_version = "v3"
def list_endpoints(self):
"""GET endpoints."""
diff --git a/tempest/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index e457c1f..ab1dc94 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,27 +14,22 @@
# under the License.
import json
-from urlparse import urlparse
+import urlparse
from tempest.common.rest_client import RestClient
+from tempest import config
+from tempest import exceptions
+
+CONF = config.CONF
class IdentityV3ClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(IdentityV3ClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(IdentityV3ClientJSON, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
-
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(IdentityV3ClientJSON, self).request(method, url,
- headers=headers,
- body=body)
+ self.api_version = "v3"
def create_user(self, user_name, **kwargs):
"""Creates a user."""
@@ -274,11 +267,50 @@
body = json.loads(body)
return resp, body['group']
+ def get_group(self, group_id):
+ """Get group details."""
+ resp, body = self.get('groups/%s' % group_id, self.headers)
+ body = json.loads(body)
+ return resp, body['group']
+
+ def update_group(self, group_id, **kwargs):
+ """Updates a group."""
+ resp, body = self.get_group(group_id)
+ name = kwargs.get('name', body['name'])
+ description = kwargs.get('description', body['description'])
+ post_body = {
+ 'name': name,
+ 'description': description
+ }
+ post_body = json.dumps({'group': post_body})
+ resp, body = self.patch('groups/%s' % group_id, post_body,
+ self.headers)
+ body = json.loads(body)
+ return resp, body['group']
+
def delete_group(self, group_id):
"""Delete a group."""
resp, body = self.delete('groups/%s' % str(group_id))
return resp, body
+ def add_group_user(self, group_id, user_id):
+ """Add user into group."""
+ resp, body = self.put('groups/%s/users/%s' % (group_id, user_id),
+ None, self.headers)
+ return resp, body
+
+ def list_group_users(self, group_id):
+ """List users in group."""
+ resp, body = self.get('groups/%s/users' % group_id, self.headers)
+ body = json.loads(body)
+ return resp, body['users']
+
+ def delete_group_user(self, group_id, user_id):
+ """Delete user in group."""
+ resp, body = self.delete('groups/%s/users/%s' % (group_id, user_id),
+ self.headers)
+ return resp, body
+
def assign_user_role_on_project(self, project_id, user_id, role_id):
"""Add roles to a user on a project."""
resp, body = self.put('projects/%s/users/%s/roles/%s' %
@@ -422,44 +454,89 @@
class V3TokenClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(V3TokenClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
- self.endpoint_url = 'adminURL'
+ def __init__(self):
+ super(V3TokenClientJSON, self).__init__(None)
+ auth_url = CONF.identity.uri_v3
+ # If the v3 url is not set, get it from the v2 one
+ if auth_url is None:
+ auth_url = CONF.identity.uri.replace(urlparse.urlparse(
+ CONF.identity.uri).path, "/v3")
- auth_url = config.identity.uri
-
- if 'tokens' not in auth_url:
- auth_url = auth_url.rstrip('/') + '/tokens'
+ if 'auth/tokens' not in auth_url:
+ auth_url = auth_url.rstrip('/') + '/auth/tokens'
self.auth_url = auth_url
- self.config = config
- def auth(self, user_id, password):
+ def auth(self, user, password, tenant=None, user_type='id', domain=None):
+ """
+ :param user: user id or name, as specified in user_type
+ :param domain: the user and tenant domain
+
+ Accepts different combinations of credentials. Restrictions:
+ - tenant and domain are only name (no id)
+ - user domain and tenant domain are assumed identical
+ - domain scope is not supported here
+ Sample sample valid combinations:
+ - user_id, password
+ - username, password, domain
+ - username, password, tenant, domain
+ Validation is left to the server side.
+ """
creds = {
'auth': {
'identity': {
'methods': ['password'],
'password': {
'user': {
- 'id': user_id,
- 'password': password
+ 'password': password,
}
}
}
}
}
- headers = {'Content-Type': 'application/json'}
+ if user_type == 'id':
+ creds['auth']['identity']['password']['user']['id'] = user
+ else:
+ creds['auth']['identity']['password']['user']['name'] = user
+ if domain is not None:
+ _domain = dict(name=domain)
+ creds['auth']['identity']['password']['user']['domain'] = _domain
+ if tenant is not None:
+ project = dict(name=tenant, domain=_domain)
+ scope = dict(project=project)
+ creds['auth']['scope'] = scope
+
body = json.dumps(creds)
- resp, body = self.post("auth/tokens", headers=headers, body=body)
+ resp, body = self.post(self.auth_url, headers=self.headers, body=body)
return resp, body
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(V3TokenClientJSON, self).request(method, url,
- headers=headers,
- body=body)
+ def request(self, method, url, headers=None, body=None):
+ """A simple HTTP request interface."""
+ self._log_request(method, url, headers, body)
+ resp, resp_body = self.http_obj.request(url, method,
+ headers=headers, body=body)
+ self._log_response(resp, resp_body)
+
+ if resp.status in [401, 403]:
+ resp_body = json.loads(resp_body)
+ raise exceptions.Unauthorized(resp_body['error']['message'])
+ elif resp.status not in [200, 201, 204]:
+ raise exceptions.IdentityError(
+ 'Unexpected status code {0}'.format(resp.status))
+
+ return resp, json.loads(resp_body)
+
+ def get_token(self, user, password, tenant, domain='Default',
+ auth_data=False):
+ """
+ :param user: username
+ Returns (token id, token data) for supplied credentials
+ """
+ resp, body = self.auth(user, password, tenant, user_type='name',
+ domain=domain)
+
+ token = resp.get('x-subject-token')
+ if auth_data:
+ return token, body['token']
+ else:
+ return token
diff --git a/tempest/services/identity/v3/json/policy_client.py b/tempest/services/identity/v3/json/policy_client.py
index 27404c4..c376979 100644
--- a/tempest/services/identity/v3/json/policy_client.py
+++ b/tempest/services/identity/v3/json/policy_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,27 +14,20 @@
# under the License.
import json
-from urlparse import urlparse
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class PolicyClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(PolicyClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(PolicyClientJSON, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
-
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(PolicyClientJSON, self).request(method, url,
- headers=headers,
- body=body)
+ self.api_version = "v3"
def create_policy(self, blob, type):
"""Creates a Policy."""
diff --git a/tempest/services/identity/v3/json/service_client.py b/tempest/services/identity/v3/json/service_client.py
index dde572e..92f7629 100644
--- a/tempest/services/identity/v3/json/service_client.py
+++ b/tempest/services/identity/v3/json/service_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,27 +14,20 @@
# under the License.
import json
-from urlparse import urlparse
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class ServiceClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ServiceClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(ServiceClientJSON, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
-
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(ServiceClientJSON, self).request(method, url,
- headers=headers,
- body=body)
+ self.api_version = "v3"
def update_service(self, service_id, **kwargs):
"""Updates a service."""
diff --git a/tempest/services/identity/v3/xml/credentials_client.py b/tempest/services/identity/v3/xml/credentials_client.py
index dc0ade1..eca86ab 100644
--- a/tempest/services/identity/v3/xml/credentials_client.py
+++ b/tempest/services/identity/v3/xml/credentials_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,36 +14,28 @@
# under the License.
import json
-from urlparse import urlparse
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
XMLNS = "http://docs.openstack.org/identity/api/v3"
class CredentialsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(CredentialsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(CredentialsClientXML, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
-
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(CredentialsClientXML, self).request(method, url,
- headers=headers,
- body=body)
+ self.api_version = "v3"
def _parse_body(self, body):
data = xml_to_json(body)
diff --git a/tempest/services/identity/v3/xml/endpoints_client.py b/tempest/services/identity/v3/xml/endpoints_client.py
index e211cee..a20a9f5 100644
--- a/tempest/services/identity/v3/xml/endpoints_client.py
+++ b/tempest/services/identity/v3/xml/endpoints_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -14,26 +12,28 @@
# 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 urlparse
from lxml import etree
from tempest.common import http
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
XMLNS = "http://docs.openstack.org/identity/api/v3"
class EndPointClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(EndPointClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(EndPointClientXML, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
+ self.api_version = "v3"
def _parse_array(self, node):
array = []
@@ -49,12 +49,9 @@
def request(self, method, url, headers=None, body=None, wait=None):
"""Overriding the existing HTTP request in super class RestClient."""
- dscv = self.config.identity.disable_ssl_certificate_validation
+ dscv = CONF.identity.disable_ssl_certificate_validation
self.http_obj = http.ClosingHttp(
disable_ssl_certificate_validation=dscv)
- self._set_auth()
- self.base_url = self.base_url.replace(
- urlparse.urlparse(self.base_url).path, "/v3")
return super(EndPointClientXML, self).request(method, url,
headers=headers,
body=body)
diff --git a/tempest/services/identity/v3/xml/identity_client.py b/tempest/services/identity/v3/xml/identity_client.py
index 3fffc1f..e7b85c1 100644
--- a/tempest/services/identity/v3/xml/identity_client.py
+++ b/tempest/services/identity/v3/xml/identity_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,26 +13,31 @@
# License for the specific language governing permissions and limitations
# under the License.
-from urlparse import urlparse
+import json
+import urlparse
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
+from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
XMLNS = "http://docs.openstack.org/identity/api/v3"
class IdentityV3ClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(IdentityV3ClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(IdentityV3ClientXML, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
+ self.api_version = "v3"
def _parse_projects(self, node):
array = []
@@ -52,6 +55,14 @@
array.append(xml_to_json(child))
return array
+ def _parse_group_users(self, node):
+ array = []
+ for child in node.getchildren():
+ tag_list = child.tag.split('}', 1)
+ if tag_list[1] == "user":
+ array.append(xml_to_json(child))
+ return array
+
def _parse_roles(self, node):
array = []
for child in node.getchildren():
@@ -67,17 +78,8 @@
return array
def _parse_body(self, body):
- json = xml_to_json(body)
- return json
-
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class RestClient."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(IdentityV3ClientXML, self).request(method, url,
- headers=headers,
- body=body)
+ _json = xml_to_json(body)
+ return _json
def create_user(self, user_name, **kwargs):
"""Creates a user."""
@@ -318,11 +320,50 @@
body = self._parse_body(etree.fromstring(body))
return resp, body
+ def get_group(self, group_id):
+ """Get group details."""
+ resp, body = self.get('groups/%s' % group_id, self.headers)
+ body = self._parse_body(etree.fromstring(body))
+ return resp, body
+
+ def update_group(self, group_id, **kwargs):
+ """Updates a group."""
+ resp, body = self.get_group(group_id)
+ name = kwargs.get('name', body['name'])
+ description = kwargs.get('description', body['description'])
+ post_body = Element("group",
+ xmlns=XMLNS,
+ name=name,
+ description=description)
+ resp, body = self.patch('groups/%s' % group_id,
+ str(Document(post_body)),
+ self.headers)
+ body = self._parse_body(etree.fromstring(body))
+ return resp, body
+
def delete_group(self, group_id):
"""Delete a group."""
resp, body = self.delete('groups/%s' % group_id, self.headers)
return resp, body
+ def add_group_user(self, group_id, user_id):
+ """Add user into group."""
+ resp, body = self.put('groups/%s/users/%s' % (group_id, user_id),
+ '', self.headers)
+ return resp, body
+
+ def list_group_users(self, group_id):
+ """List users in group."""
+ resp, body = self.get('groups/%s/users' % group_id, self.headers)
+ body = self._parse_group_users(etree.fromstring(body))
+ return resp, body
+
+ def delete_group_user(self, group_id, user_id):
+ """Delete user in group."""
+ resp, body = self.delete('groups/%s/users/%s' % (group_id, user_id),
+ self.headers)
+ return resp, body
+
def assign_user_role_on_project(self, project_id, user_id, role_id):
"""Add roles to a user on a project."""
resp, body = self.put('projects/%s/users/%s/roles/%s' %
@@ -406,26 +447,41 @@
class V3TokenClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(V3TokenClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
- self.endpoint_url = 'adminURL'
-
- auth_url = config.identity.uri
-
- if 'tokens' not in auth_url:
- auth_url = auth_url.rstrip('/') + '/tokens'
+ def __init__(self):
+ super(V3TokenClientXML, self).__init__(None)
+ auth_url = CONF.identity.uri_v3
+ # If the v3 url is not set, get it from the v2 one
+ if auth_url is None:
+ auth_url = CONF.identity.uri.replace(urlparse.urlparse(
+ CONF.identity.uri).path, "/v3")
+ if 'auth/tokens' not in auth_url:
+ auth_url = auth_url.rstrip('/') + '/auth/tokens'
self.auth_url = auth_url
- self.config = config
- def auth(self, user_id, password):
- user = Element('user',
- id=user_id,
- password=password)
+ def auth(self, user, password, tenant=None, user_type='id', domain=None):
+ """
+ :param user: user id or name, as specified in user_type
+
+ Accepts different combinations of credentials. Restrictions:
+ - tenant and domain are only name (no id)
+ - user domain and tenant domain are assumed identical
+ Sample sample valid combinations:
+ - user_id, password
+ - username, password, domain
+ - username, password, tenant, domain
+ Validation is left to the server side.
+ """
+ if user_type == 'id':
+ _user = Element('user', id=user, password=password)
+ else:
+ _user = Element('user', name=user, password=password)
+ if domain is not None:
+ _domain = Element('domain', name=domain)
+ _user.append(_domain)
+
password = Element('password')
- password.append(user)
+ password.append(_user)
method = Element('method')
method.append(Text('password'))
@@ -434,18 +490,51 @@
identity = Element('identity')
identity.append(methods)
identity.append(password)
+
auth = Element('auth')
auth.append(identity)
- headers = {'Content-Type': 'application/xml'}
- resp, body = self.post("auth/tokens", headers=headers,
+
+ if tenant is not None:
+ project = Element('project', name=tenant)
+ project.append(_domain)
+ scope = Element('scope')
+ scope.append(project)
+ auth.append(scope)
+
+ resp, body = self.post(self.auth_url, headers=self.headers,
body=str(Document(auth)))
return resp, body
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(V3TokenClientXML, self).request(method, url,
- headers=headers,
- body=body)
+ def request(self, method, url, headers=None, body=None):
+ """A simple HTTP request interface."""
+ # Send XML, accept JSON. XML response is not easily
+ # converted to the corresponding JSON one
+ headers['Accept'] = 'application/json'
+ self._log_request(method, url, headers, body)
+ resp, resp_body = self.http_obj.request(url, method,
+ headers=headers, body=body)
+ self._log_response(resp, resp_body)
+
+ if resp.status in [401, 403]:
+ resp_body = json.loads(resp_body)
+ raise exceptions.Unauthorized(resp_body['error']['message'])
+ elif resp.status not in [200, 201, 204]:
+ raise exceptions.IdentityError(
+ 'Unexpected status code {0}'.format(resp.status))
+
+ return resp, json.loads(resp_body)
+
+ def get_token(self, user, password, tenant, domain='Default',
+ auth_data=False):
+ """
+ :param user: username
+ Returns (token id, token data) for supplied credentials
+ """
+ resp, body = self.auth(user, password, tenant, user_type='name',
+ domain=domain)
+
+ token = resp.get('x-subject-token')
+ if auth_data:
+ return token, body['token']
+ else:
+ return token
diff --git a/tempest/services/identity/v3/xml/policy_client.py b/tempest/services/identity/v3/xml/policy_client.py
index 0f07728..429c6a4 100644
--- a/tempest/services/identity/v3/xml/policy_client.py
+++ b/tempest/services/identity/v3/xml/policy_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,26 +13,27 @@
# License for the specific language governing permissions and limitations
# under the License.
-from urlparse import urlparse
-
from lxml import etree
from tempest.common import http
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
XMLNS = "http://docs.openstack.org/identity/api/v3"
class PolicyClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(PolicyClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(PolicyClientXML, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
+ self.api_version = "v3"
def _parse_array(self, node):
array = []
@@ -50,12 +49,9 @@
def request(self, method, url, headers=None, body=None, wait=None):
"""Overriding the existing HTTP request in super class RestClient."""
- dscv = self.config.identity.disable_ssl_certificate_validation
+ dscv = CONF.identity.disable_ssl_certificate_validation
self.http_obj = http.ClosingHttp(
disable_ssl_certificate_validation=dscv)
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
return super(PolicyClientXML, self).request(method, url,
headers=headers,
body=body)
diff --git a/tempest/services/identity/v3/xml/service_client.py b/tempest/services/identity/v3/xml/service_client.py
index 306245b..df9b234 100644
--- a/tempest/services/identity/v3/xml/service_client.py
+++ b/tempest/services/identity/v3/xml/service_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,26 +13,26 @@
# License for the specific language governing permissions and limitations
# under the License.
-from urlparse import urlparse
-
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
XMLNS = "http://docs.openstack.org/identity/api/v3"
class ServiceClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ServiceClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
+ def __init__(self, auth_provider):
+ super(ServiceClientXML, self).__init__(auth_provider)
+ self.service = CONF.identity.catalog_type
self.endpoint_url = 'adminURL'
+ self.api_version = "v3"
def _parse_array(self, node):
array = []
@@ -46,15 +44,6 @@
data = xml_to_json(body)
return data
- def request(self, method, url, headers=None, body=None, wait=None):
- """Overriding the existing HTTP request in super class rest_client."""
- self._set_auth()
- self.base_url = self.base_url.replace(urlparse(self.base_url).path,
- "/v3")
- return super(ServiceClientXML, self).request(method, url,
- headers=headers,
- body=body)
-
def update_service(self, service_id, **kwargs):
"""Updates a service_id."""
resp, body = self.get_service(service_id)
diff --git a/tempest/services/identity/xml/identity_client.py b/tempest/services/identity/xml/identity_client.py
index 9c0a72c..81846da 100644
--- a/tempest/services/identity/xml/identity_client.py
+++ b/tempest/services/identity/xml/identity_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -14,58 +12,24 @@
# 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 tempest import config
+from tempest.services.compute.xml import common as xml
+from tempest.services.identity.json import identity_client
-import json
-
-from lxml import etree
-
-from tempest.common import http
-from tempest.common.rest_client import RestClientXML
-from tempest import exceptions
-from tempest.services.compute.xml.common import Document
-from tempest.services.compute.xml.common import Element
-from tempest.services.compute.xml.common import xml_to_json
-
+CONF = config.CONF
XMLNS = "http://docs.openstack.org/identity/api/v2.0"
-class IdentityClientXML(RestClientXML):
-
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(IdentityClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.identity.catalog_type
- self.endpoint_url = 'adminURL'
-
- def _parse_array(self, node):
- array = []
- for child in node.getchildren():
- array.append(xml_to_json(child))
- return array
-
- def _parse_body(self, body):
- data = xml_to_json(body)
- return data
-
- def has_admin_extensions(self):
- """
- Returns True if the KSADM Admin Extensions are supported
- False otherwise
- """
- if hasattr(self, '_has_admin_extensions'):
- return self._has_admin_extensions
- resp, body = self.list_roles()
- self._has_admin_extensions = ('status' in resp and resp.status != 503)
- return self._has_admin_extensions
+class IdentityClientXML(identity_client.IdentityClientJSON):
+ TYPE = "xml"
def create_role(self, name):
"""Create a role."""
- create_role = Element("role", xmlns=XMLNS, name=name)
- resp, body = self.post('OS-KSADM/roles', str(Document(create_role)),
- self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
+ create_role = xml.Element("role", xmlns=XMLNS, name=name)
+ resp, body = self.post('OS-KSADM/roles',
+ str(xml.Document(create_role)))
+ return resp, self._parse_resp(body)
def create_tenant(self, name, **kwargs):
"""
@@ -75,70 +39,18 @@
enabled <true|false>: Initial tenant status (default is true)
"""
en = kwargs.get('enabled', 'true')
- create_tenant = Element("tenant",
- xmlns=XMLNS,
- name=name,
- description=kwargs.get('description', ''),
- enabled=str(en).lower())
- resp, body = self.post('tenants', str(Document(create_tenant)),
- self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
-
- def delete_role(self, role_id):
- """Delete a role."""
- resp, body = self.delete('OS-KSADM/roles/%s' % str(role_id),
- self.headers)
- return resp, body
-
- def list_user_roles(self, tenant_id, user_id):
- """Returns a list of roles assigned to a user for a tenant."""
- url = '/tenants/%s/users/%s/roles' % (tenant_id, user_id)
- resp, body = self.get(url, self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
-
- def assign_user_role(self, tenant_id, user_id, role_id):
- """Add roles to a user on a tenant."""
- resp, body = self.put('/tenants/%s/users/%s/roles/OS-KSADM/%s' %
- (tenant_id, user_id, role_id), '', self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
-
- def remove_user_role(self, tenant_id, user_id, role_id):
- """Removes a role assignment for a user on a tenant."""
- return self.delete('/tenants/%s/users/%s/roles/OS-KSADM/%s' %
- (tenant_id, user_id, role_id), self.headers)
-
- def delete_tenant(self, tenant_id):
- """Delete a tenant."""
- resp, body = self.delete('tenants/%s' % str(tenant_id), self.headers)
- return resp, body
-
- def get_tenant(self, tenant_id):
- """Get tenant details."""
- resp, body = self.get('tenants/%s' % str(tenant_id), self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
-
- def list_roles(self):
- """Returns roles."""
- resp, body = self.get('OS-KSADM/roles', self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
+ create_tenant = xml.Element("tenant",
+ xmlns=XMLNS,
+ name=name,
+ description=kwargs.get('description', ''),
+ enabled=str(en).lower())
+ resp, body = self.post('tenants', str(xml.Document(create_tenant)))
+ return resp, self._parse_resp(body)
def list_tenants(self):
"""Returns tenants."""
- resp, body = self.get('tenants', self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
-
- def get_tenant_by_name(self, tenant_name):
- resp, tenants = self.list_tenants()
- for tenant in tenants:
- if tenant['name'] == tenant_name:
- return tenant
- raise exceptions.NotFound('No such tenant')
+ resp, body = self.get('tenants')
+ return resp, self._parse_resp(body)
def update_tenant(self, tenant_id, **kwargs):
"""Updates a tenant."""
@@ -146,169 +58,69 @@
name = kwargs.get('name', body['name'])
desc = kwargs.get('description', body['description'])
en = kwargs.get('enabled', body['enabled'])
- update_tenant = Element("tenant",
- xmlns=XMLNS,
- id=tenant_id,
- name=name,
- description=desc,
- enabled=str(en).lower())
+ update_tenant = xml.Element("tenant",
+ xmlns=XMLNS,
+ id=tenant_id,
+ name=name,
+ description=desc,
+ enabled=str(en).lower())
resp, body = self.post('tenants/%s' % tenant_id,
- str(Document(update_tenant)),
- self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
+ str(xml.Document(update_tenant)))
+ return resp, self._parse_resp(body)
def create_user(self, name, password, tenant_id, email, **kwargs):
"""Create a user."""
- create_user = Element("user",
- xmlns=XMLNS,
- name=name,
- password=password,
- tenantId=tenant_id,
- email=email)
+ create_user = xml.Element("user",
+ xmlns=XMLNS,
+ name=name,
+ password=password,
+ tenantId=tenant_id,
+ email=email)
if 'enabled' in kwargs:
create_user.add_attr('enabled', str(kwargs['enabled']).lower())
- resp, body = self.post('users', str(Document(create_user)),
- self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
+ resp, body = self.post('users', str(xml.Document(create_user)))
+ return resp, self._parse_resp(body)
def update_user(self, user_id, **kwargs):
"""Updates a user."""
if 'enabled' in kwargs:
kwargs['enabled'] = str(kwargs['enabled']).lower()
- update_user = Element("user", xmlns=XMLNS, **kwargs)
+ update_user = xml.Element("user", xmlns=XMLNS, **kwargs)
resp, body = self.put('users/%s' % user_id,
- str(Document(update_user)),
- self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
-
- def get_user(self, user_id):
- """GET a user."""
- resp, body = self.get("users/%s" % user_id, self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
-
- def delete_user(self, user_id):
- """Delete a user."""
- resp, body = self.delete("users/%s" % user_id, self.headers)
- return resp, body
-
- def get_users(self):
- """Get the list of users."""
- resp, body = self.get("users", self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
+ str(xml.Document(update_user)))
+ return resp, self._parse_resp(body)
def enable_disable_user(self, user_id, enabled):
"""Enables or disables a user."""
- enable_user = Element("user", enabled=str(enabled).lower())
+ enable_user = xml.Element("user", enabled=str(enabled).lower())
resp, body = self.put('users/%s/enabled' % user_id,
- str(Document(enable_user)), self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
+ str(xml.Document(enable_user)), self.headers)
+ return resp, self._parse_resp(body)
- def delete_token(self, token_id):
- """Delete a token."""
- resp, body = self.delete("tokens/%s" % token_id, self.headers)
- return resp, body
-
- def list_users_for_tenant(self, tenant_id):
- """List users for a Tenant."""
- resp, body = self.get('/tenants/%s/users' % tenant_id, self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
-
- def get_user_by_username(self, tenant_id, username):
- resp, users = self.list_users_for_tenant(tenant_id)
- for user in users:
- if user['name'] == username:
- return user
- raise exceptions.NotFound('No such user')
-
- def create_service(self, name, type, **kwargs):
+ def create_service(self, name, service_type, **kwargs):
"""Create a service."""
OS_KSADM = "http://docs.openstack.org/identity/api/ext/OS-KSADM/v1.0"
- create_service = Element("service",
- xmlns=OS_KSADM,
- name=name,
- type=type,
- description=kwargs.get('description'))
+ create_service = xml.Element("service",
+ xmlns=OS_KSADM,
+ name=name,
+ type=service_type,
+ description=kwargs.get('description'))
resp, body = self.post('OS-KSADM/services',
- str(Document(create_service)),
- self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
-
- def list_services(self):
- """Returns services."""
- resp, body = self.get('OS-KSADM/services', self.headers)
- body = self._parse_array(etree.fromstring(body))
- return resp, body
-
- def get_service(self, service_id):
- """Get Service."""
- url = '/OS-KSADM/services/%s' % service_id
- resp, body = self.get(url, self.headers)
- body = self._parse_body(etree.fromstring(body))
- return resp, body
-
- def delete_service(self, service_id):
- """Delete Service."""
- url = '/OS-KSADM/services/%s' % service_id
- return self.delete(url, self.headers)
+ str(xml.Document(create_service)))
+ return resp, self._parse_resp(body)
-class TokenClientXML(RestClientXML):
-
- def __init__(self, config):
- auth_url = config.identity.uri
-
- # TODO(jaypipes) Why is this all repeated code in here?
- # Normalize URI to ensure /tokens is in it.
- if 'tokens' not in auth_url:
- auth_url = auth_url.rstrip('/') + '/tokens'
-
- self.auth_url = auth_url
- self.config = config
+class TokenClientXML(identity_client.TokenClientJSON):
+ TYPE = "xml"
def auth(self, user, password, tenant):
- passwordCreds = Element("passwordCredentials",
- username=user,
- password=password)
- auth = Element("auth", tenantName=tenant)
+ passwordCreds = xml.Element("passwordCredentials",
+ username=user,
+ password=password)
+ auth = xml.Element("auth", tenantName=tenant)
auth.append(passwordCreds)
- headers = {'Content-Type': 'application/xml'}
- resp, body = self.post(self.auth_url, headers=headers,
- body=str(Document(auth)))
- return resp, body
-
- def request(self, method, url, headers=None, body=None):
- """A simple HTTP request interface."""
- dscv = self.config.identity.disable_ssl_certificate_validation
- self.http_obj = http.ClosingHttp(
- disable_ssl_certificate_validation=dscv)
- if headers is None:
- headers = {}
- self._log_request(method, url, headers, body)
- resp, resp_body = self.http_obj.request(url, method,
- headers=headers, body=body)
- self._log_response(resp, resp_body)
-
- if resp.status in (401, 403):
- resp_body = json.loads(resp_body)
- raise exceptions.Unauthorized(resp_body['error']['message'])
-
- return resp, resp_body
-
- def get_token(self, user, password, tenant):
- resp, body = self.auth(user, password, tenant)
- if resp['status'] != '202':
- body = json.loads(body)
- access = body['access']
- token = access['token']
- return token['id']
+ resp, body = self.post(self.auth_url, body=str(xml.Document(auth)))
+ return resp, body['access']
diff --git a/tempest/services/image/v1/json/image_client.py b/tempest/services/image/v1/json/image_client.py
index 61dd050..bc9db38 100644
--- a/tempest/services/image/v1/json/image_client.py
+++ b/tempest/services/image/v1/json/image_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
@@ -24,20 +22,21 @@
from tempest.common import glance_http
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
class ImageClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ImageClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.images.catalog_type
- if config.service_available.glance:
- self.http = self._get_http()
+ def __init__(self, auth_provider):
+ super(ImageClientJSON, self).__init__(auth_provider)
+ self.service = CONF.image.catalog_type
+ self._http = None
def _image_meta_from_headers(self, headers):
meta = {'properties': {}}
@@ -105,13 +104,9 @@
return None
def _get_http(self):
- token, endpoint = self.keystone_auth(self.user,
- self.password,
- self.auth_url,
- self.service,
- self.tenant_name)
- dscv = self.config.identity.disable_ssl_certificate_validation
- return glance_http.HTTPClient(endpoint=endpoint, token=token,
+ dscv = CONF.identity.disable_ssl_certificate_validation
+ return glance_http.HTTPClient(auth_provider=self.auth_provider,
+ filters=self.filters,
insecure=dscv)
def _create_with_data(self, headers, data):
@@ -131,6 +126,13 @@
body = json.loads(''.join([c for c in body_iter]))
return resp, body['image']
+ @property
+ def http(self):
+ if self._http is None:
+ if CONF.service_available.glance:
+ self._http = self._get_http()
+ return self._http
+
def create_image(self, name, container_format, disk_format, **kwargs):
params = {
"name": name,
diff --git a/tempest/services/image/v2/json/image_client.py b/tempest/services/image/v2/json/image_client.py
index c654a49..b825519 100644
--- a/tempest/services/image/v2/json/image_client.py
+++ b/tempest/services/image/v2/json/image_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
@@ -22,24 +20,23 @@
from tempest.common import glance_http
from tempest.common import rest_client
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class ImageClientV2JSON(rest_client.RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ImageClientV2JSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.images.catalog_type
- if config.service_available.glance:
- self.http = self._get_http()
+ def __init__(self, auth_provider):
+ super(ImageClientV2JSON, self).__init__(auth_provider)
+ self.service = CONF.image.catalog_type
+ self._http = None
def _get_http(self):
- token, endpoint = self.keystone_auth(self.user, self.password,
- self.auth_url, self.service,
- self.tenant_name)
- dscv = self.config.identity.disable_ssl_certificate_validation
- return glance_http.HTTPClient(endpoint=endpoint, token=token,
+ dscv = CONF.identity.disable_ssl_certificate_validation
+ return glance_http.HTTPClient(auth_provider=self.auth_provider,
+ filters=self.filters,
insecure=dscv)
def get_images_schema(self):
@@ -64,6 +61,13 @@
jsonschema.validate(body, schema)
+ @property
+ def http(self):
+ if self._http is None:
+ if CONF.service_available.glance:
+ self._http = self._get_http()
+ return self._http
+
def create_image(self, name, container_format, disk_format, **kwargs):
params = {
"name": name,
diff --git a/tempest/services/network/json/network_client.py b/tempest/services/network/json/network_client.py
index e26697e..1458c7b 100644
--- a/tempest/services/network/json/network_client.py
+++ b/tempest/services/network/json/network_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# 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
@@ -33,9 +31,8 @@
quotas
"""
- def get_rest_client(self, config, username,
- password, auth_url, tenant_name=None):
- return RestClient(config, username, password, auth_url, tenant_name)
+ def get_rest_client(self, auth_provider):
+ return RestClient(auth_provider)
def deserialize_single(self, body):
return json.loads(body)
@@ -49,50 +46,8 @@
def serialize(self, data):
return json.dumps(data)
- def create_network(self, name, **kwargs):
- post_body = {'network': kwargs}
- post_body['network']['name'] = name
- body = json.dumps(post_body)
- uri = '%s/networks' % (self.uri_prefix)
- resp, body = self.post(uri, body)
- body = json.loads(body)
- return resp, body
-
- def create_bulk_network(self, count, names):
- network_list = list()
- for i in range(count):
- network_list.append({'name': names[i]})
- post_body = {'networks': network_list}
- body = json.dumps(post_body)
- uri = '%s/networks' % (self.uri_prefix)
- resp, body = self.post(uri, body)
- body = json.loads(body)
- return resp, body
-
- def create_subnet(self, net_uuid, cidr, ip_version=4, **kwargs):
- post_body = {'subnet': kwargs}
- post_body['subnet']['ip_version'] = ip_version
- post_body['subnet']['network_id'] = net_uuid
- post_body['subnet']['cidr'] = cidr
- body = json.dumps(post_body)
- uri = '%s/subnets' % (self.uri_prefix)
- resp, body = self.post(uri, body)
- body = json.loads(body)
- return resp, body
-
- def create_port(self, network_id, **kwargs):
- post_body = {
- 'port': {
- 'network_id': network_id,
- }
- }
- for key, val in kwargs.items():
- post_body['port'][key] = val
- body = json.dumps(post_body)
- uri = '%s/ports' % (self.uri_prefix)
- resp, body = self.post(uri, body)
- body = json.loads(body)
- return resp, body
+ def serialize_list(self, data, root=None, item=None):
+ return self.serialize(data)
def update_quotas(self, tenant_id, **kwargs):
put_body = {'quota': kwargs}
@@ -107,42 +62,6 @@
resp, body = self.delete(uri)
return resp, body
- def update_subnet(self, subnet_id, new_name):
- put_body = {
- 'subnet': {
- 'name': new_name,
- }
- }
- body = json.dumps(put_body)
- uri = '%s/subnets/%s' % (self.uri_prefix, subnet_id)
- resp, body = self.put(uri, body)
- body = json.loads(body)
- return resp, body
-
- def update_port(self, port_id, new_name):
- put_body = {
- 'port': {
- 'name': new_name,
- }
- }
- body = json.dumps(put_body)
- uri = '%s/ports/%s' % (self.uri_prefix, port_id)
- resp, body = self.put(uri, body)
- body = json.loads(body)
- return resp, body
-
- def update_network(self, network_id, new_name):
- put_body = {
- "network": {
- "name": new_name,
- }
- }
- body = json.dumps(put_body)
- uri = '%s/networks/%s' % (self.uri_prefix, network_id)
- resp, body = self.put(uri, body)
- body = json.loads(body)
- return resp, body
-
def create_router(self, name, admin_state_up=True, **kwargs):
post_body = {'router': kwargs}
post_body['router']['name'] = name
@@ -274,22 +193,6 @@
body = json.loads(body)
return resp, body
- def create_bulk_subnet(self, subnet_list):
- post_body = {'subnets': subnet_list}
- body = json.dumps(post_body)
- uri = '%s/subnets' % (self.uri_prefix)
- resp, body = self.post(uri, body)
- body = json.loads(body)
- return resp, body
-
- def create_bulk_port(self, port_list):
- post_body = {'ports': port_list}
- body = json.dumps(post_body)
- uri = '%s/ports' % (self.uri_prefix)
- resp, body = self.post(uri, body)
- body = json.loads(body)
- return resp, body
-
def create_vip(self, name, protocol, protocol_port, subnet_id, pool_id):
post_body = {
"vip": {
diff --git a/tempest/services/network/network_client_base.py b/tempest/services/network/network_client_base.py
index 5ddf6ff..07716fa 100644
--- a/tempest/services/network/network_client_base.py
+++ b/tempest/services/network/network_client_base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# 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
@@ -14,6 +12,10 @@
import urllib
+from tempest import config
+
+CONF = config.CONF
+
# the following map is used to construct proper URI
# for the given neutron resource
service_resource_prefix_map = {
@@ -44,16 +46,14 @@
class NetworkClientBase(object):
- def __init__(self, config, username, password,
- auth_url, tenant_name=None):
+ def __init__(self, auth_provider):
self.rest_client = self.get_rest_client(
- config, username, password, auth_url, tenant_name)
- self.rest_client.service = self.rest_client.config.network.catalog_type
+ auth_provider)
+ self.rest_client.service = CONF.network.catalog_type
self.version = '2.0'
self.uri_prefix = "v%s" % (self.version)
- def get_rest_client(self, config, username, password,
- auth_url, tenant_name):
+ def get_rest_client(self, auth_provider):
raise NotImplementedError
def post(self, uri, body, headers=None):
@@ -163,3 +163,31 @@
if name[:prefix_len] == prefix:
return method_functors[index](name[prefix_len:])
raise AttributeError(name)
+
+ # Common methods that are hard to automate
+ def create_bulk_network(self, count, names):
+ network_list = list()
+ for i in range(count):
+ network_list.append({'name': names[i]})
+ post_data = {'networks': network_list}
+ body = self.serialize_list(post_data, "networks", "network")
+ uri = self.get_uri("networks")
+ resp, body = self.post(uri, body)
+ body = {'networks': self.deserialize_list(body)}
+ return resp, body
+
+ def create_bulk_subnet(self, subnet_list):
+ post_data = {'subnets': subnet_list}
+ body = self.serialize_list(post_data, 'subnets', 'subnet')
+ uri = self.get_uri('subnets')
+ resp, body = self.post(uri, body)
+ body = {'subnets': self.deserialize_list(body)}
+ return resp, body
+
+ def create_bulk_port(self, port_list):
+ post_data = {'ports': port_list}
+ body = self.serialize_list(post_data, 'ports', 'port')
+ uri = self.get_uri('ports')
+ resp, body = self.post(uri, body)
+ body = {'ports': self.deserialize_list(body)}
+ return resp, body
diff --git a/tempest/services/network/xml/network_client.py b/tempest/services/network/xml/network_client.py
index a57f278..720c842 100644
--- a/tempest/services/network/xml/network_client.py
+++ b/tempest/services/network/xml/network_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# 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
@@ -30,10 +28,14 @@
PLURALS = ['dns_nameservers', 'host_routes', 'allocation_pools',
'fixed_ips', 'extensions']
- def get_rest_client(self, config, username, password,
- auth_url, tenant_name=None):
- return RestClientXML(config, username, password,
- auth_url, tenant_name)
+ def get_rest_client(self, auth_provider):
+ return RestClientXML(auth_provider)
+
+ def _parse_array(self, node):
+ array = []
+ for child in node.getchildren():
+ array.append(xml_to_json(child))
+ return array
def deserialize_list(self, body):
return parse_array(etree.fromstring(body), self.PLURALS)
@@ -46,84 +48,34 @@
# expecting the dict with single key
root = body.keys()[0]
post_body = Element(root)
+ post_body.add_attr('xmlns:xsi',
+ 'http://www.w3.org/2001/XMLSchema-instance')
for name, attr in body[root].items():
- elt = Element(name, attr)
+ elt = self._get_element(name, attr)
post_body.append(elt)
return str(Document(post_body))
- def create_network(self, name):
- uri = '%s/networks' % (self.uri_prefix)
- post_body = Element("network")
- p2 = Element("name", name)
- post_body.append(p2)
- resp, body = self.post(uri, str(Document(post_body)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
+ def serialize_list(self, body, root_name=None, item_name=None):
+ # expecting dict in form
+ # body = {'resources': [res_dict1, res_dict2, ...]
+ post_body = Element(root_name)
+ post_body.add_attr('xmlns:xsi',
+ 'http://www.w3.org/2001/XMLSchema-instance')
+ for item in body[body.keys()[0]]:
+ elt = Element(item_name)
+ for name, attr in item.items():
+ elt_content = self._get_element(name, attr)
+ elt.append(elt_content)
+ post_body.append(elt)
+ return str(Document(post_body))
- def create_bulk_network(self, count, names):
- uri = '%s/networks' % (self.uri_prefix)
- post_body = Element("networks")
- for i in range(count):
- p1 = Element("network")
- p2 = Element("name", names[i])
- p1.append(p2)
- post_body.append(p1)
- resp, body = self.post(uri, str(Document(post_body)))
- networks = parse_array(etree.fromstring(body))
- networks = {"networks": networks}
- return resp, networks
-
- def create_subnet(self, net_uuid, cidr):
- uri = '%s/subnets' % (self.uri_prefix)
- subnet = Element("subnet")
- p2 = Element("network_id", net_uuid)
- p3 = Element("cidr", cidr)
- p4 = Element("ip_version", 4)
- subnet.append(p2)
- subnet.append(p3)
- subnet.append(p4)
- resp, body = self.post(uri, str(Document(subnet)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
-
- def create_port(self, net_uuid, **kwargs):
- uri = '%s/ports' % (self.uri_prefix)
- port = Element("port")
- p1 = Element('network_id', net_uuid)
- port.append(p1)
- for key, val in kwargs.items():
- key = Element(key, val)
- port.append(key)
- resp, body = self.post(uri, str(Document(port)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
-
- def update_port(self, port_id, name):
- uri = '%s/ports/%s' % (self.uri_prefix, str(port_id))
- port = Element("port")
- p2 = Element("name", name)
- port.append(p2)
- resp, body = self.put(uri, str(Document(port)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
-
- def update_subnet(self, subnet_id, name):
- uri = '%s/subnets/%s' % (self.uri_prefix, str(subnet_id))
- subnet = Element("subnet")
- p2 = Element("name", name)
- subnet.append(p2)
- resp, body = self.put(uri, str(Document(subnet)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
-
- def update_network(self, net_id, name):
- uri = '%s/networks/%s' % (self.uri_prefix, str(net_id))
- network = Element("network")
- p2 = Element("name", name)
- network.append(p2)
- resp, body = self.put(uri, str(Document(network)))
- body = _root_tag_fetcher_and_xml_to_json_parse(body)
- return resp, body
+ def _get_element(self, name, value):
+ if value is None:
+ xml_elem = Element(name)
+ xml_elem.add_attr("xsi:nil", "true")
+ return xml_elem
+ else:
+ return Element(name, value)
def create_security_group(self, name):
uri = '%s/security-groups' % (self.uri_prefix)
@@ -149,36 +101,6 @@
body = _root_tag_fetcher_and_xml_to_json_parse(body)
return resp, body
- def create_bulk_subnet(self, subnet_list):
- uri = '%s/subnets' % (self.uri_prefix)
- post_body = Element("subnets")
- for i in range(len(subnet_list)):
- v = subnet_list[i]
- p1 = Element("subnet")
- for k, kv in v.iteritems():
- p2 = Element(k, kv)
- p1.append(p2)
- post_body.append(p1)
- resp, body = self.post(uri, str(Document(post_body)))
- subnets = parse_array(etree.fromstring(body))
- subnets = {"subnets": subnets}
- return resp, subnets
-
- def create_bulk_port(self, port_list):
- uri = '%s/ports' % (self.uri_prefix)
- post_body = Element("ports")
- for i in range(len(port_list)):
- v = port_list[i]
- p1 = Element("port")
- for k, kv in v.iteritems():
- p2 = Element(k, kv)
- p1.append(p2)
- post_body.append(p1)
- resp, body = self.post(uri, str(Document(post_body)))
- ports = parse_array(etree.fromstring(body))
- ports = {"ports": ports}
- return resp, ports
-
def create_vip(self, name, protocol, protocol_port, subnet_id, pool_id):
uri = '%s/lb/vips' % (self.uri_prefix)
post_body = Element("vip")
diff --git a/tempest/services/object_storage/account_client.py b/tempest/services/object_storage/account_client.py
index 94b55c3..efac5f5 100644
--- a/tempest/services/object_storage/account_client.py
+++ b/tempest/services/object_storage/account_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,24 +18,55 @@
from tempest.common import http
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class AccountClient(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AccountClient, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.object_storage.catalog_type
+ def __init__(self, auth_provider):
+ super(AccountClient, self).__init__(auth_provider)
+ self.service = CONF.object_storage.catalog_type
self.format = 'json'
+ def create_account(self, data=None,
+ params=None,
+ metadata={},
+ remove_metadata={},
+ metadata_prefix='X-Account-Meta-',
+ remove_metadata_prefix='X-Remove-Account-Meta-'):
+ """Create an account."""
+ url = ''
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+
+ headers = {}
+ for key in metadata:
+ headers[metadata_prefix + key] = metadata[key]
+ for key in remove_metadata:
+ headers[remove_metadata_prefix + key] = remove_metadata[key]
+
+ resp, body = self.put(url, data, headers)
+ return resp, body
+
+ def delete_account(self, data=None, params=None):
+ """Delete an account."""
+ url = ''
+ if params:
+ if 'bulk-delete' in params:
+ url += 'bulk-delete&'
+ url = '?%s%s' % (url, urllib.urlencode(params))
+
+ resp, body = self.delete(url, headers={}, body=data)
+ return resp, body
+
def list_account_metadata(self):
"""
HEAD on the storage URL
Returns all account metadata headers
"""
-
- headers = {"X-Storage-Token": self.token}
- resp, body = self.head('', headers=headers)
+ resp, body = self.head('')
return resp, body
def create_account_metadata(self, metadata,
@@ -56,7 +85,7 @@
Deletes an account metadata entry.
"""
- headers = {"X-Storage-Token": self.token}
+ headers = {}
for item in metadata:
headers[metadata_prefix + item] = 'x'
resp, body = self.post('', headers=headers, body=None)
@@ -65,8 +94,8 @@
def list_account_containers(self, params=None):
"""
GET on the (base) storage URL
- Given the X-Storage-URL and a valid X-Auth-Token, returns
- a list of all containers for the account.
+ Given valid X-Auth-Token, returns a list of all containers for the
+ account.
Optional Arguments:
limit=[integer value N]
@@ -92,18 +121,28 @@
url = '?' + urllib.urlencode(params)
resp, body = self.get(url)
+
+ if params and params.get('format') == 'json':
+ body = json.loads(body)
+ return resp, body
+
+ def list_extensions(self):
+ self.skip_path()
+ resp, body = self.get('info')
+ self.reset_path()
body = json.loads(body)
return resp, body
class AccountClientCustomizedHeader(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(AccountClientCustomizedHeader, self).__init__(config, username,
- password, auth_url,
- tenant_name)
+ # TODO(andreaf) This class is now redundant, to be removed in next patch
+
+ def __init__(self, auth_provider):
+ super(AccountClientCustomizedHeader, self).__init__(
+ auth_provider)
# Overwrites json-specific header encoding in RestClient
- self.service = self.config.object_storage.catalog_type
+ self.service = CONF.object_storage.catalog_type
self.format = 'json'
def request(self, method, url, headers=None, body=None):
@@ -111,14 +150,17 @@
self.http_obj = http.ClosingHttp()
if headers is None:
headers = {}
- if self.base_url is None:
- self._set_auth()
- req_url = "%s/%s" % (self.base_url, url)
-
+ # Authorize the request
+ req_url, req_headers, req_body = self.auth_provider.auth_request(
+ method=method, url=url, headers=headers, body=body,
+ filters=self.filters
+ )
self._log_request(method, req_url, headers, body)
+ # use original body
resp, resp_body = self.http_obj.request(req_url, method,
- headers=headers, body=body)
+ headers=req_headers,
+ body=req_body)
self._log_response(resp, resp_body)
if resp.status == 401 or resp.status == 403:
@@ -129,8 +171,8 @@
def list_account_containers(self, params=None, metadata=None):
"""
GET on the (base) storage URL
- Given the X-Storage-URL and a valid X-Auth-Token, returns
- a list of all containers for the account.
+ Given a valid X-Auth-Token, returns a list of all containers for the
+ account.
Optional Arguments:
limit=[integer value N]
diff --git a/tempest/services/object_storage/container_client.py b/tempest/services/object_storage/container_client.py
index 166c945..f224407 100644
--- a/tempest/services/object_storage/container_client.py
+++ b/tempest/services/object_storage/container_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,20 +17,27 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+from xml.etree import ElementTree as etree
+
+CONF = config.CONF
class ContainerClient(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ContainerClient, self).__init__(config, username, password,
- auth_url, tenant_name)
+ def __init__(self, auth_provider):
+ super(ContainerClient, self).__init__(auth_provider)
# Overwrites json-specific header encoding in RestClient
self.headers = {}
- self.service = self.config.object_storage.catalog_type
+ self.service = CONF.object_storage.catalog_type
self.format = 'json'
- def create_container(self, container_name, metadata=None,
- metadata_prefix='X-Container-Meta-'):
+ def create_container(
+ self, container_name,
+ metadata=None,
+ remove_metadata=None,
+ metadata_prefix='X-Container-Meta-',
+ remove_metadata_prefix='X-Remove-Container-Meta-'):
"""
Creates a container, with optional metadata passed in as a
dictionary
@@ -43,6 +48,9 @@
if metadata is not None:
for key in metadata:
headers[metadata_prefix + key] = metadata[key]
+ if remove_metadata is not None:
+ for key in remove_metadata:
+ headers[remove_metadata_prefix + key] = remove_metadata[key]
resp, body = self.put(url, body=None, headers=headers)
return resp, body
@@ -53,8 +61,12 @@
resp, body = self.delete(url)
return resp, body
- def update_container_metadata(self, container_name, metadata,
- metadata_prefix='X-Container-Meta-'):
+ def update_container_metadata(
+ self, container_name,
+ metadata=None,
+ remove_metadata=None,
+ metadata_prefix='X-Container-Meta-',
+ remove_metadata_prefix='X-Remove-Container-Meta-'):
"""Updates arbitrary metadata on container."""
url = str(container_name)
headers = {}
@@ -62,6 +74,9 @@
if metadata is not None:
for key in metadata:
headers[metadata_prefix + key] = metadata[key]
+ if remove_metadata is not None:
+ for key in remove_metadata:
+ headers[remove_metadata_prefix + key] = remove_metadata[key]
resp, body = self.post(url, body=None, headers=headers)
return resp, body
@@ -74,7 +89,7 @@
if metadata is not None:
for item in metadata:
- headers[metadata_prefix + item] = 'x'
+ headers[metadata_prefix + item] = metadata[item]
resp, body = self.post(url, body=None, headers=headers)
return resp, body
@@ -84,8 +99,7 @@
Retrieves container metadata headers
"""
url = str(container_name)
- headers = {"X-Storage-Token": self.token}
- resp, body = self.head(url, headers=headers)
+ resp, body = self.head(url)
return resp, body
def list_all_container_objects(self, container, params=None):
@@ -104,8 +118,9 @@
if 'marker' in params:
limit = params['marker']
- resp, objlist = self.list_container_contents(container,
- params={'limit': limit})
+ resp, objlist = self.list_container_contents(
+ container,
+ params={'limit': limit, 'format': 'json'})
return objlist
"""tmp = []
for obj in objlist:
@@ -162,10 +177,13 @@
"""
url = str(container)
- url += '?format=%s' % self.format
if params:
+ url += '?'
url += '&%s' % urllib.urlencode(params)
- resp, body = self.get(url)
- body = json.loads(body)
+ resp, body = self.get(url, headers={})
+ if params and params.get('format') == 'json':
+ body = json.loads(body)
+ elif params and params.get('format') == 'xml':
+ body = etree.fromstring(body)
return resp, body
diff --git a/tempest/services/object_storage/object_client.py b/tempest/services/object_storage/object_client.py
index 5c86d1f..79c5719 100644
--- a/tempest/services/object_storage/object_client.py
+++ b/tempest/services/object_storage/object_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,15 +17,17 @@
from tempest.common import http
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class ObjectClient(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ObjectClient, self).__init__(config, username, password,
- auth_url, tenant_name)
+ def __init__(self, auth_provider):
+ super(ObjectClient, self).__init__(auth_provider)
- self.service = self.config.object_storage.catalog_type
+ self.service = CONF.object_storage.catalog_type
def create_object(self, container, object_name, data, params=None):
"""Create storage object."""
@@ -51,7 +51,7 @@
url = "%s/%s" % (str(container), str(object_name))
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.delete(url)
+ resp, body = self.delete(url, headers={})
return resp, body
def update_object_metadata(self, container, object_name, metadata,
@@ -137,28 +137,33 @@
class ObjectClientCustomizedHeader(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ObjectClientCustomizedHeader, self).__init__(config, username,
- password, auth_url,
- tenant_name)
+ # TODO(andreaf) This class is now redundant, to be removed in next patch
+
+ def __init__(self, auth_provider):
+ super(ObjectClientCustomizedHeader, self).__init__(
+ auth_provider)
# Overwrites json-specific header encoding in RestClient
- self.service = self.config.object_storage.catalog_type
+ self.service = CONF.object_storage.catalog_type
self.format = 'json'
def request(self, method, url, headers=None, body=None):
"""A simple HTTP request interface."""
- dscv = self.config.identity.disable_ssl_certificate_validation
+ dscv = CONF.identity.disable_ssl_certificate_validation
self.http_obj = http.ClosingHttp(
disable_ssl_certificate_validation=dscv)
if headers is None:
headers = {}
- if self.base_url is None:
- self._set_auth()
- req_url = "%s/%s" % (self.base_url, url)
+ # Authorize the request
+ req_url, req_headers, req_body = self.auth_provider.auth_request(
+ method=method, url=url, headers=headers, body=body,
+ filters=self.filters
+ )
+ # Use original method
self._log_request(method, req_url, headers, body)
resp, resp_body = self.http_obj.request(req_url, method,
- headers=headers, body=body)
+ headers=req_headers,
+ body=req_body)
self._log_response(resp, resp_body)
if resp.status == 401 or resp.status == 403:
raise exceptions.Unauthorized()
diff --git a/tempest/services/orchestration/json/orchestration_client.py b/tempest/services/orchestration/json/orchestration_client.py
index e896e0d..b70b2e8 100644
--- a/tempest/services/orchestration/json/orchestration_client.py
+++ b/tempest/services/orchestration/json/orchestration_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 IBM Corp.
# All Rights Reserved.
#
@@ -21,17 +19,19 @@
import urllib
from tempest.common import rest_client
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class OrchestrationClient(rest_client.RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(OrchestrationClient, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.orchestration.catalog_type
- self.build_interval = self.config.orchestration.build_interval
- self.build_timeout = self.config.orchestration.build_timeout
+ def __init__(self, auth_provider):
+ super(OrchestrationClient, self).__init__(auth_provider)
+ self.service = CONF.orchestration.catalog_type
+ self.build_interval = CONF.orchestration.build_interval
+ self.build_timeout = CONF.orchestration.build_timeout
def list_stacks(self, params=None):
"""Lists all stacks for a user."""
@@ -102,6 +102,20 @@
body = json.loads(body)
return resp, body['stack']
+ def suspend_stack(self, stack_identifier):
+ """Suspend a stack."""
+ url = 'stacks/%s/actions' % stack_identifier
+ body = {'suspend': None}
+ resp, body = self.post(url, json.dumps(body), self.headers)
+ return resp, body
+
+ def resume_stack(self, stack_identifier):
+ """Resume a stack."""
+ url = 'stacks/%s/actions' % stack_identifier
+ body = {'resume': None}
+ resp, body = self.post(url, json.dumps(body), self.headers)
+ return resp, body
+
def list_resources(self, stack_identifier):
"""Returns the details of a single resource."""
url = "stacks/%s/resources" % stack_identifier
@@ -163,7 +177,7 @@
stack_name = body['stack_name']
stack_status = body['stack_status']
if stack_status == status:
- return
+ return body
if fail_regexp.search(stack_status):
raise exceptions.StackBuildErrorException(
stack_identifier=stack_identifier,
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/telemetry/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/services/telemetry/__init__.py
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/telemetry/json/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/services/telemetry/json/__init__.py
diff --git a/tempest/services/telemetry/json/telemetry_client.py b/tempest/services/telemetry/json/telemetry_client.py
new file mode 100644
index 0000000..e666475
--- /dev/null
+++ b/tempest/services/telemetry/json/telemetry_client.py
@@ -0,0 +1,45 @@
+# Copyright 2014 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 tempest.common.rest_client import RestClient
+from tempest.openstack.common import jsonutils as json
+import tempest.services.telemetry.telemetry_client_base as client
+
+
+class TelemetryClientJSON(client.TelemetryClientBase):
+
+ def get_rest_client(self, auth_provider):
+ return RestClient(auth_provider)
+
+ def deserialize(self, body):
+ return json.loads(body.replace("\n", ""))
+
+ def serialize(self, body):
+ return json.dumps(body)
+
+ def add_sample(self, sample_list, meter_name, meter_unit, volume,
+ sample_type, resource_id, **kwargs):
+ sample = {"counter_name": meter_name, "counter_unit": meter_unit,
+ "counter_volume": volume, "counter_type": sample_type,
+ "resource_id": resource_id}
+ for key in kwargs:
+ sample[key] = kwargs[key]
+
+ sample_list.append(self.serialize(sample))
+ return sample_list
+
+ def create_sample(self, meter_name, sample_list):
+ uri = "%s/meters/%s" % (self.uri_prefix, meter_name)
+ return self.post(uri, str(sample_list))
diff --git a/tempest/services/telemetry/telemetry_client_base.py b/tempest/services/telemetry/telemetry_client_base.py
new file mode 100644
index 0000000..a35a1ab
--- /dev/null
+++ b/tempest/services/telemetry/telemetry_client_base.py
@@ -0,0 +1,136 @@
+# Copyright 2013 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 abc
+import six
+import urllib
+
+from tempest import config
+
+CONF = config.CONF
+
+
+@six.add_metaclass(abc.ABCMeta)
+class TelemetryClientBase(object):
+
+ """
+ Tempest REST client for Ceilometer V2 API.
+ Implements the following basic Ceilometer abstractions:
+ resources
+ meters
+ alarms
+ queries
+ statistics
+ """
+
+ def __init__(self, auth_provider):
+ self.rest_client = self.get_rest_client(auth_provider)
+ self.rest_client.service = CONF.telemetry.catalog_type
+ self.headers = self.rest_client.headers
+ self.version = '2'
+ self.uri_prefix = "v%s" % self.version
+
+ @abc.abstractmethod
+ def get_rest_client(self, auth_provider):
+ """
+ :param config:
+ :param username:
+ :param password:
+ :param auth_url:
+ :param tenant_name:
+ :return: RestClient
+ """
+
+ @abc.abstractmethod
+ def deserialize(self, body):
+ """
+ :param body:
+ :return: Deserialize body
+ """
+
+ @abc.abstractmethod
+ def serialize(self, body):
+ """
+ :param body:
+ :return: Serialize body
+ """
+
+ def post(self, uri, body):
+ body = self.serialize(body)
+ resp, body = self.rest_client.post(uri, body, self.headers)
+ body = self.deserialize(body)
+ return resp, body
+
+ def put(self, uri, body):
+ return self.rest_client.put(uri, body, self.headers)
+
+ def get(self, uri):
+ resp, body = self.rest_client.get(uri, self.headers)
+ body = self.deserialize(body)
+ return resp, body
+
+ def delete(self, uri):
+ resp, body = self.rest_client.delete(uri)
+ if body:
+ body = self.deserialize(body)
+ return resp, body
+
+ def helper_list(self, uri, query=None, period=None):
+ uri_dict = {}
+ if query:
+ uri_dict = {'q.field': query[0],
+ 'q.op': query[1],
+ 'q.value': query[2]}
+ if period:
+ uri_dict['period'] = period
+ if uri_dict:
+ uri += "?%s" % urllib.urlencode(uri_dict)
+ return self.get(uri)
+
+ def list_resources(self):
+ uri = '%s/resources' % self.uri_prefix
+ return self.get(uri)
+
+ def list_meters(self):
+ uri = '%s/meters' % self.uri_prefix
+ return self.get(uri)
+
+ def list_alarms(self):
+ uri = '%s/alarms' % self.uri_prefix
+ return self.get(uri)
+
+ def list_statistics(self, meter, period=None, query=None):
+ uri = "%s/meters/%s/statistics" % (self.uri_prefix, meter)
+ return self.helper_list(uri, query, period)
+
+ def list_samples(self, meter_id, query=None):
+ uri = '%s/meters/%s' % (self.uri_prefix, meter_id)
+ return self.helper_list(uri, query)
+
+ def get_resource(self, resource_id):
+ uri = '%s/resources/%s' % (self.uri_prefix, resource_id)
+ return self.get(uri)
+
+ def get_alarm(self, alarm_id):
+ uri = '%s/alarms/%s' % (self.uri_prefix, alarm_id)
+ return self.get(uri)
+
+ def delete_alarm(self, alarm_id):
+ uri = "%s/alarms/%s" % (self.uri_prefix, alarm_id)
+ return self.delete(uri)
+
+ def create_alarm(self, **kwargs):
+ uri = "%s/alarms" % self.uri_prefix
+ return self.post(uri, kwargs)
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/telemetry/xml/__init__.py
similarity index 100%
rename from tempest/services/compute/v3/xml/__init__.py
rename to tempest/services/telemetry/xml/__init__.py
diff --git a/tempest/services/telemetry/xml/telemetry_client.py b/tempest/services/telemetry/xml/telemetry_client.py
new file mode 100644
index 0000000..f29fe22
--- /dev/null
+++ b/tempest/services/telemetry/xml/telemetry_client.py
@@ -0,0 +1,39 @@
+# Copyright 2014 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 lxml import etree
+
+from tempest.common.rest_client import RestClientXML
+from tempest.services.compute.xml.common import Document
+from tempest.services.compute.xml.common import xml_to_json
+import tempest.services.telemetry.telemetry_client_base as client
+
+
+class TelemetryClientXML(client.TelemetryClientBase):
+
+ def get_rest_client(self, auth_provider):
+ return RestClientXML(auth_provider)
+
+ def _parse_array(self, body):
+ array = []
+ for child in body.getchildren():
+ array.append(xml_to_json(child))
+ return array
+
+ def serialize(self, body):
+ return str(Document(body))
+
+ def deserialize(self, body):
+ return self._parse_array(etree.fromstring(body))
diff --git a/tempest/services/volume/json/admin/volume_hosts_client.py b/tempest/services/volume/json/admin/volume_hosts_client.py
index fc28ada..6efb258 100644
--- a/tempest/services/volume/json/admin/volume_hosts_client.py
+++ b/tempest/services/volume/json/admin/volume_hosts_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,6 +17,9 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class VolumeHostsClientJSON(RestClient):
@@ -26,13 +27,12 @@
Client class to send CRUD Volume Hosts API requests to a Cinder endpoint
"""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumeHostsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
+ def __init__(self, auth_provider):
+ super(VolumeHostsClientJSON, self).__init__(auth_provider)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.volume.build_interval
- self.build_timeout = self.config.volume.build_timeout
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.volume.build_interval
+ self.build_timeout = CONF.volume.build_timeout
def list_hosts(self, params=None):
"""Lists all hosts."""
diff --git a/tempest/services/volume/json/admin/volume_types_client.py b/tempest/services/volume/json/admin/volume_types_client.py
index 44ad785..653532e 100644
--- a/tempest/services/volume/json/admin/volume_types_client.py
+++ b/tempest/services/volume/json/admin/volume_types_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,6 +17,9 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class VolumeTypesClientJSON(RestClient):
@@ -26,13 +27,12 @@
Client class to send CRUD Volume Types API requests to a Cinder endpoint
"""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumeTypesClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
+ def __init__(self, auth_provider):
+ super(VolumeTypesClientJSON, self).__init__(auth_provider)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.volume.build_interval
- self.build_timeout = self.config.volume.build_timeout
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.volume.build_interval
+ self.build_timeout = CONF.volume.build_timeout
def list_volume_types(self, params=None):
"""List all the volume_types created."""
diff --git a/tempest/services/volume/json/extensions_client.py b/tempest/services/volume/json/extensions_client.py
index 01dd3e9..257b7c8 100644
--- a/tempest/services/volume/json/extensions_client.py
+++ b/tempest/services/volume/json/extensions_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -18,14 +16,16 @@
import json
from tempest.common.rest_client import RestClient
+from tempest import config
+
+CONF = config.CONF
class ExtensionsClientJSON(RestClient):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ExtensionsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.volume.catalog_type
+ def __init__(self, auth_provider):
+ super(ExtensionsClientJSON, self).__init__(auth_provider)
+ self.service = CONF.volume.catalog_type
def list_extensions(self):
url = 'extensions'
diff --git a/tempest/services/volume/json/snapshots_client.py b/tempest/services/volume/json/snapshots_client.py
index 9435122..0a79469 100644
--- a/tempest/services/volume/json/snapshots_client.py
+++ b/tempest/services/volume/json/snapshots_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -17,22 +15,24 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
class SnapshotsClientJSON(RestClient):
"""Client class to send CRUD Volume API requests."""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(SnapshotsClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
+ def __init__(self, auth_provider):
+ super(SnapshotsClientJSON, self).__init__(auth_provider)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.volume.build_interval
- self.build_timeout = self.config.volume.build_timeout
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.volume.build_interval
+ self.build_timeout = CONF.volume.build_timeout
def list_snapshots(self, params=None):
"""List all the snapshot."""
@@ -149,3 +149,47 @@
url = 'snapshots/%s/action' % str(snapshot_id)
resp, body = self.post(url, post_body, self.headers)
return resp, body
+
+ def create_snapshot_metadata(self, snapshot_id, metadata):
+ """Create metadata for the snapshot."""
+ put_body = json.dumps({'metadata': metadata})
+ url = "snapshots/%s/metadata" % str(snapshot_id)
+ resp, body = self.post(url, put_body, self.headers)
+ body = json.loads(body)
+ return resp, body['metadata']
+
+ def get_snapshot_metadata(self, snapshot_id):
+ """Get metadata of the snapshot."""
+ url = "snapshots/%s/metadata" % str(snapshot_id)
+ resp, body = self.get(url, self.headers)
+ body = json.loads(body)
+ return resp, body['metadata']
+
+ def update_snapshot_metadata(self, snapshot_id, metadata):
+ """Update metadata for the snapshot."""
+ put_body = json.dumps({'metadata': metadata})
+ url = "snapshots/%s/metadata" % str(snapshot_id)
+ resp, body = self.put(url, put_body, self.headers)
+ body = json.loads(body)
+ return resp, body['metadata']
+
+ def update_snapshot_metadata_item(self, snapshot_id, id, meta_item):
+ """Update metadata item for the snapshot."""
+ put_body = json.dumps({'meta': meta_item})
+ url = "snapshots/%s/metadata/%s" % (str(snapshot_id), str(id))
+ resp, body = self.put(url, put_body, self.headers)
+ body = json.loads(body)
+ return resp, body['meta']
+
+ def delete_snapshot_metadata_item(self, snapshot_id, id):
+ """Delete metadata item for the snapshot."""
+ url = "snapshots/%s/metadata/%s" % (str(snapshot_id), str(id))
+ resp, body = self.delete(url, self.headers)
+ return resp, body
+
+ def force_delete_snapshot(self, snapshot_id):
+ """Force Delete Snapshot."""
+ post_body = json.dumps({'os-force_delete': {}})
+ resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body,
+ self.headers)
+ return resp, body
diff --git a/tempest/services/volume/json/volumes_client.py b/tempest/services/volume/json/volumes_client.py
index afba4b0..0524212 100644
--- a/tempest/services/volume/json/volumes_client.py
+++ b/tempest/services/volume/json/volumes_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -20,21 +18,23 @@
import urllib
from tempest.common.rest_client import RestClient
+from tempest import config
from tempest import exceptions
+CONF = config.CONF
+
class VolumesClientJSON(RestClient):
"""
Client class to send CRUD Volume API requests to a Cinder endpoint
"""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumesClientJSON, self).__init__(config, username, password,
- auth_url, tenant_name)
+ def __init__(self, auth_provider):
+ super(VolumesClientJSON, self).__init__(auth_provider)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.volume.build_interval
- self.build_timeout = self.config.volume.build_timeout
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.volume.build_interval
+ self.build_timeout = CONF.volume.build_timeout
def get_attachment_from_volume(self, volume):
"""Return the element 'attachment' from input volumes."""
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/volume/v2/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/services/volume/v2/__init__.py
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/volume/v2/json/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/services/volume/v2/json/__init__.py
diff --git a/tempest/services/volume/v2/json/volumes_client.py b/tempest/services/volume/v2/json/volumes_client.py
new file mode 100644
index 0000000..0524212
--- /dev/null
+++ b/tempest/services/volume/v2/json/volumes_client.py
@@ -0,0 +1,302 @@
+# Copyright 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 json
+import time
+import urllib
+
+from tempest.common.rest_client import RestClient
+from tempest import config
+from tempest import exceptions
+
+CONF = config.CONF
+
+
+class VolumesClientJSON(RestClient):
+ """
+ Client class to send CRUD Volume API requests to a Cinder endpoint
+ """
+
+ def __init__(self, auth_provider):
+ super(VolumesClientJSON, self).__init__(auth_provider)
+
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.volume.build_interval
+ self.build_timeout = CONF.volume.build_timeout
+
+ def get_attachment_from_volume(self, volume):
+ """Return the element 'attachment' from input volumes."""
+ return volume['attachments'][0]
+
+ def list_volumes(self, params=None):
+ """List all the volumes created."""
+ url = 'volumes'
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body['volumes']
+
+ def list_volumes_with_detail(self, params=None):
+ """List the details of all volumes."""
+ url = 'volumes/detail'
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body['volumes']
+
+ def get_volume(self, volume_id):
+ """Returns the details of a single volume."""
+ url = "volumes/%s" % str(volume_id)
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body['volume']
+
+ def create_volume(self, size, **kwargs):
+ """
+ Creates a new Volume.
+ size(Required): Size of volume in GB.
+ Following optional keyword arguments are accepted:
+ display_name: Optional Volume Name.
+ metadata: A dictionary of values to be used as metadata.
+ volume_type: Optional Name of volume_type for the volume
+ snapshot_id: When specified the volume is created from this snapshot
+ imageRef: When specified the volume is created from this image
+ """
+ post_body = {'size': size}
+ post_body.update(kwargs)
+ post_body = json.dumps({'volume': post_body})
+ resp, body = self.post('volumes', post_body, self.headers)
+ body = json.loads(body)
+ return resp, body['volume']
+
+ def update_volume(self, volume_id, **kwargs):
+ """Updates the Specified Volume."""
+ put_body = json.dumps({'volume': kwargs})
+ resp, body = self.put('volumes/%s' % volume_id, put_body,
+ self.headers)
+ body = json.loads(body)
+ return resp, body['volume']
+
+ def delete_volume(self, volume_id):
+ """Deletes the Specified Volume."""
+ return self.delete("volumes/%s" % str(volume_id))
+
+ def upload_volume(self, volume_id, image_name, disk_format):
+ """Uploads a volume in Glance."""
+ post_body = {
+ 'image_name': image_name,
+ 'disk_format': disk_format
+ }
+ post_body = json.dumps({'os-volume_upload_image': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ body = json.loads(body)
+ return resp, body['os-volume_upload_image']
+
+ def attach_volume(self, volume_id, instance_uuid, mountpoint):
+ """Attaches a volume to a given instance on a given mountpoint."""
+ post_body = {
+ 'instance_uuid': instance_uuid,
+ 'mountpoint': mountpoint,
+ }
+ post_body = json.dumps({'os-attach': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ return resp, body
+
+ def detach_volume(self, volume_id):
+ """Detaches a volume from an instance."""
+ post_body = {}
+ post_body = json.dumps({'os-detach': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ return resp, body
+
+ def reserve_volume(self, volume_id):
+ """Reserves a volume."""
+ post_body = {}
+ post_body = json.dumps({'os-reserve': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ return resp, body
+
+ def unreserve_volume(self, volume_id):
+ """Restore a reserved volume ."""
+ post_body = {}
+ post_body = json.dumps({'os-unreserve': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ return resp, body
+
+ def wait_for_volume_status(self, volume_id, status):
+ """Waits for a Volume to reach a given status."""
+ resp, body = self.get_volume(volume_id)
+ volume_name = body['display_name']
+ volume_status = body['status']
+ start = int(time.time())
+
+ while volume_status != status:
+ time.sleep(self.build_interval)
+ resp, body = self.get_volume(volume_id)
+ volume_status = body['status']
+ if volume_status == 'error':
+ raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
+
+ if int(time.time()) - start >= self.build_timeout:
+ message = ('Volume %s failed to reach %s status within '
+ 'the required time (%s s).' %
+ (volume_name, status, self.build_timeout))
+ raise exceptions.TimeoutException(message)
+
+ def is_resource_deleted(self, id):
+ try:
+ self.get_volume(id)
+ except exceptions.NotFound:
+ return True
+ return False
+
+ def extend_volume(self, volume_id, extend_size):
+ """Extend a volume."""
+ post_body = {
+ 'new_size': extend_size
+ }
+ post_body = json.dumps({'os-extend': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ return resp, body
+
+ def reset_volume_status(self, volume_id, status):
+ """Reset the Specified Volume's Status."""
+ post_body = json.dumps({'os-reset_status': {"status": status}})
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body,
+ self.headers)
+ return resp, body
+
+ def volume_begin_detaching(self, volume_id):
+ """Volume Begin Detaching."""
+ post_body = json.dumps({'os-begin_detaching': {}})
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body,
+ self.headers)
+ return resp, body
+
+ def volume_roll_detaching(self, volume_id):
+ """Volume Roll Detaching."""
+ post_body = json.dumps({'os-roll_detaching': {}})
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body,
+ self.headers)
+ return resp, body
+
+ def create_volume_transfer(self, vol_id, display_name=None):
+ """Create a volume transfer."""
+ post_body = {
+ 'volume_id': vol_id
+ }
+ if display_name:
+ post_body['name'] = display_name
+ post_body = json.dumps({'transfer': post_body})
+ resp, body = self.post('os-volume-transfer',
+ post_body,
+ self.headers)
+ body = json.loads(body)
+ return resp, body['transfer']
+
+ def get_volume_transfer(self, transfer_id):
+ """Returns the details of a volume transfer."""
+ url = "os-volume-transfer/%s" % str(transfer_id)
+ resp, body = self.get(url, self.headers)
+ body = json.loads(body)
+ return resp, body['transfer']
+
+ def list_volume_transfers(self, params=None):
+ """List all the volume transfers created."""
+ url = 'os-volume-transfer'
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body['transfers']
+
+ def delete_volume_transfer(self, transfer_id):
+ """Delete a volume transfer."""
+ return self.delete("os-volume-transfer/%s" % str(transfer_id))
+
+ def accept_volume_transfer(self, transfer_id, transfer_auth_key):
+ """Accept a volume transfer."""
+ post_body = {
+ 'auth_key': transfer_auth_key,
+ }
+ url = 'os-volume-transfer/%s/accept' % transfer_id
+ post_body = json.dumps({'accept': post_body})
+ resp, body = self.post(url, post_body, self.headers)
+ body = json.loads(body)
+ return resp, body['transfer']
+
+ def update_volume_readonly(self, volume_id, readonly):
+ """Update the Specified Volume readonly."""
+ post_body = {
+ 'readonly': readonly
+ }
+ post_body = json.dumps({'os-update_readonly_flag': post_body})
+ url = 'volumes/%s/action' % (volume_id)
+ resp, body = self.post(url, post_body, self.headers)
+ return resp, body
+
+ def force_delete_volume(self, volume_id):
+ """Force Delete Volume."""
+ post_body = json.dumps({'os-force_delete': {}})
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body,
+ self.headers)
+ return resp, body
+
+ def create_volume_metadata(self, volume_id, metadata):
+ """Create metadata for the volume."""
+ put_body = json.dumps({'metadata': metadata})
+ url = "volumes/%s/metadata" % str(volume_id)
+ resp, body = self.post(url, put_body, self.headers)
+ body = json.loads(body)
+ return resp, body['metadata']
+
+ def get_volume_metadata(self, volume_id):
+ """Get metadata of the volume."""
+ url = "volumes/%s/metadata" % str(volume_id)
+ resp, body = self.get(url, self.headers)
+ body = json.loads(body)
+ return resp, body['metadata']
+
+ def update_volume_metadata(self, volume_id, metadata):
+ """Update metadata for the volume."""
+ put_body = json.dumps({'metadata': metadata})
+ url = "volumes/%s/metadata" % str(volume_id)
+ resp, body = self.put(url, put_body, self.headers)
+ body = json.loads(body)
+ return resp, body['metadata']
+
+ def update_volume_metadata_item(self, volume_id, id, meta_item):
+ """Update metadata item for the volume."""
+ put_body = json.dumps({'meta': meta_item})
+ url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
+ resp, body = self.put(url, put_body, self.headers)
+ body = json.loads(body)
+ return resp, body['meta']
+
+ def delete_volume_metadata_item(self, volume_id, id):
+ """Delete metadata item for the volume."""
+ url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
+ resp, body = self.delete(url, self.headers)
+ return resp, body
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/services/volume/v2/xml/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/services/volume/v2/xml/__init__.py
diff --git a/tempest/services/volume/v2/xml/volumes_client.py b/tempest/services/volume/v2/xml/volumes_client.py
new file mode 100644
index 0000000..deb56fd
--- /dev/null
+++ b/tempest/services/volume/v2/xml/volumes_client.py
@@ -0,0 +1,412 @@
+# Copyright 2012 IBM Corp.
+# All Rights Reserved.
+#
+# 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 time
+import urllib
+
+from lxml import etree
+
+from tempest.common.rest_client import RestClientXML
+from tempest import config
+from tempest import exceptions
+from tempest.services.compute.xml.common import Document
+from tempest.services.compute.xml.common import Element
+from tempest.services.compute.xml.common import Text
+from tempest.services.compute.xml.common import xml_to_json
+from tempest.services.compute.xml.common import XMLNS_11
+
+CONF = config.CONF
+
+
+class VolumesClientXML(RestClientXML):
+ """
+ Client class to send CRUD Volume API requests to a Cinder endpoint
+ """
+
+ def __init__(self, auth_provider):
+ super(VolumesClientXML, self).__init__(auth_provider)
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
+
+ def _parse_volume(self, body):
+ vol = dict((attr, body.get(attr)) for attr in body.keys())
+
+ for child in body.getchildren():
+ tag = child.tag
+ if tag.startswith("{"):
+ ns, tag = tag.split("}", 1)
+ if tag == 'metadata':
+ vol['metadata'] = dict((meta.get('key'),
+ meta.text) for meta in
+ child.getchildren())
+ else:
+ vol[tag] = xml_to_json(child)
+ return vol
+
+ def get_attachment_from_volume(self, volume):
+ """Return the element 'attachment' from input volumes."""
+ return volume['attachments']['attachment']
+
+ def _check_if_bootable(self, volume):
+ """
+ Check if the volume is bootable, also change the value
+ of 'bootable' from string to boolean.
+ """
+
+ # NOTE(jdg): Version 1 of Cinder API uses lc strings
+ # We should consider being explicit in this check to
+ # avoid introducing bugs like: LP #1227837
+
+ if volume['bootable'].lower() == 'true':
+ volume['bootable'] = True
+ elif volume['bootable'].lower() == 'false':
+ volume['bootable'] = False
+ else:
+ raise ValueError(
+ 'bootable flag is supposed to be either True or False,'
+ 'it is %s' % volume['bootable'])
+ return volume
+
+ def list_volumes(self, params=None):
+ """List all the volumes created."""
+ url = 'volumes'
+
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+
+ resp, body = self.get(url, self.headers)
+ body = etree.fromstring(body)
+ volumes = []
+ if body is not None:
+ volumes += [self._parse_volume(vol) for vol in list(body)]
+ for v in volumes:
+ v = self._check_if_bootable(v)
+ return resp, volumes
+
+ def list_volumes_with_detail(self, params=None):
+ """List all the details of volumes."""
+ url = 'volumes/detail'
+
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+
+ resp, body = self.get(url, self.headers)
+ body = etree.fromstring(body)
+ volumes = []
+ if body is not None:
+ volumes += [self._parse_volume(vol) for vol in list(body)]
+ for v in volumes:
+ v = self._check_if_bootable(v)
+ return resp, volumes
+
+ def get_volume(self, volume_id):
+ """Returns the details of a single volume."""
+ url = "volumes/%s" % str(volume_id)
+ resp, body = self.get(url, self.headers)
+ body = self._parse_volume(etree.fromstring(body))
+ body = self._check_if_bootable(body)
+ return resp, body
+
+ def create_volume(self, size, **kwargs):
+ """Creates a new Volume.
+
+ :param size: Size of volume in GB. (Required)
+ :param display_name: Optional Volume Name.
+ :param metadata: An optional dictionary of values for metadata.
+ :param volume_type: Optional Name of volume_type for the volume
+ :param snapshot_id: When specified the volume is created from
+ this snapshot
+ :param imageRef: When specified the volume is created from this
+ image
+ """
+ # NOTE(afazekas): it should use a volume namespace
+ volume = Element("volume", xmlns=XMLNS_11, size=size)
+
+ if 'metadata' in kwargs:
+ _metadata = Element('metadata')
+ volume.append(_metadata)
+ for key, value in kwargs['metadata'].items():
+ meta = Element('meta')
+ meta.add_attr('key', key)
+ meta.append(Text(value))
+ _metadata.append(meta)
+ attr_to_add = kwargs.copy()
+ del attr_to_add['metadata']
+ else:
+ attr_to_add = kwargs
+
+ for key, value in attr_to_add.items():
+ volume.add_attr(key, value)
+
+ resp, body = self.post('volumes', str(Document(volume)),
+ self.headers)
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def update_volume(self, volume_id, **kwargs):
+ """Updates the Specified Volume."""
+ put_body = Element("volume", xmlns=XMLNS_11, **kwargs)
+
+ resp, body = self.put('volumes/%s' % volume_id,
+ str(Document(put_body)),
+ self.headers)
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def delete_volume(self, volume_id):
+ """Deletes the Specified Volume."""
+ return self.delete("volumes/%s" % str(volume_id))
+
+ def wait_for_volume_status(self, volume_id, status):
+ """Waits for a Volume to reach a given status."""
+ resp, body = self.get_volume(volume_id)
+ volume_status = body['status']
+ start = int(time.time())
+
+ while volume_status != status:
+ time.sleep(self.build_interval)
+ resp, body = self.get_volume(volume_id)
+ volume_status = body['status']
+ if volume_status == 'error':
+ raise exceptions.VolumeBuildErrorException(volume_id=volume_id)
+
+ if int(time.time()) - start >= self.build_timeout:
+ message = 'Volume %s failed to reach %s status within '\
+ 'the required time (%s s).' % (volume_id,
+ status,
+ self.build_timeout)
+ raise exceptions.TimeoutException(message)
+
+ def is_resource_deleted(self, id):
+ try:
+ self.get_volume(id)
+ except exceptions.NotFound:
+ return True
+ return False
+
+ def attach_volume(self, volume_id, instance_uuid, mountpoint):
+ """Attaches a volume to a given instance on a given mountpoint."""
+ post_body = Element("os-attach",
+ instance_uuid=instance_uuid,
+ mountpoint=mountpoint
+ )
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def detach_volume(self, volume_id):
+ """Detaches a volume from an instance."""
+ post_body = Element("os-detach")
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def upload_volume(self, volume_id, image_name, disk_format):
+ """Uploads a volume in Glance."""
+ post_body = Element("os-volume_upload_image",
+ image_name=image_name,
+ disk_format=disk_format)
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ volume = xml_to_json(etree.fromstring(body))
+ return resp, volume
+
+ def extend_volume(self, volume_id, extend_size):
+ """Extend a volume."""
+ post_body = Element("os-extend",
+ new_size=extend_size)
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def reset_volume_status(self, volume_id, status):
+ """Reset the Specified Volume's Status."""
+ post_body = Element("os-reset_status",
+ status=status
+ )
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def volume_begin_detaching(self, volume_id):
+ """Volume Begin Detaching."""
+ post_body = Element("os-begin_detaching")
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def volume_roll_detaching(self, volume_id):
+ """Volume Roll Detaching."""
+ post_body = Element("os-roll_detaching")
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def reserve_volume(self, volume_id):
+ """Reserves a volume."""
+ post_body = Element("os-reserve")
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def unreserve_volume(self, volume_id):
+ """Restore a reserved volume ."""
+ post_body = Element("os-unreserve")
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def create_volume_transfer(self, vol_id, display_name=None):
+ """Create a volume transfer."""
+ post_body = Element("transfer",
+ volume_id=vol_id)
+ if display_name:
+ post_body.add_attr('name', display_name)
+ resp, body = self.post('os-volume-transfer',
+ str(Document(post_body)),
+ self.headers)
+ volume = xml_to_json(etree.fromstring(body))
+ return resp, volume
+
+ def get_volume_transfer(self, transfer_id):
+ """Returns the details of a volume transfer."""
+ url = "os-volume-transfer/%s" % str(transfer_id)
+ resp, body = self.get(url, self.headers)
+ volume = xml_to_json(etree.fromstring(body))
+ return resp, volume
+
+ def list_volume_transfers(self, params=None):
+ """List all the volume transfers created."""
+ url = 'os-volume-transfer'
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+
+ resp, body = self.get(url, self.headers)
+ body = etree.fromstring(body)
+ volumes = []
+ if body is not None:
+ volumes += [self._parse_volume_transfer(vol) for vol in list(body)]
+ return resp, volumes
+
+ def _parse_volume_transfer(self, body):
+ vol = dict((attr, body.get(attr)) for attr in body.keys())
+ for child in body.getchildren():
+ tag = child.tag
+ if tag.startswith("{"):
+ tag = tag.split("}", 1)
+ vol[tag] = xml_to_json(child)
+ return vol
+
+ def delete_volume_transfer(self, transfer_id):
+ """Delete a volume transfer."""
+ return self.delete("os-volume-transfer/%s" % str(transfer_id))
+
+ def accept_volume_transfer(self, transfer_id, transfer_auth_key):
+ """Accept a volume transfer."""
+ post_body = Element("accept", auth_key=transfer_auth_key)
+ url = 'os-volume-transfer/%s/accept' % transfer_id
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ volume = xml_to_json(etree.fromstring(body))
+ return resp, volume
+
+ def update_volume_readonly(self, volume_id, readonly):
+ """Update the Specified Volume readonly."""
+ post_body = Element("os-update_readonly_flag",
+ readonly=readonly)
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def force_delete_volume(self, volume_id):
+ """Force Delete Volume."""
+ post_body = Element("os-force_delete")
+ url = 'volumes/%s/action' % str(volume_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def _metadata_body(self, meta):
+ post_body = Element('metadata')
+ for k, v in meta.items():
+ data = Element('meta', key=k)
+ data.append(Text(v))
+ post_body.append(data)
+ return post_body
+
+ def _parse_key_value(self, node):
+ """Parse <foo key='key'>value</foo> data into {'key': 'value'}."""
+ data = {}
+ for node in node.getchildren():
+ data[node.get('key')] = node.text
+ return data
+
+ def create_volume_metadata(self, volume_id, metadata):
+ """Create metadata for the volume."""
+ post_body = self._metadata_body(metadata)
+ resp, body = self.post('volumes/%s/metadata' % volume_id,
+ str(Document(post_body)),
+ self.headers)
+ body = self._parse_key_value(etree.fromstring(body))
+ return resp, body
+
+ def get_volume_metadata(self, volume_id):
+ """Get metadata of the volume."""
+ url = "volumes/%s/metadata" % str(volume_id)
+ resp, body = self.get(url, self.headers)
+ body = self._parse_key_value(etree.fromstring(body))
+ return resp, body
+
+ def update_volume_metadata(self, volume_id, metadata):
+ """Update metadata for the volume."""
+ put_body = self._metadata_body(metadata)
+ url = "volumes/%s/metadata" % str(volume_id)
+ resp, body = self.put(url, str(Document(put_body)), self.headers)
+ body = self._parse_key_value(etree.fromstring(body))
+ return resp, body
+
+ def update_volume_metadata_item(self, volume_id, id, meta_item):
+ """Update metadata item for the volume."""
+ for k, v in meta_item.items():
+ put_body = Element('meta', key=k)
+ put_body.append(Text(v))
+ url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
+ resp, body = self.put(url, str(Document(put_body)), self.headers)
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def delete_volume_metadata_item(self, volume_id, id):
+ """Delete metadata item for the volume."""
+ url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
+ return self.delete(url)
diff --git a/tempest/services/volume/xml/admin/volume_hosts_client.py b/tempest/services/volume/xml/admin/volume_hosts_client.py
index 59ce933..7278fd9 100644
--- a/tempest/services/volume/xml/admin/volume_hosts_client.py
+++ b/tempest/services/volume/xml/admin/volume_hosts_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2013 Openstack Foundation.
# All Rights Reserved.
#
@@ -20,20 +18,22 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class VolumeHostsClientXML(RestClientXML):
"""
Client class to send CRUD Volume Hosts API requests to a Cinder endpoint
"""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumeHostsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.compute.build_interval
- self.build_timeout = self.config.compute.build_timeout
+ def __init__(self, auth_provider):
+ super(VolumeHostsClientXML, self).__init__(auth_provider)
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
def _parse_array(self, node):
"""
diff --git a/tempest/services/volume/xml/admin/volume_types_client.py b/tempest/services/volume/xml/admin/volume_types_client.py
index 42e7b9a..29ba431 100644
--- a/tempest/services/volume/xml/admin/volume_types_client.py
+++ b/tempest/services/volume/xml/admin/volume_types_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -20,6 +18,7 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
@@ -27,18 +26,19 @@
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
+
class VolumeTypesClientXML(RestClientXML):
"""
Client class to send CRUD Volume Types API requests to a Cinder endpoint
"""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumeTypesClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.compute.build_interval
- self.build_timeout = self.config.compute.build_timeout
+ def __init__(self, auth_provider):
+ super(VolumeTypesClientXML, self).__init__(auth_provider)
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
def _parse_volume_type(self, body):
vol_type = dict((attr, body.get(attr)) for attr in body.keys())
diff --git a/tempest/services/volume/xml/extensions_client.py b/tempest/services/volume/xml/extensions_client.py
index b4e6536..21e1d04 100644
--- a/tempest/services/volume/xml/extensions_client.py
+++ b/tempest/services/volume/xml/extensions_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -16,16 +14,19 @@
# under the License.
from lxml import etree
+
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest.services.compute.xml.common import xml_to_json
+CONF = config.CONF
+
class ExtensionsClientXML(RestClientXML):
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(ExtensionsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.volume.catalog_type
+ def __init__(self, auth_provider):
+ super(ExtensionsClientXML, self).__init__(auth_provider)
+ self.service = CONF.volume.catalog_type
def _parse_array(self, node):
array = []
diff --git a/tempest/services/volume/xml/snapshots_client.py b/tempest/services/volume/xml/snapshots_client.py
index 5d59b07..4f066a6 100644
--- a/tempest/services/volume/xml/snapshots_client.py
+++ b/tempest/services/volume/xml/snapshots_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -18,26 +16,29 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
+from tempest.services.compute.xml.common import Text
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
class SnapshotsClientXML(RestClientXML):
"""Client class to send CRUD Volume API requests."""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(SnapshotsClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
+ def __init__(self, auth_provider):
+ super(SnapshotsClientXML, self).__init__(auth_provider)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.volume.build_interval
- self.build_timeout = self.config.volume.build_timeout
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.volume.build_interval
+ self.build_timeout = CONF.volume.build_timeout
def list_snapshots(self, params=None):
"""List all snapshot."""
@@ -170,3 +171,66 @@
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
+
+ def _metadata_body(self, meta):
+ post_body = Element('metadata')
+ for k, v in meta.items():
+ data = Element('meta', key=k)
+ data.append(Text(v))
+ post_body.append(data)
+ return post_body
+
+ def _parse_key_value(self, node):
+ """Parse <foo key='key'>value</foo> data into {'key': 'value'}."""
+ data = {}
+ for node in node.getchildren():
+ data[node.get('key')] = node.text
+ return data
+
+ def create_snapshot_metadata(self, snapshot_id, metadata):
+ """Create metadata for the snapshot."""
+ post_body = self._metadata_body(metadata)
+ resp, body = self.post('snapshots/%s/metadata' % snapshot_id,
+ str(Document(post_body)),
+ self.headers)
+ body = self._parse_key_value(etree.fromstring(body))
+ return resp, body
+
+ def get_snapshot_metadata(self, snapshot_id):
+ """Get metadata of the snapshot."""
+ url = "snapshots/%s/metadata" % str(snapshot_id)
+ resp, body = self.get(url, self.headers)
+ body = self._parse_key_value(etree.fromstring(body))
+ return resp, body
+
+ def update_snapshot_metadata(self, snapshot_id, metadata):
+ """Update metadata for the snapshot."""
+ put_body = self._metadata_body(metadata)
+ url = "snapshots/%s/metadata" % str(snapshot_id)
+ resp, body = self.put(url, str(Document(put_body)), self.headers)
+ body = self._parse_key_value(etree.fromstring(body))
+ return resp, body
+
+ def update_snapshot_metadata_item(self, snapshot_id, id, meta_item):
+ """Update metadata item for the snapshot."""
+ for k, v in meta_item.items():
+ put_body = Element('meta', key=k)
+ put_body.append(Text(v))
+ url = "snapshots/%s/metadata/%s" % (str(snapshot_id), str(id))
+ resp, body = self.put(url, str(Document(put_body)), self.headers)
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def delete_snapshot_metadata_item(self, snapshot_id, id):
+ """Delete metadata item for the snapshot."""
+ url = "snapshots/%s/metadata/%s" % (str(snapshot_id), str(id))
+ return self.delete(url)
+
+ def force_delete_snapshot(self, snapshot_id):
+ """Force Delete Snapshot."""
+ post_body = Element("os-force_delete")
+ url = 'snapshots/%s/action' % str(snapshot_id)
+ resp, body = self.post(url, str(Document(post_body)), self.headers)
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
diff --git a/tempest/services/volume/xml/volumes_client.py b/tempest/services/volume/xml/volumes_client.py
index f175138..deb56fd 100644
--- a/tempest/services/volume/xml/volumes_client.py
+++ b/tempest/services/volume/xml/volumes_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
# Copyright 2012 IBM Corp.
# All Rights Reserved.
#
@@ -21,6 +19,7 @@
from lxml import etree
from tempest.common.rest_client import RestClientXML
+from tempest import config
from tempest import exceptions
from tempest.services.compute.xml.common import Document
from tempest.services.compute.xml.common import Element
@@ -28,18 +27,19 @@
from tempest.services.compute.xml.common import xml_to_json
from tempest.services.compute.xml.common import XMLNS_11
+CONF = config.CONF
+
class VolumesClientXML(RestClientXML):
"""
Client class to send CRUD Volume API requests to a Cinder endpoint
"""
- def __init__(self, config, username, password, auth_url, tenant_name=None):
- super(VolumesClientXML, self).__init__(config, username, password,
- auth_url, tenant_name)
- self.service = self.config.volume.catalog_type
- self.build_interval = self.config.compute.build_interval
- self.build_timeout = self.config.compute.build_timeout
+ def __init__(self, auth_provider):
+ super(VolumesClientXML, self).__init__(auth_provider)
+ self.service = CONF.volume.catalog_type
+ self.build_interval = CONF.compute.build_interval
+ self.build_timeout = CONF.compute.build_timeout
def _parse_volume(self, body):
vol = dict((attr, body.get(attr)) for attr in body.keys())
diff --git a/tempest/stress/README.rst b/tempest/stress/README.rst
index 20e58d4..b56f96b 100644
--- a/tempest/stress/README.rst
+++ b/tempest/stress/README.rst
@@ -1,7 +1,7 @@
Tempest Field Guide to Stress Tests
===================================
-Nova is a distributed, asynchronous system that is prone to race condition
+OpenStack is a distributed, asynchronous system that is prone to race condition
bugs. These bugs will not be easily found during
functional testing but will be encountered by users in large deployments in a
way that is hard to debug. The stress test tries to cause these bugs to happen
diff --git a/tempest/stress/__init__.py b/tempest/stress/__init__.py
index 1caf74a..e69de29 100644
--- a/tempest/stress/__init__.py
+++ b/tempest/stress/__init__.py
@@ -1,13 +0,0 @@
-# Copyright 2013 Quanta Research Cambridge, Inc.
-#
-# 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.
diff --git a/tempest/stress/actions/__init__.py b/tempest/stress/actions/__init__.py
index 1caf74a..e69de29 100644
--- a/tempest/stress/actions/__init__.py
+++ b/tempest/stress/actions/__init__.py
@@ -1,13 +0,0 @@
-# Copyright 2013 Quanta Research Cambridge, Inc.
-#
-# 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.
diff --git a/tempest/stress/actions/server_create_destroy.py b/tempest/stress/actions/server_create_destroy.py
index 84c7cf5..4a9f0d5 100644
--- a/tempest/stress/actions/server_create_destroy.py
+++ b/tempest/stress/actions/server_create_destroy.py
@@ -13,14 +13,17 @@
# limitations under the License.
from tempest.common.utils import data_utils
+from tempest import config
import tempest.stress.stressaction as stressaction
+CONF = config.CONF
+
class ServerCreateDestroyTest(stressaction.StressAction):
def setUp(self, **kwargs):
- self.image = self.manager.config.compute.image_ref
- self.flavor = self.manager.config.compute.flavor_ref
+ self.image = CONF.compute.image_ref
+ self.flavor = CONF.compute.flavor_ref
def run(self):
name = data_utils.rand_name("instance")
diff --git a/tempest/stress/actions/ssh_floating.py b/tempest/stress/actions/ssh_floating.py
index 74a9739..a34a20d 100644
--- a/tempest/stress/actions/ssh_floating.py
+++ b/tempest/stress/actions/ssh_floating.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -16,9 +14,12 @@
import subprocess
from tempest.common.utils import data_utils
+from tempest import config
import tempest.stress.stressaction as stressaction
import tempest.test
+CONF = config.CONF
+
class FloatingStress(stressaction.StressAction):
@@ -111,8 +112,8 @@
self.logger.info("Deleted Floating IP %s", str(self.floating['ip']))
def setUp(self, **kwargs):
- self.image = self.manager.config.compute.image_ref
- self.flavor = self.manager.config.compute.flavor_ref
+ self.image = CONF.compute.image_ref
+ self.flavor = CONF.compute.flavor_ref
self.vm_extra_args = kwargs.get('vm_extra_args', {})
self.wait_after_vm_create = kwargs.get('wait_after_vm_create',
True)
diff --git a/tempest/stress/actions/unit_test.py b/tempest/stress/actions/unit_test.py
index 5ab5573..2f1d28f 100644
--- a/tempest/stress/actions/unit_test.py
+++ b/tempest/stress/actions/unit_test.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# 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
@@ -12,10 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
+from tempest import config
from tempest.openstack.common import importutils
from tempest.openstack.common import log as logging
import tempest.stress.stressaction as stressaction
+CONF = config.CONF
+
class SetUpClassRunTime(object):
@@ -75,10 +76,14 @@
self.klass.setUpClass()
self.setupclass_called = True
- self.run_core()
-
- if (self.class_setup_per == SetUpClassRunTime.action):
- self.klass.tearDownClass()
+ try:
+ self.run_core()
+ except Exception as e:
+ raise e
+ finally:
+ if (CONF.stress.leave_dirty_stack is False
+ and self.class_setup_per == SetUpClassRunTime.action):
+ self.klass.tearDownClass()
else:
self.run_core()
diff --git a/tempest/stress/actions/volume_attach_delete.py b/tempest/stress/actions/volume_attach_delete.py
index e6fcb81..c2e6072 100644
--- a/tempest/stress/actions/volume_attach_delete.py
+++ b/tempest/stress/actions/volume_attach_delete.py
@@ -12,14 +12,17 @@
# limitations under the License.
from tempest.common.utils import data_utils
+from tempest import config
import tempest.stress.stressaction as stressaction
+CONF = config.CONF
+
class VolumeAttachDeleteTest(stressaction.StressAction):
def setUp(self, **kwargs):
- self.image = self.manager.config.compute.image_ref
- self.flavor = self.manager.config.compute.flavor_ref
+ self.image = CONF.compute.image_ref
+ self.flavor = CONF.compute.flavor_ref
def run(self):
# Step 1: create volume
diff --git a/tempest/stress/cleanup.py b/tempest/stress/cleanup.py
index 1bd9485..b46de35 100644
--- a/tempest/stress/cleanup.py
+++ b/tempest/stress/cleanup.py
@@ -1,7 +1,5 @@
#!/usr/bin/env python
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Quanta Research Cambridge, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/tempest/stress/driver.py b/tempest/stress/driver.py
index d37ab6d..d4689c4 100644
--- a/tempest/stress/driver.py
+++ b/tempest/stress/driver.py
@@ -20,11 +20,14 @@
from tempest import clients
from tempest.common import ssh
from tempest.common.utils import data_utils
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import importutils
from tempest.openstack.common import log as logging
from tempest.stress import cleanup
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
processes = []
@@ -110,14 +113,13 @@
"""
admin_manager = clients.AdminManager()
- ssh_user = admin_manager.config.stress.target_ssh_user
- ssh_key = admin_manager.config.stress.target_private_key_path
- logfiles = admin_manager.config.stress.target_logfiles
- log_check_interval = int(admin_manager.config.stress.log_check_interval)
- default_thread_num = int(admin_manager.config.stress.
- default_thread_number_per_action)
+ ssh_user = CONF.stress.target_ssh_user
+ ssh_key = CONF.stress.target_private_key_path
+ logfiles = CONF.stress.target_logfiles
+ log_check_interval = int(CONF.stress.log_check_interval)
+ default_thread_num = int(CONF.stress.default_thread_number_per_action)
if logfiles:
- controller = admin_manager.config.stress.target_controller
+ controller = CONF.stress.target_controller
computes = _get_compute_nodes(controller, ssh_user, ssh_key)
for node in computes:
do_ssh("rm -f %s" % logfiles, node, ssh_user, ssh_key)
diff --git a/tempest/stress/etc/ssh_floating.json b/tempest/stress/etc/ssh_floating.json
index 0cb6776..e03fd4f 100644
--- a/tempest/stress/etc/ssh_floating.json
+++ b/tempest/stress/etc/ssh_floating.json
@@ -8,7 +8,7 @@
"new_floating": true,
"verify": ["check_icmp_echo", "check_port_ssh"],
"check_timeout": 120,
- "check_inerval": 1,
+ "check_interval": 1,
"wait_after_vm_create": true,
"wait_for_disassociate": true,
"reboot": false}
diff --git a/tempest/stress/run_stress.py b/tempest/stress/run_stress.py
index 067b994..76320d0 100755
--- a/tempest/stress/run_stress.py
+++ b/tempest/stress/run_stress.py
@@ -1,7 +1,5 @@
#!/usr/bin/env python
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Quanta Research Cambridge, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +19,11 @@
import json
import sys
from testtools.testsuite import iterate_tests
-from unittest import loader
+try:
+ from unittest import loader
+except ImportError:
+ # unittest in python 2.6 does not contain loader, so uses unittest2
+ from unittest2 import loader
from tempest.openstack.common import log as logging
from tempest.stress import driver
diff --git a/tempest/stress/stressaction.py b/tempest/stress/stressaction.py
index 61e46fa..f6770ab 100644
--- a/tempest/stress/stressaction.py
+++ b/tempest/stress/stressaction.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/test.py b/tempest/test.py
index 342846f..dcba226 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,8 +15,12 @@
import atexit
import functools
+import json
import os
+import sys
import time
+import urllib
+import uuid
import fixtures
import nose.plugins.attrib
@@ -26,6 +28,7 @@
import testtools
from tempest import clients
+from tempest.common import generate_json
from tempest.common import isolated_creds
from tempest import config
from tempest import exceptions
@@ -68,16 +71,35 @@
This decorator applies a testtools attr for each service that gets
exercised by a test case.
"""
- valid_service_list = ['compute', 'image', 'volume', 'orchestration',
- 'network', 'identity', 'object', 'dashboard']
+ service_list = {
+ 'compute': CONF.service_available.nova,
+ 'image': CONF.service_available.glance,
+ 'volume': CONF.service_available.cinder,
+ 'orchestration': CONF.service_available.heat,
+ # NOTE(mtreinish) nova-network will provide networking functionality
+ # if neutron isn't available, so always set to True.
+ 'network': True,
+ 'identity': True,
+ 'object_storage': CONF.service_available.swift,
+ 'dashboard': CONF.service_available.horizon,
+ }
def decorator(f):
for service in args:
- if service not in valid_service_list:
+ if service not in service_list:
raise exceptions.InvalidServiceTag('%s is not a valid service'
% service)
attr(type=list(args))(f)
- return f
+
+ @functools.wraps(f)
+ def wrapper(self, *func_args, **func_kwargs):
+ for service in args:
+ if not service_list[service]:
+ msg = 'Skipped because the %s service is not available' % (
+ service)
+ raise testtools.TestCase.skipException(msg)
+ return f(self, *func_args, **func_kwargs)
+ return wrapper
return decorator
@@ -157,12 +179,12 @@
"""A function that will check the list of enabled extensions from config
"""
- configs = CONF
config_dict = {
- 'compute': configs.compute_feature_enabled.api_extensions,
- 'compute_v3': configs.compute_feature_enabled.api_v3_extensions,
- 'volume': configs.volume_feature_enabled.api_extensions,
- 'network': configs.network_feature_enabled.api_extensions,
+ 'compute': CONF.compute_feature_enabled.api_extensions,
+ 'compute_v3': CONF.compute_feature_enabled.api_v3_extensions,
+ 'volume': CONF.volume_feature_enabled.api_extensions,
+ 'network': CONF.network_feature_enabled.api_extensions,
+ 'object': CONF.object_storage_feature_enabled.discoverable_apis,
}
if config_dict[service][0] == 'all':
return True
@@ -210,24 +232,38 @@
def validate_tearDownClass():
if at_exit_set:
- raise RuntimeError("tearDownClass does not calls the super's "
+ raise RuntimeError("tearDownClass does not call the super's "
"tearDownClass in these classes: "
+ str(at_exit_set) + "\n"
"If you see the exception, with another "
- "exception please do not report this one!"
- "If you are changing tempest code, make sure you",
+ "exception please do not report this one! "
+ "If you are changing tempest code, make sure you "
"are calling the super class's tearDownClass!")
atexit.register(validate_tearDownClass)
-
-class BaseTestCase(testtools.TestCase,
+if sys.version_info >= (2, 7):
+ class BaseDeps(testtools.TestCase,
testtools.testcase.WithAttributes,
testresources.ResourcedTestCase):
+ pass
+else:
+ # Define asserts for py26
+ import unittest2
- config = CONF
+ class BaseDeps(testtools.TestCase,
+ testtools.testcase.WithAttributes,
+ testresources.ResourcedTestCase,
+ unittest2.TestCase):
+ pass
+
+
+class BaseTestCase(BaseDeps):
setUpClassCalled = False
+ _service = None
+
+ network_resources = {}
@classmethod
def setUpClass(cls):
@@ -272,23 +308,43 @@
level=None))
@classmethod
- def get_client_manager(cls):
+ def get_client_manager(cls, interface=None):
"""
Returns an Openstack client manager
"""
- cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
+ cls.isolated_creds = isolated_creds.IsolatedCreds(
+ cls.__name__, network_resources=cls.network_resources)
force_tenant_isolation = getattr(cls, 'force_tenant_isolation', None)
- if (cls.config.compute.allow_tenant_isolation or
+ if (CONF.compute.allow_tenant_isolation or
force_tenant_isolation):
creds = cls.isolated_creds.get_primary_creds()
username, tenant_name, password = creds
- os = clients.Manager(username=username,
- password=password,
- tenant_name=tenant_name,
- interface=cls._interface)
+ if getattr(cls, '_interface', None):
+ os = clients.Manager(username=username,
+ password=password,
+ tenant_name=tenant_name,
+ interface=cls._interface,
+ service=cls._service)
+ elif interface:
+ os = clients.Manager(username=username,
+ password=password,
+ tenant_name=tenant_name,
+ interface=interface,
+ service=cls._service)
+ else:
+ os = clients.Manager(username=username,
+ password=password,
+ tenant_name=tenant_name,
+ service=cls._service)
else:
- os = clients.Manager(interface=cls._interface)
+ if getattr(cls, '_interface', None):
+ os = clients.Manager(interface=cls._interface,
+ service=cls._service)
+ elif interface:
+ os = clients.Manager(interface=interface, service=cls._service)
+ else:
+ os = clients.Manager(service=cls._service)
return os
@classmethod
@@ -304,19 +360,199 @@
"""
Returns an instance of the Identity Admin API client
"""
- os = clients.AdminManager(interface=cls._interface)
+ os = clients.AdminManager(interface=cls._interface,
+ service=cls._service)
admin_client = os.identity_client
return admin_client
@classmethod
- def _get_client_args(cls):
+ def set_network_resources(self, network=False, router=False, subnet=False,
+ dhcp=False):
+ """Specify which network resources should be created
- return (
- cls.config,
- cls.config.identity.admin_username,
- cls.config.identity.admin_password,
- cls.config.identity.uri
- )
+ @param network
+ @param router
+ @param subnet
+ @param dhcp
+ """
+ # network resources should be set only once from callers
+ # in order to ensure that even if it's called multiple times in
+ # a chain of overloaded methods, the attribute is set only
+ # in the leaf class
+ if not self.network_resources:
+ self.network_resources = {
+ 'network': network,
+ 'router': router,
+ 'subnet': subnet,
+ 'dhcp': dhcp}
+
+
+class NegativeAutoTest(BaseTestCase):
+
+ _resources = {}
+
+ @classmethod
+ def setUpClass(cls):
+ super(NegativeAutoTest, cls).setUpClass()
+ os = cls.get_client_manager()
+ cls.client = os.negative_client
+
+ @staticmethod
+ def load_schema(file):
+ """
+ Loads a schema from a file on a specified location.
+
+ :param file: the file name
+ """
+ #NOTE(mkoderer): must be extended for xml support
+ fn = os.path.join(
+ os.path.abspath(os.path.dirname(os.path.dirname(__file__))),
+ "etc", "schemas", file)
+ LOG.debug("Open schema file: %s" % (fn))
+ return json.load(open(fn))
+
+ @staticmethod
+ def generate_scenario(description_file):
+ """
+ Generates the test scenario list for a given description.
+
+ :param description: A dictionary with the following entries:
+ name (required) name for the api
+ http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
+ url (required) the url to be appended to the catalog url with '%s'
+ for each resource mentioned
+ resources: (optional) A list of resource names such as "server",
+ "flavor", etc. with an element for each '%s' in the url. This
+ method will call self.get_resource for each element when
+ constructing the positive test case template so negative
+ subclasses are expected to return valid resource ids when
+ appropriate.
+ json-schema (optional) A valid json schema that will be used to
+ create invalid data for the api calls. For "GET" and "HEAD",
+ the data is used to generate query strings appended to the url,
+ otherwise for the body of the http call.
+ """
+ description = NegativeAutoTest.load_schema(description_file)
+ LOG.debug(description)
+ generate_json.validate_negative_test_schema(description)
+ schema = description.get("json-schema", None)
+ resources = description.get("resources", [])
+ scenario_list = []
+ expected_result = None
+ for resource in resources:
+ if isinstance(resource, dict):
+ expected_result = resource['expected_result']
+ resource = resource['name']
+ LOG.debug("Add resource to test %s" % resource)
+ scn_name = "inv_res_%s" % (resource)
+ scenario_list.append((scn_name, {"resource": (resource,
+ str(uuid.uuid4())),
+ "expected_result": expected_result
+ }))
+ if schema is not None:
+ for invalid in generate_json.generate_invalid(schema):
+ scenario_list.append((invalid[0],
+ {"schema": invalid[1],
+ "expected_result": invalid[2]}))
+ LOG.debug(scenario_list)
+ return scenario_list
+
+ def execute(self, description_file):
+ """
+ Execute a http call on an api that are expected to
+ result in client errors. First it uses invalid resources that are part
+ of the url, and then invalid data for queries and http request bodies.
+
+ :param description: A dictionary with the following entries:
+ name (required) name for the api
+ http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
+ url (required) the url to be appended to the catalog url with '%s'
+ for each resource mentioned
+ resources: (optional) A list of resource names such as "server",
+ "flavor", etc. with an element for each '%s' in the url. This
+ method will call self.get_resource for each element when
+ constructing the positive test case template so negative
+ subclasses are expected to return valid resource ids when
+ appropriate.
+ json-schema (optional) A valid json schema that will be used to
+ create invalid data for the api calls. For "GET" and "HEAD",
+ the data is used to generate query strings appended to the url,
+ otherwise for the body of the http call.
+
+ """
+ description = NegativeAutoTest.load_schema(description_file)
+ LOG.info("Executing %s" % description["name"])
+ LOG.debug(description)
+ method = description["http-method"]
+ url = description["url"]
+
+ resources = [self.get_resource(r) for
+ r in description.get("resources", [])]
+
+ if hasattr(self, "resource"):
+ # Note(mkoderer): The resources list already contains an invalid
+ # entry (see get_resource).
+ # We just send a valid json-schema with it
+ valid = None
+ schema = description.get("json-schema", None)
+ if schema:
+ valid = generate_json.generate_valid(schema)
+ new_url, body = self._http_arguments(valid, url, method)
+ elif hasattr(self, "schema"):
+ new_url, body = self._http_arguments(self.schema, url, method)
+
+ resp, resp_body = self.client.send_request(method, new_url,
+ resources, body=body)
+ self._check_negative_response(resp.status, resp_body)
+
+ def _http_arguments(self, json_dict, url, method):
+ LOG.debug("dict: %s url: %s method: %s" % (json_dict, url, method))
+ if not json_dict:
+ return url, None
+ elif method in ["GET", "HEAD", "PUT", "DELETE"]:
+ return "%s?%s" % (url, urllib.urlencode(json_dict)), None
+ else:
+ return url, json.dumps(json_dict)
+
+ def _check_negative_response(self, result, body):
+ expected_result = getattr(self, "expected_result", None)
+ self.assertTrue(result >= 400 and result < 500 and result != 413,
+ "Expected client error, got %s:%s" %
+ (result, body))
+ self.assertTrue(expected_result is None or expected_result == result,
+ "Expected %s, got %s:%s" %
+ (expected_result, result, body))
+
+ @classmethod
+ def set_resource(cls, name, resource):
+ """
+ This function can be used in setUpClass context to register a resoruce
+ for a test.
+
+ :param name: The name of the kind of resource such as "flavor", "role",
+ etc.
+ :resource: The id of the resource
+ """
+ cls._resources[name] = resource
+
+ def get_resource(self, name):
+ """
+ Return a valid uuid for a type of resource. If a real resource is
+ needed as part of a url then this method should return one. Otherwise
+ it can return None.
+
+ :param name: The name of the kind of resource such as "flavor", "role",
+ etc.
+ """
+ if isinstance(name, dict):
+ name = name['name']
+ if hasattr(self, "resource") and self.resource[0] == name:
+ LOG.debug("Return invalid resource (%s) value: %s" %
+ (self.resource[0], self.resource[1]))
+ return self.resource[1]
+ if name in self._resources:
+ return self._resources[name]
+ return None
def call_until_true(func, duration, sleep_for):
diff --git a/tempest/test_discover/test_discover.py b/tempest/test_discover/test_discover.py
index 2e19bf2..3fbb8e1 100644
--- a/tempest/test_discover/test_discover.py
+++ b/tempest/test_discover/test_discover.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -15,7 +13,12 @@
# under the License.
import os
-import unittest
+import sys
+
+if sys.version_info >= (2, 7):
+ import unittest
+else:
+ import unittest2 as unittest
def load_tests(loader, tests, pattern):
diff --git a/tempest/tests/base.py b/tempest/tests/base.py
index ba83cf4..15e4311 100644
--- a/tempest/tests/base.py
+++ b/tempest/tests/base.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -17,6 +15,7 @@
import os
import fixtures
+import mock
import testtools
from tempest.openstack.common.fixture import moxstubout
@@ -38,3 +37,22 @@
mox_fixture = self.useFixture(moxstubout.MoxStubout())
self.mox = mox_fixture.mox
self.stubs = mox_fixture.stubs
+
+ def patch(self, target, **kwargs):
+ """
+ Returns a started `mock.patch` object for the supplied target.
+
+ The caller may then call the returned patcher to create a mock object.
+
+ The caller does not need to call stop() on the returned
+ patcher object, as this method automatically adds a cleanup
+ to the test class to stop the patcher.
+
+ :param target: String module.class or module.object expression to patch
+ :param **kwargs: Passed as-is to `mock.patch`. See mock documentation
+ for details.
+ """
+ p = mock.patch(target, **kwargs)
+ m = p.start()
+ self.addCleanup(p.stop)
+ return m
diff --git a/tempest/tests/fake_auth_provider.py b/tempest/tests/fake_auth_provider.py
new file mode 100644
index 0000000..bc68d26
--- /dev/null
+++ b/tempest/tests/fake_auth_provider.py
@@ -0,0 +1,20 @@
+# Copyright 2014 Hewlett-Packard Development Company, L.P.
+# All Rights Reserved.
+#
+# 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.
+
+
+class FakeAuthProvider(object):
+
+ def auth_request(self, method, url, headers=None, body=None, filters=None):
+ return url, headers, body
diff --git a/tempest/tests/fake_config.py b/tempest/tests/fake_config.py
index baf6b2b..42237ca 100644
--- a/tempest/tests/fake_config.py
+++ b/tempest/tests/fake_config.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -24,5 +22,30 @@
class fake_identity(object):
disable_ssl_certificate_validation = True
+ class fake_default_feature_enabled(object):
+ api_extensions = ['all']
+
+ class fake_compute_feature_enabled(fake_default_feature_enabled):
+ api_v3_extensions = ['all']
+
+ class fake_object_storage_discoverable_apis(object):
+ discoverable_apis = ['all']
+
+ class fake_service_available(object):
+ nova = True
+ glance = True
+ cinder = True
+ heat = True
+ neutron = True
+ swift = True
+ horizon = True
+
+ compute_feature_enabled = fake_compute_feature_enabled()
+ volume_feature_enabled = fake_default_feature_enabled()
+ network_feature_enabled = fake_default_feature_enabled()
+ object_storage_feature_enabled = fake_object_storage_discoverable_apis()
+
+ service_available = fake_service_available()
+
compute = fake_compute()
identity = fake_identity()
diff --git a/tempest/tests/fake_http.py b/tempest/tests/fake_http.py
index 5974377..ac5f765 100644
--- a/tempest/tests/fake_http.py
+++ b/tempest/tests/fake_http.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/tests/files/failing-tests b/tempest/tests/files/failing-tests
index 0ec5421..78efc93 100644
--- a/tempest/tests/files/failing-tests
+++ b/tempest/tests/files/failing-tests
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/tests/files/passing-tests b/tempest/tests/files/passing-tests
index 2f5b7c9..a55cb1b 100644
--- a/tempest/tests/files/passing-tests
+++ b/tempest/tests/files/passing-tests
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/services/compute/v3/xml/__init__.py b/tempest/tests/negative/__init__.py
similarity index 100%
copy from tempest/services/compute/v3/xml/__init__.py
copy to tempest/tests/negative/__init__.py
diff --git a/tempest/tests/negative/test_generate_json.py b/tempest/tests/negative/test_generate_json.py
new file mode 100644
index 0000000..a0aa088
--- /dev/null
+++ b/tempest/tests/negative/test_generate_json.py
@@ -0,0 +1,53 @@
+# Copyright 2014 Deutsche Telekom AG
+# All Rights Reserved.
+#
+# 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 tempest.common import generate_json as gen
+import tempest.test
+
+
+class TestGenerateJson(tempest.test.BaseTestCase):
+
+ fake_input_str = {"type": "string",
+ "minLength": 2,
+ "maxLength": 8,
+ 'results': {'gen_number': 404}}
+
+ fake_input_int = {"type": "integer",
+ "maximum": 255,
+ "minimum": 1}
+
+ fake_input_obj = {"type": "object",
+ "properties": {"minRam": {"type": "integer"},
+ "diskName": {"type": "string"},
+ "maxRam": {"type": "integer", }
+ }
+ }
+
+ def _validate_result(self, data):
+ self.assertTrue(isinstance(data, list))
+ for t in data:
+ self.assertTrue(isinstance(t, tuple))
+
+ def test_generate_invalid_string(self):
+ result = gen.generate_invalid(self.fake_input_str)
+ self._validate_result(result)
+
+ def test_generate_invalid_integer(self):
+ result = gen.generate_invalid(self.fake_input_int)
+ self._validate_result(result)
+
+ def test_generate_invalid_obj(self):
+ result = gen.generate_invalid(self.fake_input_obj)
+ self._validate_result(result)
diff --git a/tempest/tests/negative/test_negative_auto_test.py b/tempest/tests/negative/test_negative_auto_test.py
new file mode 100644
index 0000000..4c59383
--- /dev/null
+++ b/tempest/tests/negative/test_negative_auto_test.py
@@ -0,0 +1,64 @@
+# Copyright 2014 Deutsche Telekom AG
+# All Rights Reserved.
+#
+# 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 mock
+
+import tempest.test as test
+
+
+class TestNegativeAutoTest(test.BaseTestCase):
+ # Fake entries
+ _interface = 'json'
+ _service = 'compute'
+
+ fake_input_desc = {"name": "list-flavors-with-detail",
+ "http-method": "GET",
+ "url": "flavors/detail",
+ "json-schema": {"type": "object",
+ "properties":
+ {"minRam": {"type": "integer"},
+ "minDisk": {"type": "integer"}}
+ },
+ "resources": ["flavor", "volume", "image"]
+ }
+
+ def _check_prop_entries(self, result, entry):
+ entries = [a for a in result if entry in a[0]]
+ self.assertIsNotNone(entries)
+ self.assertIs(len(entries), 2)
+ for entry in entries:
+ self.assertIsNotNone(entry[1]['schema'])
+
+ def _check_resource_entries(self, result, entry):
+ entries = [a for a in result if entry in a[0]]
+ self.assertIsNotNone(entries)
+ self.assertIs(len(entries), 3)
+ for entry in entries:
+ self.assertIsNotNone(entry[1]['resource'])
+
+ @mock.patch('tempest.test.NegativeAutoTest.load_schema')
+ def test_generate_scenario(self, open_mock):
+ open_mock.return_value = self.fake_input_desc
+ scenarios = test.NegativeAutoTest.\
+ generate_scenario(None)
+
+ self.assertIsInstance(scenarios, list)
+ for scenario in scenarios:
+ self.assertIsInstance(scenario, tuple)
+ self.assertIsInstance(scenario[0], str)
+ self.assertIsInstance(scenario[1], dict)
+ self._check_prop_entries(scenarios, "prop_minRam")
+ self._check_prop_entries(scenarios, "prop_minDisk")
+ self._check_resource_entries(scenarios, "inv_res")
diff --git a/tempest/tests/stress/test_stress.py b/tempest/tests/stress/test_stress.py
index 4d7de9d..c76abde 100644
--- a/tempest/tests/stress/test_stress.py
+++ b/tempest/tests/stress/test_stress.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Deutsche Telekom AG
# All Rights Reserved.
#
diff --git a/tempest/tests/stress/test_stressaction.py b/tempest/tests/stress/test_stressaction.py
index 3d2901e..1a1bb67 100644
--- a/tempest/tests/stress/test_stressaction.py
+++ b/tempest/tests/stress/test_stressaction.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 Deutsche Telekom AG
# All Rights Reserved.
#
diff --git a/tempest/tests/test_compute_xml_common.py b/tempest/tests/test_compute_xml_common.py
new file mode 100644
index 0000000..bfa6a10
--- /dev/null
+++ b/tempest/tests/test_compute_xml_common.py
@@ -0,0 +1,67 @@
+# Copyright 2013 IBM Corp.
+#
+# 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 lxml import etree
+
+from tempest.services.compute.xml import common
+from tempest.tests import base
+
+
+class TestXMLParser(base.TestCase):
+
+ def test_xml_to_json_parser_bool_value(self):
+ node = etree.fromstring('''<health_monitor
+ xmlns="http://openstack.org/quantum/api/v2.0"
+ xmlns:quantum="http://openstack.org/quantum/api/v2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <admin_state_up quantum:type="bool">False</admin_state_up>
+ <fake_state_up quantum:type="bool">True</fake_state_up>
+ </health_monitor>''')
+ body = common.xml_to_json(node)
+ self.assertEqual(body['admin_state_up'], False)
+ self.assertEqual(body['fake_state_up'], True)
+
+ def test_xml_to_json_parser_int_value(self):
+ node = etree.fromstring('''<health_monitor
+ xmlns="http://openstack.org/quantum/api/v2.0"
+ xmlns:quantum="http://openstack.org/quantum/api/v2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <delay quantum:type="long">4</delay>
+ <max_retries quantum:type="int">3</max_retries>
+ </health_monitor>''')
+ body = common.xml_to_json(node)
+ self.assertEqual(body['delay'], 4L)
+ self.assertEqual(body['max_retries'], 3)
+
+ def test_xml_to_json_parser_text_value(self):
+ node = etree.fromstring('''<health_monitor
+ xmlns="http://openstack.org/quantum/api/v2.0"
+ xmlns:quantum="http://openstack.org/quantum/api/v2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <status>ACTIVE</status>
+ </health_monitor>''')
+ body = common.xml_to_json(node)
+ self.assertEqual(body['status'], 'ACTIVE')
+
+ def test_xml_to_json_parser_list_as_value(self):
+ node = etree.fromstring('''<health_monitor
+ xmlns="http://openstack.org/quantum/api/v2.0"
+ xmlns:quantum="http://openstack.org/quantum/api/v2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <elements>
+ <element>first_element</element>
+ <element>second_element</element>
+ </elements>
+ </health_monitor>''')
+ body = common.xml_to_json(node, 'elements')
+ self.assertEqual(body['elements'], ['first_element', 'second_element'])
diff --git a/tempest/tests/test_decorators.py b/tempest/tests/test_decorators.py
new file mode 100644
index 0000000..7fb38ff
--- /dev/null
+++ b/tempest/tests/test_decorators.py
@@ -0,0 +1,233 @@
+# Copyright 2013 IBM Corp.
+#
+# 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 testtools
+
+from tempest import exceptions
+from tempest.openstack.common.fixture import mockpatch
+from tempest import test
+from tempest.tests import base
+from tempest.tests import fake_config
+
+
+class BaseDecoratorsTest(base.TestCase):
+ def setUp(self):
+ super(BaseDecoratorsTest, self).setUp()
+ self.stubs.Set(test, 'CONF', fake_config.FakeConfig)
+
+
+class TestAttrDecorator(BaseDecoratorsTest):
+ def _test_attr_helper(self, expected_attrs, **decorator_args):
+ @test.attr(**decorator_args)
+ def foo():
+ pass
+
+ # By our test.attr decorator the attribute __testtools_attrs will be
+ # set only for 'type' argument, so we test it first.
+ if 'type' in decorator_args:
+ # this is what testtools sets
+ self.assertEqual(getattr(foo, '__testtools_attrs'),
+ set(expected_attrs))
+
+ # nose sets it anyway
+ for arg, value in decorator_args.items():
+ self.assertEqual(getattr(foo, arg), value)
+
+ def test_attr_without_type(self):
+ self._test_attr_helper(expected_attrs='baz', bar='baz')
+
+ def test_attr_decorator_with_smoke_type(self):
+ # smoke passed as type, so smoke and gate must have been set.
+ self._test_attr_helper(expected_attrs=['smoke', 'gate'], type='smoke')
+
+ def test_attr_decorator_with_list_type(self):
+ # if type is 'smoke' we'll get the original list of types plus 'gate'
+ self._test_attr_helper(expected_attrs=['smoke', 'foo', 'gate'],
+ type=['smoke', 'foo'])
+
+ def test_attr_decorator_with_unknown_type(self):
+ self._test_attr_helper(expected_attrs=['foo'], type='foo')
+
+ def test_attr_decorator_with_duplicated_type(self):
+ self._test_attr_helper(expected_attrs=['foo'], type=['foo', 'foo'])
+
+
+class TestServicesDecorator(BaseDecoratorsTest):
+ def _test_services_helper(self, *decorator_args):
+ class TestFoo(test.BaseTestCase):
+ @test.services(*decorator_args)
+ def test_bar(self):
+ return 0
+
+ t = TestFoo('test_bar')
+ self.assertEqual(set(decorator_args), getattr(t.test_bar,
+ '__testtools_attrs'))
+ self.assertEqual(list(decorator_args), t.test_bar.type)
+ self.assertEqual(t.test_bar(), 0)
+
+ def test_services_decorator_with_single_service(self):
+ self._test_services_helper('compute')
+
+ def test_services_decorator_with_multiple_services(self):
+ self._test_services_helper('compute', 'network')
+
+ def test_services_decorator_with_duplicated_service(self):
+ self._test_services_helper('compute', 'compute')
+
+ def test_services_decorator_with_invalid_service(self):
+ self.assertRaises(exceptions.InvalidServiceTag,
+ self._test_services_helper, 'compute',
+ 'bad_service')
+
+ def test_services_decorator_with_service_valid_and_unavailable(self):
+ self.useFixture(mockpatch.PatchObject(test.CONF.service_available,
+ 'cinder', False))
+ self.assertRaises(testtools.TestCase.skipException,
+ self._test_services_helper, 'compute',
+ 'volume')
+
+
+class TestStressDecorator(BaseDecoratorsTest):
+ def _test_stresstest_helper(self, expected_frequency='process',
+ expected_inheritance=False,
+ **decorator_args):
+ @test.stresstest(**decorator_args)
+ def foo():
+ pass
+ self.assertEqual(getattr(foo, 'st_class_setup_per'),
+ expected_frequency)
+ self.assertEqual(getattr(foo, 'st_allow_inheritance'),
+ expected_inheritance)
+ self.assertEqual(foo.type, 'stress')
+ self.assertEqual(set(['stress']), getattr(foo, '__testtools_attrs'))
+
+ def test_stresstest_decorator_default(self):
+ self._test_stresstest_helper()
+
+ def test_stresstest_decorator_class_setup_frequency(self):
+ self._test_stresstest_helper('process', class_setup_per='process')
+
+ def test_stresstest_decorator_class_setup_frequency_non_default(self):
+ self._test_stresstest_helper(expected_frequency='application',
+ class_setup_per='application')
+
+ def test_stresstest_decorator_set_frequency_and_inheritance(self):
+ self._test_stresstest_helper(expected_frequency='application',
+ expected_inheritance=True,
+ class_setup_per='application',
+ allow_inheritance=True)
+
+
+class TestSkipBecauseDecorator(BaseDecoratorsTest):
+ def _test_skip_because_helper(self, expected_to_skip=True,
+ **decorator_args):
+ class TestFoo(test.BaseTestCase):
+ _interface = 'json'
+
+ @test.skip_because(**decorator_args)
+ def test_bar(self):
+ return 0
+
+ t = TestFoo('test_bar')
+ if expected_to_skip:
+ self.assertRaises(testtools.TestCase.skipException, t.test_bar)
+ else:
+ # assert that test_bar returned 0
+ self.assertEqual(TestFoo('test_bar').test_bar(), 0)
+
+ def test_skip_because_bug(self):
+ self._test_skip_because_helper(bug='critical_bug')
+
+ def test_skip_because_bug_and_interface_match(self):
+ self._test_skip_because_helper(bug='critical_bug', interface='json')
+
+ def test_skip_because_bug_interface_not_match(self):
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='critical_bug', interface='xml')
+
+ def test_skip_because_bug_and_condition_true(self):
+ self._test_skip_because_helper(bug='critical_bug', condition=True)
+
+ def test_skip_because_bug_and_condition_false(self):
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='critical_bug', condition=False)
+
+ def test_skip_because_bug_condition_false_and_interface_match(self):
+ """
+ Assure that only condition will be evaluated if both parameters are
+ passed.
+ """
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='critical_bug', condition=False,
+ interface='json')
+
+ def test_skip_because_bug_condition_true_and_interface_not_match(self):
+ """
+ Assure that only condition will be evaluated if both parameters are
+ passed.
+ """
+ self._test_skip_because_helper(bug='critical_bug', condition=True,
+ interface='xml')
+
+ def test_skip_because_bug_without_bug_never_skips(self):
+ """Never skip without a bug parameter."""
+ self._test_skip_because_helper(expected_to_skip=False,
+ condition=True)
+ self._test_skip_because_helper(expected_to_skip=False,
+ interface='json')
+
+
+class TestRequiresExtDecorator(BaseDecoratorsTest):
+ def setUp(self):
+ super(TestRequiresExtDecorator, self).setUp()
+ self.fixture = self.useFixture(mockpatch.PatchObject(
+ test.CONF.compute_feature_enabled,
+ 'api_extensions',
+ new=['enabled_ext', 'another_ext']))
+
+ def _test_requires_ext_helper(self, expected_to_skip=True,
+ **decorator_args):
+ class TestFoo(test.BaseTestCase):
+ @test.requires_ext(**decorator_args)
+ def test_bar(self):
+ return 0
+
+ t = TestFoo('test_bar')
+ if expected_to_skip:
+ self.assertRaises(testtools.TestCase.skipException, t.test_bar)
+ else:
+ self.assertEqual(t.test_bar(), 0)
+
+ def test_requires_ext_decorator(self):
+ self._test_requires_ext_helper(expected_to_skip=False,
+ extension='enabled_ext',
+ service='compute')
+
+ def test_requires_ext_decorator_disabled_ext(self):
+ self._test_requires_ext_helper(extension='disabled_ext',
+ service='compute')
+
+ def test_requires_ext_decorator_with_all_ext_enabled(self):
+ # disable fixture so the default (all) is used.
+ self.fixture.cleanUp()
+ self._test_requires_ext_helper(expected_to_skip=False,
+ extension='random_ext',
+ service='compute')
+
+ def test_requires_ext_decorator_bad_service(self):
+ self.assertRaises(KeyError,
+ self._test_requires_ext_helper,
+ extension='enabled_ext',
+ service='bad_service')
diff --git a/tempest/tests/test_list_tests.py b/tempest/tests/test_list_tests.py
index ab0d114..157fc5f 100644
--- a/tempest/tests/test_list_tests.py
+++ b/tempest/tests/test_list_tests.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/tempest/tests/test_rest_client.py b/tempest/tests/test_rest_client.py
index ae6174c..ba43daf 100644
--- a/tempest/tests/test_rest_client.py
+++ b/tempest/tests/test_rest_client.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -15,28 +13,34 @@
# under the License.
import httplib2
+import json
from tempest.common import rest_client
+from tempest import config
from tempest import exceptions
from tempest.openstack.common.fixture import mockpatch
+from tempest.services.compute.xml import common as xml
from tempest.tests import base
+from tempest.tests import fake_auth_provider
from tempest.tests import fake_config
from tempest.tests import fake_http
class BaseRestClientTestClass(base.TestCase):
- def _set_token(self):
- self.rest_client.token = 'fake token'
+ url = 'fake_endpoint'
+
+ def _get_region(self):
+ return 'fake region'
def setUp(self):
super(BaseRestClientTestClass, self).setUp()
- self.rest_client = rest_client.RestClient(fake_config.FakeConfig(),
- 'fake_user', 'fake_pass',
- 'http://fake_url/v2.0')
+ self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakeConfig)
+ self.rest_client = rest_client.RestClient(
+ fake_auth_provider.FakeAuthProvider())
self.stubs.Set(httplib2.Http, 'request', self.fake_http.request)
- self.useFixture(mockpatch.PatchObject(self.rest_client, '_set_auth',
- side_effect=self._set_token()))
+ self.useFixture(mockpatch.PatchObject(self.rest_client, '_get_region',
+ side_effect=self._get_region()))
self.useFixture(mockpatch.PatchObject(self.rest_client,
'_log_response'))
@@ -49,36 +53,33 @@
'_error_checker'))
def test_post(self):
- __, return_dict = self.rest_client.post('fake_endpoint', {},
- {})
+ __, return_dict = self.rest_client.post(self.url, {}, {})
self.assertEqual('POST', return_dict['method'])
def test_get(self):
- __, return_dict = self.rest_client.get('fake_endpoint')
+ __, return_dict = self.rest_client.get(self.url)
self.assertEqual('GET', return_dict['method'])
def test_delete(self):
- __, return_dict = self.rest_client.delete('fake_endpoint')
+ __, return_dict = self.rest_client.delete(self.url)
self.assertEqual('DELETE', return_dict['method'])
def test_patch(self):
- __, return_dict = self.rest_client.patch('fake_endpoint', {},
- {})
+ __, return_dict = self.rest_client.patch(self.url, {}, {})
self.assertEqual('PATCH', return_dict['method'])
def test_put(self):
- __, return_dict = self.rest_client.put('fake_endpoint', {},
- {})
+ __, return_dict = self.rest_client.put(self.url, {}, {})
self.assertEqual('PUT', return_dict['method'])
def test_head(self):
self.useFixture(mockpatch.PatchObject(self.rest_client,
'response_checker'))
- __, return_dict = self.rest_client.head('fake_endpoint')
+ __, return_dict = self.rest_client.head(self.url)
self.assertEqual('HEAD', return_dict['method'])
def test_copy(self):
- __, return_dict = self.rest_client.copy('fake_endpoint')
+ __, return_dict = self.rest_client.copy(self.url)
self.assertEqual('COPY', return_dict['method'])
@@ -89,4 +90,143 @@
def test_post(self):
self.assertRaises(exceptions.NotFound, self.rest_client.post,
- 'fake_endpoint', {}, {})
+ self.url, {}, {})
+
+
+class TestRestClientHeadersJSON(TestRestClientHTTPMethods):
+ TYPE = "json"
+
+ def _verify_headers(self, resp):
+ self.assertEqual(self.rest_client._get_type(), self.TYPE)
+ resp = dict((k.lower(), v) for k, v in resp.iteritems())
+ self.assertEqual(self.header_value, resp['accept'])
+ self.assertEqual(self.header_value, resp['content-type'])
+
+ def setUp(self):
+ super(TestRestClientHeadersJSON, self).setUp()
+ self.rest_client.TYPE = self.TYPE
+ self.header_value = 'application/%s' % self.rest_client._get_type()
+
+ def test_post(self):
+ resp, __ = self.rest_client.post(self.url, {})
+ self._verify_headers(resp)
+
+ def test_get(self):
+ resp, __ = self.rest_client.get(self.url)
+ self._verify_headers(resp)
+
+ def test_delete(self):
+ resp, __ = self.rest_client.delete(self.url)
+ self._verify_headers(resp)
+
+ def test_patch(self):
+ resp, __ = self.rest_client.patch(self.url, {})
+ self._verify_headers(resp)
+
+ def test_put(self):
+ resp, __ = self.rest_client.put(self.url, {})
+ self._verify_headers(resp)
+
+ def test_head(self):
+ self.useFixture(mockpatch.PatchObject(self.rest_client,
+ 'response_checker'))
+ resp, __ = self.rest_client.head(self.url)
+ self._verify_headers(resp)
+
+ def test_copy(self):
+ resp, __ = self.rest_client.copy(self.url)
+ self._verify_headers(resp)
+
+
+class TestRestClientHeadersXML(TestRestClientHeadersJSON):
+ TYPE = "xml"
+
+ # These two tests are needed in one exemplar
+ def test_send_json_accept_xml(self):
+ resp, __ = self.rest_client.get(self.url,
+ self.rest_client.get_headers("xml",
+ "json"))
+ resp = dict((k.lower(), v) for k, v in resp.iteritems())
+ self.assertEqual("application/json", resp["content-type"])
+ self.assertEqual("application/xml", resp["accept"])
+
+ def test_send_xml_accept_json(self):
+ resp, __ = self.rest_client.get(self.url,
+ self.rest_client.get_headers("json",
+ "xml"))
+ resp = dict((k.lower(), v) for k, v in resp.iteritems())
+ self.assertEqual("application/json", resp["accept"])
+ self.assertEqual("application/xml", resp["content-type"])
+
+
+class TestRestClientParseRespXML(BaseRestClientTestClass):
+ TYPE = "xml"
+
+ keys = ["fake_key1", "fake_key2"]
+ values = ["fake_value1", "fake_value2"]
+ item_expected = {key: value for key, value in zip(keys, values)}
+ list_expected = {"body_list": [
+ {keys[0]: values[0]},
+ {keys[1]: values[1]},
+ ]}
+ dict_expected = {"body_dict": {
+ keys[0]: values[0],
+ keys[1]: values[1],
+ }}
+
+ def setUp(self):
+ self.fake_http = fake_http.fake_httplib2()
+ super(TestRestClientParseRespXML, self).setUp()
+ self.rest_client.TYPE = self.TYPE
+
+ def test_parse_resp_body_item(self):
+ body_item = xml.Element("item", **self.item_expected)
+ body = self.rest_client._parse_resp(str(xml.Document(body_item)))
+ self.assertEqual(self.item_expected, body)
+
+ def test_parse_resp_body_list(self):
+ self.rest_client.list_tags = ["fake_list", ]
+ body_list = xml.Element(self.rest_client.list_tags[0])
+ for i in range(2):
+ body_list.append(xml.Element("fake_item",
+ **self.list_expected["body_list"][i]))
+ body = self.rest_client._parse_resp(str(xml.Document(body_list)))
+ self.assertEqual(self.list_expected["body_list"], body)
+
+ def test_parse_resp_body_dict(self):
+ self.rest_client.dict_tags = ["fake_dict", ]
+ body_dict = xml.Element(self.rest_client.dict_tags[0])
+
+ for i in range(2):
+ body_dict.append(xml.Element("fake_item", xml.Text(self.values[i]),
+ key=self.keys[i]))
+
+ body = self.rest_client._parse_resp(str(xml.Document(body_dict)))
+ self.assertEqual(self.dict_expected["body_dict"], body)
+
+
+class TestRestClientParseRespJSON(TestRestClientParseRespXML):
+ TYPE = "json"
+
+ def test_parse_resp_body_item(self):
+ body = self.rest_client._parse_resp(json.dumps(self.item_expected))
+ self.assertEqual(self.item_expected, body)
+
+ def test_parse_resp_body_list(self):
+ body = self.rest_client._parse_resp(json.dumps(self.list_expected))
+ self.assertEqual(self.list_expected["body_list"], body)
+
+ def test_parse_resp_body_dict(self):
+ body = self.rest_client._parse_resp(json.dumps(self.dict_expected))
+ self.assertEqual(self.dict_expected["body_dict"], body)
+
+ def test_parse_resp_two_top_keys(self):
+ dict_two_keys = self.dict_expected.copy()
+ dict_two_keys.update({"second_key": ""})
+ body = self.rest_client._parse_resp(json.dumps(dict_two_keys))
+ self.assertEqual(dict_two_keys, body)
+
+ def test_parse_resp_one_top_key_without_list_or_dict(self):
+ data = {"one_top_key": "not_list_or_dict_value"}
+ body = self.rest_client._parse_resp(json.dumps(data))
+ self.assertEqual(data, body)
diff --git a/tempest/tests/test_ssh.py b/tempest/tests/test_ssh.py
new file mode 100644
index 0000000..a6eedc4
--- /dev/null
+++ b/tempest/tests/test_ssh.py
@@ -0,0 +1,202 @@
+# Copyright 2014 OpenStack Foundation
+#
+# 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 contextlib
+import socket
+
+import mock
+import testtools
+
+from tempest.common import ssh
+from tempest import exceptions
+from tempest.tests import base
+
+
+class TestSshClient(base.TestCase):
+
+ def test_pkey_calls_paramiko_RSAKey(self):
+ with contextlib.nested(
+ mock.patch('paramiko.RSAKey.from_private_key'),
+ mock.patch('cStringIO.StringIO')) as (rsa_mock, cs_mock):
+ cs_mock.return_value = mock.sentinel.csio
+ pkey = 'mykey'
+ ssh.Client('localhost', 'root', pkey=pkey)
+ rsa_mock.assert_called_once_with(mock.sentinel.csio)
+ cs_mock.assert_called_once_with('mykey')
+ rsa_mock.reset_mock()
+ cs_mock.rest_mock()
+ pkey = mock.sentinel.pkey
+ # Shouldn't call out to load a file from RSAKey, since
+ # a sentinel isn't a basestring...
+ ssh.Client('localhost', 'root', pkey=pkey)
+ rsa_mock.assert_not_called()
+ cs_mock.assert_not_called()
+
+ def test_get_ssh_connection(self):
+ c_mock = self.patch('paramiko.SSHClient')
+ aa_mock = self.patch('paramiko.AutoAddPolicy')
+ s_mock = self.patch('time.sleep')
+ t_mock = self.patch('time.time')
+
+ aa_mock.return_value = mock.sentinel.aa
+
+ def reset_mocks():
+ aa_mock.reset_mock()
+ c_mock.reset_mock()
+ s_mock.reset_mock()
+ t_mock.reset_mock()
+
+ # Test normal case for successful connection on first try
+ client_mock = mock.MagicMock()
+ c_mock.return_value = client_mock
+ client_mock.connect.return_value = True
+
+ client = ssh.Client('localhost', 'root', timeout=2)
+ client._get_ssh_connection(sleep=1)
+
+ aa_mock.assert_called_once_with()
+ client_mock.set_missing_host_key_policy.assert_called_once_with(
+ mock.sentinel.aa)
+ expected_connect = [mock.call(
+ 'localhost',
+ username='root',
+ pkey=None,
+ key_filename=None,
+ look_for_keys=False,
+ timeout=10.0,
+ password=None
+ )]
+ self.assertEqual(expected_connect, client_mock.connect.mock_calls)
+ s_mock.assert_not_called()
+ t_mock.assert_called_once_with()
+
+ reset_mocks()
+
+ # Test case when connection fails on first two tries and
+ # succeeds on third try (this validates retry logic)
+ client_mock.connect.side_effect = [socket.error, socket.error, True]
+ t_mock.side_effect = [
+ 1000, # Start time
+ 1000, # LOG.warning() calls time.time() loop 1
+ 1001, # Sleep loop 1
+ 1001, # LOG.warning() calls time.time() loop 2
+ 1002 # Sleep loop 2
+ ]
+
+ client._get_ssh_connection(sleep=1)
+
+ expected_sleeps = [
+ mock.call(2),
+ mock.call(3)
+ ]
+ self.assertEqual(expected_sleeps, s_mock.mock_calls)
+
+ reset_mocks()
+
+ # Test case when connection fails on first three tries and
+ # exceeds the timeout, so expect to raise a Timeout exception
+ client_mock.connect.side_effect = [
+ socket.error,
+ socket.error,
+ socket.error
+ ]
+ t_mock.side_effect = [
+ 1000, # Start time
+ 1000, # LOG.warning() calls time.time() loop 1
+ 1001, # Sleep loop 1
+ 1001, # LOG.warning() calls time.time() loop 2
+ 1002, # Sleep loop 2
+ 1003, # Sleep loop 3
+ 1004 # LOG.error() calls time.time()
+ ]
+
+ with testtools.ExpectedException(exceptions.SSHTimeout):
+ client._get_ssh_connection()
+
+ def test_exec_command(self):
+ gsc_mock = self.patch('tempest.common.ssh.Client._get_ssh_connection')
+ ito_mock = self.patch('tempest.common.ssh.Client._is_timed_out')
+ select_mock = self.patch('select.poll')
+
+ client_mock = mock.MagicMock()
+ tran_mock = mock.MagicMock()
+ chan_mock = mock.MagicMock()
+ poll_mock = mock.MagicMock()
+
+ def reset_mocks():
+ gsc_mock.reset_mock()
+ ito_mock.reset_mock()
+ select_mock.reset_mock()
+ poll_mock.reset_mock()
+ client_mock.reset_mock()
+ tran_mock.reset_mock()
+ chan_mock.reset_mock()
+
+ select_mock.return_value = poll_mock
+ gsc_mock.return_value = client_mock
+ ito_mock.return_value = True
+ client_mock.get_transport.return_value = tran_mock
+ tran_mock.open_session.return_value = chan_mock
+ poll_mock.poll.side_effect = [
+ [0, 0, 0]
+ ]
+
+ # Test for a timeout condition immediately raised
+ client = ssh.Client('localhost', 'root', timeout=2)
+ with testtools.ExpectedException(exceptions.TimeoutException):
+ client.exec_command("test")
+
+ chan_mock.fileno.assert_called_once_with()
+ chan_mock.exec_command.assert_called_once_with("test")
+ chan_mock.shutdown_write.assert_called_once_with()
+
+ SELECT_POLLIN = 1
+ poll_mock.register.assert_called_once_with(chan_mock, SELECT_POLLIN)
+ poll_mock.poll.assert_called_once_with(10)
+
+ # Test for proper reading of STDOUT and STDERROR and closing
+ # of all file descriptors.
+
+ reset_mocks()
+
+ select_mock.return_value = poll_mock
+ gsc_mock.return_value = client_mock
+ ito_mock.return_value = False
+ client_mock.get_transport.return_value = tran_mock
+ tran_mock.open_session.return_value = chan_mock
+ poll_mock.poll.side_effect = [
+ [1, 0, 0]
+ ]
+ closed_prop = mock.PropertyMock(return_value=True)
+ type(chan_mock).closed = closed_prop
+ chan_mock.recv_exit_status.return_value = 0
+ chan_mock.recv.return_value = ''
+ chan_mock.recv_stderr.return_value = ''
+
+ client = ssh.Client('localhost', 'root', timeout=2)
+ client.exec_command("test")
+
+ chan_mock.fileno.assert_called_once_with()
+ chan_mock.exec_command.assert_called_once_with("test")
+ chan_mock.shutdown_write.assert_called_once_with()
+
+ SELECT_POLLIN = 1
+ poll_mock.register.assert_called_once_with(chan_mock, SELECT_POLLIN)
+ poll_mock.poll.assert_called_once_with(10)
+ chan_mock.recv_ready.assert_called_once_with()
+ chan_mock.recv.assert_called_once_with(1024)
+ chan_mock.recv_stderr_ready.assert_called_once_with()
+ chan_mock.recv_stderr.assert_called_once_with(1024)
+ chan_mock.recv_exit_status.assert_called_once_with()
+ closed_prop.assert_called_once_with()
diff --git a/tempest/tests/test_wrappers.py b/tempest/tests/test_wrappers.py
index 88bef9b..f6ed445 100644
--- a/tempest/tests/test_wrappers.py
+++ b/tempest/tests/test_wrappers.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -29,6 +27,7 @@
super(TestWrappers, self).setUp()
# Setup test dirs
self.directory = tempfile.mkdtemp(prefix='tempest-unit')
+ self.addCleanup(shutil.rmtree, self.directory)
self.test_dir = os.path.join(self.directory, 'tests')
os.mkdir(self.test_dir)
# Setup Test files
diff --git a/tempest/thirdparty/boto/test.py b/tempest/thirdparty/boto/test.py
index 2ce5cce..b36e8c7 100644
--- a/tempest/thirdparty/boto/test.py
+++ b/tempest/thirdparty/boto/test.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -197,6 +195,7 @@
def setUpClass(cls):
super(BotoTestCase, cls).setUpClass()
cls.conclusion = decision_maker()
+ cls.os = cls.get_client_manager()
# The trash contains cleanup functions and paramaters in tuples
# (function, *args, **kwargs)
cls._resource_trash_bin = {}
@@ -261,6 +260,7 @@
LOG.exception("Cleanup failed %s" % func_name)
finally:
del cls._resource_trash_bin[key]
+ cls.clear_isolated_creds()
super(BotoTestCase, cls).tearDownClass()
# NOTE(afazekas): let the super called even on exceptions
# The real exceptions already logged, if the super throws another,
diff --git a/tempest/thirdparty/boto/test_ec2_instance_run.py b/tempest/thirdparty/boto/test_ec2_instance_run.py
index 9ded9da..a6932bc 100644
--- a/tempest/thirdparty/boto/test_ec2_instance_run.py
+++ b/tempest/thirdparty/boto/test_ec2_instance_run.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,9 +15,9 @@
from boto import exception
-from tempest import clients
from tempest.common.utils import data_utils
from tempest.common.utils.linux.remote_client import RemoteClient
+from tempest import config
from tempest import exceptions
from tempest.openstack.common import log as logging
from tempest.test import attr
@@ -29,6 +27,8 @@
from tempest.thirdparty.boto.utils.wait import re_search_wait
from tempest.thirdparty.boto.utils.wait import state_wait
+CONF = config.CONF
+
LOG = logging.getLogger(__name__)
@@ -40,16 +40,14 @@
if not cls.conclusion['A_I_IMAGES_READY']:
raise cls.skipException("".join(("EC2 ", cls.__name__,
": requires ami/aki/ari manifest")))
- cls.os = clients.Manager()
cls.s3_client = cls.os.s3_client
cls.ec2_client = cls.os.ec2api_client
cls.zone = cls.ec2_client.get_good_zone()
- config = cls.config
- cls.materials_path = config.boto.s3_materials_path
- ami_manifest = config.boto.ami_manifest
- aki_manifest = config.boto.aki_manifest
- ari_manifest = config.boto.ari_manifest
- cls.instance_type = config.boto.instance_type
+ cls.materials_path = CONF.boto.s3_materials_path
+ ami_manifest = CONF.boto.ami_manifest
+ aki_manifest = CONF.boto.aki_manifest
+ ari_manifest = CONF.boto.ari_manifest
+ cls.instance_type = CONF.boto.instance_type
cls.bucket_name = data_utils.rand_name("s3bucket-")
cls.keypair_name = data_utils.rand_name("keypair-")
cls.keypair = cls.ec2_client.create_key_pair(cls.keypair_name)
@@ -283,7 +281,7 @@
# NOTE(afazekas): it may be reports availble before it is available
ssh = RemoteClient(address.public_ip,
- self.os.config.compute.ssh_user,
+ CONF.compute.ssh_user,
pkey=self.keypair.material)
text = data_utils.rand_name("Pattern text for console output -")
resp = ssh.write_to_console(text)
diff --git a/tempest/thirdparty/boto/test_ec2_keys.py b/tempest/thirdparty/boto/test_ec2_keys.py
index 41db709..329ace3 100644
--- a/tempest/thirdparty/boto/test_ec2_keys.py
+++ b/tempest/thirdparty/boto/test_ec2_keys.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest import clients
from tempest.common.utils import data_utils
from tempest.test import attr
from tempest.test import skip_because
@@ -32,7 +29,6 @@
@classmethod
def setUpClass(cls):
super(EC2KeysTest, cls).setUpClass()
- cls.os = clients.Manager()
cls.client = cls.os.ec2api_client
cls.ec = cls.ec2_error_code
diff --git a/tempest/thirdparty/boto/test_ec2_network.py b/tempest/thirdparty/boto/test_ec2_network.py
index b4949c8..4b2f01f 100644
--- a/tempest/thirdparty/boto/test_ec2_network.py
+++ b/tempest/thirdparty/boto/test_ec2_network.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest import clients
from tempest.test import attr
from tempest.test import skip_because
from tempest.thirdparty.boto.test import BotoTestCase
@@ -26,7 +23,6 @@
@classmethod
def setUpClass(cls):
super(EC2NetworkTest, cls).setUpClass()
- cls.os = clients.Manager()
cls.client = cls.os.ec2api_client
# Note(afazekas): these tests for things duable without an instance
diff --git a/tempest/thirdparty/boto/test_ec2_security_groups.py b/tempest/thirdparty/boto/test_ec2_security_groups.py
index e8c6466..9b58603 100644
--- a/tempest/thirdparty/boto/test_ec2_security_groups.py
+++ b/tempest/thirdparty/boto/test_ec2_security_groups.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest import clients
from tempest.common.utils import data_utils
from tempest.test import attr
from tempest.thirdparty.boto.test import BotoTestCase
@@ -26,7 +23,6 @@
@classmethod
def setUpClass(cls):
super(EC2SecurityGroupTest, cls).setUpClass()
- cls.os = clients.Manager()
cls.client = cls.os.ec2api_client
@attr(type='smoke')
diff --git a/tempest/thirdparty/boto/test_ec2_volumes.py b/tempest/thirdparty/boto/test_ec2_volumes.py
index faff3ca..04671c5 100644
--- a/tempest/thirdparty/boto/test_ec2_volumes.py
+++ b/tempest/thirdparty/boto/test_ec2_volumes.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest import clients
from tempest.openstack.common import log as logging
from tempest.test import attr
from tempest.thirdparty.boto.test import BotoTestCase
@@ -33,7 +30,6 @@
@classmethod
def setUpClass(cls):
super(EC2VolumesTest, cls).setUpClass()
- cls.os = clients.Manager()
cls.client = cls.os.ec2api_client
cls.zone = cls.client.get_good_zone()
diff --git a/tempest/thirdparty/boto/test_s3_buckets.py b/tempest/thirdparty/boto/test_s3_buckets.py
index 56ee9e3..f34faac 100644
--- a/tempest/thirdparty/boto/test_s3_buckets.py
+++ b/tempest/thirdparty/boto/test_s3_buckets.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -15,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from tempest import clients
from tempest.common.utils import data_utils
from tempest.test import attr
from tempest.test import skip_because
@@ -27,7 +24,6 @@
@classmethod
def setUpClass(cls):
super(S3BucketsTest, cls).setUpClass()
- cls.os = clients.Manager()
cls.client = cls.os.s3_client
@skip_because(bug="1076965")
diff --git a/tempest/thirdparty/boto/test_s3_ec2_images.py b/tempest/thirdparty/boto/test_s3_ec2_images.py
index 2e7525a..9607a92 100644
--- a/tempest/thirdparty/boto/test_s3_ec2_images.py
+++ b/tempest/thirdparty/boto/test_s3_ec2_images.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -17,12 +15,14 @@
import os
-from tempest import clients
from tempest.common.utils import data_utils
+from tempest import config
from tempest.test import attr
from tempest.thirdparty.boto.test import BotoTestCase
from tempest.thirdparty.boto.utils.s3 import s3_upload_dir
+CONF = config.CONF
+
class S3ImagesTest(BotoTestCase):
@@ -32,14 +32,12 @@
if not cls.conclusion['A_I_IMAGES_READY']:
raise cls.skipException("".join(("EC2 ", cls.__name__,
": requires ami/aki/ari manifest")))
- cls.os = clients.Manager()
cls.s3_client = cls.os.s3_client
cls.images_client = cls.os.ec2api_client
- config = cls.config
- cls.materials_path = config.boto.s3_materials_path
- cls.ami_manifest = config.boto.ami_manifest
- cls.aki_manifest = config.boto.aki_manifest
- cls.ari_manifest = config.boto.ari_manifest
+ cls.materials_path = CONF.boto.s3_materials_path
+ cls.ami_manifest = CONF.boto.ami_manifest
+ cls.aki_manifest = CONF.boto.aki_manifest
+ cls.ari_manifest = CONF.boto.ari_manifest
cls.ami_path = cls.materials_path + os.sep + cls.ami_manifest
cls.aki_path = cls.materials_path + os.sep + cls.aki_manifest
cls.ari_path = cls.materials_path + os.sep + cls.ari_manifest
diff --git a/tempest/thirdparty/boto/test_s3_objects.py b/tempest/thirdparty/boto/test_s3_objects.py
index 57ec34a..a102a22 100644
--- a/tempest/thirdparty/boto/test_s3_objects.py
+++ b/tempest/thirdparty/boto/test_s3_objects.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
@@ -19,7 +17,6 @@
import boto.s3.key
-from tempest import clients
from tempest.common.utils import data_utils
from tempest.test import attr
from tempest.thirdparty.boto.test import BotoTestCase
@@ -30,7 +27,6 @@
@classmethod
def setUpClass(cls):
super(S3BucketsTest, cls).setUpClass()
- cls.os = clients.Manager()
cls.client = cls.os.s3_client
@attr(type='smoke')
diff --git a/tempest/thirdparty/boto/utils/s3.py b/tempest/thirdparty/boto/utils/s3.py
index 56e1191..ff5e332 100644
--- a/tempest/thirdparty/boto/utils/s3.py
+++ b/tempest/thirdparty/boto/utils/s3.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tempest/thirdparty/boto/utils/wait.py b/tempest/thirdparty/boto/utils/wait.py
index db2303a..eed0a92 100644
--- a/tempest/thirdparty/boto/utils/wait.py
+++ b/tempest/thirdparty/boto/utils/wait.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/test-requirements.txt b/test-requirements.txt
index 9486244..8d64167 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -2,7 +2,8 @@
# needed for doc build
docutils==0.9.1
sphinx>=1.1.2,<1.2
-python-subunit
-oslo.sphinx
+python-subunit>=0.0.18
+oslosphinx
mox>=0.5.3
mock>=1.0
+coverage>=3.6
diff --git a/tools/check_logs.py b/tools/check_logs.py
index 963709b..15988a6 100755
--- a/tools/check_logs.py
+++ b/tools/check_logs.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
@@ -29,7 +28,7 @@
is_neutron = os.environ.get('DEVSTACK_GATE_NEUTRON', "0") == "1"
is_grenade = (os.environ.get('DEVSTACK_GATE_GRENADE', "0") == "1" or
os.environ.get('DEVSTACK_GATE_GRENADE_FORWARD', "0") == "1")
-dump_all_errors = is_neutron
+dump_all_errors = True
def process_files(file_specs, url_specs, whitelists):
@@ -70,6 +69,7 @@
print_log_name = False
if not whitelisted:
had_errors = True
+ print("*** Not Whitelisted ***"),
print(line)
return had_errors
diff --git a/tools/colorizer.py b/tools/colorizer.py
index 76a3bd3..a3a0616 100755
--- a/tools/colorizer.py
+++ b/tools/colorizer.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2013, Nebula, Inc.
# Copyright 2010 United States Government as represented by the
diff --git a/tools/find_stack_traces.py b/tools/find_stack_traces.py
index 52a5a66..c905976 100755
--- a/tools/find_stack_traces.py
+++ b/tools/find_stack_traces.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corp.
# All Rights Reserved.
diff --git a/tools/install_venv.py b/tools/install_venv.py
index 84d0fd9..e41ca43 100644
--- a/tools/install_venv.py
+++ b/tools/install_venv.py
@@ -1,9 +1,7 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
-# flake8: noqa
+#
# Copyright 2010 OpenStack Foundation
# Copyright 2013 IBM Corp.
#
@@ -19,66 +17,55 @@
# License for the specific language governing permissions and limitations
# under the License.
-"""Installation script for Tempest's development virtualenv."""
-
import os
import sys
-import install_venv_common as install_venv
+import install_venv_common as install_venv # noqa
-class CentOS(install_venv.Fedora):
- """This covers CentOS."""
-
- def post_process(self):
- if not self.check_pkg('openssl-devel'):
- self.yum.install('openssl-devel', check_exit_code=False)
-
-
-def print_help():
- """This prints Help."""
-
+def print_help(venv, root):
help = """
- Tempest development environment setup is complete.
+ Openstack development environment setup is complete.
- Tempest development uses virtualenv to track and manage Python dependencies
- while in development and testing.
+ Openstack development uses virtualenv to track and manage Python
+ dependencies while in development and testing.
- To activate the Tempest virtualenv for the extent of your current shell
+ To activate the Openstack virtualenv for the extent of your current shell
session you can run:
- $ source .venv/bin/activate
+ $ source %s/bin/activate
Or, if you prefer, you can run commands in the virtualenv on a case by case
basis by running:
- $ tools/with_venv.sh <your command>
+ $ %s/tools/with_venv.sh <your command>
Also, make test will automatically use the virtualenv.
"""
- print(help)
+ print(help % (venv, root))
def main(argv):
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+
+ if os.environ.get('tools_path'):
+ root = os.environ['tools_path']
venv = os.path.join(root, '.venv')
+ if os.environ.get('venv'):
+ venv = os.environ['venv']
+
pip_requires = os.path.join(root, 'requirements.txt')
test_requires = os.path.join(root, 'test-requirements.txt')
py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
project = 'Tempest'
install = install_venv.InstallVenv(root, venv, pip_requires, test_requires,
py_version, project)
- if os.path.exists('/etc/redhat-release'):
- with open('/etc/redhat-release') as rh_release:
- if 'CentOS' in rh_release.read():
- install_venv.Fedora = CentOS
options = install.parse_args(argv)
install.check_python_version()
install.check_dependencies()
install.create_virtualenv(no_site_packages=options.no_site_packages)
install.install_dependencies()
- install.post_process()
- print_help()
+ print_help(venv, root)
if __name__ == '__main__':
main(sys.argv)
diff --git a/tools/skip_tracker.py b/tools/skip_tracker.py
index 0ae3323..50f33eb 100755
--- a/tools/skip_tracker.py
+++ b/tools/skip_tracker.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
diff --git a/tools/tempest_auto_config.py b/tools/tempest_auto_config.py
index fe9f5af..9aeb077 100644
--- a/tools/tempest_auto_config.py
+++ b/tools/tempest_auto_config.py
@@ -1,5 +1,3 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
diff --git a/tools/verify_tempest_config.py b/tools/verify_tempest_config.py
index 8850c2e..29eed9d 100755
--- a/tools/verify_tempest_config.py
+++ b/tools/verify_tempest_config.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corp.
#
@@ -15,20 +14,17 @@
# License for the specific language governing permissions and limitations
# under the License.
+import json
import sys
+import httplib2
+
from tempest import clients
from tempest import config
CONF = config.CONF
-
-#Dicts matching extension names to config options
-NOVA_EXTENSIONS = {
- 'disk_config': 'DiskConfig',
- 'change_password': 'ServerPassword',
- 'flavor_extra': 'FlavorExtraSpecs'
-}
+RAW_HTTP = httplib2.Http()
def verify_glance_api_versions(os):
@@ -43,33 +39,113 @@
not CONF.image_feature_enabled.api_v2))
-def verify_extensions(os):
- results = {}
- extensions_client = os.extensions_client
+def verify_nova_api_versions(os):
+ # Check nova api versions - only get base URL without PATH
+ os.servers_client.skip_path = True
+ __, body = RAW_HTTP.request(os.servers_client.base_url, 'GET')
+ body = json.loads(body)
+ # Restore full base_url
+ os.servers_client.skip_path = False
+ versions = map(lambda x: x['id'], body['versions'])
+ if CONF.compute_feature_enabled.api_v3 != ('v3.0' in versions):
+ print('Config option compute api_v3 should be change to: %s' % (
+ not CONF.compute_feature_enabled.api_v3))
+
+
+def get_extension_client(os, service):
+ extensions_client = {
+ 'nova': os.extensions_client,
+ 'nova_v3': os.extensions_v3_client,
+ 'cinder': os.volumes_extension_client,
+ 'neutron': os.network_client,
+ }
+ if service not in extensions_client:
+ print('No tempest extensions client for %s' % service)
+ exit(1)
+ return extensions_client[service]
+
+
+def get_enabled_extensions(service):
+ extensions_options = {
+ 'nova': CONF.compute_feature_enabled.api_extensions,
+ 'nova_v3': CONF.compute_feature_enabled.api_v3_extensions,
+ 'cinder': CONF.volume_feature_enabled.api_extensions,
+ 'neutron': CONF.network_feature_enabled.api_extensions,
+ }
+ if service not in extensions_options:
+ print('No supported extensions list option for %s' % service)
+ exit(1)
+ return extensions_options[service]
+
+
+def verify_extensions(os, service, results):
+ extensions_client = get_extension_client(os, service)
__, resp = extensions_client.list_extensions()
- resp = resp['extensions']
- extensions = map(lambda x: x['name'], resp)
- results['nova_features'] = {}
- for extension in NOVA_EXTENSIONS.keys():
- if NOVA_EXTENSIONS[extension] in extensions:
- results['nova_features'][extension] = True
+ if isinstance(resp, dict):
+ # Neutron's extension 'name' field has is not a single word (it has
+ # spaces in the string) Since that can't be used for list option the
+ # api_extension option in the network-feature-enabled group uses alias
+ # instead of name.
+ if service == 'neutron':
+ extensions = map(lambda x: x['alias'], resp['extensions'])
else:
- results['nova_features'][extension] = False
+ extensions = map(lambda x: x['name'], resp['extensions'])
+
+ else:
+ extensions = map(lambda x: x['name'], resp)
+ if not results.get(service):
+ results[service] = {}
+ extensions_opt = get_enabled_extensions(service)
+ if extensions_opt[0] == 'all':
+ results[service]['extensions'] = 'all'
+ return results
+ # Verify that all configured extensions are actually enabled
+ for extension in extensions_opt:
+ results[service][extension] = extension in extensions
+ # Verify that there aren't additional extensions enabled that aren't
+ # specified in the config list
+ for extension in extensions:
+ if extension not in extensions_opt:
+ results[service][extension] = False
return results
def display_results(results):
- for option in NOVA_EXTENSIONS.keys():
- config_value = getattr(CONF.compute_feature_enabled, option)
- if config_value != results['nova_features'][option]:
- print("Config option: %s should be changed to: %s" % (
- option, not config_value))
+ for service in results:
+ # If all extensions are specified as being enabled there is no way to
+ # verify this so we just assume this to be true
+ if results[service].get('extensions'):
+ continue
+ extension_list = get_enabled_extensions(service)
+ for extension in results[service]:
+ if not results[service][extension]:
+ if extension in extension_list:
+ print("%s extension: %s should not be included in the list"
+ " of enabled extensions" % (service, extension))
+ else:
+ print("%s extension: %s should be included in the list of "
+ "enabled extensions" % (service, extension))
+
+
+def check_service_availability(service):
+ if service == 'nova_v3':
+ service = 'nova'
+ return getattr(CONF.service_available, service)
def main(argv):
+ print('Running config verification...')
os = clients.ComputeAdminManager(interface='json')
- results = verify_extensions(os)
+ results = {}
+ for service in ['nova', 'nova_v3', 'cinder', 'neutron']:
+ # TODO(mtreinish) make this a keystone endpoint check for available
+ # services
+ if not check_service_availability(service):
+ print("%s is not available" % service)
+ continue
+ results = verify_extensions(os, service, results)
verify_glance_api_versions(os)
+ verify_nova_api_versions(os)
display_results(results)
diff --git a/tox.ini b/tox.ini
index 6d596e3..1580b14 100644
--- a/tox.ini
+++ b/tox.ini
@@ -6,9 +6,6 @@
[testenv]
sitepackages = True
setenv = VIRTUAL_ENV={envdir}
- LANG=en_US.UTF-8
- LANGUAGE=en_US:en
- LC_ALL=C
OS_TEST_PATH=./tempest/test_discover
usedevelop = True
install_command = pip install {opts} {packages}
@@ -25,6 +22,10 @@
setenv = OS_TEST_PATH=./tempest/tests
commands = python setup.py test --slowest --testr-arg='tempest\.tests {posargs}'
+[testenv:cover]
+setenv = OS_TEST_PATH=./tempest/tests
+commands = python setup.py testr --coverage --testr-arg='tempest\.tests {posargs}'
+
[testenv:all]
setenv = VIRTUAL_ENV={envdir}
commands =
@@ -36,6 +37,12 @@
commands =
bash tools/pretty_tox.sh '(?!.*\[.*\bslow\b.*\])(^tempest\.(api|scenario|thirdparty|cli)) {posargs}'
+[testenv:full-serial]
+# The regex below is used to select which tests to run and exclude the slow tag:
+# See the testrepostiory bug: https://bugs.launchpad.net/testrepository/+bug/1208610
+commands =
+ bash tools/pretty_tox_serial.sh '(?!.*\[.*\bslow\b.*\])(^tempest\.(api|scenario|thirdparty|cli)) {posargs}'
+
[testenv:testr-full]
commands =
bash tools/pretty_tox.sh '(?!.*\[.*\bslow\b.*\])(^tempest\.(api|scenario|thirdparty|cli)) {posargs}'