Change tempest Conflict exc to tempest-lib exc

This commit changes tempest.exceptions.Conflict to
tempest_lib.exceptions.Conflict. This is one of the migrating
rest client to tempest-lib works.

Change-Id: I860a961c442f35ef4a75013e19bfe92f61a587b8
This commit is contained in:
Masayuki Igawa 2015-01-20 14:56:42 +09:00
parent 90c914eb3a
commit d938876e88
23 changed files with 64 additions and 44 deletions

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
from tempest.api.baremetal.admin import base
from tempest.common.utils import data_utils
from tempest import exceptions as exc
@ -62,7 +64,7 @@ class TestPortsNegative(base.BaseBaremetalTest):
uuid = data_utils.rand_uuid()
self.create_port(node_id=node_id, address=address, uuid=uuid)
self.assertRaises(exc.Conflict, self.create_port, node_id=node_id,
self.assertRaises(lib_exc.Conflict, self.create_port, node_id=node_id,
address=address, uuid=uuid)
@test.attr(type=['negative', 'smoke'])
@ -99,7 +101,7 @@ class TestPortsNegative(base.BaseBaremetalTest):
node_id = self.node['uuid']
address = data_utils.rand_mac_address()
self.create_port(node_id=node_id, address=address)
self.assertRaises(exc.Conflict,
self.assertRaises(lib_exc.Conflict,
self.create_port, node_id=node_id,
address=address)
@ -190,7 +192,7 @@ class TestPortsNegative(base.BaseBaremetalTest):
patch = [{'path': '/address',
'op': 'replace',
'value': address1}]
self.assertRaises(exc.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.update_port, port_id, patch)
@test.attr(type=['negative', 'smoke'])

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
from tempest.api.compute import base
from tempest.common import tempest_fixtures as fixtures
from tempest.common.utils import data_utils
@ -69,7 +71,7 @@ class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
aggregate = self.client.create_aggregate(name=aggregate_name)
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.create_aggregate,
name=aggregate_name)
@ -151,7 +153,7 @@ class AggregatesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
self.client.add_host(aggregate['id'], self.host)
self.addCleanup(self.client.remove_host, aggregate['id'], self.host)
self.assertRaises(exceptions.Conflict, self.client.add_host,
self.assertRaises(lib_exc.Conflict, self.client.add_host,
aggregate['id'], self.host)
@test.attr(type=['negative', 'gate'])

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
import uuid
from tempest.api.compute import base
@ -112,7 +113,7 @@ class FlavorsAccessNegativeTestJSON(base.BaseV2ComputeAdminTest):
# An exception should be raised when adding flavor access to the same
# tenant
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.add_flavor_access,
new_flavor['id'],
self.tenant_id)

View File

@ -144,6 +144,6 @@ class ServersAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
self.assertEqual(202, resp.status)
self.client.wait_for_server_status(server_id, 'SUSPENDED')
# migrate an suspended server should fail
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.migrate_server,
server_id)

View File

@ -138,6 +138,6 @@ class FloatingIPsTestJSON(base.BaseFloatingIPsTest):
# Make sure no longer associated with old server
self.assertRaises((exceptions.NotFound,
lib_exc.UnprocessableEntity,
exceptions.Conflict),
lib_exc.Conflict),
self.client.disassociate_floating_ip_from_server,
self.floating_ip, self.server_id)

View File

