<s> import sys <EOL> from mox3 import mox <EOL> from neutronclient . neutron . v2_0 import agentscheduler <EOL> from neutronclient . neutron . v2_0 import network <EOL> from neutronclient . tests . unit import test_cli20 <EOL> AGENT_ID = '<STR_LIT>' <EOL> NETWORK_ID = '<STR_LIT>' <EOL> ROUTER_ID = '<STR_LIT>' <EOL> class CLITestV20AgentScheduler ( test_cli20 . CLITestV20Base ) : <EOL> def _test_add_to_agent ( self , resource , cmd , cmd_args , destination , <EOL> body , result ) : <EOL> path = ( ( self . client . agent_path + destination ) % <EOL> cmd_args [ <NUM_LIT:0> ] ) <EOL> self . mox . StubOutWithMock ( cmd , "<STR_LIT>" ) <EOL> self . mox . StubOutWithMock ( self . client . httpclient , "<STR_LIT>" ) <EOL> cmd . get_client ( ) . MultipleTimes ( ) . AndReturn ( self . client ) <EOL> result_str = self . client . serialize ( result ) <EOL> return_tup = ( test_cli20 . MyResp ( <NUM_LIT:200> ) , result_str ) <EOL> self . client . httpclient . request ( <EOL> test_cli20 . end_url ( path ) , '<STR_LIT:POST>' , <EOL> body = test_cli20 . MyComparator ( body , self . client ) , <EOL> headers = mox . ContainsKeyValue ( <EOL> '<STR_LIT>' , test_cli20 . TOKEN ) ) . AndReturn ( return_tup ) <EOL> self . mox . ReplayAll ( ) <EOL> cmd_parser = cmd . get_parser ( '<STR_LIT>' + resource ) <EOL> parsed_args = cmd_parser . parse_args ( cmd_args ) <EOL> cmd . run ( parsed_args ) <EOL> self . mox . VerifyAll ( ) <EOL> self . mox . UnsetStubs ( ) <EOL> def _test_remove_from_agent ( self , resource , cmd , cmd_args , destination ) : <EOL> path = ( ( self . client . agent_path + destination + '<STR_LIT>' ) % <EOL> cmd_args ) <EOL> self . mox . StubOutWithMock ( cmd , "<STR_LIT>" ) <EOL> self . mox . StubOutWithMock ( self . client . httpclient , "<STR_LIT>" ) <EOL> cmd . get_client ( ) . MultipleTimes ( ) . AndReturn ( self . client ) <EOL> return_tup = ( test_cli20 . MyResp ( <NUM_LIT> ) , None ) <EOL> self . client . httpclient . request ( <EOL> test_cli20 . end_url ( path ) , '<STR_LIT>' , <EOL> body = None , <EOL> headers = mox . ContainsKeyValue ( <EOL> '<STR_LIT>' , test_cli20 . TOKEN ) ) . AndReturn ( return_tup ) <EOL> self . mox . ReplayAll ( ) <EOL> cmd_parser = cmd . get_parser ( '<STR_LIT>' + resource ) <EOL> parsed_args = cmd_parser . parse_args ( cmd_args ) <EOL> cmd . run ( parsed_args ) <EOL> self . mox . VerifyAll ( ) <EOL> self . mox . UnsetStubs ( ) <EOL> class CLITestV20DHCPAgentScheduler ( CLITestV20AgentScheduler ) : <EOL> def test_add_network_to_agent ( self ) : <EOL> resource = '<STR_LIT>' <EOL> cmd = agentscheduler . AddNetworkToDhcpAgent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> args = ( AGENT_ID , NETWORK_ID ) <EOL> body = { '<STR_LIT>' : NETWORK_ID } <EOL> result = { '<STR_LIT>' : '<STR_LIT>' , } <EOL> self . _test_add_to_agent ( resource , cmd , args , self . client . DHCP_NETS , <EOL> body , result ) <EOL> def test_remove_network_from_agent ( self ) : <EOL> resource = '<STR_LIT>' <EOL> cmd = agentscheduler . RemoveNetworkFromDhcpAgent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> args = ( AGENT_ID , NETWORK_ID ) <EOL> self . _test_remove_from_agent ( resource , cmd , args , <EOL> self . client . DHCP_NETS ) <EOL> def test_list_networks_on_agent ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . ListNetworksOnDhcpAgent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> agent_id = '<STR_LIT>' <EOL> path = ( ( self . client . agent_path + self . client . DHCP_NETS ) % <EOL> agent_id ) <EOL> self . mox . StubOutWithMock ( network . ListNetwork , "<STR_LIT>" ) <EOL> network . ListNetwork . extend_list ( mox . IsA ( list ) , mox . IgnoreArg ( ) ) <EOL> self . _test_list_resources ( resources , cmd , base_args = [ agent_id ] , <EOL> path = path ) <EOL> def test_list_agents_hosting_network ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . ListDhcpAgentsHostingNetwork ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> agent_id = '<STR_LIT>' <EOL> path = ( ( self . client . network_path + self . client . DHCP_AGENTS ) % <EOL> agent_id ) <EOL> contents = { self . id_field : '<STR_LIT>' , '<STR_LIT>' : True } <EOL> self . _test_list_resources ( resources , cmd , base_args = [ agent_id ] , <EOL> path = path , response_contents = contents ) <EOL> class CLITestV20L3AgentScheduler ( CLITestV20AgentScheduler ) : <EOL> def test_add_router_to_agent ( self ) : <EOL> resource = '<STR_LIT>' <EOL> cmd = agentscheduler . AddRouterToL3Agent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> args = ( AGENT_ID , ROUTER_ID ) <EOL> body = { '<STR_LIT>' : ROUTER_ID } <EOL> result = { '<STR_LIT>' : '<STR_LIT>' , } <EOL> self . _test_add_to_agent ( resource , cmd , args , self . client . L3_ROUTERS , <EOL> body , result ) <EOL> def test_remove_router_from_agent ( self ) : <EOL> resource = '<STR_LIT>' <EOL> cmd = agentscheduler . RemoveRouterFromL3Agent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> args = ( AGENT_ID , ROUTER_ID ) <EOL> self . _test_remove_from_agent ( resource , cmd , args , <EOL> self . client . L3_ROUTERS ) <EOL> def test_list_routers_on_agent ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . ListRoutersOnL3Agent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> agent_id = '<STR_LIT>' <EOL> path = ( ( self . client . agent_path + self . client . L3_ROUTERS ) % <EOL> agent_id ) <EOL> contents = { self . id_field : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' } <EOL> self . _test_list_resources ( resources , cmd , base_args = [ agent_id ] , <EOL> path = path , response_contents = contents ) <EOL> def test_list_agents_hosting_router ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . ListL3AgentsHostingRouter ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> agent_id = '<STR_LIT>' <EOL> path = ( ( self . client . router_path + self . client . L3_AGENTS ) % <EOL> agent_id ) <EOL> contents = { self . id_field : '<STR_LIT>' , '<STR_LIT>' : True } <EOL> self . _test_list_resources ( resources , cmd , base_args = [ agent_id ] , <EOL> path = path , response_contents = contents ) <EOL> class CLITestV20LBaaSAgentScheduler ( test_cli20 . CLITestV20Base ) : <EOL> def test_list_pools_on_agent ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . ListPoolsOnLbaasAgent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> agent_id = '<STR_LIT>' <EOL> path = ( ( self . client . agent_path + self . client . LOADBALANCER_POOLS ) % <EOL> agent_id ) <EOL> self . _test_list_resources ( resources , cmd , base_args = [ agent_id ] , <EOL> path = path ) <EOL> def test_get_lbaas_agent_hosting_pool ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . GetLbaasAgentHostingPool ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> pool_id = '<STR_LIT>' <EOL> path = ( ( self . client . pool_path + self . client . LOADBALANCER_AGENT ) % <EOL> pool_id ) <EOL> contents = { self . id_field : '<STR_LIT>' , '<STR_LIT>' : True } <EOL> self . _test_list_resources ( resources , cmd , base_args = [ pool_id ] , <EOL> path = path , response_contents = contents ) <EOL> class CLITestV20LBaaSV2AgentScheduler ( test_cli20 . CLITestV20Base ) : <EOL> def test_list_loadbalancers_on_agent ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . ListLoadBalancersOnLbaasAgent ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> agent_id = '<STR_LIT>' <EOL> path = ( ( self . client . agent_path + self . client . AGENT_LOADBALANCERS ) % <EOL> agent_id ) <EOL> self . _test_list_resources ( resources , cmd , base_args = [ agent_id ] , <EOL> path = path ) <EOL> def test_get_lbaas_agent_hosting_pool ( self ) : <EOL> resources = '<STR_LIT>' <EOL> cmd = agentscheduler . GetLbaasAgentHostingLoadBalancer ( <EOL> test_cli20 . MyApp ( sys . stdout ) , None ) <EOL> lb_id = '<STR_LIT>' <EOL> path = ( ( self . client . lbaas_loadbalancer_path + <EOL> self . client . LOADBALANCER_HOSTING_AGENT ) % lb_id ) <EOL> contents = { self . id_field : '<STR_LIT>' , '<STR_LIT>' : True } <EOL> self . _test_list_resources ( resources , cmd , base_args = [ lb_id ] , <EOL> path = path , response_contents = contents ) </s>
