Merge lp:~openstack-gd/nova/lp783478 into lp:~hudson-openstack/nova/trunk

Proposed by Eldar Nugaev
Status: Merged
Approved by: Vish Ishaya
Approved revision: 1076
Merged at revision: 1096
Proposed branch: lp:~openstack-gd/nova/lp783478
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 88 lines (+34/-7)
1 file modified
bin/nova-manage (+34/-7)
To merge this branch: bzr merge lp:~openstack-gd/nova/lp783478
Reviewer Review Type Date Requested Status
Vish Ishaya (community) Approve
Matt Dietz (community) Approve
Devin Carlen (community) Approve
Ilya Alekseyev (community) Approve
Review via email: mp+61126@code.launchpad.net

Commit message

print information about nova-manage project problems

Description of the change

Added catching NotFound errors and print information
User %user% could not be found
Project %project% could not be found

To post a comment you must log in.
Revision history for this message
Brian Lamar (blamar) wrote :

While pedantic, pylint is going to complain about single letter "e" variables. I think many people have been using "ex". Also, can you add example text to the bug report or here showing what this looks like before and after. I think that should suffice as I'm not sure it's practical to automatically test bin/nova-manage.

Revision history for this message
Ed Leafe (ed-leafe) wrote :

> While pedantic, pylint is going to complain about single letter "e" variables.
> I think many people have been using "ex".

Catching an exception using the name 'e' is probably the most common usage in Python; the second most common is 'err', although I dislike that as it confuses errors and exceptions. I can't say that I've ever seen 'ex' used outside of some places in nova. I would be much more concerned about using the older structure of 'except SomeException, e:' (separating the class and the exception object with a comma); this syntax should not be used; instead, it would be much more preferable to use the 'except SomeException as e:'.

Revision history for this message
Vish Ishaya (vishvananda) wrote :

Yes, the ex change was because of pylint. Maybe we should just tell pylint to shut up about single letter variable names?

On May 16, 2011, at 10:51 AM, Ed Leafe wrote:

>> While pedantic, pylint is going to complain about single letter "e" variables.
>> I think many people have been using "ex".
>
> Catching an exception using the name 'e' is probably the most common usage in Python; the second most common is 'err', although I dislike that as it confuses errors and exceptions. I can't say that I've ever seen 'ex' used outside of some places in nova. I would be much more concerned about using the older structure of 'except SomeException, e:' (separating the class and the exception object with a comma); this syntax should not be used; instead, it would be much more preferable to use the 'except SomeException as e:'.
> --
> https://code.launchpad.net/~openstack-gd/nova/lp783478/+merge/61126
> You are subscribed to branch lp:nova.

Revision history for this message
Ilya Alekseyev (ilyaalekseyev) wrote :

Not sure is it important to disable usage of single letter variables, but seems patch solving the problem.
So, lgtm.

review: Approve
Revision history for this message
Brian Lamar (blamar) wrote :

> Yes, the ex change was because of pylint. Maybe we should just tell pylint to
> shut up about single letter variable names?

I'd be opposed to allowing single-letter variable names everywhere though, it just makes for poorly readable code. Exception handling should be short and sweet in most cases and I don't want pylint one-off ignores next to all of the "except Exception, e" so my recommendation for "ex" stands.

Revision history for this message
Eldar Nugaev (reldan) wrote :

Ok. No problem. Fixed

Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
Rick Harris (rconradharris) wrote :

Generally agree w/ Brian that single-letter vars are bad form; though, to me at least, it seems like there is a lazy-consensus in the Python community that the following cases are acceptable:

 * Exception handlers (except Exception as `e`)
 * List/Generator comprehensions (e.g. [h.name for h in hosts])
 * Index variables (`i` and `j`)

Since pylint doesn't seem to be smart enough to distinguish between these cases, I'd vote we disable that rule and continue our current process of keeping it the reviewer's call.

It'd be a shame if pylint led to *less* idiomatic code.

Revision history for this message
Matt Dietz (cerberus) wrote :