@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
from tempest.api.compute import base
from tempest.common.utils import data_utils
from tempest import config
@ -102,7 +104,7 @@ class ImagesOneServerNegativeTestJSON(base.BaseV2ComputeTest):
# Create second snapshot
alt_snapshot_name = data_utils.rand_name('test-snap-')
self.assertRaises(exceptions.Conflict, self.client.create_image,
self.assertRaises(lib_exc.Conflict, self.client.create_image,
self.server_id, alt_snapshot_name)
@test.attr(type=['negative', 'gate'])

View File

@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
from tempest.api.compute import base
from tempest.common.utils import data_utils
from tempest import exceptions
@ -68,7 +70,7 @@ class KeyPairsNegativeTestJSON(base.BaseV2ComputeTest):
k_name = data_utils.rand_name('keypair-')
self.client.create_keypair(k_name)
# Now try the same keyname to create another key
self.assertRaises(exceptions.Conflict, self._create_keypair,
self.assertRaises(lib_exc.Conflict, self._create_keypair,
k_name)
self.client.delete_keypair(k_name)

View File

@ -18,6 +18,7 @@ import logging
import urlparse
from tempest_lib import decorators
from tempest_lib import exceptions as lib_exc
import testtools
from tempest.api.compute import base
@ -464,7 +465,7 @@ class ServerActionsTestJSON(base.BaseV2ComputeTest):
self.assertEqual(200, resp.status)
self.assertEqual(server['status'], 'ACTIVE')
# Locked server is not allowed to be stopped by non-admin user
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.servers_client.stop, self.server_id)
resp, server = self.servers_client.unlock_server(self.server_id)
self.assertEqual(202, resp.status)

View File

@ -12,6 +12,8 @@
# 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_lib import exceptions as lib_exc
import testtools
from tempest.api.compute import base
@ -81,13 +83,13 @@ class ServerRescueNegativeTestJSON(base.BaseV2ComputeTest):
self.addCleanup(self._unpause, self.server_id)
self.assertEqual(202, resp.status)
self.servers_client.wait_for_server_status(self.server_id, 'PAUSED')
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.servers_client.rescue_server,
self.server_id)
@test.attr(type=['negative', 'gate'])
def test_rescued_vm_reboot(self):
self.assertRaises(exceptions.Conflict, self.servers_client.reboot,
self.assertRaises(lib_exc.Conflict, self.servers_client.reboot,
self.rescue_id, 'HARD')
@test.attr(type=['negative', 'gate'])
@ -100,7 +102,7 @@ class ServerRescueNegativeTestJSON(base.BaseV2ComputeTest):
@test.attr(type=['negative', 'gate'])
def test_rescued_vm_rebuild(self):
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.servers_client.rebuild,
self.rescue_id,
self.image_ref_alt)
@ -117,7 +119,7 @@ class ServerRescueNegativeTestJSON(base.BaseV2ComputeTest):
self.addCleanup(self._unrescue, self.server_id)
# Attach the volume to the server
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.servers_client.attach_volume,
self.server_id,
volume['id'],
@ -144,7 +146,7 @@ class ServerRescueNegativeTestJSON(base.BaseV2ComputeTest):
self.addCleanup(self._unrescue, self.server_id)
# Detach the volume from the server expecting failure
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.servers_client.detach_volume,
self.server_id,
volume['id'])

View File

