<s> import collections <EOL> import mock <EOL> from neutron . tests import base <EOL> from networking_cisco . apps . saf . agent . vdp import lldpad <EOL> from networking_cisco . apps . saf . agent . vdp import lldpad_constants as vdp_con <EOL> from networking_cisco . apps . saf . common import dfa_sys_lib as utils <EOL> try : <EOL> OrderedDict = collections . OrderedDict <EOL> except AttributeError : <EOL> import ordereddict <EOL> OrderedDict = ordereddict . OrderedDict <EOL> class LldpadDriverTest ( base . BaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> '''<STR_LIT>''' <EOL> super ( LldpadDriverTest , self ) . setUp ( ) <EOL> self . root_helper = '<STR_LIT>' <EOL> self . port_name = "<STR_LIT>" <EOL> self . uplink = "<STR_LIT>" <EOL> self . port_str = "<STR_LIT>" <EOL> self . execute = mock . patch . object ( <EOL> utils , "<STR_LIT>" , spec = utils . execute ) . start ( ) <EOL> self . fill_default_vsi_params ( ) <EOL> self . _test_lldp_init ( ) <EOL> def _test_lldp_init ( self ) : <EOL> '''<STR_LIT>''' <EOL> with mock . patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) as period_fn : <EOL> period_obj = period_fn . return_value <EOL> parent = mock . MagicMock ( ) <EOL> parent . attach_mock ( period_obj . run , '<STR_LIT>' ) <EOL> self . lldpad = lldpad . LldpadDriver ( self . port_str , self . uplink , <EOL> self . root_helper ) <EOL> expected_calls = [ mock . call . run ( ) ] <EOL> parent . assert_has_calls ( expected_calls ) <EOL> def test_init ( self ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> def _test_enable_lldp ( self , is_ncb = True ) : <EOL> '''<STR_LIT>''' <EOL> self . lldpad . enable_lldp ( ) <EOL> if is_ncb is True : <EOL> self . execute . assert_called_with ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , self . port_str , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] , root_helper = self . root_helper ) <EOL> def test_enable_lldp ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . _test_enable_lldp ( is_ncb = True ) <EOL> def test_enable_evb ( self ) : <EOL> '''<STR_LIT>''' <EOL> parent = mock . MagicMock ( ) <EOL> parent . attach_mock ( self . execute , '<STR_LIT>' ) <EOL> self . lldpad . enable_evb ( ) <EOL> expected_calls = [ mock . call . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> self . port_str , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] , <EOL> root_helper = self . root_helper ) , <EOL> mock . call . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> self . port_str , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:-c>" , "<STR_LIT>" ] , <EOL> root_helper = self . root_helper ) ] <EOL> parent . assert_has_calls ( expected_calls ) <EOL> def fill_default_vsi_params ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . uuid = "<STR_LIT>" <EOL> self . vsiid = self . uuid <EOL> self . mgrid = <NUM_LIT:0> <EOL> self . typeid = <NUM_LIT:0> <EOL> self . typeidver = <NUM_LIT:0> <EOL> self . gid = <NUM_LIT> <EOL> self . mac = "<STR_LIT>" <EOL> self . vlan = <NUM_LIT:0> <EOL> self . mgrid_str = "<STR_LIT>" <EOL> self . typeid_str = "<STR_LIT>" <EOL> self . typeidver_str = "<STR_LIT>" <EOL> self . vsiid_str = "<STR_LIT>" <EOL> self . filter_str = "<STR_LIT>" <EOL> self . mode_str = "<STR_LIT>" <EOL> def _test_vnic_assert ( self , test_vlan , vlan_ret , filter_str , new_nwk , <EOL> parent , is_rest = <NUM_LIT:0> ) : <EOL> '''<STR_LIT>''' <EOL> if new_nwk : <EOL> if is_rest == <NUM_LIT:1> : <EOL> expected_calls = [ mock . call . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> self . port_str , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:-c>" , <EOL> self . mode_str , "<STR_LIT:-c>" , <EOL> self . mgrid_str , "<STR_LIT:-c>" , <EOL> self . typeid_str , "<STR_LIT:-c>" , <EOL> self . typeidver_str , "<STR_LIT:-c>" , <EOL> self . vsiid_str ] , <EOL> root_helper = ( <EOL> self . root_helper ) ) ] <EOL> else : <EOL> expected_calls = [ mock . call . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> self . port_str , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:-c>" , <EOL> self . mode_str , "<STR_LIT:-c>" , <EOL> self . mgrid_str , "<STR_LIT:-c>" , <EOL> self . typeid_str , "<STR_LIT:-c>" , <EOL> self . typeidver_str , "<STR_LIT:-c>" , <EOL> self . vsiid_str , "<STR_LIT:-c>" , <EOL> "<STR_LIT>" , "<STR_LIT:-c>" , <EOL> filter_str ] , <EOL> root_helper = ( <EOL> self . root_helper ) ) ] <EOL> self . assertEqual ( vlan_ret , test_vlan ) <EOL> self . assertEqual ( test_vlan , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . <EOL> get ( '<STR_LIT>' ) ) <EOL> else : <EOL> expected_calls = [ mock . call . execute ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> self . port_str , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT:-c>" , self . mode_str , <EOL> "<STR_LIT:-c>" , self . mgrid_str , "<STR_LIT:-c>" , <EOL> self . typeid_str , "<STR_LIT:-c>" , <EOL> self . typeidver_str , "<STR_LIT:-c>" , <EOL> self . vsiid_str , "<STR_LIT:-c>" , <EOL> "<STR_LIT>" , "<STR_LIT:-c>" , <EOL> filter_str ] , <EOL> root_helper = self . root_helper ) ] <EOL> parent . assert_has_calls ( expected_calls ) <EOL> self . assertEqual ( self . mgrid , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . typeid , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . typeidver , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . vsiid , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( vdp_con . VDP_FILTER_GIDMACVID , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . gid , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . mac , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . get ( '<STR_LIT>' ) ) <EOL> def test_vdp_port_up_new_nwk ( self ) : <EOL> '''<STR_LIT>''' <EOL> expected_vlan = <NUM_LIT> <EOL> parent = mock . MagicMock ( ) <EOL> parent . attach_mock ( self . execute , '<STR_LIT>' ) <EOL> self . execute . return_value = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . lldpad . send_vdp_query_msg = mock . Mock ( ) <EOL> vlan_ret = self . lldpad . send_vdp_vnic_up ( port_uuid = self . uuid , <EOL> vsiid = self . vsiid , <EOL> mgrid = self . mgrid , <EOL> typeid = self . typeid , <EOL> typeid_ver = self . typeidver , <EOL> gid = self . gid , <EOL> mac = self . mac , <EOL> new_network = True ) <EOL> self . _test_vnic_assert ( expected_vlan , vlan_ret , self . filter_str , True , <EOL> parent ) <EOL> def test_vdp_port_up_new_nwk_after_restart ( self ) : <EOL> '''<STR_LIT>''' <EOL> expected_vlan = <NUM_LIT> <EOL> parent = mock . MagicMock ( ) <EOL> parent . attach_mock ( self . execute , '<STR_LIT>' ) <EOL> self . execute . return_value = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> vlan_ret = self . lldpad . send_vdp_vnic_up ( port_uuid = self . uuid , <EOL> vsiid = self . vsiid , <EOL> mgrid = self . mgrid , <EOL> typeid = self . typeid , <EOL> typeid_ver = self . typeidver , <EOL> gid = self . gid , <EOL> mac = self . mac , <EOL> new_network = True ) <EOL> self . _test_vnic_assert ( expected_vlan , vlan_ret , self . filter_str , True , <EOL> parent , is_rest = <NUM_LIT:1> ) <EOL> def test_vdp_port_up_new_nwk_invalid_vlan ( self ) : <EOL> '''<STR_LIT>''' <EOL> expected_vlan = - <NUM_LIT:1> <EOL> parent = mock . MagicMock ( ) <EOL> parent . attach_mock ( self . execute , '<STR_LIT>' ) <EOL> self . execute . return_value = "<STR_LIT>" <EOL> vlan_ret = self . lldpad . send_vdp_vnic_up ( port_uuid = self . uuid , <EOL> vsiid = self . vsiid , <EOL> mgrid = self . mgrid , <EOL> typeid = self . typeid , <EOL> typeid_ver = self . typeidver , <EOL> gid = self . gid , <EOL> mac = self . mac , <EOL> new_network = True ) <EOL> self . _test_vnic_assert ( expected_vlan , vlan_ret , self . filter_str , True , <EOL> parent ) <EOL> def test_vdp_port_up_old_nwk ( self ) : <EOL> '''<STR_LIT>''' <EOL> parent = mock . MagicMock ( ) <EOL> parent . attach_mock ( self . execute , '<STR_LIT>' ) <EOL> self . execute . return_value = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> filter_str = "<STR_LIT>" <EOL> stored_vlan = <NUM_LIT> <EOL> self . lldpad . send_vdp_vnic_up ( port_uuid = self . uuid , vsiid = self . vsiid , <EOL> mgrid = self . mgrid , <EOL> typeid = self . typeid , <EOL> typeid_ver = self . typeidver , <EOL> gid = self . gid , <EOL> mac = self . mac , vlan = <NUM_LIT:0> , <EOL> new_network = False ) <EOL> self . _test_vnic_assert ( stored_vlan , <EOL> self . lldpad . vdp_vif_map [ self . uuid ] . <EOL> get ( '<STR_LIT>' ) , filter_str , False , parent ) <EOL> def test_vdp_port_down ( self ) : <EOL> '''<STR_LIT>''' <EOL> parent = mock . MagicMock ( ) <EOL> parent . attach_mock ( self . execute , '<STR_LIT>' ) <EOL> filter_str = "<STR_LIT>" <EOL> stored_vlan = <NUM_LIT:100> <EOL> mode_str = "<STR_LIT>" <EOL> self . lldpad . send_vdp_vnic_down ( port_uuid = self . uuid , vsiid = self . vsiid , <EOL> mgrid = self . mgrid , <EOL> typeid = self . typeid , <EOL> typeid_ver = self . typeidver , <EOL> gid = self . gid , <EOL> mac = self . mac , vlan = stored_vlan ) <EOL> self . execute . assert_called_with ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , self . port_str , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:-c>" , mode_str , "<STR_LIT:-c>" , self . mgrid_str , <EOL> "<STR_LIT:-c>" , self . typeid_str , "<STR_LIT:-c>" , self . typeidver_str , <EOL> "<STR_LIT:-c>" , self . vsiid_str , "<STR_LIT:-c>" , "<STR_LIT>" , <EOL> "<STR_LIT:-c>" , filter_str ] , root_helper = self . root_helper ) <EOL> self . assertNotIn ( self . uuid , self . lldpad . vdp_vif_map ) </s>
