Merge lp:~danwent/neutron/lp835216 into lp:neutron/diablo

Proposed by dan wendlandt
Status: Merged
Merged at revision: 58
Proposed branch: lp:~danwent/neutron/lp835216
Merge into: lp:neutron/diablo
Diff against target: 155 lines (+43/-14)
2 files modified
quantum/client.py (+28/-14)
quantum/common/exceptions.py (+15/-0)
To merge this branch: bzr merge lp:~danwent/neutron/lp835216
Reviewer Review Type Date Requested Status
Brad Hall (community) Approve
Sumit Naiksatam Approve
Review via email: mp+73319@code.launchpad.net

Description of the change

fixes lp835216

To post a comment you must log in.
Revision history for this message
Sumit Naiksatam (snaiksat) wrote :

Tested, works, changes look good, thanks!

~Sumit.

review: Approve
Revision history for this message
Brad Hall (bgh) wrote :

Looks good.. thanks for doing this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'quantum/client.py'
2--- quantum/client.py 2011-08-26 08:41:19 +0000
3+++ quantum/client.py 2011-08-30 02:02:16 +0000
4@@ -32,8 +32,8 @@
5 421: exceptions.NetworkInUse,
6 430: exceptions.PortNotFound,
7 431: exceptions.StateInvalid,
8- 432: exceptions.PortInUse,
9- 440: exceptions.AlreadyAttached}
10+ 432: exceptions.PortInUseClient,
11+ 440: exceptions.AlreadyAttachedClient}
12
13
14 class ApiCall(object):
15@@ -131,7 +131,7 @@
16 return conn.getresponse()
17
18 def do_request(self, method, action, body=None,
19- headers=None, params=None):
20+ headers=None, params=None, exception_args={}):
21 """
22 Connects to the server and issues a request.
23 Returns the result data, or raises an appropriate exception if
24@@ -190,7 +190,7 @@
25 LOG.debug("Error message: %s", error_message)
26 # Create exception with HTTP status code and message
27 if res.status in EXCEPTIONS:
28- raise EXCEPTIONS[res.status]()
29+ raise EXCEPTIONS[res.status](**exception_args)
30 # Add error code and message to exception arguments
31 ex = Exception("Server returned error: %s" % status_code)
32 ex.args = ([dict(status_code=status_code,
33@@ -254,7 +254,8 @@
34 """
35 Fetches the details of a certain network
36 """
37- return self.do_request("GET", self.network_path % (network))
38+ return self.do_request("GET", self.network_path % (network),
39+ exception_args={"net_id": network})
40
41 @ApiCall
42 def create_network(self, body=None):
43@@ -268,14 +269,16 @@
44 """
45 Updates a network
46 """
47- return self.do_request("PUT", self.network_path % (network), body=body)
48+ return self.do_request("PUT", self.network_path % (network), body=body,
49+ exception_args={"net_id": network})
50
51 @ApiCall
52 def delete_network(self, network):
53 """
54 Deletes the specified network
55 """
56- return self.do_request("DELETE", self.network_path % (network))
57+ return self.do_request("DELETE", self.network_path % (network),
58+ exception_args={"net_id": network})
59
60 @ApiCall
61 def list_ports(self, network):
62@@ -289,7 +292,8 @@
63 """
64 Fetches the details of a certain port
65 """
66- return self.do_request("GET", self.port_path % (network, port))
67+ return self.do_request("GET", self.port_path % (network, port),
68+ exception_args={"net_id": network, "port_id": port})
69
70 @ApiCall
71 def create_port(self, network, body=None):
72@@ -297,14 +301,16 @@
73 Creates a new port on a given network
74 """
75 body = self.serialize(body)
76- return self.do_request("POST", self.ports_path % (network), body=body)
77+ return self.do_request("POST", self.ports_path % (network), body=body,
78+ exception_args={"net_id": network})
79
80 @ApiCall
81 def delete_port(self, network, port):
82 """
83 Deletes the specified port from a network
84 """
85- return self.do_request("DELETE", self.port_path % (network, port))
86+ return self.do_request("DELETE", self.port_path % (network, port),
87+ exception_args={"net_id": network, "port_id": port})
88
89 @ApiCall
90 def set_port_state(self, network, port, body=None):
91@@ -312,14 +318,18 @@
92 Sets the state of the specified port
93 """
94 return self.do_request("PUT",
95- self.port_path % (network, port), body=body)
96+ self.port_path % (network, port), body=body,
97+ exception_args={"net_id": network,
98+ "port_id": port,
99+ "port_state": str(body)})
100
101 @ApiCall
102 def show_port_attachment(self, network, port):
103 """
104 Fetches the attachment-id associated with the specified port
105 """
106- return self.do_request("GET", self.attachment_path % (network, port))
107+ return self.do_request("GET", self.attachment_path % (network, port),
108+ exception_args={"net_id": network, "port_id": port})
109
110 @ApiCall
111 def attach_resource(self, network, port, body=None):
112@@ -327,7 +337,10 @@
113 Sets the attachment-id of the specified port
114 """
115 return self.do_request("PUT",
116- self.attachment_path % (network, port), body=body)
117+ self.attachment_path % (network, port), body=body,
118+ exception_args={"net_id": network,
119+ "port_id": port,
120+ "attach_id": str(body)})
121
122 @ApiCall
123 def detach_resource(self, network, port):
124@@ -335,4 +348,5 @@
125 Removes the attachment-id of the specified port
126 """
127 return self.do_request("DELETE",
128- self.attachment_path % (network, port))
129+ self.attachment_path % (network, port),
130+ exception_args={"net_id": network, "port_id": port})
131
132=== modified file 'quantum/common/exceptions.py'
133--- quantum/common/exceptions.py 2011-08-22 14:30:54 +0000
134+++ quantum/common/exceptions.py 2011-08-30 02:02:16 +0000
135@@ -111,6 +111,21 @@
136 "already plugged into port %(att_port_id)s")
137
138
139+# NOTE: on the client side, we often do not know all of the information
140+# that is known on the server, thus, we create separate exception for
141+# those scenarios
142+class PortInUseClient(QuantumException):
143+ message = _("Unable to complete operation on port %(port_id)s " \
144+ "for network %(net_id)s. An attachment " \
145+ "is plugged into the logical port.")
146+
147+
148+class AlreadyAttachedClient(QuantumException):
149+ message = _("Unable to plug the attachment %(att_id)s into port " \
150+ "%(port_id)s for network %(net_id)s. The attachment is " \
151+ "already plugged into another port.")
152+
153+
154 class Duplicate(Error):
155 pass
156

Subscribers

People subscribed via source and target branches