Merge "Test updating port's admin_state_up"
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 fe4959b..2443399 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -825,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/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/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/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_networks.py b/tempest/api/network/test_networks.py
index 218f9c0..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()
@@ -213,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()
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/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 cf4e052..f4b2d4c 100644
--- a/tempest/api/volume/test_volume_transfers.py
+++ b/tempest/api/volume/test_volume_transfers.py
@@ -49,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
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/test_volumes_list.py b/tempest/api/volume/v2/test_volumes_list.py
index 049544d..d0e8b99 100644
--- a/tempest/api/volume/v2/test_volumes_list.py
+++ b/tempest/api/volume/v2/test_volumes_list.py
@@ -23,10 +23,10 @@
LOG = logging.getLogger(__name__)
-VOLUME_FIELDS = ('id', 'display_name')
+VOLUME_FIELDS = ('id', 'name')
-class VolumesListTest(base.BaseVolumeV1Test):
+class VolumesV2ListTestJSON(base.BaseVolumeV2Test):
"""
This test creates a number of 1G volumes. To run successfully,
@@ -48,7 +48,7 @@
return
def str_vol(vol):
- return "%s:%s" % (vol['id'], vol['display_name'])
+ 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],
@@ -57,7 +57,7 @@
@classmethod
def setUpClass(cls):
- super(VolumesListTest, cls).setUpClass()
+ super(VolumesV2ListTestJSON, cls).setUpClass()
cls.client = cls.volumes_client
# Create 3 test volumes
@@ -67,7 +67,6 @@
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'])
@@ -90,9 +89,10 @@
for volid in cls.volume_id_list:
resp, _ = cls.client.delete_volume(volid)
cls.client.wait_for_resource_deletion(volid)
- super(VolumesListTest, cls).tearDownClass()
+ super(VolumesV2ListTestJSON, cls).tearDownClass()
- def _list_by_param_value_and_assert(self, params, with_detail=False):
+ 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.
@@ -104,17 +104,22 @@
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
- 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)
+ 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):
@@ -136,64 +141,44 @@
@attr(type='gate')
def test_volume_list_by_name(self):
volume = self.volume_list[data_utils.rand_int_id(0, 2)]
- params = {'display_name': volume['display_name']}
+ 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]['display_name'],
- volume['display_name'])
+ 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 = {'display_name': volume['display_name']}
+ 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]['display_name'],
- volume['display_name'])
+ self.assertEqual(fetched_vol[0]['name'], volume['name'])
@attr(type='gate')
def test_volumes_list_by_status(self):
params = {'status': 'available'}
- resp, fetched_list = self.client.list_volumes(params)
- self.assertEqual(200, resp.status)
- for volume in fetched_list:
- self.assertEqual('available', volume['status'])
- self.assertVolumesIn(fetched_list, self.volume_list,
- fields=VOLUME_FIELDS)
+ self._list_by_param_value_and_assert(params)
@attr(type='gate')
def test_volumes_list_details_by_status(self):
params = {'status': 'available'}
- resp, fetched_list = self.client.list_volumes_with_detail(params)
- self.assertEqual(200, resp.status)
- for volume in fetched_list:
- self.assertEqual('available', volume['status'])
- self.assertVolumesIn(fetched_list, self.volume_list)
+ 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}
- resp, fetched_list = self.client.list_volumes(params)
- self.assertEqual(200, resp.status)
- for volume in fetched_list:
- self.assertEqual(zone, volume['availability_zone'])
- self.assertVolumesIn(fetched_list, self.volume_list,
- fields=VOLUME_FIELDS)
+ 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}
- resp, fetched_list = self.client.list_volumes_with_detail(params)
- self.assertEqual(200, resp.status)
- for volume in fetched_list:
- self.assertEqual(zone, volume['availability_zone'])
- self.assertVolumesIn(fetched_list, self.volume_list)
+ self._list_by_param_value_and_assert(params, with_detail=True)
@attr(type='gate')
def test_volume_list_with_param_metadata(self):
@@ -211,18 +196,19 @@
def test_volume_list_param_display_name_and_status(self):
# Test to list volume when display name and status param is given
volume = self.volume_list[data_utils.rand_int_id(0, 2)]
- params = {'display_name': volume['display_name'],
+ params = {'name': volume['name'],
'status': 'available'}
- self._list_by_param_value_and_assert(params)
+ 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 = {'display_name': volume['display_name'],
+ params = {'name': volume['name'],
'status': 'available'}
- self._list_by_param_value_and_assert(params, with_detail=True)
+ self._list_by_param_value_and_assert(params, expected_list=[volume],
+ with_detail=True)
-class VolumeListTestXML(VolumesListTest):
+class VolumesV2ListTestXML(VolumesV2ListTestJSON):
_interface = 'xml'
diff --git a/tempest/auth.py b/tempest/auth.py
index 90017c1..582cfdd 100644
--- a/tempest/auth.py
+++ b/tempest/auth.py
@@ -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
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 033fe70..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):
"""
@@ -150,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):
@@ -159,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):
@@ -218,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
@@ -248,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(
@@ -265,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)
@@ -390,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."""
@@ -415,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):
@@ -440,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 d24ab34..fa051d5 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -392,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"),
]
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/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 bc9db38..62c7d2f 100644
--- a/tempest/services/image/v1/json/image_client.py
+++ b/tempest/services/image/v1/json/image_client.py
@@ -241,7 +241,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 +252,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 b825519..58819d0 100644
--- a/tempest/services/image/v2/json/image_client.py
+++ b/tempest/services/image/v2/json/image_client.py
@@ -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 96b9b1d..07716fa 100644
--- a/tempest/services/network/network_client_base.py
+++ b/tempest/services/network/network_client_base.py
@@ -115,9 +115,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 e9208b7..efac5f5 100644
--- a/tempest/services/object_storage/account_client.py
+++ b/tempest/services/object_storage/account_client.py
@@ -58,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 95b428b..f224407 100644
--- a/tempest/services/object_storage/container_client.py
+++ b/tempest/services/object_storage/container_client.py
@@ -181,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 b70b2e8..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):
@@ -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/json/volumes_client.py b/tempest/services/volume/v2/json/volumes_client.py
index 0524212..bd98402 100644
--- a/tempest/services/volume/v2/json/volumes_client.py
+++ b/tempest/services/volume/v2/json/volumes_client.py
@@ -24,14 +24,15 @@
CONF = config.CONF
-class VolumesClientJSON(RestClient):
+class VolumesV2ClientJSON(RestClient):
"""
- Client class to send CRUD Volume API requests to a Cinder endpoint
+ Client class to send CRUD Volume V2 API requests to a Cinder endpoint
"""
def __init__(self, auth_provider):
- super(VolumesClientJSON, self).__init__(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
@@ -72,7 +73,7 @@
Creates a new Volume.
size(Required): Size of volume in GB.
Following optional keyword arguments are accepted:
- display_name: Optional Volume Name.
+ 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
@@ -81,15 +82,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 +105,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 +117,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 +125,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 +133,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,13 +141,13 @@
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):
"""Waits for a Volume to reach a given status."""
resp, body = self.get_volume(volume_id)
- volume_name = body['display_name']
+ volume_name = body['name']
volume_status = body['status']
start = int(time.time())
@@ -178,48 +178,43 @@
}
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):
+ def create_volume_transfer(self, vol_id, name=None):
"""Create a volume transfer."""
post_body = {
'volume_id': vol_id
}
- if display_name:
- post_body['name'] = display_name
+ if name:
+ post_body['name'] = 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 +238,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 +249,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 +277,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 +285,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/xml/volumes_client.py b/tempest/services/volume/v2/xml/volumes_client.py
index deb56fd..69e3f5b 100644
--- a/tempest/services/volume/v2/xml/volumes_client.py
+++ b/tempest/services/volume/v2/xml/volumes_client.py
@@ -30,13 +30,15 @@
CONF = config.CONF
-class VolumesClientXML(RestClientXML):
+class VolumesV2ClientXML(RestClientXML):
"""
Client class to send CRUD Volume API requests to a Cinder endpoint
"""
def __init__(self, auth_provider):
- super(VolumesClientXML, self).__init__(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
@@ -87,13 +89,11 @@
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:
volumes += [self._parse_volume(vol) for vol in list(body)]
- for v in volumes:
- v = self._check_if_bootable(v)
return resp, volumes
def list_volumes_with_detail(self, params=None):
@@ -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
@@ -124,7 +124,7 @@
"""Creates a new Volume.
:param size: Size of volume in GB. (Required)
- :param display_name: Optional Volume Name.
+ :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
@@ -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,27 +278,26 @@
"""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
- def create_volume_transfer(self, vol_id, display_name=None):
+ def create_volume_transfer(self, vol_id, name=None):
"""Create a volume transfer."""
post_body = Element("transfer",
volume_id=vol_id)
- if display_name:
- post_body.add_attr('name', display_name)
+ if name:
+ post_body.add_attr('name', 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/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..dcba226 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
@@ -222,10 +242,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 +438,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 +498,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 +544,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/test_decorators.py b/tempest/tests/test_decorators.py
new file mode 100644
index 0000000..7fb38ff
--- /dev/null
+++ b/tempest/tests/test_decorators.py
@@ -0,0 +1,233 @@
+# Copyright 2013 IBM Corp.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+import testtools
+
+from tempest import exceptions
+from tempest.openstack.common.fixture import mockpatch
+from tempest import test
+from tempest.tests import base
+from tempest.tests import fake_config
+
+
+class BaseDecoratorsTest(base.TestCase):
+ def setUp(self):
+ super(BaseDecoratorsTest, self).setUp()
+ self.stubs.Set(test, 'CONF', fake_config.FakeConfig)
+
+
+class TestAttrDecorator(BaseDecoratorsTest):
+ def _test_attr_helper(self, expected_attrs, **decorator_args):
+ @test.attr(**decorator_args)
+ def foo():
+ pass
+
+ # By our test.attr decorator the attribute __testtools_attrs will be
+ # set only for 'type' argument, so we test it first.
+ if 'type' in decorator_args:
+ # this is what testtools sets
+ self.assertEqual(getattr(foo, '__testtools_attrs'),
+ set(expected_attrs))
+
+ # nose sets it anyway
+ for arg, value in decorator_args.items():
+ self.assertEqual(getattr(foo, arg), value)
+
+ def test_attr_without_type(self):
+ self._test_attr_helper(expected_attrs='baz', bar='baz')
+
+ def test_attr_decorator_with_smoke_type(self):
+ # smoke passed as type, so smoke and gate must have been set.
+ self._test_attr_helper(expected_attrs=['smoke', 'gate'], type='smoke')
+
+ def test_attr_decorator_with_list_type(self):
+ # if type is 'smoke' we'll get the original list of types plus 'gate'
+ self._test_attr_helper(expected_attrs=['smoke', 'foo', 'gate'],
+ type=['smoke', 'foo'])
+
+ def test_attr_decorator_with_unknown_type(self):
+ self._test_attr_helper(expected_attrs=['foo'], type='foo')
+
+ def test_attr_decorator_with_duplicated_type(self):
+ self._test_attr_helper(expected_attrs=['foo'], type=['foo', 'foo'])
+
+
+class TestServicesDecorator(BaseDecoratorsTest):
+ def _test_services_helper(self, *decorator_args):
+ class TestFoo(test.BaseTestCase):
+ @test.services(*decorator_args)
+ def test_bar(self):
+ return 0
+
+ t = TestFoo('test_bar')
+ self.assertEqual(set(decorator_args), getattr(t.test_bar,
+ '__testtools_attrs'))
+ self.assertEqual(list(decorator_args), t.test_bar.type)
+ self.assertEqual(t.test_bar(), 0)
+
+ def test_services_decorator_with_single_service(self):
+ self._test_services_helper('compute')
+
+ def test_services_decorator_with_multiple_services(self):
+ self._test_services_helper('compute', 'network')
+
+ def test_services_decorator_with_duplicated_service(self):
+ self._test_services_helper('compute', 'compute')
+
+ def test_services_decorator_with_invalid_service(self):
+ self.assertRaises(exceptions.InvalidServiceTag,
+ self._test_services_helper, 'compute',
+ 'bad_service')
+
+ def test_services_decorator_with_service_valid_and_unavailable(self):
+ self.useFixture(mockpatch.PatchObject(test.CONF.service_available,
+ 'cinder', False))
+ self.assertRaises(testtools.TestCase.skipException,
+ self._test_services_helper, 'compute',
+ 'volume')
+
+
+class TestStressDecorator(BaseDecoratorsTest):
+ def _test_stresstest_helper(self, expected_frequency='process',
+ expected_inheritance=False,
+ **decorator_args):
+ @test.stresstest(**decorator_args)
+ def foo():
+ pass
+ self.assertEqual(getattr(foo, 'st_class_setup_per'),
+ expected_frequency)
+ self.assertEqual(getattr(foo, 'st_allow_inheritance'),
+ expected_inheritance)
+ self.assertEqual(foo.type, 'stress')
+ self.assertEqual(set(['stress']), getattr(foo, '__testtools_attrs'))
+
+ def test_stresstest_decorator_default(self):
+ self._test_stresstest_helper()
+
+ def test_stresstest_decorator_class_setup_frequency(self):
+ self._test_stresstest_helper('process', class_setup_per='process')
+
+ def test_stresstest_decorator_class_setup_frequency_non_default(self):
+ self._test_stresstest_helper(expected_frequency='application',
+ class_setup_per='application')
+
+ def test_stresstest_decorator_set_frequency_and_inheritance(self):
+ self._test_stresstest_helper(expected_frequency='application',
+ expected_inheritance=True,
+ class_setup_per='application',
+ allow_inheritance=True)
+
+
+class TestSkipBecauseDecorator(BaseDecoratorsTest):
+ def _test_skip_because_helper(self, expected_to_skip=True,
+ **decorator_args):
+ class TestFoo(test.BaseTestCase):
+ _interface = 'json'
+
+ @test.skip_because(**decorator_args)
+ def test_bar(self):
+ return 0
+
+ t = TestFoo('test_bar')
+ if expected_to_skip:
+ self.assertRaises(testtools.TestCase.skipException, t.test_bar)
+ else:
+ # assert that test_bar returned 0
+ self.assertEqual(TestFoo('test_bar').test_bar(), 0)
+
+ def test_skip_because_bug(self):
+ self._test_skip_because_helper(bug='critical_bug')
+
+ def test_skip_because_bug_and_interface_match(self):
+ self._test_skip_because_helper(bug='critical_bug', interface='json')
+
+ def test_skip_because_bug_interface_not_match(self):
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='critical_bug', interface='xml')
+
+ def test_skip_because_bug_and_condition_true(self):
+ self._test_skip_because_helper(bug='critical_bug', condition=True)
+
+ def test_skip_because_bug_and_condition_false(self):
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='critical_bug', condition=False)
+
+ def test_skip_because_bug_condition_false_and_interface_match(self):
+ """
+ Assure that only condition will be evaluated if both parameters are
+ passed.
+ """
+ self._test_skip_because_helper(expected_to_skip=False,
+ bug='critical_bug', condition=False,
+ interface='json')
+
+ def test_skip_because_bug_condition_true_and_interface_not_match(self):
+ """
+ Assure that only condition will be evaluated if both parameters are
+ passed.
+ """
+ self._test_skip_because_helper(bug='critical_bug', condition=True,
+ interface='xml')
+
+ def test_skip_because_bug_without_bug_never_skips(self):
+ """Never skip without a bug parameter."""
+ self._test_skip_because_helper(expected_to_skip=False,
+ condition=True)
+ self._test_skip_because_helper(expected_to_skip=False,
+ interface='json')
+
+
+class TestRequiresExtDecorator(BaseDecoratorsTest):
+ def setUp(self):
+ super(TestRequiresExtDecorator, self).setUp()
+ self.fixture = self.useFixture(mockpatch.PatchObject(
+ test.CONF.compute_feature_enabled,
+ 'api_extensions',
+ new=['enabled_ext', 'another_ext']))
+
+ def _test_requires_ext_helper(self, expected_to_skip=True,
+ **decorator_args):
+ class TestFoo(test.BaseTestCase):
+ @test.requires_ext(**decorator_args)
+ def test_bar(self):
+ return 0
+
+ t = TestFoo('test_bar')
+ if expected_to_skip:
+ self.assertRaises(testtools.TestCase.skipException, t.test_bar)
+ else:
+ self.assertEqual(t.test_bar(), 0)
+
+ def test_requires_ext_decorator(self):
+ self._test_requires_ext_helper(expected_to_skip=False,
+ extension='enabled_ext',
+ service='compute')
+
+ def test_requires_ext_decorator_disabled_ext(self):
+ self._test_requires_ext_helper(extension='disabled_ext',
+ service='compute')
+
+ def test_requires_ext_decorator_with_all_ext_enabled(self):
+ # disable fixture so the default (all) is used.
+ self.fixture.cleanUp()
+ self._test_requires_ext_helper(expected_to_skip=False,
+ extension='random_ext',
+ service='compute')
+
+ def test_requires_ext_decorator_bad_service(self):
+ self.assertRaises(KeyError,
+ self._test_requires_ext_helper,
+ extension='enabled_ext',
+ service='bad_service')
diff --git a/tempest/tests/test_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