Merge "network: add metering api operations"
diff --git a/README.rst b/README.rst
index bff2bf8..9daf873 100644
--- a/README.rst
+++ b/README.rst
@@ -118,3 +118,15 @@
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
index d1c1077..c16075c 100644
--- a/etc/schemas/compute/flavors/flavor_details.json
+++ b/etc/schemas/compute/flavors/flavor_details.json
@@ -2,5 +2,7 @@
"name": "get-flavor-details",
"http-method": "GET",
"url": "flavors/%s",
- "resources": ["flavor"]
+ "resources": [
+ {"name": "flavor", "expected_result": 404}
+ ]
}
diff --git a/etc/schemas/compute/servers/get_console_output.json b/etc/schemas/compute/servers/get_console_output.json
index 7c3860f..8d974ba 100644
--- a/etc/schemas/compute/servers/get_console_output.json
+++ b/etc/schemas/compute/servers/get_console_output.json
@@ -2,7 +2,9 @@
"name": "get-console-output",
"http-method": "POST",
"url": "servers/%s/action",
- "resources": ["server"],
+ "resources": [
+ {"name":"server", "expected_result": 404}
+ ],
"json-schema": {
"type": "object",
"properties": {
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 990cb37..2443399 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -398,8 +398,7 @@
#uri_v3=<None>
# Identity API version to be used for authentication for API
-# tests. Planned to extend to tenant isolation, scenario tests
-# and CLI tests. (string value)
+# tests. (string value)
#auth_version=v2
# The identity region name to use. Also used as the other
@@ -826,4 +825,7 @@
# Is the v1 volume API enabled (boolean value)
#api_v1=true
+# Is the v2 volume API enabled (boolean value)
+#api_v2=true
+
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index fd069e7..e6ddf1c 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -296,11 +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
cls.volumes_client = cls.os.volumes_client
cls.certificates_client = cls.os.certificates_v3_client
cls.keypairs_client = cls.os.keypairs_v3_client
@@ -372,13 +369,10 @@
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
cls.hypervisor_admin_client = cls.os_adm.hypervisor_v3_client
- cls.tenant_usages_admin_client = cls.os_adm.tenant_usages_v3_client
cls.flavors_admin_client = cls.os_adm.flavors_v3_client
cls.aggregates_admin_client = cls.os_adm.aggregates_v3_client
cls.hosts_admin_client = cls.os_adm.hosts_v3_client
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
deleted file mode 100644
index a86b7f5..0000000
--- a/tempest/api/compute/v3/admin/test_instance_usage_audit_log.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# 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.
-
-import datetime
-import urllib
-
-from tempest.api.compute import base
-from tempest import test
-
-
-class InstanceUsageAuditLogV3Test(base.BaseV3ComputeAdminTest):
-
- _interface = 'json'
-
- @classmethod
- def setUpClass(cls):
- super(InstanceUsageAuditLogV3Test, cls).setUpClass()
- cls.adm_client = cls.instance_usages_audit_log_admin_client
-
- @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()
- self.assertEqual(200, resp.status)
- expected_items = ['total_errors', 'total_instances', 'log',
- 'num_hosts_running', 'num_hosts_done',
- 'num_hosts', 'hosts_not_run', 'overall_status',
- 'period_ending', 'period_beginning',
- 'num_hosts_not_run']
- for item in expected_items:
- self.assertIn(item, body)
-
- @test.attr(type='gate')
- def test_list_instance_usage_audit_logs_with_filter_before(self):
- # Get instance usage audit log before specified time
- 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',
- 'num_hosts_running', 'num_hosts_done', 'num_hosts',
- 'hosts_not_run', 'overall_status', 'period_ending',
- 'period_beginning', 'num_hosts_not_run']
- for item in expected_items:
- self.assertIn(item, body)
- 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
deleted file mode 100644
index 0438825..0000000
--- a/tempest/api/compute/v3/admin/test_instance_usage_audit_log_negative.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# 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 tempest.api.compute import base
-from tempest import exceptions
-from tempest import test
-
-
-class InstanceUsageLogNegativeV3Test(base.BaseV3ComputeAdminTest):
-
- _interface = 'json'
-
- @classmethod
- def setUpClass(cls):
- super(InstanceUsageLogNegativeV3Test, cls).setUpClass()
- cls.adm_client = cls.instance_usages_audit_log_admin_client
-
- @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)
-
- @test.attr(type=['negative', 'gate'])
- def test_get_instance_usage_audit_logs_with_invalid_time(self):
- self.assertRaises(exceptions.BadRequest,
- self.adm_client.list_instance_usage_audit_logs,
- "invalid_time")
diff --git a/tempest/api/compute/v3/admin/test_simple_tenant_usage.py b/tempest/api/compute/v3/admin/test_simple_tenant_usage.py
deleted file mode 100644
index e16332f..0000000
--- a/tempest/api/compute/v3/admin/test_simple_tenant_usage.py
+++ /dev/null
@@ -1,85 +0,0 @@
-# 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 datetime
-
-from tempest.api.compute import base
-from tempest import test
-from tempest.test import attr
-import time
-
-
-class TenantUsagesV3Test(base.BaseV3ComputeAdminTest):
-
- _interface = 'json'
-
- @classmethod
- def setUpClass(cls):
- 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()
-
- resp, tenants = cls.identity_client.list_tenants()
- cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
- cls.client.tenant_name][0]
-
- # Create a server in the demo tenant
- resp, server = cls.create_test_server(wait_until='ACTIVE')
- time.sleep(2)
-
- now = datetime.datetime.now()
- cls.start = cls._parse_strtime(now - datetime.timedelta(days=1))
- cls.end = cls._parse_strtime(now + datetime.timedelta(days=1))
-
- @classmethod
- def _parse_strtime(cls, at):
- # 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
- params = {'start': self.start,
- 'end': self.end,
- 'detailed': int(bool(True))}
- resp, tenant_usage = self.adm_client.list_tenant_usages(params)
- 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
- params = {'start': self.start,
- 'end': self.end}
- resp, tenant_usage = self.adm_client.get_tenant_usage(
- self.tenant_id, params)
-
- 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
- params = {'start': self.start,
- 'end': self.end}
- resp, tenant_usage = self.client.get_tenant_usage(
- self.tenant_id, params)
-
- self.assertEqual(200, resp.status)
- self.assertEqual(len(tenant_usage), 8)
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
deleted file mode 100644
index 17849c5..0000000
--- a/tempest/api/compute/v3/admin/test_simple_tenant_usage_negative.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# 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 datetime
-
-from tempest.api.compute import base
-from tempest import exceptions
-from tempest import test
-from tempest.test import attr
-
-
-class TenantUsagesNegativeV3Test(base.BaseV3ComputeAdminTest):
-
- _interface = 'json'
-
- @classmethod
- def setUpClass(cls):
- 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()
- now = datetime.datetime.now()
- cls.start = cls._parse_strtime(now - datetime.timedelta(days=1))
- cls.end = cls._parse_strtime(now + datetime.timedelta(days=1))
-
- @classmethod
- def _parse_strtime(cls, at):
- # Returns formatted datetime
- return at.strftime('%Y-%m-%dT%H:%M:%S.%f')
-
- @attr(type=['negative', 'gate'])
- def test_get_usage_tenant_with_empty_tenant_id(self):
- # Get usage for a specific tenant empty
- params = {'start': self.start,
- 'end': self.end}
- self.assertRaises(exceptions.NotFound,
- 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
- params = {'start': self.end,
- 'end': self.start}
- resp, tenants = self.identity_client.list_tenants()
- tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
- self.client.tenant_name][0]
- self.assertRaises(exceptions.BadRequest,
- 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
- params = {'start': self.start,
- 'end': self.end,
- 'detailed': int(bool(True))}
- self.assertRaises(exceptions.Unauthorized,
- self.client.list_tenant_usages, params)
diff --git a/tempest/api/compute/v3/images/test_image_metadata.py b/tempest/api/compute/v3/images/test_image_metadata.py
deleted file mode 100644
index cd4e5e7..0000000
--- a/tempest/api/compute/v3/images/test_image_metadata.py
+++ /dev/null
@@ -1,111 +0,0 @@
-# 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
deleted file mode 100644
index e76af2c..0000000
--- a/tempest/api/compute/v3/images/test_image_metadata_negative.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# 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_oneserver.py b/tempest/api/compute/v3/images/test_images_oneserver.py
index 18772df..cd40948 100644
--- a/tempest/api/compute/v3/images/test_images_oneserver.py
+++ b/tempest/api/compute/v3/images/test_images_oneserver.py
@@ -20,13 +20,13 @@
from tempest.common.utils import data_utils
from tempest import config
from tempest.openstack.common import log as logging
-from tempest.test import attr
+from tempest import test
CONF = config.CONF
LOG = logging.getLogger(__name__)
-class ImagesOneServerTest(base.BaseV2ComputeTest):
+class ImagesOneServerV3Test(base.BaseV3ComputeTest):
_interface = 'json'
def tearDown(self):
@@ -34,12 +34,12 @@
for image_id in self.image_ids:
self.client.delete_image(image_id)
self.image_ids.remove(image_id)
- super(ImagesOneServerTest, self).tearDown()
+ super(ImagesOneServerV3Test, 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()
+ super(ImagesOneServerV3Test, self).setUp()
# Check if the server is in a clean state after test
try:
self.servers_client.wait_for_server_status(self.server_id,
@@ -53,7 +53,7 @@
@classmethod
def setUpClass(cls):
- super(ImagesOneServerTest, cls).setUpClass()
+ super(ImagesOneServerV3Test, cls).setUpClass()
cls.client = cls.images_client
if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
@@ -86,13 +86,14 @@
@testtools.skipUnless(CONF.compute_feature_enabled.create_image,
'Environment unable to create images.')
- @attr(type='smoke')
+ @test.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)
+ resp, body = self.servers_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')
@@ -117,12 +118,13 @@
self.assertEqual('204', resp['status'])
self.client.wait_for_resource_deletion(image_id)
- @attr(type=['gate'])
+ @test.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)
+ resp, body = self.servers_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
index bc276d1..f2f2375 100644
--- a/tempest/api/compute/v3/images/test_images_oneserver_negative.py
+++ b/tempest/api/compute/v3/images/test_images_oneserver_negative.py
@@ -20,15 +20,14 @@
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
+from tempest import test
CONF = config.CONF
LOG = logging.getLogger(__name__)
-class ImagesOneServerNegativeTest(base.BaseV2ComputeTest):
+class ImagesOneServerNegativeV3Test(base.BaseV3ComputeTest):
_interface = 'json'
def tearDown(self):
@@ -36,12 +35,12 @@
for image_id in self.image_ids:
self.client.delete_image(image_id)
self.image_ids.remove(image_id)
- super(ImagesOneServerNegativeTest, self).tearDown()
+ super(ImagesOneServerNegativeV3Test, 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()
+ super(ImagesOneServerNegativeV3Test, self).setUp()
# Check if the server is in a clean state after test
try:
self.servers_client.wait_for_server_status(self.server_id,
@@ -58,7 +57,7 @@
@classmethod
def setUpClass(cls):
- super(ImagesOneServerNegativeTest, cls).setUpClass()
+ super(ImagesOneServerNegativeV3Test, cls).setUpClass()
cls.client = cls.images_client
if not CONF.service_available.glance:
skip_msg = ("%s skipped as glance is not available" % cls.__name__)
@@ -85,41 +84,44 @@
cls.alt_manager = clients.AltManager()
cls.alt_client = cls.alt_manager.images_client
- @skip_because(bug="1006725")
- @attr(type=['negative', 'gate'])
+ @test.skip_because(bug="1006725")
+ @test.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,
+ self.servers_client.create_image,
+ self.server_id,
invalid_name)
- @attr(type=['negative', 'gate'])
+ @test.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.assertRaises(exceptions.BadRequest,
+ self.servers_client.create_image,
self.server_id, snapshot_name, meta)
- @attr(type=['negative', 'gate'])
+ @test.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.assertRaises(exceptions.BadRequest,
+ self.servers_client.create_image,
self.server_id, snapshot_name, meta)
- @attr(type=['negative', 'gate'])
+ @test.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)
+ resp, body = self.servers_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)
@@ -127,23 +129,26 @@
# Create second snapshot
alt_snapshot_name = data_utils.rand_name('test-snap-')
- self.assertRaises(exceptions.Conflict, self.client.create_image,
+ self.assertRaises(exceptions.Conflict,
+ self.servers_client.create_image,
self.server_id, alt_snapshot_name)
- @attr(type=['negative', 'gate'])
+ @test.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.assertRaises(exceptions.BadRequest,
+ self.servers_client.create_image,
self.server_id, snapshot_name)
- @attr(type=['negative', 'gate'])
+ @test.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)
+ resp, body = self.servers_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)
@@ -151,7 +156,7 @@
# 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.assertEqual('200', 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
deleted file mode 100644
index 457ca53..0000000
--- a/tempest/api/compute/v3/images/test_list_image_filters.py
+++ /dev/null
@@ -1,225 +0,0 @@
-# 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/data_processing/base.py b/tempest/api/data_processing/base.py
index ab882cd..5b272ef 100644
--- a/tempest/api/data_processing/base.py
+++ b/tempest/api/data_processing/base.py
@@ -63,7 +63,7 @@
except Exception:
# ignore errors while auto removing created resource
pass
-
+ cls.clear_isolated_creds()
super(BaseDataProcessingTest, cls).tearDownClass()
@classmethod
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/admin/test_users_negative.py b/tempest/api/identity/admin/test_users_negative.py
index e9e7818..060f24a 100644
--- a/tempest/api/identity/admin/test_users_negative.py
+++ b/tempest/api/identity/admin/test_users_negative.py
@@ -207,7 +207,7 @@
@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.auth_provider.auth_data[0]
+ token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(exceptions.Unauthorized, self.client.get_users)
self.client.auth_provider.clear_auth()
diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py
index 37b848c..e439238 100644
--- a/tempest/api/image/base.py
+++ b/tempest/api/image/base.py
@@ -106,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
@@ -147,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_images.py b/tempest/api/image/v1/test_images.py
index 8c62c05..517123d 100644
--- a/tempest/api/image/v1/test_images.py
+++ b/tempest/api/image/v1/test_images.py
@@ -16,8 +16,9 @@
import cStringIO as StringIO
from tempest.api.image import base
+from tempest.common.utils import data_utils
from tempest import config
-from tempest.test import attr
+from tempest import test
CONF = config.CONF
@@ -25,7 +26,7 @@
class CreateRegisterImagesTest(base.BaseV1ImageTest):
"""Here we test the registration and creation of images."""
- @attr(type='gate')
+ @test.attr(type='gate')
def test_register_then_upload(self):
# Register, then upload an image
properties = {'prop1': 'val1'}
@@ -48,7 +49,7 @@
self.assertIn('size', body)
self.assertEqual(1024, body.get('size'))
- @attr(type='gate')
+ @test.attr(type='gate')
def test_register_remote_image(self):
# Register a new remote image
resp, body = self.create_image(name='New Remote Image',
@@ -66,12 +67,12 @@
self.assertEqual(properties['key1'], 'value1')
self.assertEqual(properties['key2'], 'value2')
- @attr(type='gate')
+ @test.attr(type='gate')
def test_register_http_image(self):
resp, body = self.create_image(name='New Http Image',
container_format='bare',
disk_format='raw', is_public=True,
- copy_from=CONF.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'))
@@ -80,7 +81,7 @@
resp, body = self.client.get_image(image_id)
self.assertEqual(resp['status'], '200')
- @attr(type='gate')
+ @test.attr(type='gate')
def test_register_image_with_min_ram(self):
# Register an image with min ram
properties = {'prop1': 'val1'}
@@ -110,7 +111,6 @@
@classmethod
def setUpClass(cls):
super(ListImagesTest, cls).setUpClass()
-
# We add a few images here to test the listing functionality of
# the images API
img1 = cls._create_remote_image('one', 'bare', 'raw')
@@ -131,7 +131,7 @@
# 1x with size 42
cls.size42_set = set((img5,))
# 3x with size 142
- cls.size142_set = set((img6, img7, img8))
+ cls.size142_set = set((img6, img7, img8,))
# dup named
cls.dup_set = set((img3, img4))
@@ -168,7 +168,7 @@
image_id = image['id']
return image_id
- @attr(type='gate')
+ @test.attr(type='gate')
def test_index_no_params(self):
# Simple test to see all fixture images returned
resp, images_list = self.client.image_list()
@@ -177,7 +177,7 @@
for image_id in self.created_images:
self.assertIn(image_id, image_list)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_index_disk_format(self):
resp, images_list = self.client.image_list(disk_format='ami')
self.assertEqual(resp['status'], '200')
@@ -187,7 +187,7 @@
self.assertTrue(self.ami_set <= result_set)
self.assertFalse(self.created_set - self.ami_set <= result_set)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_index_container_format(self):
resp, images_list = self.client.image_list(container_format='bare')
self.assertEqual(resp['status'], '200')
@@ -197,7 +197,7 @@
self.assertTrue(self.bare_set <= result_set)
self.assertFalse(self.created_set - self.bare_set <= result_set)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_index_max_size(self):
resp, images_list = self.client.image_list(size_max=42)
self.assertEqual(resp['status'], '200')
@@ -207,7 +207,7 @@
self.assertTrue(self.size42_set <= result_set)
self.assertFalse(self.created_set - self.size42_set <= result_set)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_index_min_size(self):
resp, images_list = self.client.image_list(size_min=142)
self.assertEqual(resp['status'], '200')
@@ -217,7 +217,7 @@
self.assertTrue(self.size142_set <= result_set)
self.assertFalse(self.size42_set <= result_set)
- @attr(type='gate')
+ @test.attr(type='gate')
def test_index_status_active_detail(self):
resp, images_list = self.client.image_list_detail(status='active',
sort_key='size',
@@ -230,7 +230,7 @@
top_size = size
self.assertEqual(image['status'], 'active')
- @attr(type='gate')
+ @test.attr(type='gate')
def test_index_name(self):
resp, images_list = self.client.image_list_detail(
name='New Remote Image dup')
@@ -240,3 +240,139 @@
self.assertEqual(image['name'], 'New Remote Image dup')
self.assertTrue(self.dup_set <= result_set)
self.assertFalse(self.created_set - self.dup_set <= result_set)
+
+
+class ListSnapshotImagesTest(base.BaseV1ImageTest):
+ @classmethod
+ def setUpClass(cls):
+ super(ListSnapshotImagesTest, cls).setUpClass()
+ if not CONF.compute_feature_enabled.api_v3:
+ cls.servers_client = cls.os.servers_client
+ else:
+ cls.servers_client = cls.os.servers_v3_client
+ cls.servers = []
+ # We add a few images here to test the listing functionality of
+ # the images API
+ cls.snapshot = cls._create_snapshot(
+ 'snapshot', CONF.compute.image_ref,
+ CONF.compute.flavor_ref)
+ cls.snapshot_set = set((cls.snapshot,))
+
+ image_file = StringIO.StringIO('*' * 42)
+ resp, image = cls.create_image(name="Standard Image",
+ container_format='ami',
+ disk_format='ami',
+ is_public=True, data=image_file)
+ cls.image_id = image['id']
+ cls.client.wait_for_image_status(image['id'], 'active')
+
+ @classmethod
+ def tearDownClass(cls):
+ for server in cls.servers:
+ cls.servers_client.delete_server(server['id'])
+ super(ListSnapshotImagesTest, cls).tearDownClass()
+
+ @classmethod
+ def _create_snapshot(cls, name, image_id, flavor, **kwargs):
+ resp, server = cls.servers_client.create_server(
+ name, image_id, flavor, **kwargs)
+ cls.servers.append(server)
+ cls.servers_client.wait_for_server_status(
+ server['id'], 'ACTIVE')
+ resp, image = cls.servers_client.create_image(
+ server['id'], name)
+ image_id = data_utils.parse_image_id(resp['location'])
+ cls.created_images.append(image_id)
+ cls.client.wait_for_image_status(image_id,
+ 'active')
+ return image_id
+
+ @test.attr(type='gate')
+ def test_index_server_id(self):
+ # The images should contain images filtered by server id
+ resp, images = self.client.image_list_detail(
+ {'instance_uuid': self.servers[0]['id']})
+ self.assertEqual(200, resp.status)
+ result_set = set(map(lambda x: x['id'], images))
+ self.assertEqual(self.snapshot_set, result_set)
+
+ @test.attr(type='gate')
+ def test_index_type(self):
+ # The list of servers should be filtered by image type
+ params = {'image_type': 'snapshot'}
+ resp, images = self.client.image_list_detail(params)
+
+ self.assertEqual(200, resp.status)
+ result_set = set(map(lambda x: x['id'], images))
+ self.assertIn(self.snapshot, result_set)
+
+ @test.attr(type='gate')
+ def test_index_limit(self):
+ # Verify only the expected number of results are returned
+ resp, images = self.client.image_list_detail(limit=1)
+
+ self.assertEqual(200, resp.status)
+ self.assertEqual(1, len(images))
+
+ @test.attr(type='gate')
+ def test_index_by_change_since(self):
+ # Verify an update image is returned
+ # Becoming ACTIVE will modify the updated time
+ # Filter by the image's created time
+ resp, image = self.client.get_image_meta(self.snapshot)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(self.snapshot, image['id'])
+ resp, images = self.client.image_list_detail(
+ changes_since=image['updated_at'])
+
+ self.assertEqual(200, resp.status)
+ result_set = set(map(lambda x: x['id'], images))
+ self.assertIn(self.image_id, result_set)
+ self.assertNotIn(self.snapshot, result_set)
+
+
+class UpdateImageMetaTest(base.BaseV1ImageTest):
+ @classmethod
+ def setUpClass(cls):
+ super(UpdateImageMetaTest, cls).setUpClass()
+ cls.image_id = cls._create_standard_image('1', 'ami', 'ami', 42)
+
+ @classmethod
+ def _create_standard_image(cls, name, container_format,
+ disk_format, size):
+ """
+ Create a new standard image and return the ID of the newly-registered
+ image. Note that the size of the new image is a random number between
+ 1024 and 4096
+ """
+ image_file = StringIO.StringIO('*' * size)
+ name = 'New Standard Image %s' % name
+ resp, image = cls.create_image(name=name,
+ container_format=container_format,
+ disk_format=disk_format,
+ is_public=True, data=image_file,
+ properties={'key1': 'value1'})
+ image_id = image['id']
+ return image_id
+
+ @test.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.get_image_meta(self.image_id)
+ expected = {'key1': 'value1'}
+ self.assertEqual(expected, resp_metadata['properties'])
+
+ @test.attr(type='gate')
+ def test_update_image_metadata(self):
+ # The metadata for the image should match the updated values
+ req_metadata = {'key1': 'alt1', 'key2': 'value2'}
+ resp, metadata = self.client.get_image_meta(self.image_id)
+ self.assertEqual(200, resp.status)
+ self.assertEqual(metadata['properties'], {'key1': 'value1'})
+ metadata['properties'].update(req_metadata)
+ resp, metadata = self.client.update_image(
+ self.image_id, properties=metadata['properties'])
+
+ resp, resp_metadata = self.client.get_image_meta(self.image_id)
+ expected = {'key1': 'alt1', 'key2': 'value2'}
+ self.assertEqual(expected, resp_metadata['properties'])
diff --git a/tempest/api/network/admin/test_agent_management.py b/tempest/api/network/admin/test_agent_management.py
index b05f275..342bc6a 100644
--- a/tempest/api/network/admin/test_agent_management.py
+++ b/tempest/api/network/admin/test_agent_management.py
@@ -14,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):
@@ -23,11 +23,14 @@
@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'])
@@ -38,20 +41,20 @@
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)
- @attr(type='smoke')
+ @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
@@ -63,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 13309cd..ecd992a 100644
--- a/tempest/api/network/admin/test_dhcp_agent_scheduler.py
+++ b/tempest/api/network/admin/test_dhcp_agent_scheduler.py
@@ -13,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):
@@ -22,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()
@@ -29,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'])
@@ -55,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 bfb7b48..7c02787 100644
--- a/tempest/api/network/admin/test_l3_agent_scheduler.py
+++ b/tempest/api/network/admin/test_l3_agent_scheduler.py
@@ -17,7 +17,7 @@
from tempest import test
-class L3AgentSchedulerJSON(base.BaseAdminNetworkTest):
+class L3AgentSchedulerTestJSON(base.BaseAdminNetworkTest):
_interface = 'json'
"""
@@ -33,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)
@@ -61,5 +61,5 @@
self.assertEqual(204, resp.status)
-class L3AgentSchedulerXML(L3AgentSchedulerJSON):
+class L3AgentSchedulerTestXML(L3AgentSchedulerTestJSON):
_interface = 'xml'
diff --git a/tempest/api/network/test_extensions.py b/tempest/api/network/test_extensions.py
index a177d65..529f8e9 100644
--- a/tempest/api/network/test_extensions.py
+++ b/tempest/api/network/test_extensions.py
@@ -44,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 69367ab..b31c090 100644
--- a/tempest/api/network/test_floating_ips.py
+++ b/tempest/api/network/test_floating_ips.py
@@ -16,7 +16,7 @@
from tempest.api.network import base
from tempest.common.utils import data_utils
from tempest import config
-from tempest.test import attr
+from tempest import test
CONF = config.CONF
@@ -46,6 +46,9 @@
@classmethod
def setUpClass(cls):
super(FloatingIPTestJSON, cls).setUpClass()
+ 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
@@ -59,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(
@@ -110,7 +113,7 @@
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)
@@ -133,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 65eebf2..d5f2b5b 100644
--- a/tempest/api/network/test_load_balancer.py
+++ b/tempest/api/network/test_load_balancer.py
@@ -18,7 +18,7 @@
from tempest import test
-class LoadBalancerJSON(base.BaseNetworkTest):
+class LoadBalancerTestJSON(base.BaseNetworkTest):
_interface = 'json'
"""
@@ -39,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)
@@ -210,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 3aa765c..e12dedd 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -118,6 +118,18 @@
self.assertEqual(self.name, network['name'])
@attr(type='smoke')
+ def test_show_network_fields(self):
+ # Verifies showing some fields of a network works
+ field_list = [('fields', 'id'), ('fields', 'name'), ]
+ resp, body = self.client.show_network(self.network['id'],
+ field_list=field_list)
+ self.assertEqual('200', resp['status'])
+ network = body['network']
+ self.assertEqual(len(network), 2)
+ self.assertEqual(self.network['id'], network['id'])
+ self.assertEqual(self.name, network['name'])
+
+ @attr(type='smoke')
def test_list_networks(self):
# Verify the network exists in the list of all networks
resp, body = self.client.list_networks()
@@ -155,6 +167,18 @@
self.assertEqual(self.cidr, subnet['cidr'])
@attr(type='smoke')
+ def test_show_subnet_fields(self):
+ # Verifies showing some fields of a subnet works
+ field_list = [('fields', 'id'), ('fields', 'cidr'), ]
+ resp, body = self.client.show_subnet(self.subnet['id'],
+ field_list=field_list)
+ self.assertEqual('200', resp['status'])
+ subnet = body['subnet']
+ self.assertEqual(len(subnet), 2)
+ self.assertEqual(self.subnet['id'], subnet['id'])
+ self.assertEqual(self.cidr, subnet['cidr'])
+
+ @attr(type='smoke')
def test_list_subnets(self):
# Verify the subnet exists in the list of all subnets
resp, body = self.client.list_subnets()
@@ -189,12 +213,17 @@
network_id=self.network['id'])
self.assertEqual('201', resp['status'])
port = body['port']
+ self.assertTrue(port['admin_state_up'])
# Verification of port update
new_port = "New_Port"
- resp, body = self.client.update_port(port['id'], name=new_port)
+ resp, body = self.client.update_port(
+ port['id'],
+ name=new_port,
+ admin_state_up=False)
self.assertEqual('200', resp['status'])
updated_port = body['port']
self.assertEqual(updated_port['name'], new_port)
+ self.assertFalse(updated_port['admin_state_up'])
# Verification of port delete
resp, body = self.client.delete_port(port['id'])
self.assertEqual('204', resp['status'])
@@ -208,6 +237,17 @@
self.assertEqual(self.port['id'], port['id'])
@attr(type='smoke')
+ def test_show_port_fields(self):
+ # Verifies showing fields of a port works
+ field_list = [('fields', 'id'), ]
+ resp, body = self.client.show_port(self.port['id'],
+ field_list=field_list)
+ self.assertEqual('200', resp['status'])
+ port = body['port']
+ self.assertEqual(len(port), 1)
+ self.assertEqual(self.port['id'], port['id'])
+
+ @attr(type='smoke')
def test_list_ports(self):
# Verify the port exists in the list of all ports
resp, body = self.client.list_ports()
@@ -239,7 +279,7 @@
_interface = 'xml'
-class BulkNetworkOpsJSON(base.BaseNetworkTest):
+class BulkNetworkOpsTestJSON(base.BaseNetworkTest):
_interface = 'json'
"""
@@ -263,7 +303,7 @@
@classmethod
def setUpClass(cls):
- super(BulkNetworkOpsJSON, cls).setUpClass()
+ super(BulkNetworkOpsTestJSON, cls).setUpClass()
cls.network1 = cls.create_network()
cls.network2 = cls.create_network()
@@ -390,5 +430,5 @@
self.assertIn(n['id'], ports_list)
-class BulkNetworkOpsXML(BulkNetworkOpsJSON):
+class BulkNetworkOpsTestXML(BulkNetworkOpsTestJSON):
_interface = 'xml'
diff --git a/tempest/api/network/test_quotas.py b/tempest/api/network/test_quotas.py
index a5be395..38784d8 100644
--- a/tempest/api/network/test_quotas.py
+++ b/tempest/api/network/test_quotas.py
@@ -17,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):
@@ -46,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 f3fac93..d552c70 100644
--- a/tempest/api/network/test_routers.py
+++ b/tempest/api/network/test_routers.py
@@ -29,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):
diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py
index 0d65b64..e6ad4de 100644
--- a/tempest/api/network/test_routers_negative.py
+++ b/tempest/api/network/test_routers_negative.py
@@ -16,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):
@@ -25,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,
@@ -37,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,
@@ -46,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 b95182d..6eebf5b 100644
--- a/tempest/api/network/test_security_groups.py
+++ b/tempest/api/network/test_security_groups.py
@@ -14,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()
@@ -33,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()
@@ -51,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()
@@ -80,7 +87,7 @@
for rule in rule_list_body['security_group_rules']]
self.assertIn(rule_create_body['security_group_rule']['id'], rule_list)
- @attr(type='smoke')
+ @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,
diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py
index 98e109e..e1f4055 100644
--- a/tempest/api/network/test_security_groups_negative.py
+++ b/tempest/api/network/test_security_groups_negative.py
@@ -17,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,
@@ -44,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()
@@ -55,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()
@@ -73,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'
@@ -81,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/telemetry/base.py b/tempest/api/telemetry/base.py
index 1f661a6..c4614c6 100644
--- a/tempest/api/telemetry/base.py
+++ b/tempest/api/telemetry/base.py
@@ -10,7 +10,9 @@
# 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
@@ -22,6 +24,28 @@
@classmethod
def setUpClass(cls):
- super(BaseTelemetryTest, cls).setUpClass()
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/volume/admin/test_multi_backend.py b/tempest/api/volume/admin/test_multi_backend.py
index cb1a6cb..b0c878b 100644
--- a/tempest/api/volume/admin/test_multi_backend.py
+++ b/tempest/api/volume/admin/test_multi_backend.py
@@ -14,8 +14,6 @@
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
@@ -36,20 +34,7 @@
cls.backend1_name = CONF.volume.backend1_name
cls.backend2_name = CONF.volume.backend2_name
- adm_user = CONF.identity.admin_username
- adm_pass = CONF.identity.admin_password
- adm_tenant = CONF.identity.admin_tenant_name
- auth_url = CONF.identity.uri
-
- cls.volume_client = volumes_client.VolumesClientJSON(adm_user,
- adm_pass,
- auth_url,
- adm_tenant)
- cls.type_client = volume_types_client.VolumeTypesClientJSON(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:
@@ -57,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'])
@@ -72,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'])
@@ -97,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/base.py b/tempest/api/volume/base.py
index de2b240..6b6f638 100644
--- a/tempest/api/volume/base.py
+++ b/tempest/api/volume/base.py
@@ -69,18 +69,6 @@
# only in a single location in the source, and could be more general.
@classmethod
- def create_volume(cls, size=1, **kwargs):
- """Wrapper utility that returns a test volume."""
- vol_name = data_utils.rand_name('Volume')
- resp, volume = cls.volumes_client.create_volume(size,
- display_name=vol_name,
- **kwargs)
- assert 200 == resp.status
- cls.volumes.append(volume)
- cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
- return volume
-
- @classmethod
def clear_volumes(cls):
for volume in cls.volumes:
try:
@@ -120,6 +108,18 @@
cls.volumes_client = cls.os.volumes_client
cls.volumes_extension_client = cls.os.volumes_extension_client
+ @classmethod
+ def create_volume(cls, size=1, **kwargs):
+ """Wrapper utility that returns a test volume."""
+ vol_name = data_utils.rand_name('Volume')
+ resp, volume = cls.volumes_client.create_volume(size,
+ display_name=vol_name,
+ **kwargs)
+ assert 200 == resp.status
+ cls.volumes.append(volume)
+ cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
+ return volume
+
class BaseVolumeV1AdminTest(BaseVolumeV1Test):
"""Base test case class for all Volume Admin API tests."""
@@ -144,3 +144,25 @@
cls.os_adm = clients.AdminManager(interface=cls._interface)
cls.client = cls.os_adm.volume_types_client
cls.hosts_client = cls.os_adm.volume_hosts_client
+
+
+class BaseVolumeV2Test(BaseVolumeTest):
+ @classmethod
+ def setUpClass(cls):
+ if not CONF.volume_feature_enabled.api_v2:
+ msg = "Volume API v2 not supported"
+ raise cls.skipException(msg)
+ super(BaseVolumeV2Test, cls).setUpClass()
+ cls.volumes_client = cls.os.volumes_v2_client
+
+ @classmethod
+ def create_volume(cls, size=1, **kwargs):
+ """Wrapper utility that returns a test volume."""
+ vol_name = data_utils.rand_name('Volume')
+ resp, volume = cls.volumes_client.create_volume(size,
+ name=vol_name,
+ **kwargs)
+ assert 202 == resp.status
+ cls.volumes.append(volume)
+ cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
+ return volume
diff --git a/tempest/api/volume/test_volume_transfers.py b/tempest/api/volume/test_volume_transfers.py
index fc4f07d..f4b2d4c 100644
--- a/tempest/api/volume/test_volume_transfers.py
+++ b/tempest/api/volume/test_volume_transfers.py
@@ -13,6 +13,8 @@
# 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
@@ -47,7 +49,7 @@
interface=cls._interface)
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()
_, tenants = identity_client.list_tenants()
cls.alt_tenant_id = [tnt['id'] for tnt in tenants
@@ -87,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,
@@ -107,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_snapshots.py b/tempest/api/volume/test_volumes_snapshots.py
index 487ada6..56915e6 100644
--- a/tempest/api/volume/test_volumes_snapshots.py
+++ b/tempest/api/volume/test_volumes_snapshots.py
@@ -12,10 +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.test import attr
LOG = logging.getLogger(__name__)
+CONF = config.CONF
class VolumesSnapshotTest(base.BaseVolumeV1Test):
@@ -35,6 +37,11 @@
def tearDownClass(cls):
super(VolumesSnapshotTest, cls).tearDownClass()
+ def _detach(self, volume_id):
+ """Detach volume."""
+ self.volumes_client.detach_volume(volume_id)
+ self.volumes_client.wait_for_volume_status(volume_id, 'available')
+
def _list_by_param_values_and_assert(self, params, with_detail=False):
"""
Perform list or list_details action with given params
@@ -57,6 +64,32 @@
self.assertEqual(params[key], snap[key], msg)
@attr(type='gate')
+ def test_snapshot_create_with_volume_in_use(self):
+ # Create a snapshot when volume status is in-use
+ # Create a test instance
+ server_name = data_utils.rand_name('instance-')
+ resp, server = self.servers_client.create_server(server_name,
+ self.image_ref,
+ self.flavor_ref)
+ self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
+ self.addCleanup(self.servers_client.delete_server, server['id'])
+ mountpoint = '/dev/%s' % CONF.compute.volume_device_name
+ resp, body = self.volumes_client.attach_volume(
+ self.volume_origin['id'], server['id'], mountpoint)
+ self.assertEqual(202, resp.status)
+ self.volumes_client.wait_for_volume_status(self.volume_origin['id'],
+ 'in-use')
+ self.addCleanup(self._detach, self.volume_origin['id'])
+ # Snapshot a volume even if it's attached to an instance
+ snapshot = self.create_snapshot(self.volume_origin['id'],
+ force=True)
+ # Delete the snapshot
+ self.snapshots_client.delete_snapshot(snapshot['id'])
+ self.assertEqual(202, resp.status)
+ self.snapshots_client.wait_for_resource_deletion(snapshot['id'])
+ self.snapshots.remove(snapshot)
+
+ @attr(type='gate')
def test_snapshot_create_get_list_update_delete(self):
# Create a snapshot
s_name = data_utils.rand_name('snap')
diff --git a/tempest/api/volume/v2/__init__.py b/tempest/api/volume/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/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..d0e8b99
--- /dev/null
+++ b/tempest/api/volume/v2/test_volumes_list.py
@@ -0,0 +1,214 @@
+# 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', 'name')
+
+
+class VolumesV2ListTestJSON(base.BaseVolumeV2Test):
+
+ """
+ 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['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(VolumesV2ListTestJSON, 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(VolumesV2ListTestJSON, cls).tearDownClass()
+
+ def _list_by_param_value_and_assert(self, params, expected_list=None,
+ 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)
+ if expected_list is None:
+ expected_list = self.volume_list
+ self.assertVolumesIn(fetched_vol_list, expected_list,
+ fields=VOLUME_FIELDS)
+ # Validating params of fetched volumes
+ if with_detail:
+ 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 = {'name': volume['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]['name'], volume['name'])
+
+ @attr(type='gate')
+ def test_volume_list_details_by_name(self):
+ volume = self.volume_list[data_utils.rand_int_id(0, 2)]
+ params = {'name': volume['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]['name'], volume['name'])
+
+ @attr(type='gate')
+ def test_volumes_list_by_status(self):
+ params = {'status': 'available'}
+ self._list_by_param_value_and_assert(params)
+
+ @attr(type='gate')
+ def test_volumes_list_details_by_status(self):
+ params = {'status': 'available'}
+ self._list_by_param_value_and_assert(params, with_detail=True)
+
+ @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}
+ self._list_by_param_value_and_assert(params)
+
+ @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}
+ self._list_by_param_value_and_assert(params, with_detail=True)
+
+ @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 = {'name': volume['name'],
+ 'status': 'available'}
+ self._list_by_param_value_and_assert(params, expected_list=[volume])
+
+ @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 = {'name': volume['name'],
+ 'status': 'available'}
+ self._list_by_param_value_and_assert(params, expected_list=[volume],
+ with_detail=True)
+
+
+class VolumesV2ListTestXML(VolumesV2ListTestJSON):
+ _interface = 'xml'
diff --git a/tempest/auth.py b/tempest/auth.py
index 8d826cf..582cfdd 100644
--- a/tempest/auth.py
+++ b/tempest/auth.py
@@ -68,10 +68,10 @@
"""
Decorate request with authentication data
"""
- raise NotImplemented
+ raise NotImplementedError
def _get_auth(self):
- raise NotImplemented
+ raise NotImplementedError
@classmethod
def check_credentials(cls, credentials):
@@ -98,7 +98,7 @@
self.cache = None
def is_expired(self, auth_data):
- raise NotImplemented
+ raise NotImplementedError
def auth_request(self, method, url, headers=None, body=None, filters=None):
"""
@@ -110,9 +110,6 @@
:param filters: select a base URL out of the catalog
:returns a Tuple (url, headers, body)
"""
- LOG.debug("Auth request m:{m}, u:{u}, h:{h}, b:{b}, f:{f}".format(
- m=method, u=url, h=headers, b=body, f=filters
- ))
orig_req = dict(url=url, headers=headers, body=body)
auth_url, auth_headers, auth_body = self._decorate_request(
@@ -127,7 +124,6 @@
auth_data=self.alt_auth_data)
alt_auth_req = dict(url=alt_url, headers=alt_headers,
body=alt_body)
- self._log_auth_request(alt_auth_req, 'ALTERNATE')
auth_req[self.alt_part] = alt_auth_req[self.alt_part]
else:
@@ -137,21 +133,8 @@
# Next auth request will be normal, unless otherwise requested
self.reset_alt_auth_data()
- self._log_auth_request(auth_req, 'Authorized Request:')
-
return auth_req['url'], auth_req['headers'], auth_req['body']
- def _log_auth_request(self, auth_req, tag):
- url = auth_req.get('url', None)
- headers = copy.deepcopy(auth_req.get('headers', None))
- body = auth_req.get('body', None)
- if headers is not None:
- if 'X-Auth-Token' in headers.keys():
- headers['X-Auth-Token'] = '<Token Omitted>'
- LOG.debug("[{tag}]: u: {url}, h: {headers}, b: {body}".format(
- tag=tag, url=url, headers=headers, body=body
- ))
-
def reset_alt_auth_data(self):
"""
Configure auth provider to provide valid authentication data
@@ -176,7 +159,7 @@
"""
Extracts the base_url based on provided filters
"""
- raise NotImplemented
+ raise NotImplementedError
class KeystoneAuthProvider(AuthProvider):
@@ -208,10 +191,10 @@
return _url, _headers, body
def _auth_client(self):
- raise NotImplemented
+ raise NotImplementedError
def _auth_params(self):
- raise NotImplemented
+ raise NotImplementedError
def _get_auth(self):
# Bypasses the cache
@@ -223,7 +206,7 @@
token, auth_data = auth_func(**auth_params)
return token, auth_data
else:
- raise NotImplemented
+ raise NotImplementedError
def get_token(self):
return self.auth_data[0]
@@ -250,7 +233,7 @@
else:
return xml_id.TokenClientXML()
else:
- raise NotImplemented
+ raise NotImplementedError
def _auth_params(self):
if self.client_type == 'tempest':
@@ -260,7 +243,7 @@
tenant=self.credentials.get('tenant_name', None),
auth_data=True)
else:
- raise NotImplemented
+ raise NotImplementedError
def base_url(self, filters, auth_data=None):
"""
@@ -299,7 +282,7 @@
path = "/" + filters['api_version']
noversion_path = "/".join(parts.path.split("/")[2:])
if noversion_path != "":
- path += 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, "/")
@@ -334,7 +317,7 @@
else:
return xml_v3id.V3TokenClientXML()
else:
- raise NotImplemented
+ raise NotImplementedError
def _auth_params(self):
if self.client_type == 'tempest':
@@ -345,7 +328,7 @@
domain=self.credentials['domain_name'],
auth_data=True)
else:
- raise NotImplemented
+ raise NotImplementedError
def base_url(self, filters, auth_data=None):
"""
diff --git a/tempest/cli/simple_read_only/test_neutron.py b/tempest/cli/simple_read_only/test_neutron.py
index ebf0dc4..cd81378 100644
--- a/tempest/cli/simple_read_only/test_neutron.py
+++ b/tempest/cli/simple_read_only/test_neutron.py
@@ -57,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')
@@ -83,6 +86,7 @@
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)
@@ -107,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')
@@ -115,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')
diff --git a/tempest/clients.py b/tempest/clients.py
index fd46656..c262a20 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -63,8 +63,6 @@
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 \
@@ -75,8 +73,6 @@
ServersV3ClientJSON
from tempest.services.compute.v3.json.services_client import \
ServicesV3ClientJSON
-from tempest.services.compute.v3.json.tenant_usages_client import \
- TenantUsagesV3ClientJSON
from tempest.services.compute.v3.json.version_client import \
VersionV3ClientJSON
from tempest.services.compute.xml.aggregates_client import AggregatesClientXML
@@ -156,6 +152,8 @@
ExtensionsClientJSON as VolumeExtensionClientJSON
from tempest.services.volume.json.snapshots_client import SnapshotsClientJSON
from tempest.services.volume.json.volumes_client import VolumesClientJSON
+from tempest.services.volume.v2.json.volumes_client import VolumesV2ClientJSON
+from tempest.services.volume.v2.xml.volumes_client import VolumesV2ClientXML
from tempest.services.volume.xml.admin.volume_hosts_client import \
VolumeHostsClientXML
from tempest.services.volume.xml.admin.volume_types_client import \
@@ -216,6 +214,7 @@
auth_provider)
self.snapshots_client = SnapshotsClientXML(auth_provider)
self.volumes_client = VolumesClientXML(auth_provider)
+ self.volumes_v2_client = VolumesV2ClientXML(auth_provider)
self.volume_types_client = VolumeTypesClientXML(
auth_provider)
self.identity_client = IdentityClientXML(auth_provider)
@@ -280,6 +279,7 @@
auth_provider)
self.snapshots_client = SnapshotsClientJSON(auth_provider)
self.volumes_client = VolumesClientJSON(auth_provider)
+ self.volumes_v2_client = VolumesV2ClientJSON(auth_provider)
self.volume_types_client = VolumeTypesClientJSON(
auth_provider)
self.identity_client = IdentityClientJSON(auth_provider)
@@ -305,8 +305,6 @@
self.aggregates_client = AggregatesClientJSON(
auth_provider)
self.services_client = ServicesClientJSON(auth_provider)
- self.tenant_usages_v3_client = TenantUsagesV3ClientJSON(
- auth_provider)
self.tenant_usages_client = TenantUsagesClientJSON(
auth_provider)
self.version_v3_client = VersionV3ClientJSON(auth_provider)
@@ -321,8 +319,6 @@
auth_provider)
self.instance_usages_audit_log_client = \
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(
@@ -445,6 +441,6 @@
base = super(OrchestrationManager, self)
base.__init__(CONF.identity.admin_username,
CONF.identity.admin_password,
- CONF.identity.tenant_name,
+ CONF.identity.admin_tenant_name,
interface=interface,
service=service)
diff --git a/tempest/common/generate_json.py b/tempest/common/generate_json.py
index 0a0afe4..c8e86dc 100644
--- a/tempest/common/generate_json.py
+++ b/tempest/common/generate_json.py
@@ -203,36 +203,62 @@
return invalids
-type_map_valid = {"string": generate_valid_string,
- "integer": generate_valid_integer,
- "object": generate_valid_object}
+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]}
+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": {"type": "string"}},
- "results": {"type": "object",
- "properties": {}}
- },
- "required": ["name", "http-method", "url"],
- "additionalProperties": False,
- }
+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):
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index 8a85602..212d41d 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -38,7 +38,21 @@
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, auth_provider):
@@ -49,6 +63,9 @@
# 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 = CONF.compute.build_interval
@@ -65,6 +82,19 @@
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, service:%s, base_url:%s, "
@@ -74,7 +104,7 @@
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 _get_region(self, service):
"""
@@ -108,6 +138,10 @@
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,
@@ -146,7 +180,7 @@
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):
@@ -155,10 +189,10 @@
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):
@@ -214,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
@@ -244,8 +319,7 @@
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."""
# Authenticate the request with the auth provider
req_url, req_headers, req_body = self.auth_provider.auth_request(
@@ -261,12 +335,13 @@
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 headers is None:
- headers = {}
+ # 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)
@@ -386,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."""
@@ -411,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):
@@ -436,11 +519,11 @@
if method == "GET":
resp, body = self.get(url)
elif method == "POST":
- resp, body = self.post(url, body, self.headers)
+ resp, body = self.post(url, body)
elif method == "PUT":
- resp, body = self.put(url, body, self.headers)
+ resp, body = self.put(url, body)
elif method == "PATCH":
- resp, body = self.patch(url, body, self.headers)
+ resp, body = self.patch(url, body)
elif method == "HEAD":
resp, body = self.head(url)
elif method == "DELETE":
diff --git a/tempest/config.py b/tempest/config.py
index 068193b..fa051d5 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -46,8 +46,7 @@
cfg.StrOpt('auth_version',
default='v2',
help="Identity API version to be used for authentication "
- "for API tests. Planned to extend to tenant isolation, "
- "scenario tests and CLI tests."),
+ "for API tests."),
cfg.StrOpt('region',
default='RegionOne',
help="The identity region name to use. Also used as the other "
@@ -393,6 +392,9 @@
cfg.BoolOpt('api_v1',
default=True,
help="Is the v1 volume API enabled"),
+ cfg.BoolOpt('api_v2',
+ default=True,
+ help="Is the v2 volume API enabled"),
]
@@ -786,7 +788,7 @@
self.compute_feature_enabled = cfg.CONF['compute-feature-enabled']
self.identity = cfg.CONF.identity
self.identity_feature_enabled = cfg.CONF['identity-feature-enabled']
- self.images = cfg.CONF.image
+ 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']
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 0c9d503..0fc304a 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -22,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
@@ -112,7 +112,7 @@
region = CONF.identity.region
endpoint = self.identity_client.service_catalog.url_for(
attr='region', filter_value=region,
- service_type='image', endpoint_type='publicURL')
+ 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)
@@ -146,7 +146,7 @@
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,
@@ -167,11 +167,12 @@
keystone = self._get_identity_client(username, password, tenant_name)
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
diff --git a/tempest/scenario/test_load_balancer_basic.py b/tempest/scenario/test_load_balancer_basic.py
index f4ca958..68f6e62 100644
--- a/tempest/scenario/test_load_balancer_basic.py
+++ b/tempest/scenario/test_load_balancer_basic.py
@@ -214,10 +214,11 @@
resp.append(
urllib.urlopen(
"http://{0}/".format(floating_ip_vip)).read())
- self.assertEqual({"server1\n", "server2\n"}, set(resp))
+ 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):
diff --git a/tempest/scenario/test_network_basic_ops.py b/tempest/scenario/test_network_basic_ops.py
index 020a256..0c0234f 100644
--- a/tempest/scenario/test_network_basic_ops.py
+++ b/tempest/scenario/test_network_basic_ops.py
@@ -19,9 +19,7 @@
from tempest import config
from tempest.openstack.common import log as logging
from tempest.scenario import manager
-
-from tempest.test import attr
-from tempest.test import services
+from tempest import test
CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -113,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.
@@ -235,8 +237,8 @@
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()
diff --git a/tempest/services/baremetal/base.py b/tempest/services/baremetal/base.py
index 6e86466..5f6b513 100644
--- a/tempest/services/baremetal/base.py
+++ b/tempest/services/baremetal/base.py
@@ -114,7 +114,7 @@
"""
uri = self._get_uri(resource, permanent=permanent)
- resp, body = self.get(uri, self.headers)
+ resp, body = self.get(uri)
return resp, self.deserialize(body)
@@ -127,7 +127,7 @@
"""
uri = self._get_uri(resource, uuid=uuid, permanent=permanent)
- resp, body = self.get(uri, self.headers)
+ resp, body = self.get(uri)
return resp, self.deserialize(body)
@@ -145,7 +145,7 @@
body = self.serialize(object_type, object_dict)
uri = self._get_uri(resource)
- resp, body = self.post(uri, headers=self.headers, body=body)
+ resp, body = self.post(uri, body=body)
return resp, self.deserialize(body)
@@ -160,7 +160,7 @@
"""
uri = self._get_uri(resource, uuid)
- resp, body = self.delete(uri, self.headers)
+ resp, body = self.delete(uri)
return resp, body
def _patch_request(self, resource, uuid, patch_object):
@@ -176,7 +176,7 @@
uri = self._get_uri(resource, uuid)
patch_body = json.dumps(patch_object)
- resp, body = self.patch(uri, headers=self.headers, body=patch_body)
+ resp, body = self.patch(uri, body=patch_body)
return resp, self.deserialize(body)
@handle_errors
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
deleted file mode 100644
index 3a6ac5f..0000000
--- a/tempest/services/compute/v3/json/instance_usage_audit_log_client.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# 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.
-
-import json
-
-from tempest.common.rest_client import RestClient
-from tempest import config
-
-CONF = config.CONF
-
-
-class InstanceUsagesAuditLogV3ClientJSON(RestClient):
-
- 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, 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/tenant_usages_client.py b/tempest/services/compute/v3/json/tenant_usages_client.py
deleted file mode 100644
index 6d59e20..0000000
--- a/tempest/services/compute/v3/json/tenant_usages_client.py
+++ /dev/null
@@ -1,47 +0,0 @@
-# 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 json
-import urllib
-
-from tempest.common.rest_client import RestClient
-from tempest import config
-
-CONF = config.CONF
-
-
-class TenantUsagesV3ClientJSON(RestClient):
-
- 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'
- if params:
- url += '?%s' % urllib.urlencode(params)
-
- resp, body = self.get(url)
- body = json.loads(body)
- return resp, body['tenant_usages'][0]
-
- 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)
- body = json.loads(body)
- return resp, body['tenant_usage']
diff --git a/tempest/services/data_processing/v1_1/client.py b/tempest/services/data_processing/v1_1/client.py
index db21201..e96b44b 100644
--- a/tempest/services/data_processing/v1_1/client.py
+++ b/tempest/services/data_processing/v1_1/client.py
@@ -77,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 c018215..349a9e9 100644
--- a/tempest/services/identity/json/identity_client.py
+++ b/tempest/services/identity/json/identity_client.py
@@ -12,20 +12,23 @@
import json
-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):
+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
@@ -43,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):
"""
@@ -60,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."""
@@ -92,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."""
@@ -133,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."""
@@ -149,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."""
@@ -184,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)
@@ -215,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."""
@@ -238,7 +216,7 @@
return self.delete(url)
-class TokenClientJSON(RestClient):
+class TokenClientJSON(IdentityClientJSON):
def __init__(self):
super(TokenClientJSON, self).__init__(None)
@@ -261,15 +239,17 @@
}
}
body = json.dumps(creds)
- resp, body = self.post(self.auth_url, headers=self.headers, body=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."""
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)
@@ -282,7 +262,9 @@
raise exceptions.IdentityError(
'Unexpected status code {0}'.format(resp.status))
- return resp, json.loads(resp_body)
+ if isinstance(resp_body, str):
+ resp_body = json.loads(resp_body)
+ return resp, resp_body
def get_token(self, user, password, tenant, auth_data=False):
"""
diff --git a/tempest/services/identity/v3/json/credentials_client.py b/tempest/services/identity/v3/json/credentials_client.py
index a0fbb76..5d6632a 100644
--- a/tempest/services/identity/v3/json/credentials_client.py
+++ b/tempest/services/identity/v3/json/credentials_client.py
@@ -40,8 +40,7 @@
"user_id": user_id
}
post_body = json.dumps({'credential': post_body})
- resp, body = self.post('credentials', post_body,
- self.headers)
+ resp, body = self.post('credentials', post_body)
body = json.loads(body)
body['credential']['blob'] = json.loads(body['credential']['blob'])
return resp, body['credential']
@@ -63,8 +62,7 @@
"user_id": user_id
}
post_body = json.dumps({'credential': post_body})
- resp, body = self.patch('credentials/%s' % credential_id, post_body,
- self.headers)
+ resp, body = self.patch('credentials/%s' % credential_id, post_body)
body = json.loads(body)
body['credential']['blob'] = json.loads(body['credential']['blob'])
return resp, body['credential']
diff --git a/tempest/services/identity/v3/json/endpoints_client.py b/tempest/services/identity/v3/json/endpoints_client.py
index 1b78115..652c345 100644
--- a/tempest/services/identity/v3/json/endpoints_client.py
+++ b/tempest/services/identity/v3/json/endpoints_client.py
@@ -47,7 +47,7 @@
'enabled': enabled
}
post_body = json.dumps({'endpoint': post_body})
- resp, body = self.post('endpoints', post_body, self.headers)
+ resp, body = self.post('endpoints', post_body)
body = json.loads(body)
return resp, body['endpoint']
@@ -66,8 +66,7 @@
if enabled is not None:
post_body['enabled'] = enabled
post_body = json.dumps({'endpoint': post_body})
- resp, body = self.patch('endpoints/%s' % endpoint_id, post_body,
- self.headers)
+ resp, body = self.patch('endpoints/%s' % endpoint_id, post_body)
body = json.loads(body)
return resp, body['endpoint']
diff --git a/tempest/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index ab1dc94..ec3229e 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -49,8 +49,7 @@
'password': password
}
post_body = json.dumps({'user': post_body})
- resp, body = self.post('users', post_body,
- self.headers)
+ resp, body = self.post('users', post_body)
body = json.loads(body)
return resp, body['user']
@@ -72,14 +71,13 @@
'description': description
}
post_body = json.dumps({'user': post_body})
- resp, body = self.patch('users/%s' % user_id, post_body,
- self.headers)
+ resp, body = self.patch('users/%s' % user_id, post_body)
body = json.loads(body)
return resp, body['user']
def list_user_projects(self, user_id):
"""Lists the projects on which a user has roles assigned."""
- resp, body = self.get('users/%s/projects' % user_id, self.headers)
+ resp, body = self.get('users/%s/projects' % user_id)
body = json.loads(body)
return resp, body['projects']
@@ -112,7 +110,7 @@
'name': name
}
post_body = json.dumps({'project': post_body})
- resp, body = self.post('projects', post_body, self.headers)
+ resp, body = self.post('projects', post_body)
body = json.loads(body)
return resp, body['project']
@@ -135,8 +133,7 @@
'domain_id': domain_id,
}
post_body = json.dumps({'project': post_body})
- resp, body = self.patch('projects/%s' % project_id, post_body,
- self.headers)
+ resp, body = self.patch('projects/%s' % project_id, post_body)
body = json.loads(body)
return resp, body['project']
@@ -157,7 +154,7 @@
'name': name
}
post_body = json.dumps({'role': post_body})
- resp, body = self.post('roles', post_body, self.headers)
+ resp, body = self.post('roles', post_body)
body = json.loads(body)
return resp, body['role']
@@ -173,8 +170,7 @@
'name': name
}
post_body = json.dumps({'role': post_body})
- resp, body = self.patch('roles/%s' % str(role_id), post_body,
- self.headers)
+ resp, body = self.patch('roles/%s' % str(role_id), post_body)
body = json.loads(body)
return resp, body['role']
@@ -186,8 +182,7 @@
def assign_user_role(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' %
- (project_id, user_id, role_id), None,
- self.headers)
+ (project_id, user_id, role_id), None)
return resp, body
def create_domain(self, name, **kwargs):
@@ -200,7 +195,7 @@
'name': name
}
post_body = json.dumps({'domain': post_body})
- resp, body = self.post('domains', post_body, self.headers)
+ resp, body = self.post('domains', post_body)
body = json.loads(body)
return resp, body['domain']
@@ -227,8 +222,7 @@
'name': name
}
post_body = json.dumps({'domain': post_body})
- resp, body = self.patch('domains/%s' % domain_id, post_body,
- self.headers)
+ resp, body = self.patch('domains/%s' % domain_id, post_body)
body = json.loads(body)
return resp, body['domain']
@@ -263,13 +257,13 @@
'name': name
}
post_body = json.dumps({'group': post_body})
- resp, body = self.post('groups', post_body, self.headers)
+ resp, body = self.post('groups', post_body)
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)
+ resp, body = self.get('groups/%s' % group_id)
body = json.loads(body)
return resp, body['group']
@@ -283,8 +277,7 @@
'description': description
}
post_body = json.dumps({'group': post_body})
- resp, body = self.patch('groups/%s' % group_id, post_body,
- self.headers)
+ resp, body = self.patch('groups/%s' % group_id, post_body)
body = json.loads(body)
return resp, body['group']
@@ -296,33 +289,30 @@
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)
+ None)
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)
+ resp, body = self.get('groups/%s/users' % group_id)
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)
+ resp, body = self.delete('groups/%s/users/%s' % (group_id, user_id))
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' %
- (project_id, user_id, role_id), None,
- self.headers)
+ (project_id, user_id, role_id), None)
return resp, body
def assign_user_role_on_domain(self, domain_id, user_id, role_id):
"""Add roles to a user on a domain."""
resp, body = self.put('domains/%s/users/%s/roles/%s' %
- (domain_id, user_id, role_id), None,
- self.headers)
+ (domain_id, user_id, role_id), None)
return resp, body
def list_user_roles_on_project(self, project_id, user_id):
@@ -354,15 +344,13 @@
def assign_group_role_on_project(self, project_id, group_id, role_id):
"""Add roles to a user on a project."""
resp, body = self.put('projects/%s/groups/%s/roles/%s' %
- (project_id, group_id, role_id), None,
- self.headers)
+ (project_id, group_id, role_id), None)
return resp, body
def assign_group_role_on_domain(self, domain_id, group_id, role_id):
"""Add roles to a user on a domain."""
resp, body = self.put('domains/%s/groups/%s/roles/%s' %
- (domain_id, group_id, role_id), None,
- self.headers)
+ (domain_id, group_id, role_id), None)
return resp, body
def list_group_roles_on_project(self, project_id, group_id):
@@ -404,7 +392,7 @@
'expires_at': expires_at
}
post_body = json.dumps({'trust': post_body})
- resp, body = self.post('OS-TRUST/trusts', post_body, self.headers)
+ resp, body = self.post('OS-TRUST/trusts', post_body)
body = json.loads(body)
return resp, body['trust']
@@ -507,11 +495,16 @@
creds['auth']['scope'] = scope
body = json.dumps(creds)
- resp, body = self.post(self.auth_url, headers=self.headers, body=body)
+ resp, body = self.post(self.auth_url, body=body)
return resp, body
def request(self, method, url, headers=None, body=None):
"""A simple HTTP request interface."""
+ if headers is None:
+ # Always accept 'json', for xml token client 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)
diff --git a/tempest/services/identity/v3/json/policy_client.py b/tempest/services/identity/v3/json/policy_client.py
index c376979..5a3f891 100644
--- a/tempest/services/identity/v3/json/policy_client.py
+++ b/tempest/services/identity/v3/json/policy_client.py
@@ -36,7 +36,7 @@
"type": type
}
post_body = json.dumps({'policy': post_body})
- resp, body = self.post('policies', post_body, self.headers)
+ resp, body = self.post('policies', post_body)
body = json.loads(body)
return resp, body['policy']
@@ -62,8 +62,7 @@
}
post_body = json.dumps({'policy': post_body})
url = 'policies/%s' % policy_id
- resp, body = self.patch(url, post_body,
- self.headers)
+ resp, body = self.patch(url, post_body)
body = json.loads(body)
return resp, body['policy']
diff --git a/tempest/services/identity/v3/json/service_client.py b/tempest/services/identity/v3/json/service_client.py
index 92f7629..094e567 100644
--- a/tempest/services/identity/v3/json/service_client.py
+++ b/tempest/services/identity/v3/json/service_client.py
@@ -41,8 +41,7 @@
'name': name
}
patch_body = json.dumps({'service': patch_body})
- resp, body = self.patch('services/%s' % service_id,
- patch_body, self.headers)
+ resp, body = self.patch('services/%s' % service_id, patch_body)
body = json.loads(body)
return resp, body['service']
diff --git a/tempest/services/identity/v3/xml/credentials_client.py b/tempest/services/identity/v3/xml/credentials_client.py
index eca86ab..f6fa678 100644
--- a/tempest/services/identity/v3/xml/credentials_client.py
+++ b/tempest/services/identity/v3/xml/credentials_client.py
@@ -61,8 +61,7 @@
credential = Element('credential', project_id=project_id,
type=cred_type, user_id=user_id)
credential.append(blob)
- resp, body = self.post('credentials', str(Document(credential)),
- self.headers)
+ resp, body = self.post('credentials', str(Document(credential)))
body = self._parse_body(etree.fromstring(body))
body['blob'] = json.loads(body['blob'])
return resp, body
@@ -85,27 +84,25 @@
type=cred_type, user_id=user_id)
credential.append(blob)
resp, body = self.patch('credentials/%s' % credential_id,
- str(Document(credential)),
- self.headers)
+ str(Document(credential)))
body = self._parse_body(etree.fromstring(body))
body['blob'] = json.loads(body['blob'])
return resp, body
def get_credential(self, credential_id):
"""To GET Details of a credential."""
- resp, body = self.get('credentials/%s' % credential_id, self.headers)
+ resp, body = self.get('credentials/%s' % credential_id)
body = self._parse_body(etree.fromstring(body))
body['blob'] = json.loads(body['blob'])
return resp, body
def list_credentials(self):
"""Lists out all the available credentials."""
- resp, body = self.get('credentials', self.headers)
+ resp, body = self.get('credentials')
body = self._parse_creds(etree.fromstring(body))
return resp, body
def delete_credential(self, credential_id):
"""Deletes a credential."""
- resp, body = self.delete('credentials/%s' % credential_id,
- self.headers)
+ resp, body = self.delete('credentials/%s' % credential_id)
return resp, body
diff --git a/tempest/services/identity/v3/xml/endpoints_client.py b/tempest/services/identity/v3/xml/endpoints_client.py
index a20a9f5..2a88c15 100644
--- a/tempest/services/identity/v3/xml/endpoints_client.py
+++ b/tempest/services/identity/v3/xml/endpoints_client.py
@@ -58,7 +58,7 @@
def list_endpoints(self):
"""Get the list of endpoints."""
- resp, body = self.get("endpoints", self.headers)
+ resp, body = self.get("endpoints")
body = self._parse_array(etree.fromstring(body))
return resp, body
@@ -72,8 +72,7 @@
interface=interface,
url=url, region=region,
enabled=enabled)
- resp, body = self.post('endpoints', str(Document(create_endpoint)),
- self.headers)
+ resp, body = self.post('endpoints', str(Document(create_endpoint)))
body = self._parse_body(etree.fromstring(body))
return resp, body
@@ -94,8 +93,7 @@
endpoint.add_attr("region", region)
if enabled is not None:
endpoint.add_attr("enabled", enabled)
- resp, body = self.patch('endpoints/%s' % str(endpoint_id),
- str(doc), self.headers)
+ resp, body = self.patch('endpoints/%s' % str(endpoint_id), str(doc))
body = self._parse_body(etree.fromstring(body))
return resp, body
diff --git a/tempest/services/identity/v3/xml/identity_client.py b/tempest/services/identity/v3/xml/identity_client.py
index e7b85c1..6304628 100644
--- a/tempest/services/identity/v3/xml/identity_client.py
+++ b/tempest/services/identity/v3/xml/identity_client.py
@@ -98,8 +98,7 @@
enabled=str(en).lower(),
project_id=project_id,
domain_id=domain_id)
- resp, body = self.post('users', str(Document(post_body)),
- self.headers)
+ resp, body = self.post('users', str(Document(post_body)))
body = self._parse_body(etree.fromstring(body))
return resp, body
@@ -120,32 +119,31 @@
description=description,
enabled=str(en).lower())
resp, body = self.patch('users/%s' % user_id,
- str(Document(update_user)),
- self.headers)
+ str(Document(update_user)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def list_user_projects(self, user_id):
"""Lists the projects on which a user has roles assigned."""
- resp, body = self.get('users/%s/projects' % user_id, self.headers)
+ resp, body = self.get('users/%s/projects' % user_id)
body = self._parse_projects(etree.fromstring(body))
return resp, body
def get_users(self):
"""Get the list of users."""
- resp, body = self.get("users", self.headers)
+ resp, body = self.get("users")
body = self._parse_array(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)
+ resp, body = self.get("users/%s" % user_id)
body = self._parse_body(etree.fromstring(body))
return resp, body
def delete_user(self, user_id):
"""Deletes a User."""
- resp, body = self.delete("users/%s" % user_id, self.headers)
+ resp, body = self.delete("users/%s" % user_id)
return resp, body
def create_project(self, name, **kwargs):
@@ -160,14 +158,13 @@
enabled=str(en).lower(),
name=name)
resp, body = self.post('projects',
- str(Document(post_body)),
- self.headers)
+ str(Document(post_body)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def list_projects(self):
"""Get the list of projects."""
- resp, body = self.get("projects", self.headers)
+ resp, body = self.get("projects")
body = self._parse_projects(etree.fromstring(body))
return resp, body
@@ -185,14 +182,13 @@
enabled=str(en).lower(),
domain_id=domain_id)
resp, body = self.patch('projects/%s' % project_id,
- str(Document(post_body)),
- self.headers)
+ str(Document(post_body)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def get_project(self, project_id):
"""GET a Project."""
- resp, body = self.get("projects/%s" % project_id, self.headers)
+ resp, body = self.get("projects/%s" % project_id)
body = self._parse_body(etree.fromstring(body))
return resp, body
@@ -206,15 +202,13 @@
post_body = Element("role",
xmlns=XMLNS,
name=name)
- resp, body = self.post('roles',
- str(Document(post_body)),
- self.headers)
+ resp, body = self.post('roles', str(Document(post_body)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def get_role(self, role_id):
"""GET a Role."""
- resp, body = self.get('roles/%s' % str(role_id), self.headers)
+ resp, body = self.get('roles/%s' % str(role_id))
body = self._parse_body(etree.fromstring(body))
return resp, body
@@ -224,21 +218,19 @@
xmlns=XMLNS,
name=name)
resp, body = self.patch('roles/%s' % str(role_id),
- str(Document(post_body)),
- self.headers)
+ str(Document(post_body)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def delete_role(self, role_id):
"""Delete a role."""
- resp, body = self.delete('roles/%s' % str(role_id),
- self.headers)
+ resp, body = self.delete('roles/%s' % str(role_id))
return resp, body
def assign_user_role(self, project_id, user_id, role_id):
"""Add roles to a user on a tenant."""
resp, body = self.put('projects/%s/users/%s/roles/%s' %
- (project_id, user_id, role_id), '', self.headers)
+ (project_id, user_id, role_id), '')
return resp, body
def create_domain(self, name, **kwargs):
@@ -250,20 +242,19 @@
name=name,
description=description,
enabled=str(en).lower())
- resp, body = self.post('domains', str(Document(post_body)),
- self.headers)
+ resp, body = self.post('domains', str(Document(post_body)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def list_domains(self):
"""Get the list of domains."""
- resp, body = self.get("domains", self.headers)
+ resp, body = self.get("domains")
body = self._parse_domains(etree.fromstring(body))
return resp, body
def delete_domain(self, domain_id):
"""Delete a domain."""
- resp, body = self.delete('domains/%s' % domain_id, self.headers)
+ resp, body = self.delete('domains/%s' % domain_id)
return resp, body
def update_domain(self, domain_id, **kwargs):
@@ -278,14 +269,13 @@
description=description,
enabled=str(en).lower())
resp, body = self.patch('domains/%s' % domain_id,
- str(Document(post_body)),
- self.headers)
+ str(Document(post_body)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def get_domain(self, domain_id):
"""Get Domain details."""
- resp, body = self.get('domains/%s' % domain_id, self.headers)
+ resp, body = self.get('domains/%s' % domain_id)
body = self._parse_body(etree.fromstring(body))
return resp, body
@@ -315,14 +305,13 @@
description=description,
domain_id=domain_id,
project_id=project_id)
- resp, body = self.post('groups', str(Document(post_body)),
- self.headers)
+ resp, body = self.post('groups', str(Document(post_body)))
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)
+ resp, body = self.get('groups/%s' % group_id)
body = self._parse_body(etree.fromstring(body))
return resp, body
@@ -336,112 +325,105 @@
name=name,
description=description)
resp, body = self.patch('groups/%s' % group_id,
- str(Document(post_body)),
- self.headers)
+ str(Document(post_body)))
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)
+ resp, body = self.delete('groups/%s' % 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),
- '', self.headers)
+ resp, body = self.put('groups/%s/users/%s' % (group_id, user_id), '')
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)
+ resp, body = self.get('groups/%s/users' % group_id)
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)
+ resp, body = self.delete('groups/%s/users/%s' % (group_id, user_id))
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' %
- (project_id, user_id, role_id), '',
- self.headers)
+ (project_id, user_id, role_id), '')
return resp, body
def assign_user_role_on_domain(self, domain_id, user_id, role_id):
"""Add roles to a user on a domain."""
resp, body = self.put('domains/%s/users/%s/roles/%s' %
- (domain_id, user_id, role_id), '',
- self.headers)
+ (domain_id, user_id, role_id), '')
return resp, body
def list_user_roles_on_project(self, project_id, user_id):
"""list roles of a user on a project."""
resp, body = self.get('projects/%s/users/%s/roles' %
- (project_id, user_id), self.headers)
+ (project_id, user_id))
body = self._parse_roles(etree.fromstring(body))
return resp, body
def list_user_roles_on_domain(self, domain_id, user_id):
"""list roles of a user on a domain."""
resp, body = self.get('domains/%s/users/%s/roles' %
- (domain_id, user_id), self.headers)
+ (domain_id, user_id))
body = self._parse_roles(etree.fromstring(body))
return resp, body
def revoke_role_from_user_on_project(self, project_id, user_id, role_id):
"""Delete role of a user on a project."""
resp, body = self.delete('projects/%s/users/%s/roles/%s' %
- (project_id, user_id, role_id), self.headers)
+ (project_id, user_id, role_id))
return resp, body
def revoke_role_from_user_on_domain(self, domain_id, user_id, role_id):
"""Delete role of a user on a domain."""
resp, body = self.delete('domains/%s/users/%s/roles/%s' %
- (domain_id, user_id, role_id), self.headers)
+ (domain_id, user_id, role_id))
return resp, body
def assign_group_role_on_project(self, project_id, group_id, role_id):
"""Add roles to a user on a project."""
resp, body = self.put('projects/%s/groups/%s/roles/%s' %
- (project_id, group_id, role_id), '',
- self.headers)
+ (project_id, group_id, role_id), '')
return resp, body
def assign_group_role_on_domain(self, domain_id, group_id, role_id):
"""Add roles to a user on a domain."""
resp, body = self.put('domains/%s/groups/%s/roles/%s' %
- (domain_id, group_id, role_id), '',
- self.headers)
+ (domain_id, group_id, role_id), '')
return resp, body
def list_group_roles_on_project(self, project_id, group_id):
"""list roles of a user on a project."""
resp, body = self.get('projects/%s/groups/%s/roles' %
- (project_id, group_id), self.headers)
+ (project_id, group_id))
body = self._parse_roles(etree.fromstring(body))
return resp, body
def list_group_roles_on_domain(self, domain_id, group_id):
"""list roles of a user on a domain."""
resp, body = self.get('domains/%s/groups/%s/roles' %
- (domain_id, group_id), self.headers)
+ (domain_id, group_id))
body = self._parse_roles(etree.fromstring(body))
return resp, body
def revoke_role_from_group_on_project(self, project_id, group_id, role_id):
"""Delete role of a user on a project."""
resp, body = self.delete('projects/%s/groups/%s/roles/%s' %
- (project_id, group_id, role_id), self.headers)
+ (project_id, group_id, role_id))
return resp, body
def revoke_role_from_group_on_domain(self, domain_id, group_id, role_id):
"""Delete role of a user on a domain."""
resp, body = self.delete('domains/%s/groups/%s/roles/%s' %
- (domain_id, group_id, role_id), self.headers)
+ (domain_id, group_id, role_id))
return resp, body
@@ -501,15 +483,16 @@
scope.append(project)
auth.append(scope)
- resp, body = self.post(self.auth_url, headers=self.headers,
- body=str(Document(auth)))
+ resp, body = self.post(self.auth_url, body=str(Document(auth)))
return resp, 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'
+ if headers is None:
+ # Always accept 'json', for xml token client 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)
diff --git a/tempest/services/identity/v3/xml/policy_client.py b/tempest/services/identity/v3/xml/policy_client.py
index 429c6a4..a7e63a7 100644
--- a/tempest/services/identity/v3/xml/policy_client.py
+++ b/tempest/services/identity/v3/xml/policy_client.py
@@ -59,21 +59,20 @@
def create_policy(self, blob, type):
"""Creates a Policy."""
create_policy = Element("policy", xmlns=XMLNS, blob=blob, type=type)
- resp, body = self.post('policies', str(Document(create_policy)),
- self.headers)
+ resp, body = self.post('policies', str(Document(create_policy)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def list_policies(self):
"""Lists the policies."""
- resp, body = self.get('policies', self.headers)
+ resp, body = self.get('policies')
body = self._parse_array(etree.fromstring(body))
return resp, body
def get_policy(self, policy_id):
"""Lists out the given policy."""
url = 'policies/%s' % policy_id
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = self._parse_body(etree.fromstring(body))
return resp, body
@@ -83,8 +82,7 @@
type = kwargs.get('type')
update_policy = Element("policy", xmlns=XMLNS, type=type)
url = 'policies/%s' % policy_id
- resp, body = self.patch(url, str(Document(update_policy)),
- self.headers)
+ resp, body = self.patch(url, str(Document(update_policy)))
body = self._parse_body(etree.fromstring(body))
return resp, body
diff --git a/tempest/services/identity/v3/xml/service_client.py b/tempest/services/identity/v3/xml/service_client.py
index df9b234..f43ed2c 100644
--- a/tempest/services/identity/v3/xml/service_client.py
+++ b/tempest/services/identity/v3/xml/service_client.py
@@ -57,14 +57,13 @@
description=description,
type=type)
resp, body = self.patch('services/%s' % service_id,
- str(Document(update_service)),
- self.headers)
+ str(Document(update_service)))
body = self._parse_body(etree.fromstring(body))
return resp, body
def get_service(self, service_id):
"""Get Service."""
url = 'services/%s' % service_id
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = self._parse_body(etree.fromstring(body))
return resp, body
diff --git a/tempest/services/identity/xml/identity_client.py b/tempest/services/identity/xml/identity_client.py
index 7c36680..50403fb 100644
--- a/tempest/services/identity/xml/identity_client.py
+++ b/tempest/services/identity/xml/identity_client.py
@@ -12,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.
-
-import json
-
-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 xml_to_json
+from tempest.services.compute.xml import common as xml
+from tempest.services.identity.json import identity_client
CONF = config.CONF
XMLNS = "http://docs.openstack.org/identity/api/v2.0"
-class IdentityClientXML(RestClientXML):
-
- def __init__(self, auth_provider):
- super(IdentityClientXML, self).__init__(auth_provider)
- self.service = CONF.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):
"""
@@ -73,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."""
@@ -144,173 +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)))
+ 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):
- super(TokenClientXML, self).__init__(None)
- auth_url = CONF.identity.uri
-
- # 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
+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)
- resp, body = self.post(self.auth_url, headers=self.headers,
- body=str(Document(auth)))
+ resp, body = self.post(self.auth_url, body=str(xml.Document(auth)))
return resp, body['access']
-
- def request(self, method, url, headers=None, body=None):
- """A simple HTTP request interface."""
- if headers is None:
- headers = {}
- # 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]:
- raise exceptions.IdentityError(
- 'Unexpected status code {0}'.format(resp.status))
-
- return resp, json.loads(resp_body)
-
- 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 auth_data:
- return body['token']['id'], body
- else:
- return body['token']['id']
diff --git a/tempest/services/image/v1/json/image_client.py b/tempest/services/image/v1/json/image_client.py
index 17271cc..932fa14 100644
--- a/tempest/services/image/v1/json/image_client.py
+++ b/tempest/services/image/v1/json/image_client.py
@@ -35,7 +35,7 @@
def __init__(self, auth_provider):
super(ImageClientJSON, self).__init__(auth_provider)
- self.service = CONF.images.catalog_type
+ self.service = CONF.image.catalog_type
self._http = None
def _image_meta_from_headers(self, headers):
@@ -157,7 +157,7 @@
return resp, body['image']
def update_image(self, image_id, name=None, container_format=None,
- data=None):
+ data=None, properties=None):
params = {}
headers = {}
if name is not None:
@@ -166,6 +166,9 @@
if container_format is not None:
params['container_format'] = container_format
+ if properties is not None:
+ params['properties'] = properties
+
headers.update(self._image_meta_to_headers(params))
if data is not None:
@@ -190,7 +193,8 @@
body = json.loads(body)
return resp, body['images']
- def image_list_detail(self, properties=dict(), **kwargs):
+ def image_list_detail(self, properties=dict(), changes_since=None,
+ **kwargs):
url = 'v1/images/detail'
params = {}
@@ -199,6 +203,9 @@
kwargs.update(params)
+ if changes_since is not None:
+ kwargs['changes-since'] = changes_since
+
if len(kwargs) > 0:
url += '?%s' % urllib.urlencode(kwargs)
@@ -241,7 +248,7 @@
body = None
if can_share:
body = json.dumps({'member': {'can_share': True}})
- resp, __ = self.put(url, body, self.headers)
+ resp, __ = self.put(url, body)
return resp
def delete_member(self, member_id, image_id):
@@ -252,7 +259,7 @@
def replace_membership_list(self, image_id, member_list):
url = 'v1/images/%s/members' % image_id
body = json.dumps({'membership': member_list})
- resp, data = self.put(url, body, self.headers)
+ resp, data = self.put(url, body)
data = json.loads(data)
return resp, data
diff --git a/tempest/services/image/v2/json/image_client.py b/tempest/services/image/v2/json/image_client.py
index 38aef2d..58819d0 100644
--- a/tempest/services/image/v2/json/image_client.py
+++ b/tempest/services/image/v2/json/image_client.py
@@ -30,7 +30,7 @@
def __init__(self, auth_provider):
super(ImageClientV2JSON, self).__init__(auth_provider)
- self.service = CONF.images.catalog_type
+ self.service = CONF.image.catalog_type
self._http = None
def _get_http(self):
@@ -86,7 +86,7 @@
data = json.dumps(params)
self._validate_schema(data)
- resp, body = self.post('v2/images', data, self.headers)
+ resp, body = self.post('v2/images', data)
body = json.loads(body)
return resp, body
@@ -132,7 +132,7 @@
def add_image_tag(self, image_id, tag):
url = 'v2/images/%s/tags/%s' % (image_id, tag)
- resp, body = self.put(url, body=None, headers=self.headers)
+ resp, body = self.put(url, body=None)
return resp, body
def delete_image_tag(self, image_id, tag):
@@ -150,7 +150,7 @@
def add_member(self, image_id, member_id):
url = 'v2/images/%s/members' % image_id
data = json.dumps({'member': member_id})
- resp, body = self.post(url, data, self.headers)
+ resp, body = self.post(url, data)
body = json.loads(body)
self.expected_success(200, resp)
return resp, body
@@ -159,7 +159,7 @@
"""Valid status are: ``pending``, ``accepted``, ``rejected``."""
url = 'v2/images/%s/members/%s' % (image_id, member_id)
data = json.dumps({'status': status})
- resp, body = self.put(url, data, self.headers)
+ resp, body = self.put(url, data)
body = json.loads(body)
self.expected_success(200, resp)
return resp, body
diff --git a/tempest/services/network/network_client_base.py b/tempest/services/network/network_client_base.py
index 51c10e9..f3f8d70 100644
--- a/tempest/services/network/network_client_base.py
+++ b/tempest/services/network/network_client_base.py
@@ -117,9 +117,14 @@
return _delete
def _shower(self, resource_name):
- def _show(resource_id):
+ def _show(resource_id, field_list=[]):
+ # field_list is a sequence of two-element tuples, with the
+ # first element being 'fields'. An example:
+ # [('fields', 'id'), ('fields', 'name')]
plural = self.pluralize(resource_name)
uri = '%s/%s' % (self.get_uri(plural), resource_id)
+ if field_list:
+ uri += '?' + urllib.urlencode(field_list)
resp, body = self.get(uri)
body = self.deserialize_single(body)
return resp, body
diff --git a/tempest/services/object_storage/account_client.py b/tempest/services/object_storage/account_client.py
index 924d9a8..efac5f5 100644
--- a/tempest/services/object_storage/account_client.py
+++ b/tempest/services/object_storage/account_client.py
@@ -30,10 +30,6 @@
self.service = CONF.object_storage.catalog_type
self.format = 'json'
- @property
- def token(self):
- return self.auth_provider.auth_data[0]
-
def create_account(self, data=None,
params=None,
metadata={},
@@ -62,7 +58,7 @@
url += 'bulk-delete&'
url = '?%s%s' % (url, urllib.urlencode(params))
- resp, body = self.delete(url, headers=None, body=data)
+ resp, body = self.delete(url, headers={}, body=data)
return resp, body
def list_account_metadata(self):
diff --git a/tempest/services/object_storage/container_client.py b/tempest/services/object_storage/container_client.py
index 63a6460..f224407 100644
--- a/tempest/services/object_storage/container_client.py
+++ b/tempest/services/object_storage/container_client.py
@@ -32,10 +32,6 @@
self.service = CONF.object_storage.catalog_type
self.format = 'json'
- @property
- def token(self):
- return self.auth_provider.auth_data[0]
-
def create_container(
self, container_name,
metadata=None,
@@ -185,7 +181,7 @@
url += '?'
url += '&%s' % urllib.urlencode(params)
- resp, body = self.get(url)
+ resp, body = self.get(url, headers={})
if params and params.get('format') == 'json':
body = json.loads(body)
elif params and params.get('format') == 'xml':
diff --git a/tempest/services/object_storage/object_client.py b/tempest/services/object_storage/object_client.py
index ca4f1c1..09e484e 100644
--- a/tempest/services/object_storage/object_client.py
+++ b/tempest/services/object_storage/object_client.py
@@ -32,7 +32,7 @@
def create_object(self, container, object_name, data, params=None):
"""Create storage object."""
- headers = dict(self.headers)
+ headers = self.get_headers()
if not data:
headers['content-length'] = '0'
url = "%s/%s" % (str(container), str(object_name))
@@ -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,
@@ -131,7 +131,7 @@
def create_object_segments(self, container, object_name, segment, data):
"""Creates object segments."""
url = "{0}/{1}/{2}".format(container, object_name, segment)
- resp, body = self.put(url, data, self.headers)
+ resp, body = self.put(url, data)
return resp, body
diff --git a/tempest/services/orchestration/json/orchestration_client.py b/tempest/services/orchestration/json/orchestration_client.py
index 0a16b9f..113003c 100644
--- a/tempest/services/orchestration/json/orchestration_client.py
+++ b/tempest/services/orchestration/json/orchestration_client.py
@@ -90,7 +90,7 @@
# Password must be provided on stack create so that heat
# can perform future operations on behalf of the user
- headers = dict(self.headers)
+ headers = self.get_headers()
headers['X-Auth-Key'] = self.password
headers['X-Auth-User'] = self.user
return headers, body
@@ -106,14 +106,14 @@
"""Suspend a stack."""
url = 'stacks/%s/actions' % stack_identifier
body = {'suspend': None}
- resp, body = self.post(url, json.dumps(body), self.headers)
+ resp, body = self.post(url, json.dumps(body))
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)
+ resp, body = self.post(url, json.dumps(body))
return resp, body
def list_resources(self, stack_identifier):
@@ -177,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,
@@ -232,7 +232,7 @@
def _validate_template(self, post_body):
"""Returns the validation request result."""
post_body = json.dumps(post_body)
- resp, body = self.post('validate', post_body, self.headers)
+ resp, body = self.post('validate', post_body)
body = json.loads(body)
return resp, body
diff --git a/tempest/services/telemetry/json/telemetry_client.py b/tempest/services/telemetry/json/telemetry_client.py
index 747d7c1..e666475 100644
--- a/tempest/services/telemetry/json/telemetry_client.py
+++ b/tempest/services/telemetry/json/telemetry_client.py
@@ -29,10 +29,6 @@
def serialize(self, body):
return json.dumps(body)
- def create_alarm(self, **kwargs):
- uri = "%s/alarms" % self.uri_prefix
- return self.post(uri, kwargs)
-
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,
diff --git a/tempest/services/telemetry/telemetry_client_base.py b/tempest/services/telemetry/telemetry_client_base.py
index 200c94a..610f07b 100644
--- a/tempest/services/telemetry/telemetry_client_base.py
+++ b/tempest/services/telemetry/telemetry_client_base.py
@@ -38,7 +38,6 @@
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
@@ -69,12 +68,12 @@
def post(self, uri, body):
body = self.serialize(body)
- resp, body = self.rest_client.post(uri, body, self.headers)
+ resp, body = self.rest_client.post(uri, body)
body = self.deserialize(body)
return resp, body
def put(self, uri, body):
- return self.rest_client.put(uri, body, self.headers)
+ return self.rest_client.put(uri, body)
def get(self, uri):
resp, body = self.rest_client.get(uri)
@@ -124,9 +123,13 @@
return self.get(uri)
def get_alarm(self, alarm_id):
- uri = '%s/meter/%s' % (self.uri_prefix, 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/volume/json/admin/volume_types_client.py b/tempest/services/volume/json/admin/volume_types_client.py
index 653532e..0d50524 100644
--- a/tempest/services/volume/json/admin/volume_types_client.py
+++ b/tempest/services/volume/json/admin/volume_types_client.py
@@ -64,7 +64,7 @@
}
post_body = json.dumps({'volume_type': post_body})
- resp, body = self.post('types', post_body, self.headers)
+ resp, body = self.post('types', post_body)
body = json.loads(body)
return resp, body['volume_type']
@@ -98,7 +98,7 @@
"""
url = "types/%s/extra_specs" % str(vol_type_id)
post_body = json.dumps({'extra_specs': extra_spec})
- resp, body = self.post(url, post_body, self.headers)
+ resp, body = self.post(url, post_body)
body = json.loads(body)
return resp, body['extra_specs']
@@ -119,6 +119,6 @@
url = "types/%s/extra_specs/%s" % (str(vol_type_id),
str(extra_spec_name))
put_body = json.dumps(extra_spec)
- resp, body = self.put(url, put_body, self.headers)
+ resp, body = self.put(url, put_body)
body = json.loads(body)
return resp, body
diff --git a/tempest/services/volume/json/snapshots_client.py b/tempest/services/volume/json/snapshots_client.py
index 0a79469..ba33c49 100644
--- a/tempest/services/volume/json/snapshots_client.py
+++ b/tempest/services/volume/json/snapshots_client.py
@@ -72,15 +72,14 @@
post_body = {'volume_id': volume_id}
post_body.update(kwargs)
post_body = json.dumps({'snapshot': post_body})
- resp, body = self.post('snapshots', post_body, self.headers)
+ resp, body = self.post('snapshots', post_body)
body = json.loads(body)
return resp, body['snapshot']
def update_snapshot(self, snapshot_id, **kwargs):
"""Updates a snapshot."""
put_body = json.dumps({'snapshot': kwargs})
- resp, body = self.put('snapshots/%s' % snapshot_id, put_body,
- self.headers)
+ resp, body = self.put('snapshots/%s' % snapshot_id, put_body)
body = json.loads(body)
return resp, body['snapshot']
@@ -135,8 +134,7 @@
def reset_snapshot_status(self, snapshot_id, status):
"""Reset the specified snapshot's status."""
post_body = json.dumps({'os-reset_status': {"status": status}})
- resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body,
- self.headers)
+ resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body)
return resp, body
def update_snapshot_status(self, snapshot_id, status, progress):
@@ -147,21 +145,21 @@
}
post_body = json.dumps({'os-update_snapshot_status': post_body})
url = 'snapshots/%s/action' % str(snapshot_id)
- resp, body = self.post(url, post_body, self.headers)
+ resp, body = self.post(url, post_body)
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)
+ resp, body = self.post(url, put_body)
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)
+ resp, body = self.get(url)
body = json.loads(body)
return resp, body['metadata']
@@ -169,7 +167,7 @@
"""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)
+ resp, body = self.put(url, put_body)
body = json.loads(body)
return resp, body['metadata']
@@ -177,19 +175,18 @@
"""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)
+ resp, body = self.put(url, put_body)
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)
+ resp, body = self.delete(url)
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)
+ resp, body = self.post('snapshots/%s/action' % snapshot_id, post_body)
return resp, body
diff --git a/tempest/services/volume/json/volumes_client.py b/tempest/services/volume/json/volumes_client.py
index 0524212..2183c56 100644
--- a/tempest/services/volume/json/volumes_client.py
+++ b/tempest/services/volume/json/volumes_client.py
@@ -81,15 +81,14 @@
post_body = {'size': size}
post_body.update(kwargs)
post_body = json.dumps({'volume': post_body})
- resp, body = self.post('volumes', post_body, self.headers)
+ resp, body = self.post('volumes', post_body)
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)
+ resp, body = self.put('volumes/%s' % volume_id, put_body)
body = json.loads(body)
return resp, body['volume']
@@ -105,7 +104,7 @@
}
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)
+ resp, body = self.post(url, post_body)
body = json.loads(body)
return resp, body['os-volume_upload_image']
@@ -117,7 +116,7 @@
}
post_body = json.dumps({'os-attach': post_body})
url = 'volumes/%s/action' % (volume_id)
- resp, body = self.post(url, post_body, self.headers)
+ resp, body = self.post(url, post_body)
return resp, body
def detach_volume(self, volume_id):
@@ -125,7 +124,7 @@
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)
+ resp, body = self.post(url, post_body)
return resp, body
def reserve_volume(self, volume_id):
@@ -133,7 +132,7 @@
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)
+ resp, body = self.post(url, post_body)
return resp, body
def unreserve_volume(self, volume_id):
@@ -141,7 +140,7 @@
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)
+ resp, body = self.post(url, post_body)
return resp, body
def wait_for_volume_status(self, volume_id, status):
@@ -178,28 +177,25 @@
}
post_body = json.dumps({'os-extend': post_body})
url = 'volumes/%s/action' % (volume_id)
- resp, body = self.post(url, post_body, self.headers)
+ resp, body = self.post(url, post_body)
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)
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body)
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)
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body)
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)
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body)
return resp, body
def create_volume_transfer(self, vol_id, display_name=None):
@@ -210,16 +206,14 @@
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)
+ resp, body = self.post('os-volume-transfer', post_body)
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)
+ resp, body = self.get(url)
body = json.loads(body)
return resp, body['transfer']
@@ -243,7 +237,7 @@
}
url = 'os-volume-transfer/%s/accept' % transfer_id
post_body = json.dumps({'accept': post_body})
- resp, body = self.post(url, post_body, self.headers)
+ resp, body = self.post(url, post_body)
body = json.loads(body)
return resp, body['transfer']
@@ -254,28 +248,27 @@
}
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)
+ resp, body = self.post(url, post_body)
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)
+ resp, body = self.post('volumes/%s/action' % volume_id, post_body)
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)
+ resp, body = self.post(url, put_body)
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)
+ resp, body = self.get(url)
body = json.loads(body)
return resp, body['metadata']
@@ -283,7 +276,7 @@
"""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)
+ resp, body = self.put(url, put_body)
body = json.loads(body)
return resp, body['metadata']
@@ -291,12 +284,12 @@
"""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)
+ resp, body = self.put(url, put_body)
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)
+ resp, body = self.delete(url)
return resp, body
diff --git a/tempest/services/volume/v2/__init__.py b/tempest/services/volume/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/services/volume/v2/__init__.py
diff --git a/tempest/services/volume/v2/json/__init__.py b/tempest/services/volume/v2/json/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/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..bd98402
--- /dev/null
+++ b/tempest/services/volume/v2/json/volumes_client.py
@@ -0,0 +1,296 @@
+# 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 VolumesV2ClientJSON(RestClient):
+ """
+ Client class to send CRUD Volume V2 API requests to a Cinder endpoint
+ """
+
+ def __init__(self, auth_provider):
+ super(VolumesV2ClientJSON, self).__init__(auth_provider)
+
+ self.api_version = "v2"
+ 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:
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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['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)
+ 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)
+ 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)
+ 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)
+ return resp, body
+
+ def create_volume_transfer(self, vol_id, name=None):
+ """Create a volume transfer."""
+ post_body = {
+ 'volume_id': vol_id
+ }
+ if name:
+ post_body['name'] = name
+ post_body = json.dumps({'transfer': post_body})
+ resp, body = self.post('os-volume-transfer', post_body)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ return resp, body
diff --git a/tempest/services/volume/v2/xml/__init__.py b/tempest/services/volume/v2/xml/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/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..69e3f5b
--- /dev/null
+++ b/tempest/services/volume/v2/xml/volumes_client.py
@@ -0,0 +1,408 @@
+# 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 VolumesV2ClientXML(RestClientXML):
+ """
+ Client class to send CRUD Volume API requests to a Cinder endpoint
+ """
+
+ def __init__(self, auth_provider):
+ super(VolumesV2ClientXML, self).__init__(auth_provider)
+
+ self.api_version = "v2"
+ 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)
+ body = etree.fromstring(body)
+ volumes = []
+ if body is not None:
+ volumes += [self._parse_volume(vol) for vol in list(body)]
+ 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)
+ 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)
+ 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 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ if body:
+ body = xml_to_json(etree.fromstring(body))
+ return resp, body
+
+ def create_volume_transfer(self, vol_id, name=None):
+ """Create a volume transfer."""
+ post_body = Element("transfer",
+ volume_id=vol_id)
+ if name:
+ post_body.add_attr('name', name)
+ resp, body = self.post('os-volume-transfer',
+ str(Document(post_body)))
+ 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)
+ 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)
+ 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)))
+ 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)))
+ 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)))
+ 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)))
+ 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)
+ 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)))
+ 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)))
+ 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 7278fd9..59652fa 100644
--- a/tempest/services/volume/xml/admin/volume_hosts_client.py
+++ b/tempest/services/volume/xml/admin/volume_hosts_client.py
@@ -67,6 +67,6 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = self._parse_array(etree.fromstring(body))
return resp, body
diff --git a/tempest/services/volume/xml/admin/volume_types_client.py b/tempest/services/volume/xml/admin/volume_types_client.py
index 29ba431..802d27a 100644
--- a/tempest/services/volume/xml/admin/volume_types_client.py
+++ b/tempest/services/volume/xml/admin/volume_types_client.py
@@ -72,7 +72,7 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
volume_types = []
if body is not None:
@@ -83,7 +83,7 @@
def get_volume_type(self, type_id):
"""Returns the details of a single volume_type."""
url = "types/%s" % str(type_id)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
return resp, self._parse_volume_type(body)
@@ -108,8 +108,7 @@
spec.append(Text(value))
_extra_specs.append(spec)
- resp, body = self.post('types', str(Document(vol_type)),
- self.headers)
+ resp, body = self.post('types', str(Document(vol_type)))
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -124,7 +123,7 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
extra_specs = []
if body is not None:
@@ -136,7 +135,7 @@
"""Returns the details of a single volume_type extra spec."""
url = "types/%s/extra_specs/%s" % (str(vol_type_id),
str(extra_spec_name))
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
return resp, self._parse_volume_type_extra_specs(body)
@@ -160,8 +159,7 @@
else:
extra_specs = None
- resp, body = self.post(url, str(Document(extra_specs)),
- self.headers)
+ resp, body = self.post(url, str(Document(extra_specs)))
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -190,8 +188,7 @@
spec.append(Text(value))
extra_specs.append(spec)
- resp, body = self.put(url, str(Document(extra_specs)),
- self.headers)
+ resp, body = self.put(url, str(Document(extra_specs)))
body = xml_to_json(etree.fromstring(body))
return resp, body
diff --git a/tempest/services/volume/xml/extensions_client.py b/tempest/services/volume/xml/extensions_client.py
index 21e1d04..03743a6 100644
--- a/tempest/services/volume/xml/extensions_client.py
+++ b/tempest/services/volume/xml/extensions_client.py
@@ -36,6 +36,6 @@
def list_extensions(self):
url = 'extensions'
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = self._parse_array(etree.fromstring(body))
return resp, body
diff --git a/tempest/services/volume/xml/snapshots_client.py b/tempest/services/volume/xml/snapshots_client.py
index 4f066a6..9abe042 100644
--- a/tempest/services/volume/xml/snapshots_client.py
+++ b/tempest/services/volume/xml/snapshots_client.py
@@ -47,7 +47,7 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
snapshots = []
for snap in body:
@@ -61,7 +61,7 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
snapshots = []
for snap in body:
@@ -71,7 +71,7 @@
def get_snapshot(self, snapshot_id):
"""Returns the details of a single snapshot."""
url = "snapshots/%s" % str(snapshot_id)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
return resp, xml_to_json(body)
@@ -86,8 +86,7 @@
snapshot = Element("snapshot", xmlns=XMLNS_11, volume_id=volume_id)
for key, value in kwargs.items():
snapshot.add_attr(key, value)
- resp, body = self.post('snapshots', str(Document(snapshot)),
- self.headers)
+ resp, body = self.post('snapshots', str(Document(snapshot)))
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -96,8 +95,7 @@
put_body = Element("snapshot", xmlns=XMLNS_11, **kwargs)
resp, body = self.put('snapshots/%s' % snapshot_id,
- str(Document(put_body)),
- self.headers)
+ str(Document(put_body)))
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -155,7 +153,7 @@
status=status
)
url = 'snapshots/%s/action' % str(snapshot_id)
- resp, body = self.post(url, str(Document(post_body)), self.headers)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -167,7 +165,7 @@
progress=progress
)
url = 'snapshots/%s/action' % str(snapshot_id)
- resp, body = self.post(url, str(Document(post_body)), self.headers)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -191,15 +189,14 @@
"""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)
+ str(Document(post_body)))
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)
+ resp, body = self.get(url)
body = self._parse_key_value(etree.fromstring(body))
return resp, body
@@ -207,7 +204,7 @@
"""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)
+ resp, body = self.put(url, str(Document(put_body)))
body = self._parse_key_value(etree.fromstring(body))
return resp, body
@@ -217,7 +214,7 @@
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)
+ resp, body = self.put(url, str(Document(put_body)))
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -230,7 +227,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
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 deb56fd..2b500ae 100644
--- a/tempest/services/volume/xml/volumes_client.py
+++ b/tempest/services/volume/xml/volumes_client.py
@@ -87,7 +87,7 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
volumes = []
if body is not None:
@@ -103,7 +103,7 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
volumes = []
if body is not None:
@@ -115,7 +115,7 @@
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)
+ resp, body = self.get(url)
body = self._parse_volume(etree.fromstring(body))
body = self._check_if_bootable(body)
return resp, body
@@ -151,8 +151,7 @@
for key, value in attr_to_add.items():
volume.add_attr(key, value)
- resp, body = self.post('volumes', str(Document(volume)),
- self.headers)
+ resp, body = self.post('volumes', str(Document(volume)))
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -161,8 +160,7 @@
put_body = Element("volume", xmlns=XMLNS_11, **kwargs)
resp, body = self.put('volumes/%s' % volume_id,
- str(Document(put_body)),
- self.headers)
+ str(Document(put_body)))
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -204,7 +202,7 @@
mountpoint=mountpoint
)
url = 'volumes/%s/action' % str(volume_id)
- resp, body = self.post(url, str(Document(post_body)), self.headers)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -213,7 +211,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -224,7 +222,7 @@
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)
+ resp, body = self.post(url, str(Document(post_body)))
volume = xml_to_json(etree.fromstring(body))
return resp, volume
@@ -233,7 +231,7 @@
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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -244,7 +242,7 @@
status=status
)
url = 'volumes/%s/action' % str(volume_id)
- resp, body = self.post(url, str(Document(post_body)), self.headers)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -253,7 +251,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -262,7 +260,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -271,7 +269,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -280,7 +278,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -292,15 +290,14 @@
if display_name:
post_body.add_attr('name', display_name)
resp, body = self.post('os-volume-transfer',
- str(Document(post_body)),
- self.headers)
+ str(Document(post_body)))
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)
+ resp, body = self.get(url)
volume = xml_to_json(etree.fromstring(body))
return resp, volume
@@ -310,7 +307,7 @@
if params:
url += '?%s' % urllib.urlencode(params)
- resp, body = self.get(url, self.headers)
+ resp, body = self.get(url)
body = etree.fromstring(body)
volumes = []
if body is not None:
@@ -334,7 +331,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
volume = xml_to_json(etree.fromstring(body))
return resp, volume
@@ -343,7 +340,7 @@
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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -352,7 +349,7 @@
"""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)
+ resp, body = self.post(url, str(Document(post_body)))
if body:
body = xml_to_json(etree.fromstring(body))
return resp, body
@@ -376,15 +373,14 @@
"""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)
+ str(Document(post_body)))
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)
+ resp, body = self.get(url)
body = self._parse_key_value(etree.fromstring(body))
return resp, body
@@ -392,7 +388,7 @@
"""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)
+ resp, body = self.put(url, str(Document(put_body)))
body = self._parse_key_value(etree.fromstring(body))
return resp, body
@@ -402,7 +398,7 @@
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)
+ resp, body = self.put(url, str(Document(put_body)))
body = xml_to_json(etree.fromstring(body))
return resp, body
diff --git a/tempest/test.py b/tempest/test.py
index 5464c03..253e946 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -17,6 +17,7 @@
import functools
import json
import os
+import sys
import time
import urllib
import uuid
@@ -70,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_storage', '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
@@ -129,6 +149,8 @@
else:
skip = True
if "bug" in kwargs and skip is True:
+ if not kwargs['bug'].isdigit():
+ raise ValueError('bug must be a valid bug number')
msg = "Skipped until Bug: %s is resolved." % kwargs["bug"]
raise testtools.TestCase.skipException(msg)
return f(self, *func_args, **func_kwargs)
@@ -222,10 +244,23 @@
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
+
+ class BaseDeps(testtools.TestCase,
+ testtools.testcase.WithAttributes,
+ testresources.ResourcedTestCase,
+ unittest2.TestCase):
+ pass
+
+
+class BaseTestCase(BaseDeps):
setUpClassCalled = False
_service = None
@@ -405,11 +440,16 @@
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()))
+ str(uuid.uuid4())),
+ "expected_result": expected_result
}))
if schema is not None:
for invalid in generate_json.generate_invalid(schema):
@@ -460,16 +500,12 @@
if schema:
valid = generate_json.generate_valid(schema)
new_url, body = self._http_arguments(valid, url, method)
- resp, resp_body = self.client.send_request(method, new_url,
- resources, body=body)
- self._check_negative_response(resp.status, resp_body)
- return
-
- if hasattr(self, "schema"):
+ 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)
+
+ 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))
@@ -510,6 +546,8 @@
: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]))
diff --git a/tempest/tests/fake_config.py b/tempest/tests/fake_config.py
index a50aaeb..42237ca 100644
--- a/tempest/tests/fake_config.py
+++ b/tempest/tests/fake_config.py
@@ -22,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/negative/__init__.py b/tempest/tests/negative/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/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/test_decorators.py b/tempest/tests/test_decorators.py
new file mode 100644
index 0000000..88920dc
--- /dev/null
+++ b/tempest/tests/test_decorators.py
@@ -0,0 +1,238 @@
+# 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='12345')
+
+ def test_skip_because_bug_and_interface_match(self):
+ self._test_skip_because_helper(bug='12346', interface='json')
+
+ def test_skip_because_bug_interface_not_match(self):
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='12347', interface='xml')
+
+ def test_skip_because_bug_and_condition_true(self):
+ self._test_skip_because_helper(bug='12348', condition=True)
+
+ def test_skip_because_bug_and_condition_false(self):
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='12349', 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='12350', 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='12351', 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')
+
+ def test_skip_because_invalid_bug_number(self):
+ """Raise ValueError if with an invalid bug number"""
+ self.assertRaises(ValueError, self._test_skip_because_helper,
+ bug='critical_bug')
+
+
+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_rest_client.py b/tempest/tests/test_rest_client.py
index ead112b..ba43daf 100644
--- a/tempest/tests/test_rest_client.py
+++ b/tempest/tests/test_rest_client.py
@@ -13,11 +13,13 @@
# 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
@@ -26,6 +28,8 @@
class BaseRestClientTestClass(base.TestCase):
+ url = 'fake_endpoint'
+
def _get_region(self):
return 'fake region'
@@ -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/test-requirements.txt b/test-requirements.txt
index 3fe2f27..8d64167 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -3,7 +3,7 @@
docutils==0.9.1
sphinx>=1.1.2,<1.2
python-subunit>=0.0.18
-oslo.sphinx
+oslosphinx
mox>=0.5.3
mock>=1.0
coverage>=3.6
diff --git a/tools/check_logs.py b/tools/check_logs.py
index f3204e3..15988a6 100755
--- a/tools/check_logs.py
+++ b/tools/check_logs.py
@@ -28,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):
@@ -69,6 +69,7 @@
print_log_name = False
if not whitelisted:
had_errors = True
+ print("*** Not Whitelisted ***"),
print(line)
return had_errors
diff --git a/tox.ini b/tox.ini
index 88f2537..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}
@@ -40,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}'