From: Dan Wendlandt Date: Tue, 30 Aug 2011 01:59:14 +0000 (-0700) Subject: lp835216 client lib was not passing in kwargs when creating exceptions X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8e86ccf37dc8c54dd5a3f7df1b21db417f9dd7aa;p=openstack-build%2Fneutron-build.git lp835216 client lib was not passing in kwargs when creating exceptions --- diff --git a/quantum/client.py b/quantum/client.py index 92c1be23d..ffcb3a3b6 100644 --- a/quantum/client.py +++ b/quantum/client.py @@ -32,8 +32,8 @@ EXCEPTIONS = { 421: exceptions.NetworkInUse, 430: exceptions.PortNotFound, 431: exceptions.StateInvalid, - 432: exceptions.PortInUse, - 440: exceptions.AlreadyAttached} + 432: exceptions.PortInUseClient, + 440: exceptions.AlreadyAttachedClient} class ApiCall(object): @@ -131,7 +131,7 @@ class Client(object): return conn.getresponse() def do_request(self, method, action, body=None, - headers=None, params=None): + headers=None, params=None, exception_args={}): """ Connects to the server and issues a request. Returns the result data, or raises an appropriate exception if @@ -190,7 +190,7 @@ class Client(object): LOG.debug("Error message: %s", error_message) # Create exception with HTTP status code and message if res.status in EXCEPTIONS: - raise EXCEPTIONS[res.status]() + raise EXCEPTIONS[res.status](**exception_args) # Add error code and message to exception arguments ex = Exception("Server returned error: %s" % status_code) ex.args = ([dict(status_code=status_code, @@ -254,7 +254,8 @@ class Client(object): """ Fetches the details of a certain network """ - return self.do_request("GET", self.network_path % (network)) + return self.do_request("GET", self.network_path % (network), + exception_args={"net_id": network}) @ApiCall def create_network(self, body=None): @@ -268,14 +269,16 @@ class Client(object): """ Updates a network """ - return self.do_request("PUT", self.network_path % (network), body=body) + return self.do_request("PUT", self.network_path % (network), body=body, + exception_args={"net_id": network}) @ApiCall def delete_network(self, network): """ Deletes the specified network """ - return self.do_request("DELETE", self.network_path % (network)) + return self.do_request("DELETE", self.network_path % (network), + exception_args={"net_id": network}) @ApiCall def list_ports(self, network): @@ -289,7 +292,8 @@ class Client(object): """ Fetches the details of a certain port """ - return self.do_request("GET", self.port_path % (network, port)) + return self.do_request("GET", self.port_path % (network, port), + exception_args={"net_id": network, "port_id": port}) @ApiCall def create_port(self, network, body=None): @@ -297,14 +301,16 @@ class Client(object): Creates a new port on a given network """ body = self.serialize(body) - return self.do_request("POST", self.ports_path % (network), body=body) + return self.do_request("POST", self.ports_path % (network), body=body, + exception_args={"net_id": network}) @ApiCall def delete_port(self, network, port): """ Deletes the specified port from a network """ - return self.do_request("DELETE", self.port_path % (network, port)) + return self.do_request("DELETE", self.port_path % (network, port), + exception_args={"net_id": network, "port_id": port}) @ApiCall def set_port_state(self, network, port, body=None): @@ -312,14 +318,18 @@ class Client(object): Sets the state of the specified port """ return self.do_request("PUT", - self.port_path % (network, port), body=body) + self.port_path % (network, port), body=body, + exception_args={"net_id": network, + "port_id": port, + "port_state": str(body)}) @ApiCall def show_port_attachment(self, network, port): """ Fetches the attachment-id associated with the specified port """ - return self.do_request("GET", self.attachment_path % (network, port)) + return self.do_request("GET", self.attachment_path % (network, port), + exception_args={"net_id": network, "port_id": port}) @ApiCall def attach_resource(self, network, port, body=None): @@ -327,7 +337,10 @@ class Client(object): Sets the attachment-id of the specified port """ return self.do_request("PUT", - self.attachment_path % (network, port), body=body) + self.attachment_path % (network, port), body=body, + exception_args={"net_id": network, + "port_id": port, + "attach_id": str(body)}) @ApiCall def detach_resource(self, network, port): @@ -335,4 +348,5 @@ class Client(object): Removes the attachment-id of the specified port """ return self.do_request("DELETE", - self.attachment_path % (network, port)) + self.attachment_path % (network, port), + exception_args={"net_id": network, "port_id": port}) diff --git a/quantum/common/exceptions.py b/quantum/common/exceptions.py index 816851f7a..46d15b28b 100644 --- a/quantum/common/exceptions.py +++ b/quantum/common/exceptions.py @@ -111,6 +111,21 @@ class AlreadyAttached(QuantumException): "already plugged into port %(att_port_id)s") +# NOTE: on the client side, we often do not know all of the information +# that is known on the server, thus, we create separate exception for +# those scenarios +class PortInUseClient(QuantumException): + message = _("Unable to complete operation on port %(port_id)s " \ + "for network %(net_id)s. An attachment " \ + "is plugged into the logical port.") + + +class AlreadyAttachedClient(QuantumException): + message = _("Unable to plug the attachment %(att_id)s into port " \ + "%(port_id)s for network %(net_id)s. The attachment is " \ + "already plugged into another port.") + + class Duplicate(Error): pass