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
diff --git a/tempest/api/baremetal/admin/test_ports_negative.py b/tempest/api/baremetal/admin/test_ports_negative.py
index 8080eb6..07d0fac 100644
--- a/tempest/api/baremetal/admin/test_ports_negative.py
+++ b/tempest/api/baremetal/admin/test_ports_negative.py
@@ -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 @@
         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 @@
         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 @@
         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'])
diff --git a/tempest/api/compute/admin/test_aggregates_negative.py b/tempest/api/compute/admin/test_aggregates_negative.py
index a450e5d..ccd294d 100644
--- a/tempest/api/compute/admin/test_aggregates_negative.py
+++ b/tempest/api/compute/admin/test_aggregates_negative.py
@@ -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 @@
         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 @@
         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'])
diff --git a/tempest/api/compute/admin/test_flavors_access_negative.py b/tempest/api/compute/admin/test_flavors_access_negative.py
index 4ba9eb2..3487503 100644
--- a/tempest/api/compute/admin/test_flavors_access_negative.py
+++ b/tempest/api/compute/admin/test_flavors_access_negative.py
@@ -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 @@
 
         # 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)
diff --git a/tempest/api/compute/admin/test_servers_negative.py b/tempest/api/compute/admin/test_servers_negative.py
index 9800bb4..81dabb1 100644
--- a/tempest/api/compute/admin/test_servers_negative.py
+++ b/tempest/api/compute/admin/test_servers_negative.py
@@ -144,6 +144,6 @@
         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)
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions.py b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
index e6f4fb0..a5990bc 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
@@ -138,6 +138,6 @@
         # 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)
diff --git a/tempest/api/compute/images/test_images_oneserver_negative.py b/tempest/api/compute/images/test_images_oneserver_negative.py
index 46cec9b..700a62f 100644
--- a/tempest/api/compute/images/test_images_oneserver_negative.py
+++ b/tempest/api/compute/images/test_images_oneserver_negative.py
@@ -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 @@
 
         # 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'])
diff --git a/tempest/api/compute/keypairs/test_keypairs_negative.py b/tempest/api/compute/keypairs/test_keypairs_negative.py
index 4e06d6c..374b76c 100644
--- a/tempest/api/compute/keypairs/test_keypairs_negative.py
+++ b/tempest/api/compute/keypairs/test_keypairs_negative.py
@@ -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 @@
         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)
 
diff --git a/tempest/api/compute/servers/test_server_actions.py b/tempest/api/compute/servers/test_server_actions.py
index 9edaede..b32a73b 100644
--- a/tempest/api/compute/servers/test_server_actions.py
+++ b/tempest/api/compute/servers/test_server_actions.py
@@ -18,6 +18,7 @@
 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 @@
         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)
diff --git a/tempest/api/compute/servers/test_server_rescue_negative.py b/tempest/api/compute/servers/test_server_rescue_negative.py
index c01a95c..f2d3d9d 100644
--- a/tempest/api/compute/servers/test_server_rescue_negative.py
+++ b/tempest/api/compute/servers/test_server_rescue_negative.py
@@ -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 @@
         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 @@
 
     @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 @@
         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 @@
         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'])
diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py
index 18c7fc4..27a3257 100644
--- a/tempest/api/compute/servers/test_servers_negative.py
+++ b/tempest/api/compute/servers/test_servers_negative.py
@@ -144,7 +144,7 @@
         # 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 @@
     @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 @@
         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 @@
     @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 @@
     @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 @@
         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 @@
     @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)
diff --git a/tempest/api/identity/admin/test_roles_negative.py b/tempest/api/identity/admin/test_roles_negative.py
index 58f726a..8dc0350 100644
--- a/tempest/api/identity/admin/test_roles_negative.py
+++ b/tempest/api/identity/admin/test_roles_negative.py
@@ -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 @@
         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 @@
         # 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'])
diff --git a/tempest/api/identity/admin/test_tenant_negative.py b/tempest/api/identity/admin/test_tenant_negative.py
index 75f0152..0a62993 100644
--- a/tempest/api/identity/admin/test_tenant_negative.py
+++ b/tempest/api/identity/admin/test_tenant_negative.py
@@ -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 @@
 
         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'])
diff --git a/tempest/api/identity/admin/test_users_negative.py b/tempest/api/identity/admin/test_users_negative.py
index c039da6..71bb9f8 100644
--- a/tempest/api/identity/admin/test_users_negative.py
+++ b/tempest/api/identity/admin/test_users_negative.py
@@ -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 @@
     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)
 
diff --git a/tempest/api/identity/admin/v3/test_projects_negative.py b/tempest/api/identity/admin/v3/test_projects_negative.py
index f5e832b..9b0da6c 100644
--- a/tempest/api/identity/admin/v3/test_projects_negative.py
+++ b/tempest/api/identity/admin/v3/test_projects_negative.py
@@ -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 @@
         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):
diff --git a/tempest/api/network/admin/test_external_networks_negative.py b/tempest/api/network/admin/test_external_networks_negative.py
index 7dbb347..8eb6888 100644
--- a/tempest/api/network/admin/test_external_networks_negative.py
+++ b/tempest/api/network/admin/test_external_networks_negative.py
@@ -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 @@
         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)
diff --git a/tempest/api/network/test_dhcp_ipv6.py b/tempest/api/network/test_dhcp_ipv6.py
index 1257699..f7a6fb7 100644
--- a/tempest/api/network/test_dhcp_ipv6.py
+++ b/tempest/api/network/test_dhcp_ipv6.py
@@ -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 @@
                          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,
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index 65aeb24..4160bd5 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -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 @@
         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'])
diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py
index d571e92..8409f8d 100644
--- a/tempest/api/network/test_routers_negative.py
+++ b/tempest/api/network/test_routers_negative.py
@@ -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 @@
     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'])
 
diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py
index fb51e30..b98f6dd 100644
--- a/tempest/api/network/test_security_groups_negative.py
+++ b/tempest/api/network/test_security_groups_negative.py
@@ -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 @@
     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 @@
 
         # 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)
diff --git a/tempest/cmd/javelin.py b/tempest/cmd/javelin.py
index 889b2dd..094f37e 100755
--- a/tempest/cmd/javelin.py
+++ b/tempest/cmd/javelin.py
@@ -110,6 +110,7 @@
 import unittest
 
 import netaddr
+from tempest_lib import exceptions as lib_exc
 import yaml
 
 import tempest.auth
@@ -297,7 +298,7 @@
             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
 
diff --git a/tempest/common/service_client.py b/tempest/common/service_client.py
index 95101ec..cd7265c 100644
--- a/tempest/common/service_client.py
+++ b/tempest/common/service_client.py
@@ -65,8 +65,6 @@
             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
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index 1baae8b..93e435e 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -163,10 +163,6 @@
     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")
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 8e9f3ea..16f44b5 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -19,6 +19,7 @@
 
 import netaddr
 import six
+from tempest_lib import exceptions as lib_exc
 
 from tempest import auth
 from tempest import clients
@@ -628,7 +629,7 @@
             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 @@
                 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: