<s> import unittest <EOL> import mock <EOL> from networkapiclient . exception import IpNaoExisteError <EOL> from hm . lb_managers import networkapi_cloudstack <EOL> from hm . model import load_balancer , host <EOL> class NetworkApiCloudstackLBTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . conf = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:key>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def test_init ( self ) : <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> self . assertEqual ( manager . cs_client . api_url , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . cs_client . api_key , '<STR_LIT:key>' ) <EOL> self . assertEqual ( manager . cs_client . secret , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . create_project_id , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . networkapi_endpoint , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . networkapi_user , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . networkapi_password , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_network_index , <NUM_LIT:1> ) <EOL> self . assertEqual ( manager . vip_config . environment_p44 , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . client , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . finality , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . healthcheck , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . healthcheck_expect , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . lb_method , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . cache , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . maxconn , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . business_area , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . service_name , '<STR_LIT>' ) <EOL> self . assertEqual ( manager . vip_config . port_mapping , [ "<STR_LIT>" ] ) <EOL> def test_init_multiple_ports ( self ) : <EOL> self . conf . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> self . assertEqual ( manager . vip_config . port_mapping , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_create_load_balancer ( self , Vip , Ip , EnvironmentVIP , logger ) : <EOL> client_evip = mock . Mock ( ) <EOL> client_evip . search . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> EnvironmentVIP . return_value = client_evip <EOL> client_ip = mock . Mock ( ) <EOL> client_ip . get_available_ip4_for_vip . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } } <EOL> Ip . return_value = client_ip <EOL> client_vip = mock . Mock ( ) <EOL> client_vip . add . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> Vip . return_value = client_vip <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> lb = manager . create_load_balancer ( "<STR_LIT>" ) <EOL> self . assertEqual ( <NUM_LIT> , lb . id ) <EOL> self . assertEqual ( <NUM_LIT> , lb . ip_id ) <EOL> self . assertEqual ( "<STR_LIT>" , lb . address ) <EOL> self . assertEqual ( "<STR_LIT>" , lb . name ) <EOL> self . assertEqual ( "<STR_LIT>" , lb . project_id ) <EOL> EnvironmentVIP . assert_called_with ( self . conf [ "<STR_LIT>" ] , self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> Ip . assert_called_with ( self . conf [ "<STR_LIT>" ] , self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> Vip . assert_called_with ( self . conf [ "<STR_LIT>" ] , self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> client_evip . search . assert_called_with ( ambiente_p44_txt = self . conf [ "<STR_LIT>" ] , <EOL> cliente_txt = self . conf [ "<STR_LIT>" ] , <EOL> finalidade_txt = self . conf [ "<STR_LIT>" ] ) <EOL> client_ip . get_available_ip4_for_vip . assert_called_with ( <NUM_LIT> , u"<STR_LIT>" ) <EOL> client_vip . add . assert_called_with ( id_ipv4 = <NUM_LIT> , id_ipv6 = None , <EOL> id_healthcheck_expect = self . conf [ "<STR_LIT>" ] , <EOL> finality = self . conf [ "<STR_LIT>" ] , <EOL> client = self . conf [ "<STR_LIT>" ] , <EOL> environment = self . conf [ "<STR_LIT>" ] , <EOL> cache = self . conf [ "<STR_LIT>" ] , <EOL> method_bal = self . conf [ "<STR_LIT>" ] , <EOL> persistence = self . conf [ "<STR_LIT>" ] , <EOL> healthcheck_type = u"<STR_LIT>" , <EOL> timeout = u"<STR_LIT:5>" , <EOL> healthcheck = self . conf [ "<STR_LIT>" ] , <EOL> host = "<STR_LIT>" , <EOL> maxcon = self . conf [ "<STR_LIT>" ] , <EOL> areanegocio = self . conf [ "<STR_LIT>" ] , <EOL> nome_servico = self . conf [ "<STR_LIT>" ] , <EOL> reals = [ ] , reals_prioritys = [ ] , <EOL> reals_weights = [ ] , ports = [ "<STR_LIT>" ] , l7_filter = None ) <EOL> client_vip . validate . assert_called_with ( <NUM_LIT> ) <EOL> client_vip . criar . assert_called_with ( <NUM_LIT> ) <EOL> logger . debug . assert_called_with ( u"<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_create_vip_failure ( self , Vip , Ip , EnvironmentVIP , CloudStack ) : <EOL> client_evip = mock . Mock ( ) <EOL> client_evip . search . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> EnvironmentVIP . return_value = client_evip <EOL> client_ip = mock . Mock ( ) <EOL> client_ip . get_available_ip4_for_vip . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> Ip . return_value = client_ip <EOL> client_vip = mock . Mock ( ) <EOL> client_vip . add . side_effect = Exception ( "<STR_LIT>" ) <EOL> Vip . return_value = client_vip <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> with self . assertRaises ( Exception ) as cm : <EOL> manager . create_load_balancer ( "<STR_LIT>" ) <EOL> exc = cm . exception <EOL> self . assertEqual ( ( "<STR_LIT>" , ) , exc . args ) <EOL> client_evip . search . assert_called_with ( ambiente_p44_txt = self . conf [ "<STR_LIT>" ] , <EOL> cliente_txt = self . conf [ "<STR_LIT>" ] , <EOL> finalidade_txt = self . conf [ "<STR_LIT>" ] ) <EOL> client_ip . get_available_ip4_for_vip . assert_called_with ( <NUM_LIT> , u"<STR_LIT>" ) <EOL> client_ip . delete_ip4 . assert_called_with ( <NUM_LIT> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_create_vip_failure_on_validate ( self , Vip , Ip , EnvironmentVIP , CloudStack ) : <EOL> client_evip = mock . Mock ( ) <EOL> client_evip . search . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> EnvironmentVIP . return_value = client_evip <EOL> client_ip = mock . Mock ( ) <EOL> client_ip . get_available_ip4_for_vip . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> Ip . return_value = client_ip <EOL> client_vip = mock . Mock ( ) <EOL> client_vip . add . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> client_vip . validate . side_effect = Exception ( "<STR_LIT>" ) <EOL> Vip . return_value = client_vip <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> with self . assertRaises ( Exception ) as cm : <EOL> manager . create_load_balancer ( "<STR_LIT>" ) <EOL> exc = cm . exception <EOL> self . assertEqual ( ( "<STR_LIT>" , ) , exc . args ) <EOL> client_evip . search . assert_called_with ( ambiente_p44_txt = self . conf [ "<STR_LIT>" ] , <EOL> cliente_txt = self . conf [ "<STR_LIT>" ] , <EOL> finalidade_txt = self . conf [ "<STR_LIT>" ] ) <EOL> client_ip . get_available_ip4_for_vip . assert_called_with ( <NUM_LIT> , u"<STR_LIT>" ) <EOL> client_ip . delete_ip4 . assert_called_with ( <NUM_LIT> ) <EOL> client_vip . remove_script . assert_called_with ( <NUM_LIT> ) <EOL> client_vip . remover . assert_called_with ( <NUM_LIT> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_create_vip_failure_on_remove ( self , Vip , Ip , EnvironmentVIP , CloudStack , logger ) : <EOL> client_evip = mock . Mock ( ) <EOL> client_evip . search . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> EnvironmentVIP . return_value = client_evip <EOL> client_ip = mock . Mock ( ) <EOL> client_ip . get_available_ip4_for_vip . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> Ip . return_value = client_ip <EOL> client_vip = mock . Mock ( ) <EOL> client_vip . add . return_value = { "<STR_LIT>" : { "<STR_LIT:id>" : <NUM_LIT> } } <EOL> client_vip . validate . side_effect = Exception ( "<STR_LIT>" ) <EOL> client_vip . remover . side_effect = Exception ( "<STR_LIT>" ) <EOL> Vip . return_value = client_vip <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> with self . assertRaises ( Exception ) as cm : <EOL> manager . create_load_balancer ( "<STR_LIT>" ) <EOL> exc = cm . exception <EOL> self . assertEqual ( ( "<STR_LIT>" , ) , exc . args ) <EOL> client_evip . search . assert_called_with ( ambiente_p44_txt = self . conf [ "<STR_LIT>" ] , <EOL> cliente_txt = self . conf [ "<STR_LIT>" ] , <EOL> finalidade_txt = self . conf [ "<STR_LIT>" ] ) <EOL> client_ip . get_available_ip4_for_vip . assert_called_with ( <NUM_LIT> , u"<STR_LIT>" ) <EOL> client_ip . delete_ip4 . assert_called_with ( <NUM_LIT> ) <EOL> client_vip . remove_script . assert_called_with ( <NUM_LIT> ) <EOL> client_vip . remover . assert_called_with ( <NUM_LIT> ) <EOL> logger . error . assert_called_with ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_destroy_load_balancer ( self , Ip , Vip , CloudStack ) : <EOL> client_vip = mock . Mock ( ) <EOL> Vip . return_value = client_vip <EOL> client_ip = mock . Mock ( ) <EOL> Ip . return_value = client_ip <EOL> cloudstack_client = CloudStack . return_value <EOL> lb = load_balancer . LoadBalancer ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ip_id = "<STR_LIT>" , <EOL> project_id = "<STR_LIT>" <EOL> ) <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> manager . destroy_load_balancer ( lb ) <EOL> Vip . assert_called_with ( self . conf [ "<STR_LIT>" ] , self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> client_vip . remove_script . assert_called_with ( "<STR_LIT>" ) <EOL> client_vip . remover . assert_called_with ( "<STR_LIT>" ) <EOL> Ip . assert_called_with ( self . conf [ "<STR_LIT>" ] , self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> client_ip . delete_ip4 . assert_called_with ( "<STR_LIT>" ) <EOL> data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . removeGloboNetworkVip . assert_called_with ( data ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_remove_vip_ip_not_found ( self , Ip , Vip , CloudStack ) : <EOL> client_vip = mock . Mock ( ) <EOL> Vip . return_value = client_vip <EOL> client_ip = mock . Mock ( ) <EOL> client_ip . delete_ip4 . side_effect = IpNaoExisteError ( "<STR_LIT>" ) <EOL> Ip . return_value = client_ip <EOL> lb = load_balancer . LoadBalancer ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ip_id = "<STR_LIT>" , <EOL> project_id = "<STR_LIT>" <EOL> ) <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> manager . destroy_load_balancer ( lb ) <EOL> Vip . assert_called_with ( self . conf [ "<STR_LIT>" ] , self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> client_vip . remove_script . assert_called_with ( "<STR_LIT>" ) <EOL> client_vip . remover . assert_called_with ( "<STR_LIT>" ) <EOL> Ip . assert_called_with ( self . conf [ "<STR_LIT>" ] , self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> client_ip . delete_ip4 . assert_called_with ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_attach_real ( self , CloudStack ) : <EOL> self . conf . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> vms = { "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] } ] } <EOL> CloudStack . return_value = cloudstack_client = mock . Mock ( ) <EOL> cloudstack_client . listVirtualMachines . return_value = vms <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> lb = load_balancer . LoadBalancer ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ip_id = "<STR_LIT>" , <EOL> project_id = None , <EOL> ) <EOL> h = host . Host ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> manager . attach_real ( lb , h ) <EOL> list_data = { "<STR_LIT:id>" : "<STR_LIT>" } <EOL> cloudstack_client . listVirtualMachines . assert_called_with ( list_data ) <EOL> net_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . addGloboNetworkVipToAccount . assert_called_with ( net_data ) <EOL> assoc_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . associateGloboNetworkRealToVip . assert_called_with ( assoc_data ) <EOL> CloudStack . assert_called_with ( <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_attach_real_with_project_id ( self , CloudStack ) : <EOL> self . conf . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> vms = { "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] } ] } <EOL> CloudStack . return_value = cloudstack_client = mock . Mock ( ) <EOL> cloudstack_client . listVirtualMachines . return_value = vms <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> lb = load_balancer . LoadBalancer ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ip_id = "<STR_LIT>" , <EOL> project_id = "<STR_LIT>" <EOL> ) <EOL> h = host . Host ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> manager . attach_real ( lb , h ) <EOL> list_data = { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . listVirtualMachines . assert_called_with ( list_data ) <EOL> net_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . addGloboNetworkVipToAccount . assert_called_with ( net_data ) <EOL> assoc_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . associateGloboNetworkRealToVip . assert_called_with ( assoc_data ) <EOL> CloudStack . assert_called_with ( <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_attach_real_with_network_index ( self , CloudStack ) : <EOL> vms = { "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : [ <EOL> { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] } ] } <EOL> CloudStack . return_value = cloudstack_client = mock . Mock ( ) <EOL> cloudstack_client . listVirtualMachines . return_value = vms <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> lb = load_balancer . LoadBalancer ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ip_id = "<STR_LIT>" , <EOL> project_id = None , <EOL> ) <EOL> h = host . Host ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> manager . attach_real ( lb , h ) <EOL> list_data = { "<STR_LIT:id>" : "<STR_LIT>" } <EOL> cloudstack_client . listVirtualMachines . assert_called_with ( list_data ) <EOL> net_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . addGloboNetworkVipToAccount . assert_called_with ( net_data ) <EOL> assoc_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . associateGloboNetworkRealToVip . assert_called_with ( assoc_data ) <EOL> CloudStack . assert_called_with ( <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_detach_real ( self , CloudStack ) : <EOL> self . conf . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> vms = { "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] } ] } <EOL> CloudStack . return_value = cloudstack_client = mock . Mock ( ) <EOL> cloudstack_client . listVirtualMachines . return_value = vms <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> lb = load_balancer . LoadBalancer ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ip_id = "<STR_LIT>" , <EOL> project_id = None <EOL> ) <EOL> h = host . Host ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> manager . detach_real ( lb , h ) <EOL> list_data = { "<STR_LIT:id>" : "<STR_LIT>" } <EOL> cloudstack_client . listVirtualMachines . assert_called_with ( list_data ) <EOL> assoc_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . disassociateGloboNetworkRealFromVip . assert_called_with ( assoc_data ) <EOL> CloudStack . assert_called_with ( <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_detach_real_with_project_id ( self , CloudStack ) : <EOL> self . conf . update ( { '<STR_LIT>' : '<STR_LIT:0>' } ) <EOL> vms = { "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] } ] } <EOL> CloudStack . return_value = cloudstack_client = mock . Mock ( ) <EOL> cloudstack_client . listVirtualMachines . return_value = vms <EOL> manager = networkapi_cloudstack . NetworkApiCloudstackLB ( self . conf ) <EOL> lb = load_balancer . LoadBalancer ( <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> ip_id = "<STR_LIT>" , <EOL> project_id = "<STR_LIT>" <EOL> ) <EOL> h = host . Host ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> manager . detach_real ( lb , h ) <EOL> list_data = { "<STR_LIT:id>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . listVirtualMachines . assert_called_with ( list_data ) <EOL> assoc_data = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> cloudstack_client . disassociateGloboNetworkRealFromVip . assert_called_with ( assoc_data ) <EOL> CloudStack . assert_called_with ( <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] , <EOL> self . conf [ "<STR_LIT>" ] ) </s>