Also agree on the issue of single letter variable names. While there are cases where I think it makes sense, as detailed above, I don't want to open the floodgates to lazy developers.

review: Approve
Revision history for this message
Eldar Nugaev (reldan) wrote :

Thank you, Matt.
Could you please change status to approved?

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Attempt to merge into lp:nova failed due to conflicts:

text conflict in bin/nova-manage

Revision history for this message
Vish Ishaya (vishvananda) wrote :

looks like this needs a trunk merge.

review: Needs Fixing
Revision history for this message
Eldar Nugaev (reldan) wrote :

Thanks Vish.
Merged with trunk and conflicts resolved

lp:~openstack-gd/nova/lp783478 updated
1076. By Eldar Nugaev

Merge and conflict resolving

Revision history for this message
Vish Ishaya (vishvananda) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/nova-manage'
2--- bin/nova-manage 2011-05-17 16:15:21 +0000
3+++ bin/nova-manage 2011-05-20 09:34:30 +0000
4@@ -362,27 +362,47 @@
5 def add(self, project_id, user_id):
6 """Adds user to project
7 arguments: project_id user_id"""
8- self.manager.add_to_project(user_id, project_id)
9+ try:
10+ self.manager.add_to_project(user_id, project_id)
11+ except exception.UserNotFound as ex:
12+ print ex
13+ raise
14
15 def create(self, name, project_manager, description=None):
16 """Creates a new project
17 arguments: name project_manager [description]"""
18- self.manager.create_project(name, project_manager, description)
19+ try:
20+ self.manager.create_project(name, project_manager, description)
21+ except exception.UserNotFound as ex:
22+ print ex
23+ raise
24
25 def modify(self, name, project_manager, description=None):
26 """Modifies a project
27 arguments: name project_manager [description]"""
28- self.manager.modify_project(name, project_manager, description)
29+ try:
30+ self.manager.modify_project(name, project_manager, description)
31+ except exception.UserNotFound as ex:
32+ print ex
33+ raise
34
35 def delete(self, name):
36 """Deletes an existing project
37 arguments: name"""
38- self.manager.delete_project(name)
39+ try:
40+ self.manager.delete_project(name)
41+ except exception.ProjectNotFound as ex:
42+ print ex
43+ raise
44
45 def environment(self, project_id, user_id, filename='novarc'):
46 """Exports environment variables to an sourcable file
47 arguments: project_id user_id [filename='novarc]"""
48- rc = self.manager.get_environment_rc(user_id, project_id)
49+ try:
50+ rc = self.manager.get_environment_rc(user_id, project_id)
51+ except (exception.UserNotFound, exception.ProjectNotFound) as ex:
52+ print ex
53+ raise
54 with open(filename, 'w') as f:
55 f.write(rc)
56
57@@ -399,7 +419,7 @@
58 if key:
59 try:
60 db.quota_update(ctxt, project_id, key, value)
61- except exception.NotFound:
62+ except exception.ProjectQuotaNotFound:
63 db.quota_create(ctxt, project_id, key, value)
64 project_quota = quota.get_quota(ctxt, project_id)
65 for key, value in project_quota.iteritems():
66@@ -408,7 +428,11 @@
67 def remove(self, project_id, user_id):
68 """Removes user from project
69 arguments: project_id user_id"""
70- self.manager.remove_from_project(user_id, project_id)
71+ try:
72+ self.manager.remove_from_project(user_id, project_id)
73+ except (exception.UserNotFound, exception.ProjectNotFound) as ex:
74+ print ex
75+ raise
76
77 def scrub(self, project_id):
78 """Deletes data associated with project
79@@ -427,6 +451,9 @@
80 zip_file = self.manager.get_credentials(user_id, project_id)
81 with open(filename, 'w') as f:
82 f.write(zip_file)
83+ except (exception.UserNotFound, exception.ProjectNotFound) as ex:
84+ print ex
85+ raise
86 except db.api.NoMoreNetworks:
87 print _('No more networks available. If this is a new '
88 'installation, you need\nto call something like this:\n\n'