From a35d35824045f3e05d101cb759f59a691848085b Mon Sep 17 00:00:00 2001 From: Sushil Kumar Date: Sun, 5 Jan 2014 17:45:35 +0000 Subject: [PATCH] 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 --- troveclient/common.py | 6 +++--- troveclient/v1/accounts.py | 2 +- troveclient/v1/backups.py | 8 ++++---- troveclient/v1/databases.py | 4 ++-- troveclient/v1/hosts.py | 2 +- troveclient/v1/instances.py | 8 ++++---- troveclient/v1/limits.py | 2 +- troveclient/v1/management.py | 2 +- troveclient/v1/quota.py | 4 ++-- troveclient/v1/root.py | 4 ++-- troveclient/v1/security_groups.py | 6 +++--- troveclient/v1/users.py | 14 +++++++------- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/troveclient/common.py b/troveclient/common.py index a3ffd8e4..8869dbfd 100644 --- a/troveclient/common.py +++ b/troveclient/common.py @@ -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): diff --git a/troveclient/v1/accounts.py b/troveclient/v1/accounts.py index b0a606a4..6b76ac25 100644 --- a/troveclient/v1/accounts.py +++ b/troveclient/v1/accounts.py @@ -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) diff --git a/troveclient/v1/backups.py b/troveclient/v1/backups.py index 04f13c34..0b23e346 100644 --- a/troveclient/v1/backups.py +++ b/troveclient/v1/backups.py @@ -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) diff --git a/troveclient/v1/databases.py b/troveclient/v1/databases.py index 8089230d..32eaacff 100644 --- a/troveclient/v1/databases.py +++ b/troveclient/v1/databases.py @@ -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): """ diff --git a/troveclient/v1/hosts.py b/troveclient/v1/hosts.py index 98897993..ada421a2 100644 --- a/troveclient/v1/hosts.py +++ b/troveclient/v1/hosts.py @@ -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): """ diff --git a/troveclient/v1/instances.py b/troveclient/v1/instances.py index fad73314..4e2c4e4d 100644 --- a/troveclient/v1/instances.py +++ b/troveclient/v1/instances.py @@ -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 diff --git a/troveclient/v1/limits.py b/troveclient/v1/limits.py index 252daf3d..beb6b26a 100644 --- a/troveclient/v1/limits.py +++ b/troveclient/v1/limits.py @@ -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.") diff --git a/troveclient/v1/management.py b/troveclient/v1/management.py index 38c7c964..183c545a 100644 --- a/troveclient/v1/management.py +++ b/troveclient/v1/management.py @@ -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': {}} diff --git a/troveclient/v1/quota.py b/troveclient/v1/quota.py index 46c10300..edbc0109 100644 --- a/troveclient/v1/quota.py +++ b/troveclient/v1/quota.py @@ -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: diff --git a/troveclient/v1/root.py b/troveclient/v1/root.py index 297af59f..46e52189 100644 --- a/troveclient/v1/root.py +++ b/troveclient/v1/root.py @@ -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 diff --git a/troveclient/v1/security_groups.py b/troveclient/v1/security_groups.py index 0caf2771..a7dd61a6 100644 --- a/troveclient/v1/security_groups.py +++ b/troveclient/v1/security_groups.py @@ -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): diff --git a/troveclient/v1/users.py b/troveclient/v1/users.py index 2da58d04..357b9298 100644 --- a/troveclient/v1/users.py +++ b/troveclient/v1/users.py @@ -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)