#NEWLINE# def test_novanet_assignment_when_network_cfg_changed_then_node_added( self ) : #NEWLINE# #INDENT# cluster = self . env . create_cluster ( api = True , net_provider = consts . CLUSTER_NET_PROVIDERS . nova_network ) #NEWLINE# resp = self . env . nova_networks_get ( cluster [ 'id' ] ) #NEWLINE# nets = resp . json_body #NEWLINE# for net in nets [ 'networks' ] : #NEWLINE# #INDENT# if ( net [ 'name' ] == 'management' ) : #NEWLINE# #INDENT# net [ 'vlan_start' ] = None #NEWLINE# #UNINDENT# #UNINDENT# resp = self . env . nova_networks_put ( cluster [ 'id' ] , nets ) #NEWLINE# self . assertEqual ( resp . status_code , 200 ) #NEWLINE# mac = self . env . generate_random_mac ( ) #NEWLINE# meta = self . env . default_metadata ( ) #NEWLINE# self . env . set_interfaces_in_meta ( meta , [ { #NEWLINE# #INDENT# 'name' : 'eth0' , #NEWLINE# 'mac' : mac , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'eth1' , #NEWLINE# 'mac' : self . env . generate_random_mac ( ) , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'eth2' , #NEWLINE# 'mac' : self . env . generate_random_mac ( ) , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# node = self . env . create_node ( api = True , meta = meta , mac = mac ) #NEWLINE# resp = self . app . put ( reverse ( 'NodeCollectionHandler' ) , jsonutils . dumps ( [ { #NEWLINE# #INDENT# 'id' : node [ 'id' ] , #NEWLINE# 'cluster_id' : cluster [ 'id' ] , #NEWLINE# #UNINDENT# } ] ) , headers = response . default_headers ) #NEWLINE# self . assertEqual ( resp . status_code , 200 ) #NEWLINE# resp = self . app . get ( reverse ( 'NodeNICsHandler' , kwargs = { #NEWLINE# #INDENT# 'node_id' : node [ 'id' ] , #NEWLINE# #UNINDENT# } ) , headers = self . default_headers ) #NEWLINE# self . assertEqual ( resp . status_code , 200 ) #NEWLINE# response = resp . json_body #NEWLINE# net_name_per_nic = [ [ 'fuelweb_admin' , 'storage' , 'fixed' ] , [ 'public' ] , [ 'management' ] ] #NEWLINE# for ( i , nic ) in enumerate ( sorted ( response , key = ( lambda x : x [ 'name' ] ) ) ) : #NEWLINE# #INDENT# net_names = set ( [ net [ 'name' ] for net in nic [ 'assigned_networks' ] ] ) #NEWLINE# self . assertEqual ( set ( net_name_per_nic [ i ] ) , net_names ) #NEWLINE# #UNINDENT# for net in nets [ 'networks' ] : #NEWLINE# #INDENT# if ( net [ 'name' ] == 'public' ) : #NEWLINE# #INDENT# net [ 'vlan_start' ] = 111 #NEWLINE# #UNINDENT# if ( net [ 'name' ] == 'management' ) : #NEWLINE# #INDENT# net [ 'vlan_start' ] = 112 #NEWLINE# #UNINDENT# #UNINDENT# resp = self . env . nova_networks_put ( cluster [ 'id' ] , nets ) #NEWLINE# self . assertEqual ( resp . status_code , 200 ) #NEWLINE# mac = self . env . generate_random_mac ( ) #NEWLINE# meta = self . env . default_metadata ( ) #NEWLINE# self . env . set_interfaces_in_meta ( meta , [ { #NEWLINE# #INDENT# 'name' : 'eth0' , #NEWLINE# 'mac' : mac , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'eth1' , #NEWLINE# 'mac' : self . env . generate_random_mac ( ) , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 'eth2' , #NEWLINE# 'mac' : self . env . generate_random_mac ( ) , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# node = self . env . create_node ( api = True , meta = meta , mac = mac ) #NEWLINE# resp = self . app . put ( reverse ( 'NodeCollectionHandler' ) , jsonutils . dumps ( [ { #NEWLINE# #INDENT# 'id' : node [ 'id' ] , #NEWLINE# 'cluster_id' : cluster [ 'id' ] , #NEWLINE# #UNINDENT# } ] ) , headers = self . default_headers ) #NEWLINE# self . assertEqual ( resp . status_code , 200 ) #NEWLINE# resp = self . app . get ( reverse ( 'NodeNICsHandler' , kwargs = { #NEWLINE# #INDENT# 'node_id' : node [ 'id' ] , #NEWLINE# #UNINDENT# } ) , headers = self . default_headers ) #NEWLINE# self . assertEqual ( resp . status_code , 200 ) #NEWLINE# response = resp . json_body #NEWLINE# net_name_per_nic = [ [ 'fuelweb_admin' , 'storage' , 'fixed' , 'public' , 'management' ] , [ ] , [ ] ] #NEWLINE# for ( i , nic ) in enumerate ( sorted ( response , key = ( lambda x : x [ 'name' ] ) ) ) : #NEWLINE# #INDENT# net_names = set ( [ net [ 'name' ] for net in nic [ 'assigned_networks' ] ] ) #NEWLINE# self . assertEqual ( set ( net_name_per_nic [ i ] ) , net_names )