1717# License for the specific language governing permissions and limitations
1818# under the License.
1919
20- import sys
21-
2220import netaddr
2321from neutronclient .common import exceptions as n_exc
2422from neutronclient .neutron import v2_0 as neutronv20
@@ -72,13 +70,12 @@ def validate_name(
7270 except n_exc .NeutronClientNoUniqueMatch as e :
7371 raise exception .NoUniqueMatch (six .text_type (e ))
7472 except n_exc .NeutronClientException as e :
75- exc_info = sys .exc_info ()
7673 if e .status_code == 404 :
7774 LOG .debug ('Neutron security group %s not found' , name )
7875 raise exception .SecurityGroupNotFound (six .text_type (e ))
7976 else :
8077 LOG .error ('Neutron Error: %s' , e )
81- six . reraise ( * exc_info )
78+ raise e
8279
8380
8481def parse_cidr (cidr ):
@@ -241,7 +238,6 @@ def create_security_group(context, name, description):
241238 except n_exc .BadRequest as e :
242239 raise exception .Invalid (six .text_type (e ))
243240 except n_exc .NeutronClientException as e :
244- exc_info = sys .exc_info ()
245241 LOG .exception ("Neutron Error creating security group %s" , name )
246242 if e .status_code == 401 :
247243 # TODO(arosen) Cannot raise generic response from neutron here
@@ -250,7 +246,7 @@ def create_security_group(context, name, description):
250246 raise exc .HTTPBadRequest ()
251247 elif e .status_code == 409 :
252248 raise exception .SecurityGroupLimitExceeded (six .text_type (e ))
253- six . reraise ( * exc_info )
249+ raise e
254250 return _convert_to_nova_security_group_format (security_group )
255251
256252
@@ -261,14 +257,13 @@ def update_security_group(context, security_group, name, description):
261257 security_group = neutron .update_security_group (
262258 security_group ['id' ], body ).get ('security_group' )
263259 except n_exc .NeutronClientException as e :
264- exc_info = sys .exc_info ()
265260 LOG .exception ("Neutron Error updating security group %s" , name )
266261 if e .status_code == 401 :
267262 # TODO(arosen) Cannot raise generic response from neutron here
268263 # as this error code could be related to bad input or over
269264 # quota
270265 raise exc .HTTPBadRequest ()
271- six . reraise ( * exc_info )
266+ raise e
272267 return _convert_to_nova_security_group_format (security_group )
273268
274269
@@ -314,13 +309,12 @@ def get(context, id):
314309 group = neutron .show_security_group (id ).get ('security_group' )
315310 return _convert_to_nova_security_group_format (group )
316311 except n_exc .NeutronClientException as e :
317- exc_info = sys .exc_info ()
318312 if e .status_code == 404 :
319313 LOG .debug ('Neutron security group %s not found' , id )
320314 raise exception .SecurityGroupNotFound (six .text_type (e ))
321315 else :
322316 LOG .error ("Neutron Error: %s" , e )
323- six . reraise ( * exc_info )
317+ raise e
324318
325319
326320def list (context , project , search_opts = None ):
@@ -364,14 +358,13 @@ def destroy(context, security_group):
364358 try :
365359 neutron .delete_security_group (security_group ['id' ])
366360 except n_exc .NeutronClientException as e :
367- exc_info = sys .exc_info ()
368361 if e .status_code == 404 :
369362 raise exception .SecurityGroupNotFound (six .text_type (e ))
370363 elif e .status_code == 409 :
371364 raise exception .Invalid (six .text_type (e ))
372365 else :
373366 LOG .error ("Neutron Error: %s" , e )
374- six . reraise ( * exc_info )
367+ raise e
375368
376369
377370def add_rules (context , id , name , vals ):
@@ -389,7 +382,6 @@ def add_rules(context, id, name, vals):
389382 rules = neutron .create_security_group_rule (
390383 body ).get ('security_group_rules' )
391384 except n_exc .NeutronClientException as e :
392- exc_info = sys .exc_info ()
393385 if e .status_code == 404 :
394386 LOG .exception ("Neutron Error getting security group %s" , name )
395387 raise exception .SecurityGroupNotFound (six .text_type (e ))
@@ -401,7 +393,7 @@ def add_rules(context, id, name, vals):
401393 LOG .exception ("Neutron Error: %s" , e )
402394 raise exception .Invalid (six .text_type (e ))
403395 else :
404- six . reraise ( * exc_info )
396+ raise e
405397 converted_rules = []
406398 for rule in rules :
407399 converted_rules .append (
@@ -467,13 +459,12 @@ def get_rule(context, id):
467459 rule = neutron .show_security_group_rule (
468460 id ).get ('security_group_rule' )
469461 except n_exc .NeutronClientException as e :
470- exc_info = sys .exc_info ()
471462 if e .status_code == 404 :
472463 LOG .debug ("Neutron security group rule %s not found" , id )
473464 raise exception .SecurityGroupNotFound (six .text_type (e ))
474465 else :
475466 LOG .error ("Neutron Error: %s" , e )
476- six . reraise ( * exc_info )
467+ raise e
477468 return _convert_to_nova_security_group_rule_format (rule )
478469
479470
@@ -616,15 +607,14 @@ def add_to_instance(context, instance, security_group_name):
616607 except n_exc .NeutronClientNoUniqueMatch as e :
617608 raise exception .NoUniqueMatch (six .text_type (e ))
618609 except n_exc .NeutronClientException as e :
619- exc_info = sys .exc_info ()
620610 if e .status_code == 404 :
621611 msg = (_ ("Security group %(name)s is not found for "
622612 "project %(project)s" ) %
623613 {'name' : security_group_name ,
624614 'project' : context .project_id })
625615 raise exception .SecurityGroupNotFound (msg )
626616 else :
627- six . reraise ( * exc_info )
617+ raise e
628618 params = {'device_id' : instance .uuid }
629619 try :
630620 ports = neutron .list_ports (** params ).get ('ports' )
@@ -657,12 +647,11 @@ def add_to_instance(context, instance, security_group_name):
657647 'port_id' : port ['id' ]})
658648 neutron .update_port (port ['id' ], {'port' : updated_port })
659649 except n_exc .NeutronClientException as e :
660- exc_info = sys .exc_info ()
661650 if e .status_code == 400 :
662651 raise exception .SecurityGroupCannotBeApplied (
663652 six .text_type (e ))
664653 else :
665- six . reraise ( * exc_info )
654+ raise e
666655 except Exception :
667656 with excutils .save_and_reraise_exception ():
668657 LOG .exception ("Neutron Error:" )
@@ -677,15 +666,14 @@ def remove_from_instance(context, instance, security_group_name):
677666 security_group_name ,
678667 context .project_id )
679668 except n_exc .NeutronClientException as e :
680- exc_info = sys .exc_info ()
681669 if e .status_code == 404 :
682670 msg = (_ ("Security group %(name)s is not found for "
683671 "project %(project)s" ) %
684672 {'name' : security_group_name ,
685673 'project' : context .project_id })
686674 raise exception .SecurityGroupNotFound (msg )
687675 else :
688- six . reraise ( * exc_info )
676+ raise e
689677 params = {'device_id' : instance .uuid }
690678 try :
691679 ports = neutron .list_ports (** params ).get ('ports' )
0 commit comments