Updates common.check_for_exceptions and its calls

Reasons:
- exceptions.from_response has 3 arguments but is being called with
  one argument less, which is url.

Changes:
- Updated common.check_for_exceptions to support urls as needed by
  troveclient.openstack.common.apiclient.exceptions.from_response.
- Adds url to exceptions.from_response calls in troveclient.

Closes-Bug: #1266239

Change-Id: Ie18c90349479f740369f63c48a8d9b463641f84d
This commit is contained in:
Sushil Kumar 2014-01-05 17:45:35 +00:00
parent c6a54f7e1c
commit a35d358240
12 changed files with 31 additions and 31 deletions

View File

@ -16,14 +16,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from troveclient import exceptions
from troveclient.openstack.common.apiclient import exceptions
from troveclient.openstack.common.py3kcompat import urlutils
def check_for_exceptions(resp, body):
def check_for_exceptions(resp, body, url):
if resp.status_code in (400, 422, 500):
raise exceptions.from_response(resp, body)
raise exceptions.from_response(resp, body, url)
def limit_url(url, limit=None, marker=None):

View File

@ -46,7 +46,7 @@ class Accounts(base.ManagerWithFind):
url = "/mgmt/accounts"
resp, body = self.api.client.get(url)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
if not body:
raise Exception("Call to " + url + " did not return a body.")
return base.Resource(self, body)

View File

@ -18,7 +18,7 @@
# under the License.
from troveclient import base
from troveclient.openstack.common.apiclient import exceptions
from troveclient import common
class Backup(base.Resource):
@ -73,6 +73,6 @@ class Backups(base.ManagerWithFind):
:param backup_id: The backup id to delete
"""
resp, body = self.api.client.delete("/backups/%s" % backup_id)
if resp.status_code in (422, 500):
raise exceptions.from_response(resp, body)
url = "/backups/%s" % backup_id
resp, body = self.api.client.delete(url)
common.check_for_exceptions(resp, body, url)

View File

@ -43,13 +43,13 @@ class Databases(base.ManagerWithFind):
body = {"databases": databases}
url = "/instances/%s/databases" % instance_id
resp, body = self.api.client.post(url, body=body)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def delete(self, instance_id, dbname):
"""Delete an existing database in the specified instance"""
url = "/instances/%s/databases/%s" % (instance_id, dbname)
resp, body = self.api.client.delete(url)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def list(self, instance, limit=None, marker=None):
"""

View File

@ -46,7 +46,7 @@ class Hosts(base.ManagerWithFind):
"""
url = "/mgmt/hosts/%s/instances/action" % host_id
resp, body = self.api.client.post(url, body=body)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def update_all(self, host_id):
"""

View File

@ -115,9 +115,9 @@ class Instances(base.ManagerWithFind):
:param instance_id: The instance id to delete
"""
resp, body = self.api.client.delete("/instances/%s" %
base.getid(instance))
common.check_for_exceptions(resp, body)
url = "/instances/%s" % base.getid(instance)
resp, body = self.api.client.delete(url)
common.check_for_exceptions(resp, body, url)
def _action(self, instance_id, body):
"""
@ -125,7 +125,7 @@ class Instances(base.ManagerWithFind):
"""
url = "/instances/%s/action" % instance_id
resp, body = self.api.client.post(url, body=body)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
if body:
return self.resource_class(self, body, loaded=True)
return body

View File

@ -40,7 +40,7 @@ class Limits(base.ManagerWithFind):
resp, body = self.api.client.get(url)
if resp is None or resp.status_code != 200:
raise exceptions.from_response(resp, body)
raise exceptions.from_response(resp, body, url)
if not body:
raise Exception("Call to " + url + " did not return a body.")

View File

@ -82,7 +82,7 @@ class Management(base.ManagerWithFind):
"""
url = "/mgmt/instances/%s/action" % instance_id
resp, body = self.api.client.post(url, body=body)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def stop(self, instance_id):
body = {'stop': {}}

View File

@ -33,7 +33,7 @@ class Quotas(base.ManagerWithFind):
url = "/mgmt/quotas/%s" % tenant_id
resp, body = self.api.client.get(url)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
if not body:
raise Exception("Call to " + url + " did not return a body.")
if 'quotas' not in body:
@ -47,7 +47,7 @@ class Quotas(base.ManagerWithFind):
url = "/mgmt/quotas/%s" % id
body = {"quotas": quotas}
resp, body = self.api.client.put(url, body=body)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
if not body:
raise Exception("Call to " + url + " did not return a body.")
if 'quotas' not in body:

View File

@ -34,13 +34,13 @@ class Root(base.ManagerWithFind):
specified db instance
"""
resp, body = self.api.client.post(self.url % instance_id)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, self.url)
return body['user']['name'], body['user']['password']
def is_root_enabled(self, instance_id):
"""Return whether root is enabled for the instance."""
resp, body = self.api.client.get(self.url % instance_id)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, self.url)
return self.resource_class(self, body, loaded=True)
# Appease the abc gods

View File

@ -96,9 +96,9 @@ class SecurityGroupRules(base.ManagerWithFind):
:param security_group_rule: The security group rule to delete
"""
resp, body = self.api.client.delete("/security-group-rules/%s" %
base.getid(security_group_rule))
common.check_for_exceptions(resp, body)
url = "/security-group-rules/%s" % base.getid(security_group_rule)
resp, body = self.api.client.delete(url)
common.check_for_exceptions(resp, body, url)
# Appease the abc gods
def list(self):

View File

@ -42,14 +42,14 @@ class Users(base.ManagerWithFind):
body = {"users": users}
url = "/instances/%s/users" % instance_id
resp, body = self.api.client.post(url, body=body)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def delete(self, instance_id, username, hostname=None):
"""Delete an existing user in the specified instance"""
user = common.quote_user_host(username, hostname)
url = "/instances/%s/users/%s" % (instance_id, user)
resp, body = self.api.client.delete(url)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def list(self, instance, limit=None, marker=None):
"""
@ -86,7 +86,7 @@ class Users(base.ManagerWithFind):
user_dict['user'] = newuserattr
url = "/instances/%s/users/%s" % (instance_id, user)
resp, body = self.api.client.put(url, body=user_dict)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def list_access(self, instance, username, hostname=None):
"""Show all databases the given user has access to. """
@ -95,7 +95,7 @@ class Users(base.ManagerWithFind):
url = "/instances/%(instance_id)s/users/%(user)s/databases"
local_vars = locals()
resp, body = self.api.client.get(url % local_vars)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
if not body:
raise Exception("Call to %s did not return to a body" % url)
return [databases.Database(self, db) for db in body['databases']]
@ -108,7 +108,7 @@ class Users(base.ManagerWithFind):
dbs = {'databases': [{'name': db} for db in databases]}
local_vars = locals()
resp, body = self.api.client.put(url % local_vars, body=dbs)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def revoke(self, instance, username, database, hostname=None):
"""Revoke from an existing user access permissions to a database."""
@ -118,7 +118,7 @@ class Users(base.ManagerWithFind):
"databases/%(database)s")
local_vars = locals()
resp, body = self.api.client.delete(url % local_vars)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)
def change_passwords(self, instance, users):
"""Change the password for one or more users."""
@ -126,4 +126,4 @@ class Users(base.ManagerWithFind):
user_dict = {"users": users}
url = "/instances/%s/users" % instance_id
resp, body = self.api.client.put(url, body=user_dict)
common.check_for_exceptions(resp, body)
common.check_for_exceptions(resp, body, url)