#NEWLINE# @ types . convert ( image = { #NEWLINE# #INDENT# 'type' : 'glance_image' , #NEWLINE# #UNINDENT# } , flavor = { #NEWLINE# #INDENT# 'type' : 'nova_flavor' , #NEWLINE# #UNINDENT# } ) #NEWLINE# @ validation . image_valid_on_flavor ( 'flavor' , 'image' ) #NEWLINE# @ validation . required_parameters ( 'security_group_count' , 'rules_per_security_group' ) #NEWLINE# @ validation . required_contexts ( 'network' ) #NEWLINE# @ validation . required_services ( consts . Service . NOVA ) #NEWLINE# @ validation . required_openstack ( users = True ) #NEWLINE# @ scenario . configure ( context = { #NEWLINE# #INDENT# 'cleanup' : [ 'nova' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# def boot_and_delete_server_with_secgroups( self , image , flavor , security_group_count , rules_per_security_group , **kwargs ) : #NEWLINE# #INDENT# 'Boot and delete server with security groups attached.\n\n        Plan of this scenario:\n         - create N security groups with M rules per group\n           vm with security groups)\n         - boot a VM with created security groups\n         - get list of attached security groups to server\n         - delete server\n         - delete all security groups\n         - check that all groups were attached to server\n\n        :param image: ID of the image to be used for server creation\n        :param flavor: ID of the flavor to be used for server creation\n        :param security_group_count: Number of security groups\n        :param rules_per_security_group: Number of rules per security group\n        :param **kwargs: Optional arguments for booting the instance\n        ' #NEWLINE# security_groups = self . _create_security_groups ( security_group_count ) #NEWLINE# self . _create_rules_for_security_group ( security_groups , rules_per_security_group ) #NEWLINE# secgroups_names = [ sg . name for sg in security_groups ] #NEWLINE# server = self . _boot_server ( image , flavor , security_groups = secgroups_names , ** kwargs ) #NEWLINE# action_name = 'nova.get_attached_security_groups' #NEWLINE# with atomic . ActionTimer ( self , action_name ) : #NEWLINE# #INDENT# attached_security_groups = server . list_security_group ( ) #NEWLINE# #UNINDENT# self . _delete_server ( server ) #NEWLINE# try : #NEWLINE# #INDENT# self . _delete_security_groups ( security_groups ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# if ( hasattr ( e , 'http_status' ) and ( e . http_status == 400 ) ) : #NEWLINE# #INDENT# raise NovaSecurityGroupException ( six . text_type ( e ) ) #NEWLINE# #UNINDENT# raise #NEWLINE# #UNINDENT# error_message = ( "Expected number of attached security groups to  server %(server)s is '%(all)s', but actual number is '%(attached)s'." % { #NEWLINE# #INDENT# 'attached' : len ( attached_security_groups ) , #NEWLINE# 'all' : len ( security_groups ) , #NEWLINE# 'server' : server , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( sorted ( [ sg . id for sg in security_groups ] ) , sorted ( [ sg . id for sg in attached_security_groups ] ) , error_message )