#NEWLINE# def test_instances_security_group_bindings( self ) : #NEWLINE# #INDENT# server_id = 'c5a20e8d-c4b0-47cf-9dca-ebe4f758acb1' #NEWLINE# port1_id = '4c505aec-09aa-47bc-bcc0-940477e84dc0' #NEWLINE# port2_id = 'b3b31a53-6e29-479f-ae5c-00b7b71a6d44' #NEWLINE# sg1_id = '2f7ce969-1a73-4ef9-bbd6-c9a91780ecd4' #NEWLINE# sg2_id = '20c89ce5-9388-4046-896e-64ffbd3eb584' #NEWLINE# servers = [ { #NEWLINE# #INDENT# 'id' : server_id , #NEWLINE# #UNINDENT# } ] #NEWLINE# ports = [ { #NEWLINE# #INDENT# 'id' : port1_id , #NEWLINE# 'device_id' : server_id , #NEWLINE# 'security_groups' : [ sg1_id ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'id' : port2_id , #NEWLINE# 'device_id' : server_id , #NEWLINE# 'security_groups' : [ sg2_id ] , #NEWLINE# #UNINDENT# } ] #NEWLINE# port_list = { #NEWLINE# #INDENT# 'ports' : ports , #NEWLINE# #UNINDENT# } #NEWLINE# sg1 = { #NEWLINE# #INDENT# 'id' : sg1_id , #NEWLINE# 'name' : 'wol' , #NEWLINE# #UNINDENT# } #NEWLINE# sg2 = { #NEWLINE# #INDENT# 'id' : sg2_id , #NEWLINE# 'name' : 'eor' , #NEWLINE# #UNINDENT# } #NEWLINE# security_groups_list = { #NEWLINE# #INDENT# 'security_groups' : [ sg1 , sg2 ] , #NEWLINE# #UNINDENT# } #NEWLINE# sg_bindings = { #NEWLINE# #INDENT# server_id : [ { #NEWLINE# #INDENT# 'name' : 'wol' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'eor' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# self . mocked_client . list_ports . return_value = port_list #NEWLINE# self . mocked_client . list_security_groups . return_value = security_groups_list #NEWLINE# sg_api = neutron_driver . SecurityGroupAPI ( ) #NEWLINE# result = sg_api . get_instances_security_groups_bindings ( self . context , servers ) #NEWLINE# self . assertEqual ( sg_bindings , result ) #NEWLINE# self . mocked_client . list_ports . assert_called_once_with ( device_id = [ server_id ] ) #NEWLINE# self . mocked_client . list_security_groups . assert_called_once_with ( id = mock . ANY ) #NEWLINE# self . assertEqual ( sorted ( [ sg1_id , sg2_id ] ) , sorted ( self . mocked_client . list_security_groups . call_args [ 1 ] [ 'id' ] ) )