@ -144,7 +144,7 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
# Pause a paused server.
self.client.pause_server(self.server_id)
self.client.wait_for_server_status(self.server_id, 'PAUSED')
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.pause_server,
self.server_id)
self.client.unpause_server(self.server_id)
@ -328,7 +328,7 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
@test.attr(type=['negative', 'gate'])
def test_unpause_server_invalid_state(self):
# unpause an active server.
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.unpause_server,
self.server_id)
@ -349,7 +349,7 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
resp, _ = self.client.suspend_server(self.server_id)
self.assertEqual(202, resp.status)
self.client.wait_for_server_status(self.server_id, 'SUSPENDED')
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.suspend_server,
self.server_id)
self.client.resume_server(self.server_id)
@ -368,7 +368,7 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
@test.attr(type=['negative', 'gate'])
def test_resume_server_invalid_state(self):
# resume an active server.
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.resume_server,
self.server_id)
@ -399,7 +399,7 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
@test.attr(type=['negative', 'gate'])
def test_restore_server_invalid_state(self):
# we can only restore-delete a server in 'soft-delete' state
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.restore_soft_deleted_server,
self.server_id)
@ -436,7 +436,7 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
self.assertEqual(1, len(images))
self.assertEqual(image_name, images[0]['name'])
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.shelve_server,
self.server_id)
@ -456,6 +456,6 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
@test.attr(type=['negative', 'gate'])
def test_unshelve_server_invalid_state(self):
# unshelve an active server.
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.unshelve_server,
self.server_id)

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
import uuid
from tempest.api.identity import base
@ -75,7 +76,7 @@ class RolesNegativeTestJSON(base.BaseIdentityV2AdminTest):
body = self.client.create_role(role_name)
role1_id = body.get('id')
self.addCleanup(self.client.delete_role, role1_id)
self.assertRaises(exceptions.Conflict, self.client.create_role,
self.assertRaises(lib_exc.Conflict, self.client.create_role,
role_name)
@test.attr(type=['negative', 'gate'])
@ -150,7 +151,7 @@ class RolesNegativeTestJSON(base.BaseIdentityV2AdminTest):
# Duplicate user role should not get assigned
(user, tenant, role) = self._get_role_params()
self.client.assign_user_role(tenant['id'], user['id'], role['id'])
self.assertRaises(exceptions.Conflict, self.client.assign_user_role,
self.assertRaises(lib_exc.Conflict, self.client.assign_user_role,
tenant['id'], user['id'], role['id'])
@test.attr(type=['negative', 'gate'])

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
import uuid
from tempest.api.identity import base
@ -76,7 +77,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
self.addCleanup(self.client.delete_tenant, tenant1_id)
self.addCleanup(self.data.tenants.remove, tenant)
self.assertRaises(exceptions.Conflict, self.client.create_tenant,
self.assertRaises(lib_exc.Conflict, self.client.create_tenant,
tenant_name)
@test.attr(type=['negative', 'gate'])

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
import uuid
from tempest.api.identity import base
@ -60,7 +61,7 @@ class UsersNegativeTestJSON(base.BaseIdentityV2AdminTest):
def test_create_user_with_duplicate_name(self):
# Duplicate user should not be created
self.data.setup_test_user()
self.assertRaises(exceptions.Conflict, self.client.create_user,
self.assertRaises(lib_exc.Conflict, self.client.create_user,
self.data.test_user, self.data.test_password,
self.data.tenant['id'], self.data.test_email)

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
from tempest.api.identity import base
from tempest.common.utils import data_utils
from tempest import exceptions
@ -36,7 +38,7 @@ class ProjectsNegativeTestJSON(base.BaseIdentityV3AdminTest):
self.data.projects.append(project)
self.assertRaises(
exceptions.Conflict, self.client.create_project, project_name)
lib_exc.Conflict, self.client.create_project, project_name)
@test.attr(type=['negative', 'gate'])
def test_create_project_by_unauthorized_user(self):

View File

@ -13,9 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest_lib import exceptions as lib_exc
from tempest.api.network import base
from tempest import config
from tempest import exceptions
from tempest import test
CONF = config.CONF
@ -47,7 +48,7 @@ class ExternalNetworksAdminNegativeTestJSON(base.BaseAdminNetworkTest):
fixed_ips = [{'ip_address': floating_ip_address}]
# create a port which will internally create an instance-ip
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
client.create_port,
network_id=CONF.network.public_network_id,
fixed_ips=fixed_ips)

View File

@ -16,6 +16,8 @@
import netaddr
import random
from tempest_lib import exceptions as lib_exc
from tempest.api.network import base
from tempest.common.utils import data_utils
from tempest import config
@ -348,7 +350,7 @@ class NetworksTestDHCPv6(base.BaseNetworkTest):
fixed_ips=[
{'subnet_id': subnet['id'],
'ip_address': ip}])
self.assertRaisesRegexp(exceptions.Conflict,
self.assertRaisesRegexp(lib_exc.Conflict,
"object with that identifier already exists",
self.create_port,
self.network,

View File

@ -15,6 +15,7 @@
import itertools
import netaddr
from tempest_lib import exceptions as lib_exc
from tempest.api.network import base
from tempest.common import custom_matchers
@ -614,7 +615,7 @@ class NetworksIpV6TestAttrs(NetworksIpV6TestJSON):
self.assertNotIn(subnet_slaac['id'], subnet_ids,
"Subnet wasn't deleted")
self.assertRaisesRegexp(
exceptions.Conflict,
lib_exc.Conflict,
"There are one or more ports still in use on the network",
self.client.delete_network,
slaac_network['id'])

View File

@ -14,6 +14,7 @@
# under the License.
import netaddr
from tempest_lib import exceptions as lib_exc
from tempest.api.network import base_routers as base
from tempest.common.utils import data_utils
@ -79,7 +80,7 @@ class RoutersNegativeTest(base.BaseRouterTest):
def test_router_remove_interface_in_use_returns_409(self):
self.client.add_router_interface_with_subnet_id(
self.router['id'], self.subnet['id'])
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.delete_router,
self.router['id'])

View File

@ -15,6 +15,8 @@
import uuid
from tempest_lib import exceptions as lib_exc
from tempest.api.network import base_security_groups as base
from tempest import config
from tempest import exceptions
@ -152,7 +154,7 @@ class NegativeSecGroupTest(base.BaseSecGroupTest):
def test_create_additional_default_security_group_fails(self):
# Create security group named 'default', it should be failed.
name = 'default'
self.assertRaises(exceptions.Conflict,
self.assertRaises(lib_exc.Conflict,
self.client.create_security_group,
name=name)
@ -175,7 +177,7 @@ class NegativeSecGroupTest(base.BaseSecGroupTest):
# Try creating the same security group rule, it should fail
self.assertRaises(
exceptions.Conflict, self.client.create_security_group_rule,
lib_exc.Conflict, self.client.create_security_group_rule,
security_group_id=body['security_group']['id'],
protocol='tcp', direction='ingress', ethertype=self.ethertype,
port_range_min=min_port, port_range_max=max_port)

View File

@ -110,6 +110,7 @@ import sys
import unittest
import netaddr
from tempest_lib import exceptions as lib_exc
import yaml
import tempest.auth
@ -297,7 +298,7 @@ def _assign_swift_role(user):
USERS[user]['tenant_id'],
USERS[user]['id'],
role['id'])
except exceptions.Conflict:
except lib_exc.Conflict:
# don't care if it's already assigned
pass

View File

@ -65,8 +65,6 @@ class ServiceClient(rest_client.RestClient):
raise exceptions.NotFound(ex)
except lib_exceptions.BadRequest as ex:
raise exceptions.BadRequest(ex)
except lib_exceptions.Conflict as ex:
raise exceptions.Conflict(ex)
# TODO(oomichi): This is just a workaround for failing gate tests
# when separating Forbidden from Unauthorized in tempest-lib.
# We will need to remove this translation and replace negative tests

View File

@ -163,10 +163,6 @@ class BadRequest(RestClientException):
message = "Bad request"
class Conflict(RestClientException):
message = "An object with that identifier already exists"
class ResponseWithNonEmptyBody(RFCViolation):
message = ("RFC Violation! Response with %(status)d HTTP Status Code "
"MUST NOT have a body")

View File

@ -19,6 +19,7 @@ import subprocess
import netaddr
import six
from tempest_lib import exceptions as lib_exc
from tempest import auth
from tempest import clients
@ -628,7 +629,7 @@ class NetworkScenarioTest(ScenarioTest):
try:
result = client.create_subnet(**subnet)
break
except exceptions.Conflict as e:
except lib_exc.Conflict as e:
is_overlapping_cidr = 'overlaps with another subnet' in str(e)
if not is_overlapping_cidr:
raise
@ -915,7 +916,7 @@ class NetworkScenarioTest(ScenarioTest):
try:
sg_rule = self._create_security_group_rule(
client=client, secgroup=secgroup, **ruleset)
except exceptions.Conflict as ex:
except lib_exc.Conflict as ex:
# if rule already exist - skip rule and continue
msg = 'Security group rule already exists'
if msg not in ex._error_string: