Merge lp:~salvatore-orlando/neutron/bug822813 into lp:neutron/diablo
- bug822813
- Merge into diablo
Status: | Needs review | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~salvatore-orlando/neutron/bug822813 | ||||
Merge into: | lp:neutron/diablo | ||||
Diff against target: |
2096 lines (+362/-265) 35 files modified
quantum/api/api_common.py (+5/-0) quantum/api/attachments.py (+22/-18) quantum/api/networks.py (+21/-10) quantum/api/ports.py (+29/-25) quantum/cli_lib.py (+53/-11) quantum/client.py (+20/-16) quantum/common/config.py (+2/-5) quantum/common/exceptions.py (+29/-4) quantum/common/extensions.py (+50/-7) quantum/common/test_lib.py (+5/-6) quantum/common/utils.py (+5/-6) quantum/db/api.py (+25/-23) quantum/manager.py (+1/-1) quantum/plugins/SamplePlugin.py (+40/-23) quantum/plugins/cisco/common/cisco_credentials.py (+2/-2) quantum/plugins/cisco/common/cisco_utils.py (+1/-2) quantum/plugins/cisco/conf/db_conn.ini (+3/-3) quantum/plugins/cisco/conf/plugins.ini (+1/-1) quantum/plugins/cisco/db/api.py (+1/-17) quantum/plugins/cisco/db/l2network_db.py (+0/-2) quantum/plugins/cisco/l2network_plugin.py (+26/-27) quantum/plugins/cisco/models/l2network_multi_blade.py (+0/-3) quantum/plugins/cisco/models/l2network_single_blade.py (+0/-3) quantum/plugins/cisco/run_tests.py (+1/-4) quantum/plugins/cisco/tests/unit/test_database.py (+9/-9) quantum/plugins/cisco/ucs/cisco_ucs_inventory.py (+4/-5) quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py (+0/-2) quantum/plugins/cisco/ucs/cisco_ucs_plugin.py (+1/-2) quantum/plugins/openvswitch/ovs_db.py (+0/-1) quantum/plugins/openvswitch/ovs_models.py (+1/-5) quantum/plugins/openvswitch/ovs_quantum_plugin.py (+1/-3) quantum/plugins/openvswitch/run_tests.py (+0/-4) quantum/service.py (+3/-3) quantum/utils.py (+0/-11) tests/unit/test_cli.py (+1/-1) |
||||
To merge this branch: | bzr merge lp:~salvatore-orlando/neutron/bug822813 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Somik Behera | netstack-core | Needs Fixing | |
Tyler Smith | Approve | ||
Review via email: mp+73769@code.launchpad.net |
Commit message
Description of the change
This merge proposal is aimed at reducing pylint violations.
We currently have 1321 violations, 39 high.
The proposed branch brings violations back to 981, 23 of which high.
More could be done, but I did not want to generate an overwhelming diff.
dan wendlandt (danwent) wrote : | # |
This branch is large enough that we decided to target it for Essex, not diablo.
Somik Behera (somikbehera) wrote : | # |
Hi Salvatore,
Great work! Most of changes look innocuous and help us better our pylint score!
I had just one concern regarding your changing of handling exceptions in cli_lib.py to handle only QuantumException.
I agree with your approach, and that's exactly how I would do it too, except for the fact that client.py still raises plain Exception as the default unknown exception.
client.py Line 202
# Add error code and message to exception arguments
ex = Exception("Server returned error: %s" % status_code)
The correct way to fix this in my opinion is to fix client.py to default to QuantumException as the exception client.py classes raise when we get a unknown error code from the server. QuantumException can be our catch-all exception indicating something bad but unknown happened at the remote server.
If that is difficult, then we can file a bug to that effect and revert your cli_lib.py changes to catch Exception instead of just QuantumException.
dan wendlandt (danwent) wrote : | # |
We will need to merge this commit over on github now.
Unmerged revisions
- 64. By Salvatore Orlando
-
Bringing violations back below 1000
- 63. By Salvatore Orlando
-
just starting. realized need another merge trunk
Preview Diff
1 | === modified file 'quantum/api/api_common.py' |
2 | --- quantum/api/api_common.py 2011-08-08 14:52:05 +0000 |
3 | +++ quantum/api/api_common.py 2011-09-02 10:10:23 +0000 |
4 | @@ -15,6 +15,8 @@ |
5 | # License for the specific language governing permissions and limitations |
6 | # under the License. |
7 | |
8 | +""" Base controller class for Quantum API """ |
9 | + |
10 | import logging |
11 | |
12 | from webob import exc |
13 | @@ -31,6 +33,9 @@ |
14 | |
15 | def __init__(self, plugin): |
16 | self._plugin = plugin |
17 | + # This variable will be initialized by subclasses |
18 | + if not hasattr(self, '_resource_name'): |
19 | + self._resource_name = '' |
20 | super(QuantumController, self).__init__() |
21 | |
22 | def _parse_request_params(self, req, params): |
23 | |
24 | === modified file 'quantum/api/attachments.py' |
25 | --- quantum/api/attachments.py 2011-08-25 17:50:05 +0000 |
26 | +++ quantum/api/attachments.py 2011-09-02 10:10:23 +0000 |
27 | @@ -13,6 +13,10 @@ |
28 | # License for the specific language governing permissions and limitations |
29 | # under the License. |
30 | |
31 | +""" Controller for API operations for managing attachments for |
32 | + Quantum logical ports |
33 | +""" |
34 | + |
35 | import logging |
36 | |
37 | from webob import exc |
38 | @@ -50,38 +54,38 @@ |
39 | builder = attachments_view.get_view_builder(request) |
40 | result = builder.build(att_data)['attachment'] |
41 | return dict(attachment=result) |
42 | - except exception.NetworkNotFound as e: |
43 | - return faults.Fault(faults.NetworkNotFound(e)) |
44 | - except exception.PortNotFound as e: |
45 | - return faults.Fault(faults.PortNotFound(e)) |
46 | + except exception.NetworkNotFound as ex: |
47 | + return faults.Fault(faults.NetworkNotFound(ex)) |
48 | + except exception.PortNotFound as ex: |
49 | + return faults.Fault(faults.PortNotFound(ex)) |
50 | |
51 | def attach_resource(self, request, tenant_id, network_id, id): |
52 | try: |
53 | request_params = \ |
54 | self._parse_request_params(request, |
55 | self._attachment_ops_param_list) |
56 | - except exc.HTTPError as e: |
57 | - return faults.Fault(e) |
58 | + except exc.HTTPError as ex: |
59 | + return faults.Fault(ex) |
60 | try: |
61 | LOG.debug("PLUGGING INTERFACE:%s", request_params['id']) |
62 | self._plugin.plug_interface(tenant_id, network_id, id, |
63 | request_params['id']) |
64 | return exc.HTTPNoContent() |
65 | - except exception.NetworkNotFound as e: |
66 | - return faults.Fault(faults.NetworkNotFound(e)) |
67 | - except exception.PortNotFound as e: |
68 | - return faults.Fault(faults.PortNotFound(e)) |
69 | - except exception.PortInUse as e: |
70 | - return faults.Fault(faults.PortInUse(e)) |
71 | - except exception.AlreadyAttached as e: |
72 | - return faults.Fault(faults.AlreadyAttached(e)) |
73 | + except exception.NetworkNotFound as ex: |
74 | + return faults.Fault(faults.NetworkNotFound(ex)) |
75 | + except exception.PortNotFound as ex: |
76 | + return faults.Fault(faults.PortNotFound(ex)) |
77 | + except exception.PortInUse as ex: |
78 | + return faults.Fault(faults.PortInUse(ex)) |
79 | + except exception.AlreadyAttached as ex: |
80 | + return faults.Fault(faults.AlreadyAttached(ex)) |
81 | |
82 | def detach_resource(self, request, tenant_id, network_id, id): |
83 | try: |
84 | self._plugin.unplug_interface(tenant_id, |
85 | network_id, id) |
86 | return exc.HTTPNoContent() |
87 | - except exception.NetworkNotFound as e: |
88 | - return faults.Fault(faults.NetworkNotFound(e)) |
89 | - except exception.PortNotFound as e: |
90 | - return faults.Fault(faults.PortNotFound(e)) |
91 | + except exception.NetworkNotFound as ex: |
92 | + return faults.Fault(faults.NetworkNotFound(ex)) |
93 | + except exception.PortNotFound as ex: |
94 | + return faults.Fault(faults.PortNotFound(ex)) |
95 | |
96 | === modified file 'quantum/api/networks.py' |
97 | --- quantum/api/networks.py 2011-08-17 21:48:56 +0000 |
98 | +++ quantum/api/networks.py 2011-09-02 10:10:23 +0000 |
99 | @@ -13,6 +13,8 @@ |
100 | # License for the specific language governing permissions and limitations |
101 | # under the License. |
102 | |
103 | +""" Controller for API operations for managing Quantum networks """ |
104 | + |
105 | import logging |
106 | |
107 | from webob import exc |
108 | @@ -48,6 +50,11 @@ |
109 | |
110 | def _item(self, req, tenant_id, network_id, |
111 | net_details=True, port_details=False): |
112 | + """ Retrieves a specific network. |
113 | + net_details = False, port_details = False -> only ID |
114 | + net_details = True, port_details = False -> ID, name |
115 | + net_details = True, port_details = True -> also port details |
116 | + """ |
117 | # We expect get_network_details to return information |
118 | # concerning logical ports as well. |
119 | network = self._plugin.get_network_details( |
120 | @@ -79,10 +86,14 @@ |
121 | try: |
122 | return self._item(request, tenant_id, id, |
123 | net_details=True, port_details=False) |
124 | - except exception.NetworkNotFound as e: |
125 | - return faults.Fault(faults.NetworkNotFound(e)) |
126 | + except exception.NetworkNotFound as ex: |
127 | + return faults.Fault(faults.NetworkNotFound(ex)) |
128 | |
129 | def detail(self, request, **kwargs): |
130 | + """ Implements the 'detail' action for providing details |
131 | + about a specific network. |
132 | + |
133 | + """ |
134 | tenant_id = kwargs.get('tenant_id') |
135 | network_id = kwargs.get('id') |
136 | if network_id: |
137 | @@ -100,8 +111,8 @@ |
138 | request_params = \ |
139 | self._parse_request_params(request, |
140 | self._network_ops_param_list) |
141 | - except exc.HTTPError as e: |
142 | - return faults.Fault(e) |
143 | + except exc.HTTPError as ex: |
144 | + return faults.Fault(ex) |
145 | network = self._plugin.\ |
146 | create_network(tenant_id, |
147 | request_params['name']) |
148 | @@ -122,15 +133,15 @@ |
149 | self._plugin.rename_network(tenant_id, id, |
150 | request_params['name']) |
151 | return exc.HTTPNoContent() |
152 | - except exception.NetworkNotFound as e: |
153 | - return faults.Fault(faults.NetworkNotFound(e)) |
154 | + except exception.NetworkNotFound as ex: |
155 | + return faults.Fault(faults.NetworkNotFound(ex)) |
156 | |
157 | def delete(self, request, tenant_id, id): |
158 | """ Destroys the network with the given id """ |
159 | try: |
160 | self._plugin.delete_network(tenant_id, id) |
161 | return exc.HTTPNoContent() |
162 | - except exception.NetworkNotFound as e: |
163 | - return faults.Fault(faults.NetworkNotFound(e)) |
164 | - except exception.NetworkInUse as e: |
165 | - return faults.Fault(faults.NetworkInUse(e)) |
166 | + except exception.NetworkNotFound as ex: |
167 | + return faults.Fault(faults.NetworkNotFound(ex)) |
168 | + except exception.NetworkInUse as ex: |
169 | + return faults.Fault(faults.NetworkInUse(ex)) |
170 | |
171 | === modified file 'quantum/api/ports.py' |
172 | --- quantum/api/ports.py 2011-08-17 21:48:56 +0000 |
173 | +++ quantum/api/ports.py 2011-09-02 10:10:23 +0000 |
174 | @@ -13,6 +13,8 @@ |
175 | # License for the specific language governing permissions and limitations |
176 | # under the License. |
177 | |
178 | +""" Controller for API operations for managing Quantum logical ports """ |
179 | + |
180 | import logging |
181 | |
182 | from webob import exc |
183 | @@ -32,7 +34,7 @@ |
184 | 'param-name': 'state', |
185 | 'default-value': 'DOWN', |
186 | 'required': False}, ] |
187 | - |
188 | +#look for port state in request |
189 | _serialization_metadata = { |
190 | "application/xml": { |
191 | "attributes": { |
192 | @@ -63,8 +65,8 @@ |
193 | result = [builder.build(port, port_details)['port'] |
194 | for port in port_list] |
195 | return dict(ports=result) |
196 | - except exception.NetworkNotFound as e: |
197 | - return faults.Fault(faults.NetworkNotFound(e)) |
198 | + except exception.NetworkNotFound as ex: |
199 | + return faults.Fault(faults.NetworkNotFound(ex)) |
200 | |
201 | def _item(self, request, tenant_id, network_id, port_id, |
202 | att_details=False): |
203 | @@ -81,15 +83,18 @@ |
204 | return self._items(request, tenant_id, network_id, port_details=False) |
205 | |
206 | def show(self, request, tenant_id, network_id, id): |
207 | - """ Returns port details for given port and network """ |
208 | + """ Returns info for given port and network """ |
209 | try: |
210 | return self._item(request, tenant_id, network_id, id) |
211 | - except exception.NetworkNotFound as e: |
212 | - return faults.Fault(faults.NetworkNotFound(e)) |
213 | - except exception.PortNotFound as e: |
214 | - return faults.Fault(faults.PortNotFound(e)) |
215 | + except exception.NetworkNotFound as ex: |
216 | + return faults.Fault(faults.NetworkNotFound(ex)) |
217 | + except exception.PortNotFound as ex: |
218 | + return faults.Fault(faults.PortNotFound(ex)) |
219 | |
220 | def detail(self, request, **kwargs): |
221 | + """ Implements the 'detail' action. |
222 | + Returns detailed information about a specific port. |
223 | + """ |
224 | tenant_id = kwargs.get('tenant_id') |
225 | network_id = kwargs.get('network_id') |
226 | port_id = kwargs.get('id') |
227 | @@ -117,10 +122,10 @@ |
228 | builder = ports_view.get_view_builder(request) |
229 | result = builder.build(port)['port'] |
230 | return dict(port=result) |
231 | - except exception.NetworkNotFound as e: |
232 | - return faults.Fault(faults.NetworkNotFound(e)) |
233 | - except exception.StateInvalid as e: |
234 | - return faults.Fault(faults.RequestedStateInvalid(e)) |
235 | + except exception.NetworkNotFound as ex: |
236 | + return faults.Fault(faults.NetworkNotFound(ex)) |
237 | + except exception.StateInvalid as ex: |
238 | + return faults.Fault(faults.RequestedStateInvalid(ex)) |
239 | |
240 | def update(self, request, tenant_id, network_id, id): |
241 | """ Updates the state of a port for a given network """ |
242 | @@ -134,22 +139,21 @@ |
243 | self._plugin.update_port(tenant_id, network_id, id, |
244 | request_params['state']) |
245 | return exc.HTTPNoContent() |
246 | - except exception.NetworkNotFound as e: |
247 | - return faults.Fault(faults.NetworkNotFound(e)) |
248 | - except exception.PortNotFound as e: |
249 | - return faults.Fault(faults.PortNotFound(e)) |
250 | - except exception.StateInvalid as e: |
251 | - return faults.Fault(faults.RequestedStateInvalid(e)) |
252 | + except exception.NetworkNotFound as ex: |
253 | + return faults.Fault(faults.NetworkNotFound(ex)) |
254 | + except exception.PortNotFound as ex: |
255 | + return faults.Fault(faults.PortNotFound(ex)) |
256 | + except exception.StateInvalid as ex: |
257 | + return faults.Fault(faults.RequestedStateInvalid(ex)) |
258 | |
259 | def delete(self, request, tenant_id, network_id, id): |
260 | """ Destroys the port with the given id """ |
261 | - #look for port state in request |
262 | try: |
263 | self._plugin.delete_port(tenant_id, network_id, id) |
264 | return exc.HTTPNoContent() |
265 | - except exception.NetworkNotFound as e: |
266 | - return faults.Fault(faults.NetworkNotFound(e)) |
267 | - except exception.PortNotFound as e: |
268 | - return faults.Fault(faults.PortNotFound(e)) |
269 | - except exception.PortInUse as e: |
270 | - return faults.Fault(faults.PortInUse(e)) |
271 | + except exception.NetworkNotFound as ex: |
272 | + return faults.Fault(faults.NetworkNotFound(ex)) |
273 | + except exception.PortNotFound as ex: |
274 | + return faults.Fault(faults.PortNotFound(ex)) |
275 | + except exception.PortInUse as ex: |
276 | + return faults.Fault(faults.PortInUse(ex)) |
277 | |
278 | === modified file 'quantum/cli_lib.py' |
279 | --- quantum/cli_lib.py 2011-08-26 20:22:18 +0000 |
280 | +++ quantum/cli_lib.py 2011-09-02 10:10:23 +0000 |
281 | @@ -19,17 +19,22 @@ |
282 | # @author: Brad Hall, Nicira Networks, Inc. |
283 | # @author: Salvatore Orlando, Citrix |
284 | |
285 | +""" Functions used by Quantum CLI """ |
286 | + |
287 | import Cheetah.Template as cheetah_template |
288 | import logging |
289 | import os |
290 | import sys |
291 | |
292 | +from quantum.common.exceptions import QuantumException |
293 | + |
294 | FORMAT = "json" |
295 | CLI_TEMPLATE = "cli_output.template" |
296 | LOG = logging.getLogger('quantum.cli_lib') |
297 | |
298 | |
299 | def _handle_exception(ex): |
300 | + """ Handles an exception occured in the client library. """ |
301 | LOG.exception(sys.exc_info()) |
302 | print "Exception:%s - %s" % (sys.exc_info()[0], sys.exc_info()[1]) |
303 | status_code = None |
304 | @@ -61,6 +66,7 @@ |
305 | |
306 | |
307 | def list_nets(client, *args): |
308 | + """ Lists currently available networks """ |
309 | tenant_id = args[0] |
310 | res = client.list_networks() |
311 | LOG.debug("Operation 'list_networks' executed.") |
312 | @@ -69,6 +75,7 @@ |
313 | |
314 | |
315 | def create_net(client, *args): |
316 | + """ Creates a network. Argument list must include network name. """ |
317 | tenant_id, name = args |
318 | data = {'network': {'name': name}} |
319 | new_net_id = None |
320 | @@ -79,11 +86,12 @@ |
321 | output = prepare_output("create_net", tenant_id, |
322 | dict(network_id=new_net_id)) |
323 | print output |
324 | - except Exception as ex: |
325 | + except QuantumException as ex: |
326 | _handle_exception(ex) |
327 | |
328 | |
329 | def delete_net(client, *args): |
330 | + """ Removes a networks. Argument list must include network id. """ |
331 | tenant_id, network_id = args |
332 | try: |
333 | client.delete_network(network_id) |
334 | @@ -91,11 +99,12 @@ |
335 | output = prepare_output("delete_net", tenant_id, |
336 | dict(network_id=network_id)) |
337 | print output |
338 | - except Exception as ex: |
339 | + except QuantumException as ex: |
340 | _handle_exception(ex) |
341 | |
342 | |
343 | def show_net(client, *args): |
344 | + """ Retrieves a network. Argument list must include network id. """ |
345 | tenant_id, network_id = args |
346 | try: |
347 | #NOTE(salvatore-orlando) changed for returning exclusively |
348 | @@ -104,11 +113,15 @@ |
349 | LOG.debug("Operation 'show_network_details' executed.") |
350 | output = prepare_output("show_net", tenant_id, dict(network=res)) |
351 | print output |
352 | - except Exception as ex: |
353 | + except QuantumException as ex: |
354 | _handle_exception(ex) |
355 | |
356 | |
357 | def rename_net(client, *args): |
358 | + """ Renames a network. |
359 | + Argument list must include network id, and new network name. |
360 | + |
361 | + """ |
362 | tenant_id, network_id, name = args |
363 | data = {'network': {'name': '%s' % name}} |
364 | try: |
365 | @@ -118,11 +131,15 @@ |
366 | data['network']['id'] = network_id |
367 | output = prepare_output("rename_net", tenant_id, data) |
368 | print output |
369 | - except Exception as ex: |
370 | + except QuantumException as ex: |
371 | _handle_exception(ex) |
372 | |
373 | |
374 | def list_ports(client, *args): |
375 | + """ Lists ports configured for a given network. |
376 | + Argument list must include network id. |
377 | + |
378 | + """ |
379 | tenant_id, network_id = args |
380 | try: |
381 | ports = client.list_ports(network_id) |
382 | @@ -131,11 +148,15 @@ |
383 | data['network_id'] = network_id |
384 | output = prepare_output("list_ports", tenant_id, data) |
385 | print output |
386 | - except Exception as ex: |
387 | + except QuantumException as ex: |
388 | _handle_exception(ex) |
389 | |
390 | |
391 | def create_port(client, *args): |
392 | + """ Creates a logical port on the given network. |
393 | + Argument list must include network id. |
394 | + |
395 | + """ |
396 | tenant_id, network_id = args |
397 | try: |
398 | res = client.create_port(network_id) |
399 | @@ -145,11 +166,15 @@ |
400 | dict(network_id=network_id, |
401 | port_id=new_port_id)) |
402 | print output |
403 | - except Exception as ex: |
404 | + except QuantumException as ex: |
405 | _handle_exception(ex) |
406 | |
407 | |
408 | def delete_port(client, *args): |
409 | + """ Removes a logical port from the given network. |
410 | + Argument list must include network id. |
411 | + |
412 | + """ |
413 | tenant_id, network_id, port_id = args |
414 | try: |
415 | client.delete_port(network_id, port_id) |
416 | @@ -158,12 +183,16 @@ |
417 | dict(network_id=network_id, |
418 | port_id=port_id)) |
419 | print output |
420 | - except Exception as ex: |
421 | + except QuantumException as ex: |
422 | _handle_exception(ex) |
423 | return |
424 | |
425 | |
426 | def show_port(client, *args): |
427 | + """ Retrieves a specific logical port. |
428 | + Argument list must include network id and port id. |
429 | + |
430 | + """ |
431 | tenant_id, network_id, port_id = args |
432 | try: |
433 | port = client.show_port_details(network_id, port_id)["port"] |
434 | @@ -181,11 +210,15 @@ |
435 | dict(network_id=network_id, |
436 | port=port)) |
437 | print output |
438 | - except Exception as ex: |
439 | + except QuantumException as ex: |
440 | _handle_exception(ex) |
441 | |
442 | |
443 | def set_port_state(client, *args): |
444 | + """ Updates the administrative state for a logical port. |
445 | + Argument list must include network id and port_id. |
446 | + |
447 | + """ |
448 | tenant_id, network_id, port_id, new_state = args |
449 | data = {'port': {'state': '%s' % new_state}} |
450 | try: |
451 | @@ -196,11 +229,16 @@ |
452 | data['port']['id'] = port_id |
453 | output = prepare_output("set_port_state", tenant_id, data) |
454 | print output |
455 | - except Exception as ex: |
456 | + except QuantumException as ex: |
457 | _handle_exception(ex) |
458 | |
459 | |
460 | def plug_iface(client, *args): |
461 | + """ Plugs an interface into the given logical port. |
462 | + Argument list must include network id, port id, and attachment id. |
463 | + |
464 | + """ |
465 | + |
466 | tenant_id, network_id, port_id, attachment = args |
467 | try: |
468 | data = {'attachment': {'id': '%s' % attachment}} |
469 | @@ -211,11 +249,15 @@ |
470 | port_id=port_id, |
471 | attachment=attachment)) |
472 | print output |
473 | - except Exception as ex: |
474 | + except QuantumException as ex: |
475 | _handle_exception(ex) |
476 | |
477 | |
478 | def unplug_iface(client, *args): |
479 | + """ Remove an interface from the given logical port. |
480 | + Argument list must include network id and port id. |
481 | + |
482 | + """ |
483 | tenant_id, network_id, port_id = args |
484 | try: |
485 | client.detach_resource(network_id, port_id) |
486 | @@ -224,5 +266,5 @@ |
487 | dict(network_id=network_id, |
488 | port_id=port_id)) |
489 | print output |
490 | - except Exception as ex: |
491 | + except QuantumException as ex: |
492 | _handle_exception(ex) |
493 | |
494 | === modified file 'quantum/client.py' |
495 | --- quantum/client.py 2011-08-30 01:59:14 +0000 |
496 | +++ quantum/client.py 2011-09-02 10:10:23 +0000 |
497 | @@ -16,6 +16,8 @@ |
498 | # under the License. |
499 | # @author: Tyler Smith, Cisco Systems |
500 | |
501 | +""" Client Library for accessing Quantum API """ |
502 | + |
503 | import logging |
504 | import httplib |
505 | import socket |
506 | @@ -46,7 +48,7 @@ |
507 | """ |
508 | Temporarily sets the format and tenant for this request |
509 | """ |
510 | - (format, tenant) = (instance.format, instance.tenant) |
511 | + (req_format, tenant) = (instance.format, instance.tenant) |
512 | |
513 | if 'format' in kwargs: |
514 | instance.format = kwargs['format'] |
515 | @@ -54,7 +56,7 @@ |
516 | instance.tenant = kwargs['tenant'] |
517 | |
518 | ret = self.function(instance, *args) |
519 | - (instance.format, instance.tenant) = (format, tenant) |
520 | + (instance.format, instance.tenant) = (req_format, tenant) |
521 | return ret |
522 | return with_params |
523 | |
524 | @@ -82,7 +84,7 @@ |
525 | attachment_path = "/networks/%s/ports/%s/attachment" |
526 | |
527 | def __init__(self, host="127.0.0.1", port=9696, use_ssl=False, tenant=None, |
528 | - format="xml", testingStub=None, key_file=None, cert_file=None, |
529 | + format="xml", testing_stub=None, key_file=None, cert_file=None, |
530 | logger=None, action_prefix="/v1.0/tenants/{tenant_id}"): |
531 | """ |
532 | Creates a new client to some service. |
533 | @@ -102,7 +104,7 @@ |
534 | self.tenant = tenant |
535 | self.format = format |
536 | self.connection = None |
537 | - self.testingStub = testingStub |
538 | + self.testing_stub = testing_stub |
539 | self.key_file = key_file |
540 | self.cert_file = cert_file |
541 | self.logger = logger |
542 | @@ -112,16 +114,15 @@ |
543 | """ |
544 | Returns the proper connection type |
545 | """ |
546 | - if self.testingStub: |
547 | - return self.testingStub |
548 | + if self.testing_stub: |
549 | + return self.testing_stub |
550 | if self.use_ssl: |
551 | return httplib.HTTPSConnection |
552 | else: |
553 | return httplib.HTTPConnection |
554 | |
555 | def _send_request(self, conn, method, action, body, headers): |
556 | - # Salvatore: Isolating this piece of code in its own method to |
557 | - # facilitate stubout for testing |
558 | + """ Sends a request to the API server """ |
559 | if self.logger: |
560 | self.logger.debug("Quantum Client Request:\n" \ |
561 | + method + " " + action + "\n") |
562 | @@ -131,7 +132,7 @@ |
563 | return conn.getresponse() |
564 | |
565 | def do_request(self, method, action, body=None, |
566 | - headers=None, params=None, exception_args={}): |
567 | + headers=None, params=None, exception_args=None): |
568 | """ |
569 | Connects to the server and issues a request. |
570 | Returns the result data, or raises an appropriate exception if |
571 | @@ -145,6 +146,8 @@ |
572 | |
573 | """ |
574 | LOG.debug("Client issuing request: %s", action) |
575 | + if not exception_args: |
576 | + exception_args = {} |
577 | # Ensure we have a tenant id |
578 | if not self.tenant: |
579 | raise Exception("Tenant ID not set") |
580 | @@ -196,10 +199,11 @@ |
581 | ex.args = ([dict(status_code=status_code, |
582 | message=error_message)],) |
583 | raise ex |
584 | - except (socket.error, IOError), e: |
585 | - msg = "Unable to connect to server. Got error: %s" % e |
586 | + except (socket.error, IOError), ex: |
587 | + msg = "Unable to connect to server. Got error: %s" % ex |
588 | LOG.exception(msg) |
589 | - raise Exception(msg) |
590 | + # Pylint: avoid raising/catching Exception |
591 | + raise exceptions.QuantumException(msg) |
592 | |
593 | def get_status_code(self, response): |
594 | """ |
595 | @@ -233,14 +237,14 @@ |
596 | return Serializer(self._serialization_metadata).\ |
597 | deserialize(data, self.content_type()) |
598 | |
599 | - def content_type(self, format=None): |
600 | + def content_type(self, req_format=None): |
601 | """ |
602 | Returns the mime-type for either 'xml' or 'json'. Defaults to the |
603 | currently set format |
604 | """ |
605 | - if not format: |
606 | - format = self.format |
607 | - return "application/%s" % (format) |
608 | + if not req_format: |
609 | + req_format = self.format |
610 | + return "application/%s" % (req_format) |
611 | |
612 | @ApiCall |
613 | def list_networks(self): |
614 | |
615 | === modified file 'quantum/common/config.py' |
616 | --- quantum/common/config.py 2011-06-24 13:52:17 +0000 |
617 | +++ quantum/common/config.py 2011-09-02 10:10:23 +0000 |
618 | @@ -20,19 +20,16 @@ |
619 | Routines for configuring Quantum |
620 | """ |
621 | |
622 | -import ConfigParser |
623 | import logging |
624 | import logging.config |
625 | import logging.handlers |
626 | import optparse |
627 | import os |
628 | -import re |
629 | import sys |
630 | |
631 | from paste import deploy |
632 | |
633 | from quantum.common import flags |
634 | -from quantum.common import exceptions as exception |
635 | |
636 | DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" |
637 | DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" |
638 | @@ -280,10 +277,10 @@ |
639 | |
640 | try: |
641 | app = deploy.loadapp("config:%s" % conf_file, name=app_name) |
642 | - except (LookupError, ImportError), e: |
643 | + except (LookupError, ImportError), ex: |
644 | raise RuntimeError("Unable to load %(app_name)s from " |
645 | "configuration file %(conf_file)s." |
646 | - "\nGot: %(e)r" % locals()) |
647 | + "\nGot: %(ex)r" % locals()) |
648 | return conf, app |
649 | |
650 | |
651 | |
652 | === modified file 'quantum/common/exceptions.py' |
653 | --- quantum/common/exceptions.py 2011-08-30 01:59:14 +0000 |
654 | +++ quantum/common/exceptions.py 2011-09-02 10:10:23 +0000 |
655 | @@ -26,6 +26,8 @@ |
656 | gettext.install('quantum', unicode=1) |
657 | |
658 | |
659 | +# Disabling "undefined variable" error (due to gettext) |
660 | +# pylint: disable=E0602 |
661 | class QuantumException(Exception): |
662 | """Base Quantum Exception |
663 | |
664 | @@ -40,8 +42,9 @@ |
665 | def __init__(self, **kwargs): |
666 | try: |
667 | self._error_string = self.message % kwargs |
668 | + super(QuantumException, self).__init__() |
669 | |
670 | - except Exception: |
671 | + except: |
672 | # at least get the core message out if something happened |
673 | self._error_string = self.message |
674 | |
675 | @@ -50,6 +53,10 @@ |
676 | |
677 | |
678 | class ProcessExecutionError(IOError): |
679 | + """ Exception class for error which occur when |
680 | + executing OS commands |
681 | + |
682 | + """ |
683 | def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None, |
684 | description=None): |
685 | if description is None: |
686 | @@ -62,11 +69,13 @@ |
687 | |
688 | |
689 | class Error(Exception): |
690 | + """ Generic Error Exception """ |
691 | def __init__(self, message=None): |
692 | super(Error, self).__init__(message) |
693 | |
694 | |
695 | class ApiError(Error): |
696 | + """ Class for reporting an API error """ |
697 | def __init__(self, message='Unknown', code='Unknown'): |
698 | self.message = message |
699 | self.code = code |
700 | @@ -78,34 +87,41 @@ |
701 | |
702 | |
703 | class ClassNotFound(NotFound): |
704 | + """ Class for reporting a missing class """ |
705 | message = _("Class %(class_name)s could not be found") |
706 | |
707 | |
708 | class NetworkNotFound(NotFound): |
709 | + """ Exception Raised when a Quantum network is not found """ |
710 | message = _("Network %(net_id)s could not be found") |
711 | |
712 | |
713 | class PortNotFound(NotFound): |
714 | + """ Exception Raised when a Quantum port is not found """ |
715 | message = _("Port %(port_id)s could not be found " \ |
716 | "on network %(net_id)s") |
717 | |
718 | |
719 | class StateInvalid(QuantumException): |
720 | + """ Exception raised when an invalid state is selected for a port """ |
721 | message = _("Unsupported port state: %(port_state)s") |
722 | |
723 | |
724 | class NetworkInUse(QuantumException): |
725 | + """ Exception raised on attempt to delete a network with attacchments """ |
726 | message = _("Unable to complete operation on network %(net_id)s. " \ |
727 | "There is one or more attachments plugged into its ports.") |
728 | |
729 | |
730 | class PortInUse(QuantumException): |
731 | + """ Exception raised on attempt to delete a port with an attachment. """ |
732 | message = _("Unable to complete operation on port %(port_id)s " \ |
733 | "for network %(net_id)s. The attachment '%(att_id)s" \ |
734 | "is plugged into the logical port.") |
735 | |
736 | |
737 | class AlreadyAttached(QuantumException): |
738 | + """ Exception raised when an attachment is already plugged elsewhere """ |
739 | message = _("Unable to plug the attachment %(att_id)s into port " \ |
740 | "%(port_id)s for network %(net_id)s. The attachment is " \ |
741 | "already plugged into port %(att_port_id)s") |
742 | @@ -115,12 +131,20 @@ |
743 | # that is known on the server, thus, we create separate exception for |
744 | # those scenarios |
745 | class PortInUseClient(QuantumException): |
746 | + """ Exception raised on attempt to delete a port with an attachment. |
747 | + Raised client-side only |
748 | + |
749 | + """ |
750 | message = _("Unable to complete operation on port %(port_id)s " \ |
751 | "for network %(net_id)s. An attachment " \ |
752 | "is plugged into the logical port.") |
753 | |
754 | |
755 | class AlreadyAttachedClient(QuantumException): |
756 | + """ Exception raised when an attachment is already plugged elsewhere |
757 | + Raised client-side only |
758 | + |
759 | + """ |
760 | message = _("Unable to plug the attachment %(att_id)s into port " \ |
761 | "%(port_id)s for network %(net_id)s. The attachment is " \ |
762 | "already plugged into another port.") |
763 | @@ -143,6 +167,7 @@ |
764 | |
765 | |
766 | class InvalidContentType(Invalid): |
767 | + """ Raised when an invalid content type if specified """ |
768 | message = _("Invalid content type %(content_type)s.") |
769 | |
770 | |
771 | @@ -155,10 +180,10 @@ |
772 | pass |
773 | |
774 | |
775 | -def wrap_exception(f): |
776 | +def wrap_exception(func): |
777 | def _wrap(*args, **kw): |
778 | try: |
779 | - return f(*args, **kw) |
780 | + return func(*args, **kw) |
781 | except Exception, e: |
782 | if not isinstance(e, Error): |
783 | #exc_type, exc_value, exc_traceback = sys.exc_info() |
784 | @@ -166,5 +191,5 @@ |
785 | #logging.error(traceback.extract_stack(exc_traceback)) |
786 | raise Error(str(e)) |
787 | raise |
788 | - _wrap.func_name = f.func_name |
789 | + _wrap.func_name = func.func_name |
790 | return _wrap |
791 | |
792 | === modified file 'quantum/common/extensions.py' |
793 | --- quantum/common/extensions.py 2011-08-26 10:20:55 +0000 |
794 | +++ quantum/common/extensions.py 2011-09-02 10:10:23 +0000 |
795 | @@ -16,6 +16,9 @@ |
796 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
797 | # License for the specific language governing permissions and limitations |
798 | # under the License. |
799 | + |
800 | +""" Framework for adding extension to Quantum API """ |
801 | + |
802 | import imp |
803 | import logging |
804 | import os |
805 | @@ -32,6 +35,10 @@ |
806 | LOG = logging.getLogger('quantum.common.extensions') |
807 | |
808 | |
809 | +# pylint: disable=R0201 |
810 | +# pylint: disable=R0903 |
811 | + |
812 | +# NOTE(salvatore-orlando): How is this class used? |
813 | class PluginInterface(object): |
814 | __metaclass__ = ABCMeta |
815 | |
816 | @@ -138,17 +145,23 @@ |
817 | |
818 | |
819 | class ActionExtensionController(wsgi.Controller): |
820 | + """ Controller class for extensions adding |
821 | + actions to resources. |
822 | + |
823 | + """ |
824 | |
825 | def __init__(self, application): |
826 | |
827 | self.application = application |
828 | self.action_handlers = {} |
829 | + super(ActionExtensionController, self).__init__() |
830 | |
831 | def add_action(self, action_name, handler): |
832 | + """ Adds an action to the list of actions handlers """ |
833 | self.action_handlers[action_name] = handler |
834 | |
835 | def action(self, request, id): |
836 | - |
837 | + """ Executes a specific action """ |
838 | input_dict = self._deserialize(request.body, |
839 | request.get_content_type()) |
840 | for action_name, handler in self.action_handlers.iteritems(): |
841 | @@ -160,15 +173,22 @@ |
842 | |
843 | |
844 | class RequestExtensionController(wsgi.Controller): |
845 | + """ Controller class for extensions adding attributes |
846 | + to resources. |
847 | + |
848 | + """ |
849 | |
850 | def __init__(self, application): |
851 | self.application = application |
852 | self.handlers = [] |
853 | + super(RequestExtensionController, self).__init__() |
854 | |
855 | def add_handler(self, handler): |
856 | + """ Adds an extension handler """ |
857 | self.handlers.append(handler) |
858 | |
859 | def process(self, request, *args, **kwargs): |
860 | + """ Processes the handlers on the incoming request """ |
861 | res = request.get_response(self.application) |
862 | # currently request handlers are un-ordered |
863 | for handler in self.handlers: |
864 | @@ -177,11 +197,14 @@ |
865 | |
866 | |
867 | class ExtensionController(wsgi.Controller): |
868 | + """ Controller for managing API extensions """ |
869 | |
870 | def __init__(self, extension_manager): |
871 | self.extension_manager = extension_manager |
872 | + super(ExtensionController, self).__init__() |
873 | |
874 | def _translate(self, ext): |
875 | + """ Prepares a dictionary with data about the extensions """ |
876 | ext_data = {} |
877 | ext_data['name'] = ext.get_name() |
878 | ext_data['alias'] = ext.get_alias() |
879 | @@ -192,12 +215,14 @@ |
880 | return ext_data |
881 | |
882 | def index(self, request): |
883 | + """ Retrieves a list of available extensions """ |
884 | extensions = [] |
885 | for _alias, ext in self.extension_manager.extensions.iteritems(): |
886 | extensions.append(self._translate(ext)) |
887 | return dict(extensions=extensions) |
888 | |
889 | def show(self, request, id): |
890 | + """ Retrieves a specific extension """ |
891 | # NOTE(dprince): the extensions alias is used as the 'id' for show |
892 | ext = self.extension_manager.extensions.get(id, None) |
893 | if not ext: |
894 | @@ -206,9 +231,11 @@ |
895 | return self._translate(ext) |
896 | |
897 | def delete(self, request, id): |
898 | + """ Not implemented """ |
899 | raise webob.exc.HTTPNotFound() |
900 | |
901 | def create(self, request): |
902 | + """ Not implemented """ |
903 | raise webob.exc.HTTPNotFound() |
904 | |
905 | |
906 | @@ -361,7 +388,7 @@ |
907 | resources = [] |
908 | resources.append(ResourceExtension('extensions', |
909 | ExtensionController(self))) |
910 | - for alias, ext in self.extensions.iteritems(): |
911 | + for _alias, ext in self.extensions.iteritems(): |
912 | try: |
913 | resources.extend(ext.get_resources()) |
914 | except AttributeError: |
915 | @@ -373,7 +400,7 @@ |
916 | def get_actions(self): |
917 | """Returns a list of ActionExtension objects.""" |
918 | actions = [] |
919 | - for alias, ext in self.extensions.iteritems(): |
920 | + for _alias, ext in self.extensions.iteritems(): |
921 | try: |
922 | actions.extend(ext.get_actions()) |
923 | except AttributeError: |
924 | @@ -385,7 +412,7 @@ |
925 | def get_request_extensions(self): |
926 | """Returns a list of RequestExtension objects.""" |
927 | request_exts = [] |
928 | - for alias, ext in self.extensions.iteritems(): |
929 | + for _alias, ext in self.extensions.iteritems(): |
930 | try: |
931 | request_exts.extend(ext.get_request_extensions()) |
932 | except AttributeError: |
933 | @@ -423,6 +450,7 @@ |
934 | self._load_all_extensions_from_path(self.path) |
935 | |
936 | def _load_all_extensions_from_path(self, path): |
937 | + """ Invoked by _load_all_extensions """ |
938 | for f in os.listdir(path): |
939 | try: |
940 | LOG.info(_('Loading extension file: %s'), f) |
941 | @@ -440,11 +468,15 @@ |
942 | continue |
943 | new_ext = new_ext_class() |
944 | self.add_extension(new_ext) |
945 | - except Exception as exception: |
946 | + except Exception, ex: |
947 | LOG.warn("extension file %s wasnt loaded due to %s", |
948 | - f, exception) |
949 | + f, ex) |
950 | |
951 | def add_extension(self, ext): |
952 | + """ Checks that the extensions provides all the required methods and |
953 | + then load it. |
954 | + |
955 | + """ |
956 | # Do nothing if the extension doesn't check out |
957 | if not self._check_extension(ext): |
958 | return |
959 | @@ -459,6 +491,7 @@ |
960 | |
961 | |
962 | class PluginAwareExtensionManager(ExtensionManager): |
963 | + """ Manager for API extensions which are aware of specific plugins """ |
964 | |
965 | def __init__(self, path, plugin): |
966 | self.plugin = plugin |
967 | @@ -474,6 +507,7 @@ |
968 | self._plugin_implements_interface(extension)) |
969 | |
970 | def _plugin_supports(self, extension): |
971 | + """ Verifies that the current plugins supports the extension """ |
972 | alias = extension.get_alias() |
973 | supports_extension = (hasattr(self.plugin, |
974 | "supported_extension_aliases") and |
975 | @@ -484,6 +518,10 @@ |
976 | return supports_extension |
977 | |
978 | def _plugin_implements_interface(self, extension): |
979 | + """ Verifies that the plugin correctly implements the interface |
980 | + required by the extension. |
981 | + |
982 | + """ |
983 | if(not hasattr(extension, "get_plugin_interface") or |
984 | extension.get_plugin_interface() is None): |
985 | return True |
986 | @@ -523,7 +561,12 @@ |
987 | """Add top level resources to the OpenStack API in Quantum.""" |
988 | |
989 | def __init__(self, collection, controller, parent=None, |
990 | - collection_actions={}, member_actions={}): |
991 | + collection_actions=None, member_actions=None): |
992 | + # Addressing pylint warning W0102 |
993 | + if collection_actions == None: |
994 | + collection_actions = {} |
995 | + if member_actions == None: |
996 | + member_actions = {} |
997 | self.collection = collection |
998 | self.controller = controller |
999 | self.parent = parent |
1000 | |
1001 | === modified file 'quantum/common/test_lib.py' |
1002 | --- quantum/common/test_lib.py 2011-08-07 05:03:52 +0000 |
1003 | +++ quantum/common/test_lib.py 2011-09-02 10:10:23 +0000 |
1004 | @@ -37,15 +37,14 @@ |
1005 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
1006 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
1007 | |
1008 | -import gettext |
1009 | -import os |
1010 | +""" Helper functions and classes for running unit tests """ |
1011 | + |
1012 | import unittest |
1013 | import sys |
1014 | import logging |
1015 | |
1016 | from nose import result |
1017 | from nose import core |
1018 | -from nose import config |
1019 | |
1020 | |
1021 | class _AnsiColorizer(object): |
1022 | @@ -81,8 +80,6 @@ |
1023 | return curses.tigetnum("colors") > 2 |
1024 | except: |
1025 | raise |
1026 | - # guess false in case of error |
1027 | - return False |
1028 | supported = classmethod(supported) |
1029 | |
1030 | def write(self, text, color): |
1031 | @@ -161,6 +158,8 @@ |
1032 | |
1033 | |
1034 | class QuantumTestResult(result.TextTestResult): |
1035 | + """ Creates results for unit tests in Quantum's test suite """ |
1036 | + |
1037 | def __init__(self, *args, **kw): |
1038 | result.TextTestResult.__init__(self, *args, **kw) |
1039 | self._last_case = None |
1040 | @@ -203,7 +202,7 @@ |
1041 | to the list for that class, not errors. |
1042 | """ |
1043 | stream = getattr(self, 'stream', None) |
1044 | - ec, ev, tb = err |
1045 | + ec, _ev, _tb = err |
1046 | try: |
1047 | exc_info = self._exc_info_to_string(err, test) |
1048 | except TypeError: |
1049 | |
1050 | === modified file 'quantum/common/utils.py' |
1051 | --- quantum/common/utils.py 2011-08-02 04:49:32 +0000 |
1052 | +++ quantum/common/utils.py 2011-09-02 10:10:23 +0000 |
1053 | @@ -27,7 +27,6 @@ |
1054 | import os |
1055 | import random |
1056 | import subprocess |
1057 | -import socket |
1058 | import sys |
1059 | |
1060 | |
1061 | @@ -92,7 +91,7 @@ |
1062 | |
1063 | |
1064 | def fetchfile(url, target): |
1065 | - logging.debug("Fetching %s" % url) |
1066 | + logging.debug("Fetching %s", url) |
1067 | # c = pycurl.Curl() |
1068 | # fp = open(target, "wb") |
1069 | # c.setopt(c.URL, url) |
1070 | @@ -117,7 +116,7 @@ |
1071 | result = obj.communicate() |
1072 | obj.stdin.close() |
1073 | if obj.returncode: |
1074 | - logging.debug("Result was %s" % (obj.returncode)) |
1075 | + logging.debug("Result was %s", obj.returncode) |
1076 | if check_exit_code and obj.returncode != 0: |
1077 | (stdout, stderr) = result |
1078 | raise ProcessExecutionError(exit_code=obj.returncode, |
1079 | @@ -154,9 +153,9 @@ |
1080 | |
1081 | |
1082 | def runthis(prompt, cmd, check_exit_code=True): |
1083 | - logging.debug("Running %s" % (cmd)) |
1084 | + logging.debug("Running %s", cmd) |
1085 | exit_code = subprocess.call(cmd.split(" ")) |
1086 | - logging.debug(prompt % (exit_code)) |
1087 | + logging.debug(prompt, exit_code) |
1088 | if check_exit_code and exit_code != 0: |
1089 | raise ProcessExecutionError(exit_code=exit_code, |
1090 | stdout=None, |
1091 | @@ -167,7 +166,7 @@ |
1092 | def generate_uid(topic, size=8): |
1093 | return '%s-%s' % (topic, ''.join( |
1094 | [random.choice('01234567890abcdefghijklmnopqrstuvwxyz') |
1095 | - for x in xrange(size)])) |
1096 | + for _x in xrange(size)])) |
1097 | |
1098 | |
1099 | def generate_mac(): |
1100 | |
1101 | === modified file 'quantum/db/api.py' |
1102 | --- quantum/db/api.py 2011-08-30 01:16:39 +0000 |
1103 | +++ quantum/db/api.py 2011-09-02 10:10:23 +0000 |
1104 | @@ -16,6 +16,12 @@ |
1105 | # @author: Somik Behera, Nicira Networks, Inc. |
1106 | # @author: Brad Hall, Nicira Networks, Inc. |
1107 | # @author: Dan Wendlandt, Nicira Networks, Inc. |
1108 | +# @author: Salvatore Orlando, Citrix Systems |
1109 | + |
1110 | +""" DB operations for manipulating resources defined by the core API: |
1111 | + networks, ports, and attachments |
1112 | + |
1113 | +""" |
1114 | |
1115 | import logging |
1116 | |
1117 | @@ -49,6 +55,10 @@ |
1118 | |
1119 | |
1120 | def clear_db(): |
1121 | + """ Destroys contents of the db. |
1122 | + Used in unit tests. |
1123 | + |
1124 | + """ |
1125 | global _ENGINE |
1126 | assert _ENGINE |
1127 | for table in reversed(BASE.metadata.sorted_tables): |
1128 | @@ -80,26 +90,8 @@ |
1129 | BASE.metadata.drop_all(_ENGINE) |
1130 | |
1131 | |
1132 | -def _check_duplicate_net_name(tenant_id, net_name): |
1133 | - """Checks whether a network with the same name |
1134 | - already exists for the tenant. |
1135 | - """ |
1136 | - |
1137 | - #TODO(salvatore-orlando): Not used anymore - candidate for removal |
1138 | - session = get_session() |
1139 | - try: |
1140 | - net = session.query(models.Network).\ |
1141 | - filter_by(tenant_id=tenant_id, name=net_name).\ |
1142 | - one() |
1143 | - raise q_exc.NetworkNameExists(tenant_id=tenant_id, |
1144 | - net_name=net_name, net_id=net.uuid) |
1145 | - except exc.NoResultFound: |
1146 | - # this is the "normal" path, as API spec specifies |
1147 | - # that net-names are unique within a tenant |
1148 | - pass |
1149 | - |
1150 | - |
1151 | def network_create(tenant_id, name): |
1152 | + """ Creates a network with a given name """ |
1153 | session = get_session() |
1154 | |
1155 | with session.begin(): |
1156 | @@ -110,6 +102,7 @@ |
1157 | |
1158 | |
1159 | def network_list(tenant_id): |
1160 | + """ List currently available networks """ |
1161 | session = get_session() |
1162 | return session.query(models.Network).\ |
1163 | filter_by(tenant_id=tenant_id).\ |
1164 | @@ -117,19 +110,20 @@ |
1165 | |
1166 | |
1167 | def network_get(net_id): |
1168 | + """ Retrieves a specific network """ |
1169 | session = get_session() |
1170 | try: |
1171 | return session.query(models.Network).\ |
1172 | filter_by(uuid=net_id).\ |
1173 | one() |
1174 | - except exc.NoResultFound, e: |
1175 | + except exc.NoResultFound: |
1176 | raise q_exc.NetworkNotFound(net_id=net_id) |
1177 | |
1178 | |
1179 | def network_rename(net_id, tenant_id, new_name): |
1180 | + """ Renames a specific network """ |
1181 | session = get_session() |
1182 | net = network_get(net_id) |
1183 | - _check_duplicate_net_name(tenant_id, new_name) |
1184 | net.name = new_name |
1185 | session.merge(net) |
1186 | session.flush() |
1187 | @@ -137,6 +131,7 @@ |
1188 | |
1189 | |
1190 | def network_destroy(net_id): |
1191 | + """ Removes a network """ |
1192 | session = get_session() |
1193 | try: |
1194 | net = session.query(models.Network).\ |
1195 | @@ -146,8 +141,8 @@ |
1196 | ports = session.query(models.Port).\ |
1197 | filter_by(network_id=net_id).\ |
1198 | all() |
1199 | - for p in ports: |
1200 | - session.delete(p) |
1201 | + for port in ports: |
1202 | + session.delete(port) |
1203 | |
1204 | session.delete(net) |
1205 | session.flush() |
1206 | @@ -157,6 +152,7 @@ |
1207 | |
1208 | |
1209 | def port_create(net_id, state=None): |
1210 | + """ Creates a port an a given network """ |
1211 | # confirm network exists |
1212 | network_get(net_id) |
1213 | |
1214 | @@ -170,6 +166,7 @@ |
1215 | |
1216 | |
1217 | def port_list(net_id): |
1218 | + """ Lists ports configured for a network """ |
1219 | session = get_session() |
1220 | return session.query(models.Port).\ |
1221 | filter_by(network_id=net_id).\ |
1222 | @@ -177,6 +174,7 @@ |
1223 | |
1224 | |
1225 | def port_get(port_id, net_id): |
1226 | + """ Retrieves a specific port """ |
1227 | # confirm network exists |
1228 | network_get(net_id) |
1229 | session = get_session() |
1230 | @@ -190,6 +188,7 @@ |
1231 | |
1232 | |
1233 | def port_set_state(port_id, net_id, new_state): |
1234 | + """ Updates the state of a port """ |
1235 | if new_state not in ('ACTIVE', 'DOWN'): |
1236 | raise q_exc.StateInvalid(port_state=new_state) |
1237 | |
1238 | @@ -205,6 +204,7 @@ |
1239 | |
1240 | |
1241 | def port_set_attachment(port_id, net_id, new_interface_id): |
1242 | + """ Sets the attachment for a port """ |
1243 | # confirm network exists |
1244 | network_get(net_id) |
1245 | |
1246 | @@ -235,6 +235,7 @@ |
1247 | |
1248 | |
1249 | def port_unset_attachment(port_id, net_id): |
1250 | + """ Removes the attachment for a port """ |
1251 | # confirm network exists |
1252 | network_get(net_id) |
1253 | |
1254 | @@ -246,6 +247,7 @@ |
1255 | |
1256 | |
1257 | def port_destroy(port_id, net_id): |
1258 | + """ Deletes a port """ |
1259 | # confirm network exists |
1260 | network_get(net_id) |
1261 | |
1262 | |
1263 | === modified file 'quantum/manager.py' |
1264 | --- quantum/manager.py 2011-08-26 10:20:55 +0000 |
1265 | +++ quantum/manager.py 2011-09-02 10:10:23 +0000 |
1266 | @@ -38,7 +38,7 @@ |
1267 | |
1268 | |
1269 | def find_config(basepath): |
1270 | - for root, dirs, files in os.walk(basepath): |
1271 | + for root, _dirs, files in os.walk(basepath): |
1272 | if CONFIG_FILE in files: |
1273 | return os.path.join(root, CONFIG_FILE) |
1274 | return None |
1275 | |
1276 | === modified file 'quantum/plugins/SamplePlugin.py' |
1277 | --- quantum/plugins/SamplePlugin.py 2011-09-01 16:17:36 +0000 |
1278 | +++ quantum/plugins/SamplePlugin.py 2011-09-02 10:10:23 +0000 |
1279 | @@ -16,6 +16,11 @@ |
1280 | # @author: Somik Behera, Nicira Networks, Inc. |
1281 | # @author: Salvatore Orlando, Citrix |
1282 | |
1283 | +""" Sample implementation of the quantum plugin interface |
1284 | +exposed by QuantumPluginBase. |
1285 | +FakePlugin and QuantumEcho plugin are used in unit tests. |
1286 | + |
1287 | +""" |
1288 | import logging |
1289 | |
1290 | from quantum.common import exceptions as exc |
1291 | @@ -24,6 +29,8 @@ |
1292 | LOG = logging.getLogger('quantum.plugins.SamplePlugin') |
1293 | |
1294 | |
1295 | +# pylint: disable=W0613 |
1296 | +# pylint: disable=R0201 |
1297 | class QuantumEchoPlugin(object): |
1298 | |
1299 | """ |
1300 | @@ -122,6 +129,9 @@ |
1301 | supported_extension_aliases = ["FOXNSOX"] |
1302 | |
1303 | def method_to_support_foxnsox_extension(self): |
1304 | + """ |
1305 | + Simple method invoked by API extensions unit tests |
1306 | + """ |
1307 | print("method_to_support_foxnsox_extension() called\n") |
1308 | |
1309 | |
1310 | @@ -136,15 +146,22 @@ |
1311 | db.configure_db({'sql_connection': 'sqlite:///:memory:'}) |
1312 | FakePlugin._net_counter = 0 |
1313 | |
1314 | - def _get_network(self, tenant_id, network_id): |
1315 | + def _get_network(self, network_id): |
1316 | + """ |
1317 | + Retrieves a network from db. Raises exception if network is not found. |
1318 | + """ |
1319 | try: |
1320 | network = db.network_get(network_id) |
1321 | except: |
1322 | raise exc.NetworkNotFound(net_id=network_id) |
1323 | return network |
1324 | |
1325 | - def _get_port(self, tenant_id, network_id, port_id): |
1326 | - net = self._get_network(tenant_id, network_id) |
1327 | + def _get_port(self, network_id, port_id): |
1328 | + """ |
1329 | + Retrieves a port from db. |
1330 | + Raises exception if either port or network are not found. |
1331 | + """ |
1332 | + net = self._get_network(network_id) |
1333 | try: |
1334 | port = db.port_get(port_id, network_id) |
1335 | except: |
1336 | @@ -155,6 +172,9 @@ |
1337 | return port |
1338 | |
1339 | def _validate_port_state(self, port_state): |
1340 | + """ |
1341 | + Verifies the proposed port state is allowed. |
1342 | + """ |
1343 | if port_state.upper() not in ('ACTIVE', 'DOWN'): |
1344 | raise exc.StateInvalid(port_state=port_state) |
1345 | return True |
1346 | @@ -188,7 +208,7 @@ |
1347 | are attached to the network |
1348 | """ |
1349 | LOG.debug("FakePlugin.get_network_details() called") |
1350 | - net = self._get_network(tenant_id, net_id) |
1351 | + net = self._get_network(net_id) |
1352 | # Retrieves ports for network |
1353 | ports = self.get_all_ports(tenant_id, net_id) |
1354 | return {'net-id': str(net.uuid), |
1355 | @@ -211,7 +231,7 @@ |
1356 | belonging to the specified tenant. |
1357 | """ |
1358 | LOG.debug("FakePlugin.delete_network() called") |
1359 | - net = self._get_network(tenant_id, net_id) |
1360 | + net = self._get_network(net_id) |
1361 | # Verify that no attachments are plugged into the network |
1362 | if net: |
1363 | for port in db.port_list(net_id): |
1364 | @@ -229,7 +249,7 @@ |
1365 | """ |
1366 | LOG.debug("FakePlugin.rename_network() called") |
1367 | db.network_rename(net_id, tenant_id, new_name) |
1368 | - net = self._get_network(tenant_id, net_id) |
1369 | + net = self._get_network(net_id) |
1370 | return net |
1371 | |
1372 | def get_all_ports(self, tenant_id, net_id): |
1373 | @@ -240,8 +260,8 @@ |
1374 | LOG.debug("FakePlugin.get_all_ports() called") |
1375 | port_ids = [] |
1376 | ports = db.port_list(net_id) |
1377 | - for x in ports: |
1378 | - d = {'port-id': str(x.uuid)} |
1379 | + for port in ports: |
1380 | + d = {'port-id': str(port.uuid)} |
1381 | port_ids.append(d) |
1382 | return port_ids |
1383 | |
1384 | @@ -251,7 +271,7 @@ |
1385 | that is attached to this particular port. |
1386 | """ |
1387 | LOG.debug("FakePlugin.get_port_details() called") |
1388 | - port = self._get_port(tenant_id, net_id, port_id) |
1389 | + port = self._get_port(net_id, port_id) |
1390 | return {'port-id': str(port.uuid), |
1391 | 'attachment': port.interface_id, |
1392 | 'port-state': port.state} |
1393 | @@ -262,7 +282,7 @@ |
1394 | """ |
1395 | LOG.debug("FakePlugin.create_port() called") |
1396 | # verify net_id |
1397 | - self._get_network(tenant_id, net_id) |
1398 | + self._get_network(net_id) |
1399 | port = db.port_create(net_id, port_state) |
1400 | port_item = {'port-id': str(port.uuid)} |
1401 | return port_item |
1402 | @@ -273,8 +293,8 @@ |
1403 | """ |
1404 | LOG.debug("FakePlugin.update_port() called") |
1405 | #validate port and network ids |
1406 | - self._get_network(tenant_id, net_id) |
1407 | - self._get_port(tenant_id, net_id, port_id) |
1408 | + self._get_network(net_id) |
1409 | + self._get_port(net_id, port_id) |
1410 | self._validate_port_state(new_state) |
1411 | db.port_set_state(port_id, net_id, new_state) |
1412 | port_item = {'port-id': port_id, |
1413 | @@ -289,18 +309,17 @@ |
1414 | is deleted. |
1415 | """ |
1416 | LOG.debug("FakePlugin.delete_port() called") |
1417 | - net = self._get_network(tenant_id, net_id) |
1418 | - port = self._get_port(tenant_id, net_id, port_id) |
1419 | + port = self._get_port(net_id, port_id) |
1420 | if port['interface_id']: |
1421 | raise exc.PortInUse(net_id=net_id, port_id=port_id, |
1422 | att_id=port['interface_id']) |
1423 | try: |
1424 | port = db.port_destroy(port_id, net_id) |
1425 | - except Exception, e: |
1426 | - raise Exception("Failed to delete port: %s" % str(e)) |
1427 | - d = {} |
1428 | - d["port-id"] = str(port.uuid) |
1429 | - return d |
1430 | + except Exception, ex: |
1431 | + raise Exception("Failed to delete port: %s" % str(ex)) |
1432 | + port_data = {} |
1433 | + port_data["port-id"] = str(port.uuid) |
1434 | + return port_data |
1435 | |
1436 | def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id): |
1437 | """ |
1438 | @@ -308,7 +327,7 @@ |
1439 | specified Virtual Network. |
1440 | """ |
1441 | LOG.debug("FakePlugin.plug_interface() called") |
1442 | - port = self._get_port(tenant_id, net_id, port_id) |
1443 | + port = self._get_port(net_id, port_id) |
1444 | # Validate attachment |
1445 | self._validate_attachment(tenant_id, net_id, port_id, |
1446 | remote_interface_id) |
1447 | @@ -323,7 +342,5 @@ |
1448 | specified Virtual Network. |
1449 | """ |
1450 | LOG.debug("FakePlugin.unplug_interface() called") |
1451 | - self._get_port(tenant_id, net_id, port_id) |
1452 | - # TODO(salvatore-orlando): |
1453 | - # Should unplug on port without attachment raise an Error? |
1454 | + self._get_port(net_id, port_id) |
1455 | db.port_unset_attachment(port_id, net_id) |
1456 | |
1457 | === modified file 'quantum/plugins/cisco/common/cisco_credentials.py' |
1458 | --- quantum/plugins/cisco/common/cisco_credentials.py 2011-08-26 02:54:08 +0000 |
1459 | +++ quantum/plugins/cisco/common/cisco_credentials.py 2011-09-02 10:10:23 +0000 |
1460 | @@ -58,7 +58,7 @@ |
1461 | @staticmethod |
1462 | def putCredential(cred_name, username, password): |
1463 | """Set the username and password""" |
1464 | - credential = cdb.add_credential(TENANT, cred_name, username, password) |
1465 | + _credential = cdb.add_credential(TENANT, cred_name, username, password) |
1466 | |
1467 | @staticmethod |
1468 | def getUsername(cred_name): |
1469 | @@ -75,7 +75,7 @@ |
1470 | @staticmethod |
1471 | def getCredential(cred_name): |
1472 | """Get the username and password""" |
1473 | - credential = cdb.get_credential_name(TENANT, cred_name) |
1474 | + _credential = cdb.get_credential_name(TENANT, cred_name) |
1475 | return {const.USERNAME: const.CREDENTIAL_USERNAME, |
1476 | const.PASSWORD: const.CREDENTIAL_PASSWORD} |
1477 | |
1478 | |
1479 | === modified file 'quantum/plugins/cisco/common/cisco_utils.py' |
1480 | --- quantum/plugins/cisco/common/cisco_utils.py 2011-08-20 19:44:23 +0000 |
1481 | +++ quantum/plugins/cisco/common/cisco_utils.py 2011-09-02 10:10:23 +0000 |
1482 | @@ -26,7 +26,6 @@ |
1483 | |
1484 | from quantum.plugins.cisco.common import cisco_constants as const |
1485 | from quantum.plugins.cisco.common import cisco_nova_configuration as conf |
1486 | -from quantum.plugins.cisco.db import api as db |
1487 | from quantum.plugins.cisco.db import l2network_db as cdb |
1488 | |
1489 | LOG.basicConfig(level=LOG.WARN) |
1490 | @@ -100,7 +99,7 @@ |
1491 | cursor = db.cursor() |
1492 | try: |
1493 | cursor.execute(sql_query) |
1494 | - results = cursor.fetchall() |
1495 | + _results = cursor.fetchall() |
1496 | db.commit() |
1497 | LOG.debug("DB query execution succeeded: %s" % sql_query) |
1498 | db.close() |
1499 | |
1500 | === modified file 'quantum/plugins/cisco/conf/db_conn.ini' |
1501 | --- quantum/plugins/cisco/conf/db_conn.ini 2011-08-19 17:58:32 +0000 |
1502 | +++ quantum/plugins/cisco/conf/db_conn.ini 2011-09-02 10:10:23 +0000 |
1503 | @@ -1,5 +1,5 @@ |
1504 | [DATABASE] |
1505 | name = quantum_l2network |
1506 | -user = <put_db_user_name_here> |
1507 | -pass = <put_db_password_here> |
1508 | -host = <put_quantum_mysql_host_here> |
1509 | +user = root |
1510 | +pass = citrix |
1511 | +host = 127.0.0.1 |
1512 | |
1513 | === modified file 'quantum/plugins/cisco/conf/plugins.ini' |
1514 | --- quantum/plugins/cisco/conf/plugins.ini 2011-08-22 10:34:48 +0000 |
1515 | +++ quantum/plugins/cisco/conf/plugins.ini 2011-09-02 10:10:23 +0000 |
1516 | @@ -1,5 +1,5 @@ |
1517 | [PLUGINS] |
1518 | -ucs_plugin=quantum.plugins.cisco.ucs.cisco_ucs_plugin.UCSVICPlugin |
1519 | +#ucs_plugin=quantum.plugins.cisco.ucs.cisco_ucs_plugin.UCSVICPlugin |
1520 | #nexus_plugin=quantum.plugins.cisco.nexus.cisco_nexus_plugin.NexusPlugin |
1521 | |
1522 | [INVENTORY] |
1523 | |
1524 | === modified file 'quantum/plugins/cisco/db/api.py' |
1525 | --- quantum/plugins/cisco/db/api.py 2011-08-28 19:27:27 +0000 |
1526 | +++ quantum/plugins/cisco/db/api.py 2011-09-02 10:10:23 +0000 |
1527 | @@ -76,24 +76,9 @@ |
1528 | BASE.metadata.drop_all(_ENGINE) |
1529 | |
1530 | |
1531 | -def _check_duplicate_net_name(tenant_id, net_name): |
1532 | - session = get_session() |
1533 | - try: |
1534 | - net = session.query(models.Network).\ |
1535 | - filter_by(tenant_id=tenant_id, name=net_name).\ |
1536 | - one() |
1537 | - raise q_exc.NetworkNameExists(tenant_id=tenant_id, |
1538 | - net_name=net_name, net_id=net.uuid) |
1539 | - except exc.NoResultFound: |
1540 | - # this is the "normal" path, as API spec specifies |
1541 | - # that net-names are unique within a tenant |
1542 | - pass |
1543 | - |
1544 | - |
1545 | def network_create(tenant_id, name): |
1546 | session = get_session() |
1547 | |
1548 | - _check_duplicate_net_name(tenant_id, name) |
1549 | with session.begin(): |
1550 | net = models.Network(tenant_id, name) |
1551 | session.add(net) |
1552 | @@ -123,7 +108,6 @@ |
1553 | def network_rename(tenant_id, net_id, new_name): |
1554 | session = get_session() |
1555 | net = network_get(net_id) |
1556 | - _check_duplicate_net_name(tenant_id, new_name) |
1557 | net.name = new_name |
1558 | session.merge(net) |
1559 | session.flush() |
1560 | @@ -159,7 +143,7 @@ |
1561 | def port_list(net_id): |
1562 | session = get_session() |
1563 | return session.query(models.Port).\ |
1564 | - options(joinedload(models.Port.network)). \ |
1565 | + options(joinedload(models.Port.network_id)). \ |
1566 | filter_by(network_id=net_id).\ |
1567 | all() |
1568 | |
1569 | |
1570 | === modified file 'quantum/plugins/cisco/db/l2network_db.py' |
1571 | --- quantum/plugins/cisco/db/l2network_db.py 2011-08-26 02:54:08 +0000 |
1572 | +++ quantum/plugins/cisco/db/l2network_db.py 2011-09-02 10:10:23 +0000 |
1573 | @@ -24,8 +24,6 @@ |
1574 | |
1575 | import logging as LOG |
1576 | import quantum.plugins.cisco.db.api as db |
1577 | -import quantum.plugins.cisco.db.nexus_db as ndb |
1578 | -import quantum.plugins.cisco.db.ucs_db as udb |
1579 | |
1580 | |
1581 | def initialize(): |
1582 | |
1583 | === modified file 'quantum/plugins/cisco/l2network_plugin.py' |
1584 | --- quantum/plugins/cisco/l2network_plugin.py 2011-08-26 02:54:08 +0000 |
1585 | +++ quantum/plugins/cisco/l2network_plugin.py 2011-09-02 10:10:23 +0000 |
1586 | @@ -21,7 +21,6 @@ |
1587 | |
1588 | import inspect |
1589 | import logging as LOG |
1590 | -import platform |
1591 | |
1592 | from quantum.common import exceptions as exc |
1593 | from quantum.common import utils |
1594 | @@ -197,7 +196,7 @@ |
1595 | then the port can be deleted. |
1596 | """ |
1597 | LOG.debug("delete_port() called\n") |
1598 | - network = db.network_get(net_id) |
1599 | + _network = db.network_get(net_id) |
1600 | port = db.port_get(net_id, port_id) |
1601 | attachment_id = port[const.INTERFACEID] |
1602 | if not attachment_id: |
1603 | @@ -216,7 +215,7 @@ |
1604 | Updates the state of a port on the specified Virtual Network. |
1605 | """ |
1606 | LOG.debug("update_port() called\n") |
1607 | - network = db.network_get(net_id) |
1608 | + _network = db.network_get(net_id) |
1609 | self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, |
1610 | port_id, port_state]) |
1611 | self._validate_port_state(port_state) |
1612 | @@ -231,7 +230,7 @@ |
1613 | that is attached to this particular port. |
1614 | """ |
1615 | LOG.debug("get_port_details() called\n") |
1616 | - network = db.network_get(net_id) |
1617 | + _network = db.network_get(net_id) |
1618 | self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, |
1619 | port_id]) |
1620 | port = db.port_get(net_id, port_id) |
1621 | @@ -248,7 +247,7 @@ |
1622 | specified Virtual Network. |
1623 | """ |
1624 | LOG.debug("plug_interface() called\n") |
1625 | - network = db.network_get(net_id) |
1626 | + _network = db.network_get(net_id) |
1627 | self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, |
1628 | port_id, |
1629 | remote_interface_id]) |
1630 | @@ -260,7 +259,7 @@ |
1631 | specified Virtual Network. |
1632 | """ |
1633 | LOG.debug("unplug_interface() called\n") |
1634 | - network = db.network_get(net_id) |
1635 | + _network = db.network_get(net_id) |
1636 | self._invoke_device_plugins(self._func_name(), [tenant_id, net_id, |
1637 | port_id]) |
1638 | db.port_unset_attachment(net_id, port_id) |
1639 | @@ -287,7 +286,7 @@ |
1640 | LOG.debug("get_portprofile_details() called\n") |
1641 | try: |
1642 | portprofile = cdb.get_portprofile(tenant_id, profile_id) |
1643 | - except Exception, excp: |
1644 | + except Exception: |
1645 | raise cexc.PortProfileNotFound(tenant_id=tenant_id, |
1646 | portprofile_id=profile_id) |
1647 | |
1648 | @@ -312,8 +311,8 @@ |
1649 | """Delete portprofile""" |
1650 | LOG.debug("delete_portprofile() called\n") |
1651 | try: |
1652 | - portprofile = cdb.get_portprofile(tenant_id, profile_id) |
1653 | - except Exception, excp: |
1654 | + _portprofile = cdb.get_portprofile(tenant_id, profile_id) |
1655 | + except Exception: |
1656 | raise cexc.PortProfileNotFound(tenant_id=tenant_id, |
1657 | portprofile_id=profile_id) |
1658 | |
1659 | @@ -328,8 +327,8 @@ |
1660 | """Rename port profile""" |
1661 | LOG.debug("rename_portprofile() called\n") |
1662 | try: |
1663 | - portprofile = cdb.get_portprofile(tenant_id, profile_id) |
1664 | - except Exception, excp: |
1665 | + _portprofile = cdb.get_portprofile(tenant_id, profile_id) |
1666 | + except Exception: |
1667 | raise cexc.PortProfileNotFound(tenant_id=tenant_id, |
1668 | portprofile_id=profile_id) |
1669 | portprofile = cdb.update_portprofile(tenant_id, profile_id, new_name) |
1670 | @@ -339,25 +338,25 @@ |
1671 | portprofile[const.PPQOS]) |
1672 | return new_pp |
1673 | |
1674 | - def associate_portprofile(self, tenant_id, net_id, |
1675 | + def associate_portprofile(self, tenant_id, _net_id, |
1676 | port_id, portprofile_id): |
1677 | """Associate port profile""" |
1678 | LOG.debug("associate_portprofile() called\n") |
1679 | try: |
1680 | - portprofile = cdb.get_portprofile(tenant_id, portprofile_id) |
1681 | - except Exception, excp: |
1682 | + _portprofile = cdb.get_portprofile(tenant_id, portprofile_id) |
1683 | + except Exception: |
1684 | raise cexc.PortProfileNotFound(tenant_id=tenant_id, |
1685 | portprofile_id=portprofile_id) |
1686 | |
1687 | cdb.add_pp_binding(tenant_id, port_id, portprofile_id, False) |
1688 | |
1689 | - def disassociate_portprofile(self, tenant_id, net_id, |
1690 | + def disassociate_portprofile(self, tenant_id, _net_id, |
1691 | port_id, portprofile_id): |
1692 | """Disassociate port profile""" |
1693 | LOG.debug("disassociate_portprofile() called\n") |
1694 | try: |
1695 | - portprofile = cdb.get_portprofile(tenant_id, portprofile_id) |
1696 | - except Exception, excp: |
1697 | + _portprofile = cdb.get_portprofile(tenant_id, portprofile_id) |
1698 | + except Exception: |
1699 | raise cexc.PortProfileNotFound(tenant_id=tenant_id, |
1700 | portprofile_id=portprofile_id) |
1701 | |
1702 | @@ -374,7 +373,7 @@ |
1703 | LOG.debug("get_qos_details() called\n") |
1704 | try: |
1705 | qos_level = cdb.get_qos(tenant_id, qos_id) |
1706 | - except Exception, excp: |
1707 | + except Exception: |
1708 | raise cexc.QosNotFound(tenant_id=tenant_id, |
1709 | qos_id=qos_id) |
1710 | return qos_level |
1711 | @@ -389,8 +388,8 @@ |
1712 | """Delete a QoS level""" |
1713 | LOG.debug("delete_qos() called\n") |
1714 | try: |
1715 | - qos_level = cdb.get_qos(tenant_id, qos_id) |
1716 | - except Exception, excp: |
1717 | + _qos_level = cdb.get_qos(tenant_id, qos_id) |
1718 | + except Exception: |
1719 | raise cexc.QosNotFound(tenant_id=tenant_id, |
1720 | qos_id=qos_id) |
1721 | return cdb.remove_qos(tenant_id, qos_id) |
1722 | @@ -399,8 +398,8 @@ |
1723 | """Rename QoS level""" |
1724 | LOG.debug("rename_qos() called\n") |
1725 | try: |
1726 | - qos_level = cdb.get_qos(tenant_id, qos_id) |
1727 | - except Exception, excp: |
1728 | + _qos_level = cdb.get_qos(tenant_id, qos_id) |
1729 | + except Exception: |
1730 | raise cexc.QosNotFound(tenant_id=tenant_id, |
1731 | qos_id=qos_id) |
1732 | qos = cdb.update_qos(tenant_id, qos_id, new_name) |
1733 | @@ -417,7 +416,7 @@ |
1734 | LOG.debug("get_credential_details() called\n") |
1735 | try: |
1736 | credential = cdb.get_credential(tenant_id, credential_id) |
1737 | - except Exception, excp: |
1738 | + except Exception: |
1739 | raise cexc.CredentialNotFound(tenant_id=tenant_id, |
1740 | credential_id=credential_id) |
1741 | return credential |
1742 | @@ -434,8 +433,8 @@ |
1743 | """Delete a credential""" |
1744 | LOG.debug("delete_credential() called\n") |
1745 | try: |
1746 | - credential = cdb.get_credential(tenant_id, credential_id) |
1747 | - except Exception, excp: |
1748 | + _credential = cdb.get_credential(tenant_id, credential_id) |
1749 | + except Exception: |
1750 | raise cexc.CredentialNotFound(tenant_id=tenant_id, |
1751 | credential_id=credential_id) |
1752 | credential = cdb.remove_credential(tenant_id, credential_id) |
1753 | @@ -445,8 +444,8 @@ |
1754 | """Rename the particular credential resource""" |
1755 | LOG.debug("rename_credential() called\n") |
1756 | try: |
1757 | - credential = cdb.get_credential(tenant_id, credential_id) |
1758 | - except Exception, excp: |
1759 | + _credential = cdb.get_credential(tenant_id, credential_id) |
1760 | + except Exception: |
1761 | raise cexc.CredentialNotFound(tenant_id=tenant_id, |
1762 | credential_id=credential_id) |
1763 | credential = cdb.update_credential(tenant_id, credential_id, new_name) |
1764 | |
1765 | === modified file 'quantum/plugins/cisco/models/l2network_multi_blade.py' |
1766 | --- quantum/plugins/cisco/models/l2network_multi_blade.py 2011-08-26 00:42:16 +0000 |
1767 | +++ quantum/plugins/cisco/models/l2network_multi_blade.py 2011-09-02 10:10:23 +0000 |
1768 | @@ -22,14 +22,11 @@ |
1769 | from copy import deepcopy |
1770 | import inspect |
1771 | import logging as LOG |
1772 | -import platform |
1773 | |
1774 | -from quantum.common import exceptions as exc |
1775 | from quantum.common import utils |
1776 | from quantum.plugins.cisco.l2network_model_base import L2NetworkModelBase |
1777 | from quantum.plugins.cisco import l2network_plugin_configuration as conf |
1778 | from quantum.plugins.cisco.common import cisco_constants as const |
1779 | -from quantum.plugins.cisco.common import cisco_exceptions as cexc |
1780 | |
1781 | LOG.basicConfig(level=LOG.WARN) |
1782 | LOG.getLogger(__name__) |
1783 | |
1784 | === modified file 'quantum/plugins/cisco/models/l2network_single_blade.py' |
1785 | --- quantum/plugins/cisco/models/l2network_single_blade.py 2011-08-26 00:42:16 +0000 |
1786 | +++ quantum/plugins/cisco/models/l2network_single_blade.py 2011-09-02 10:10:23 +0000 |
1787 | @@ -22,14 +22,11 @@ |
1788 | from copy import deepcopy |
1789 | import inspect |
1790 | import logging as LOG |
1791 | -import platform |
1792 | |
1793 | -from quantum.common import exceptions as exc |
1794 | from quantum.common import utils |
1795 | from quantum.plugins.cisco.l2network_model_base import L2NetworkModelBase |
1796 | from quantum.plugins.cisco import l2network_plugin_configuration as conf |
1797 | from quantum.plugins.cisco.common import cisco_constants as const |
1798 | -from quantum.plugins.cisco.common import cisco_exceptions as cexc |
1799 | |
1800 | LOG.basicConfig(level=LOG.WARN) |
1801 | LOG.getLogger(__name__) |
1802 | |
1803 | === modified file 'quantum/plugins/cisco/run_tests.py' |
1804 | --- quantum/plugins/cisco/run_tests.py 2011-08-17 19:37:22 +0000 |
1805 | +++ quantum/plugins/cisco/run_tests.py 2011-09-02 10:10:23 +0000 |
1806 | @@ -46,17 +46,14 @@ |
1807 | python quantum/plugins/cisco/run_tests.py functional.test_stores |
1808 | """ |
1809 | |
1810 | -import gettext |
1811 | -import logging |
1812 | import os |
1813 | -import unittest |
1814 | import sys |
1815 | |
1816 | from nose import config |
1817 | |
1818 | sys.path.append(os.getcwd()) |
1819 | |
1820 | -from quantum.common.test_lib import run_tests, test_config |
1821 | +from quantum.common.test_lib import run_tests |
1822 | |
1823 | if __name__ == '__main__': |
1824 | exit_status = False |
1825 | |
1826 | === modified file 'quantum/plugins/cisco/tests/unit/test_database.py' |
1827 | --- quantum/plugins/cisco/tests/unit/test_database.py 2011-08-25 23:29:30 +0000 |
1828 | +++ quantum/plugins/cisco/tests/unit/test_database.py 2011-09-02 10:10:23 +0000 |
1829 | @@ -610,9 +610,9 @@ |
1830 | net1 = self.quantum.create_network("t1", "netid1") |
1831 | port1 = self.quantum.create_port(net1["net-id"]) |
1832 | port2 = self.quantum.create_port(net1["net-id"]) |
1833 | - port_bind1 = self.dbtest.create_port_binding(port1["port-id"], |
1834 | + _port_bind1 = self.dbtest.create_port_binding(port1["port-id"], |
1835 | "vnic1", "pp1", "vlan1", 10, "qos1") |
1836 | - port_bind2 = self.dbtest.create_port_binding(port2["port-id"], |
1837 | + _port_bind2 = self.dbtest.create_port_binding(port2["port-id"], |
1838 | "vnic2", "pp2", "vlan2", 20, "qos2") |
1839 | port_bindings = self.dbtest.get_all_port_bindings() |
1840 | count = 0 |
1841 | @@ -627,7 +627,7 @@ |
1842 | """delete port binding""" |
1843 | net1 = self.quantum.create_network("t1", "netid1") |
1844 | port1 = self.quantum.create_port(net1["net-id"]) |
1845 | - port_bind1 = self.dbtest.create_port_binding(port1["port-id"], |
1846 | + _port_bind1 = self.dbtest.create_port_binding(port1["port-id"], |
1847 | "vnic1", "pp1", "vlan1", 10, "qos1") |
1848 | self.dbtest.delete_port_binding(port1["port-id"]) |
1849 | port_bindings = self.dbtest.get_all_port_bindings() |
1850 | @@ -643,9 +643,9 @@ |
1851 | """update port binding""" |
1852 | net1 = self.quantum.create_network("t1", "netid1") |
1853 | port1 = self.quantum.create_port(net1["net-id"]) |
1854 | - port_bind1 = self.dbtest.create_port_binding(port1["port-id"], |
1855 | + _port_bind1 = self.dbtest.create_port_binding(port1["port-id"], |
1856 | "vnic1", "pp1", "vlan1", 10, "qos1") |
1857 | - port_bind1 = self.dbtest.update_port_binding(port1["port-id"], |
1858 | + _port_bind1 = self.dbtest.update_port_binding(port1["port-id"], |
1859 | "vnic1", "newpp1", "newvlan1", 11, "newqos1") |
1860 | port_bindings = self.dbtest.get_all_port_bindings() |
1861 | count = 0 |
1862 | @@ -697,8 +697,8 @@ |
1863 | |
1864 | def testb_getall_nexusportbindings(self): |
1865 | """get all nexus port binding""" |
1866 | - binding1 = self.dbtest.create_nexusportbinding("port1", 10) |
1867 | - binding2 = self.dbtest.create_nexusportbinding("port2", 10) |
1868 | + _binding1 = self.dbtest.create_nexusportbinding("port1", 10) |
1869 | + _binding2 = self.dbtest.create_nexusportbinding("port2", 10) |
1870 | bindings = self.dbtest.get_all_nexusportbindings() |
1871 | count = 0 |
1872 | for bind in bindings: |
1873 | @@ -709,7 +709,7 @@ |
1874 | |
1875 | def testc_delete_nexusportbinding(self): |
1876 | """delete nexus port binding""" |
1877 | - binding1 = self.dbtest.create_nexusportbinding("port1", 10) |
1878 | + _binding1 = self.dbtest.create_nexusportbinding("port1", 10) |
1879 | self.dbtest.delete_nexusportbinding(10) |
1880 | bindings = self.dbtest.get_all_nexusportbindings() |
1881 | count = 0 |
1882 | @@ -1055,7 +1055,7 @@ |
1883 | self.assertTrue(port["net-id"] == net1["net-id"]) |
1884 | ports = self.dbtest.get_all_ports(net1["net-id"]) |
1885 | count = 0 |
1886 | - for por in ports: |
1887 | + for _port in ports: |
1888 | count += 1 |
1889 | self.assertTrue(count == 1) |
1890 | self.teardown_network_port() |
1891 | |
1892 | === modified file 'quantum/plugins/cisco/ucs/cisco_ucs_inventory.py' |
1893 | --- quantum/plugins/cisco/ucs/cisco_ucs_inventory.py 2011-08-28 05:55:08 +0000 |
1894 | +++ quantum/plugins/cisco/ucs/cisco_ucs_inventory.py 2011-09-02 10:10:23 +0000 |
1895 | @@ -27,7 +27,6 @@ |
1896 | from quantum.plugins.cisco.common import cisco_constants as const |
1897 | from quantum.plugins.cisco.common import cisco_credentials as cred |
1898 | from quantum.plugins.cisco.common import cisco_exceptions as cexc |
1899 | -from quantum.plugins.cisco.common import cisco_utils as cutil |
1900 | from quantum.plugins.cisco.db import api as db |
1901 | from quantum.plugins.cisco.db import ucs_db as udb |
1902 | from quantum.plugins.cisco.ucs \ |
1903 | @@ -247,7 +246,7 @@ |
1904 | blade_data = ucsm[chassis_id][blade_id] |
1905 | blade_intf_data = blade_data[const.BLADE_INTF_DATA] |
1906 | for blade_intf in blade_intf_data.keys(): |
1907 | - tmp = deepcopy(blade_intf_data[blade_intf]) |
1908 | + _tmp = deepcopy(blade_intf_data[blade_intf]) |
1909 | if blade_intf_data[blade_intf]\ |
1910 | [const.BLADE_INTF_RESERVATION] == \ |
1911 | const.BLADE_INTF_RESERVED and \ |
1912 | @@ -489,7 +488,7 @@ |
1913 | reserved_nic_dict = {const.RESERVED_NIC_HOSTNAME: host_name, |
1914 | const.RESERVED_NIC_NAME: dev_eth_name, |
1915 | const.BLADE_INTF_DN: blade_intf} |
1916 | - port_binding = udb.add_portbinding(port_id, blade_intf, None, |
1917 | + _port_binding = udb.add_portbinding(port_id, blade_intf, None, |
1918 | None, None, None) |
1919 | udb.update_portbinding(port_id, |
1920 | tenant_id=blade_intf_data[blade_intf]\ |
1921 | @@ -504,8 +503,8 @@ |
1922 | def unreserve_blade_interface(self, ucsm_ip, chassis_id, blade_id, |
1923 | interface_dn): |
1924 | """Unreserve a previously reserved interface on a blade""" |
1925 | - ucsm_username = cred.Store.getUsername(ucsm_ip) |
1926 | - ucsm_password = cred.Store.getPassword(ucsm_ip) |
1927 | + _ucsm_username = cred.Store.getUsername(ucsm_ip) |
1928 | + _ucsm_password = cred.Store.getPassword(ucsm_ip) |
1929 | self._inventory_state[ucsm_ip][chassis_id][blade_id] \ |
1930 | [const.BLADE_UNRESERVED_INTF_COUNT] += 1 |
1931 | blade_intf = self._inventory_state[ucsm_ip][chassis_id]\ |
1932 | |
1933 | === modified file 'quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py' |
1934 | --- quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py 2011-08-26 02:54:08 +0000 |
1935 | +++ quantum/plugins/cisco/ucs/cisco_ucs_network_driver.py 2011-09-02 10:10:23 +0000 |
1936 | @@ -27,9 +27,7 @@ |
1937 | import logging as LOG |
1938 | from xml.etree import ElementTree as et |
1939 | |
1940 | -from quantum.plugins.cisco.common import cisco_exceptions as cexc |
1941 | from quantum.plugins.cisco.common import cisco_constants as const |
1942 | -from quantum.plugins.cisco.ucs import cisco_getvif as gvif |
1943 | |
1944 | |
1945 | LOG.basicConfig(level=LOG.WARN) |
1946 | |
1947 | === modified file 'quantum/plugins/cisco/ucs/cisco_ucs_plugin.py' |
1948 | --- quantum/plugins/cisco/ucs/cisco_ucs_plugin.py 2011-08-26 02:54:08 +0000 |
1949 | +++ quantum/plugins/cisco/ucs/cisco_ucs_plugin.py 2011-09-02 10:10:23 +0000 |
1950 | @@ -21,7 +21,6 @@ |
1951 | |
1952 | import logging as LOG |
1953 | |
1954 | -from quantum.common import exceptions as exc |
1955 | from quantum.common import utils |
1956 | from quantum.plugins.cisco.common import cisco_exceptions as cexc |
1957 | from quantum.plugins.cisco.common import cisco_constants as const |
1958 | @@ -167,7 +166,7 @@ |
1959 | conf.DEFAULT_VLAN_NAME, |
1960 | conf.DEFAULT_VLAN_ID) |
1961 | profile_name = new_port_profile[const.PROFILE_NAME] |
1962 | - rsvd_nic_dict = ucs_inventory.\ |
1963 | + _rsvd_nic_dict = ucs_inventory.\ |
1964 | reserve_blade_interface(self._ucsm_ip, chassis_id, |
1965 | blade_id, blade_data_dict, |
1966 | tenant_id, port_id, |
1967 | |
1968 | === modified file 'quantum/plugins/openvswitch/ovs_db.py' |
1969 | --- quantum/plugins/openvswitch/ovs_db.py 2011-06-22 00:40:05 +0000 |
1970 | +++ quantum/plugins/openvswitch/ovs_db.py 2011-09-02 10:10:23 +0000 |
1971 | @@ -21,7 +21,6 @@ |
1972 | from sqlalchemy.orm import exc |
1973 | |
1974 | import quantum.db.api as db |
1975 | -import quantum.db.models as models |
1976 | import ovs_models |
1977 | |
1978 | |
1979 | |
1980 | === modified file 'quantum/plugins/openvswitch/ovs_models.py' |
1981 | --- quantum/plugins/openvswitch/ovs_models.py 2011-06-22 00:40:05 +0000 |
1982 | +++ quantum/plugins/openvswitch/ovs_models.py 2011-09-02 10:10:23 +0000 |
1983 | @@ -18,11 +18,7 @@ |
1984 | # @author: Dan Wendlandt, Nicira Networks, Inc. |
1985 | |
1986 | |
1987 | -import uuid |
1988 | - |
1989 | -from sqlalchemy import Column, Integer, String, ForeignKey |
1990 | -from sqlalchemy.ext.declarative import declarative_base |
1991 | -from sqlalchemy.orm import relation |
1992 | +from sqlalchemy import Column, Integer, String |
1993 | from quantum.db.models import BASE |
1994 | |
1995 | |
1996 | |
1997 | === modified file 'quantum/plugins/openvswitch/ovs_quantum_plugin.py' |
1998 | --- quantum/plugins/openvswitch/ovs_quantum_plugin.py 2011-08-26 08:02:41 +0000 |
1999 | +++ quantum/plugins/openvswitch/ovs_quantum_plugin.py 2011-09-02 10:10:23 +0000 |
2000 | @@ -19,9 +19,7 @@ |
2001 | |
2002 | import ConfigParser |
2003 | import logging as LOG |
2004 | -from optparse import OptionParser |
2005 | import os |
2006 | -import sys |
2007 | |
2008 | from quantum.common import exceptions as q_exc |
2009 | from quantum.quantum_plugin_base import QuantumPluginBase |
2010 | @@ -36,7 +34,7 @@ |
2011 | |
2012 | |
2013 | def find_config(basepath): |
2014 | - for root, dirs, files in os.walk(basepath): |
2015 | + for root, _dirs, files in os.walk(basepath): |
2016 | if CONF_FILE in files: |
2017 | return os.path.join(root, CONF_FILE) |
2018 | return None |
2019 | |
2020 | === modified file 'quantum/plugins/openvswitch/run_tests.py' |
2021 | --- quantum/plugins/openvswitch/run_tests.py 2011-08-26 08:02:41 +0000 |
2022 | +++ quantum/plugins/openvswitch/run_tests.py 2011-09-02 10:10:23 +0000 |
2023 | @@ -45,10 +45,7 @@ |
2024 | python quantum/plugins/openvswitch/run_tests.py functional.test_stores |
2025 | """ |
2026 | |
2027 | -import gettext |
2028 | -import logging |
2029 | import os |
2030 | -import unittest |
2031 | import sys |
2032 | |
2033 | from nose import config |
2034 | @@ -56,7 +53,6 @@ |
2035 | sys.path.append(os.getcwd()) |
2036 | |
2037 | from quantum.common.test_lib import run_tests, test_config |
2038 | -from quantum.plugins.openvswitch.tests.test_vlan_map import VlanMapTest |
2039 | |
2040 | if __name__ == '__main__': |
2041 | exit_status = False |
2042 | |
2043 | === modified file 'quantum/service.py' |
2044 | --- quantum/service.py 2011-06-24 13:52:17 +0000 |
2045 | +++ quantum/service.py 2011-09-02 10:10:23 +0000 |
2046 | @@ -102,9 +102,9 @@ |
2047 | |
2048 | def _run_wsgi(app_name, paste_conf, paste_config_file): |
2049 | LOG.info(_('Using paste.deploy config at: %s'), paste_config_file) |
2050 | - conf, app = config.load_paste_app(app_name, |
2051 | - {'config_file': paste_config_file}, |
2052 | - None) |
2053 | + _conf, app = config.load_paste_app(app_name, |
2054 | + {'config_file': paste_config_file}, |
2055 | + None) |
2056 | if not app: |
2057 | LOG.error(_('No known API applications configured in %s.'), |
2058 | paste_config_file) |
2059 | |
2060 | === modified file 'quantum/utils.py' |
2061 | --- quantum/utils.py 2011-05-31 17:15:00 +0000 |
2062 | +++ quantum/utils.py 2011-09-02 10:10:23 +0000 |
2063 | @@ -20,20 +20,9 @@ |
2064 | |
2065 | """Utilities and helper functions.""" |
2066 | |
2067 | -import base64 |
2068 | import datetime |
2069 | -import functools |
2070 | -import inspect |
2071 | import json |
2072 | -import os |
2073 | -import random |
2074 | -import re |
2075 | -import socket |
2076 | -import string |
2077 | -import struct |
2078 | import sys |
2079 | -import time |
2080 | -import types |
2081 | |
2082 | from common import exceptions as exception |
2083 | |
2084 | |
2085 | === modified file 'tests/unit/test_cli.py' |
2086 | --- tests/unit/test_cli.py 2011-08-30 16:00:11 +0000 |
2087 | +++ tests/unit/test_cli.py 2011-09-02 10:10:23 +0000 |
2088 | @@ -49,7 +49,7 @@ |
2089 | self.network_name_2 = "test_network_2" |
2090 | # Prepare client and plugin manager |
2091 | self.client = Client(tenant=self.tenant_id, format=FORMAT, |
2092 | - testingStub=client_stubs.FakeHTTPConnection) |
2093 | + testing_stub=client_stubs.FakeHTTPConnection) |
2094 | # Redirect stdout |
2095 | self.fake_stdout = client_stubs.FakeStdout() |
2096 | sys.stdout = self.fake_stdout |
Looks good/tests pass.