<s> from nailgun import consts <EOL> from nailgun . db . sqlalchemy import models <EOL> from nailgun import objects <EOL> from nailgun . task . task import VerifyNetworksTask <EOL> from nailgun . test . base import BaseTestCase <EOL> class TestNetworkVerification ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNetworkVerification , self ) . setUp ( ) <EOL> self . cluster = self . env . create ( <EOL> cluster_kwargs = { <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : consts . CLUSTER_NET_PROVIDERS . neutron <EOL> } , <EOL> nodes_kwargs = [ <EOL> { "<STR_LIT>" : False , <EOL> "<STR_LIT>" : True } , <EOL> ] <EOL> ) <EOL> def test_verify_networks_skips_dpdk_interface ( self ) : <EOL> node = self . env . nodes [ <NUM_LIT:0> ] <EOL> node_json = { <EOL> '<STR_LIT>' : node . id , <EOL> '<STR_LIT:name>' : node . name , <EOL> '<STR_LIT:status>' : node . status , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> dpdk_iface = None <EOL> network_config = [ ] <EOL> for iface in node . interfaces : <EOL> for ng in iface . assigned_networks_list : <EOL> vlans = [ ] <EOL> if ng . name == consts . NETWORKS . private : <EOL> vlans = [ <NUM_LIT> , <NUM_LIT> ] <EOL> dpdk_iface = iface <EOL> network_config . append ( { '<STR_LIT:name>' : ng . name , '<STR_LIT>' : vlans } ) <EOL> dpdk_iface . interface_properties [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> task = VerifyNetworksTask ( None , network_config ) <EOL> task . get_ifaces_on_deployed_node ( node , node_json , [ ] ) <EOL> self . assertNotIn ( { '<STR_LIT>' : dpdk_iface . name , '<STR_LIT>' : [ <NUM_LIT:0> ] } , <EOL> node_json [ '<STR_LIT>' ] ) <EOL> self . assertNotIn ( { '<STR_LIT>' : dpdk_iface . name , '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> ] } , <EOL> node_json [ '<STR_LIT>' ] ) <EOL> def test_skip_private_net_for_the_only_node_wo_dpdk ( self ) : <EOL> self . env . create_node ( cluster_id = self . cluster . id , <EOL> pending_addition = True , <EOL> roles = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( self . env . nodes ) , <NUM_LIT:2> ) <EOL> dpdk_iface = None <EOL> network_config = [ ] <EOL> private_ifaces = { } <EOL> for node in self . env . nodes : <EOL> nic_1 = node . interfaces [ <NUM_LIT:0> ] <EOL> nic_2 = node . interfaces [ <NUM_LIT:1> ] <EOL> default_vlans = { <EOL> consts . NETWORKS . public : [ <NUM_LIT:100> ] , <EOL> consts . NETWORKS . storage : [ <NUM_LIT> ] , <EOL> consts . NETWORKS . management : [ <NUM_LIT> ] , <EOL> consts . NETWORKS . fuelweb_admin : [ <NUM_LIT> ] , <EOL> consts . NETWORKS . private : [ <NUM_LIT> , <NUM_LIT> ] <EOL> } <EOL> if not dpdk_iface : <EOL> dpdk_iface = nic_2 <EOL> nets_1 = nic_1 . assigned_networks_list <EOL> nets_2 = nic_2 . assigned_networks_list <EOL> for i , net in enumerate ( nets_1 ) : <EOL> if net [ '<STR_LIT:name>' ] == consts . NETWORKS . private : <EOL> nets_2 . append ( nets_1 . pop ( i ) ) <EOL> break <EOL> objects . NIC . assign_networks ( nic_1 , nets_1 ) <EOL> objects . NIC . assign_networks ( nic_2 , nets_2 ) <EOL> node . status = consts . NODE_STATUSES . ready <EOL> for iface in node . interfaces : <EOL> for ng in iface . assigned_networks_list : <EOL> network_config . append ( { '<STR_LIT:name>' : ng . name , <EOL> '<STR_LIT>' : default_vlans [ ng . name ] } ) <EOL> if ng . name == consts . NETWORKS . private : <EOL> private_ifaces [ node . name ] = iface . name <EOL> dpdk_iface . interface_properties [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> task = models . Task ( <EOL> name = consts . TASK_NAMES . check_networks , <EOL> cluster = self . cluster <EOL> ) <EOL> verify_task = VerifyNetworksTask ( task , network_config ) <EOL> message = verify_task . get_message_body ( ) <EOL> for node in message [ '<STR_LIT>' ] : <EOL> self . assertNotIn ( private_ifaces [ node [ '<STR_LIT:name>' ] ] , <EOL> ( n [ '<STR_LIT>' ] for n in node [ '<STR_LIT>' ] ) ) <EOL> def test_verify_networks_checks_dpdk_interface ( self ) : <EOL> node = self . env . nodes [ <NUM_LIT:0> ] <EOL> node_json = { <EOL> '<STR_LIT>' : node . id , <EOL> '<STR_LIT:name>' : node . name , <EOL> '<STR_LIT:status>' : node . status , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> dpdk_iface = None <EOL> private_iface = None <EOL> private_ng = None <EOL> network_config = [ ] <EOL> for iface in node . interfaces : <EOL> for ng in iface . assigned_networks_list : <EOL> vlans = [ ] <EOL> if ng . name == consts . NETWORKS . public : <EOL> dpdk_iface = iface <EOL> elif ng . name == consts . NETWORKS . private : <EOL> private_iface = iface <EOL> private_ng = ng <EOL> vlans = [ <NUM_LIT> , <NUM_LIT> ] <EOL> else : <EOL> continue <EOL> network_config . append ( { '<STR_LIT:name>' : ng . name , '<STR_LIT>' : vlans } ) <EOL> dpdk_iface . interface_properties [ '<STR_LIT>' ] . update ( { '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True } ) <EOL> private_iface . assigned_networks_list = [ private_ng ] <EOL> task = VerifyNetworksTask ( None , network_config ) <EOL> task . get_ifaces_on_deployed_node ( node , node_json , [ ] ) <EOL> self . assertIn ( { '<STR_LIT>' : dpdk_iface . name , '<STR_LIT>' : [ <NUM_LIT:0> ] } , <EOL> node_json [ '<STR_LIT>' ] ) <EOL> self . assertIn ( { '<STR_LIT>' : private_iface . name , '<STR_LIT>' : [ <NUM_LIT> , <NUM_LIT> ] } , <EOL> node_json [ '<STR_LIT>' ] ) </s>
