[ovs-discuss] [nic19-2 5/5] xenserver: Fix "brctl show" compatibility by introducing "brctl" wrapper.

Justin Pettit jpettit at nicira.com
Wed Aug 19 07:04:27 UTC 2009


On Aug 18, 2009, at 11:59 PM, Justin Pettit wrote:

> This code will barf if the file can't be read, since the exception  
> is still raised from the "finally" clause.  Even if the exception  
> were caught, it would still return None, which will make callers  
> like get_bridge_id() raise an exception.  What if y
>
> def read_first_line_of_file(name):
> 	file = None
> 	line = ""
> 	try:
> 		file = open(name, 'r')
> 		line = file.readline().rstrip('\n')
> 	finally:
> 		if file:
> 			file.close()
> 	return line

Sorry, that went off prematurely.  I meant to finish the sentence  
saying that you may want to try something like that.  Obviously, this  
raises its own set of problems, since the bridge id will be garbage.   
However, I think a bad value is better than the program returning a  
traceback.  Obviously, with a bit more coding, the entire device entry  
could be skipped if a bad hardware address is returned.  (Which is  
likely the correct behavior, since the reason for a missing sysfs  
entry is probably that it was going away.)

--Justin






More information about the discuss mailing list