<s> import stubout <EOL> import webob . exc <EOL> from nova import context <EOL> from nova import exception <EOL> from nova import flags <EOL> from nova import log as logging <EOL> from nova import test <EOL> from nova . api . openstack . contrib import hosts as os_hosts <EOL> from nova . scheduler import api as scheduler_api <EOL> FLAGS = flags . FLAGS <EOL> LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> HOST_LIST = [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] <EOL> def stub_get_host_list ( req ) : <EOL> return HOST_LIST <EOL> def stub_set_host_enabled ( context , host , enabled ) : <EOL> fail = ( host == "<STR_LIT>" ) <EOL> status = "<STR_LIT>" if ( enabled ^ fail ) else "<STR_LIT>" <EOL> return status <EOL> def stub_host_power_action ( context , host , action ) : <EOL> return action <EOL> class FakeRequest ( object ) : <EOL> environ = { "<STR_LIT>" : context . get_admin_context ( ) } <EOL> class HostTestCase ( test . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( HostTestCase , self ) . setUp ( ) <EOL> self . controller = os_hosts . HostController ( ) <EOL> self . req = FakeRequest ( ) <EOL> self . stubs . Set ( scheduler_api , '<STR_LIT>' , stub_get_host_list ) <EOL> self . stubs . Set ( self . controller . compute_api , '<STR_LIT>' , <EOL> stub_set_host_enabled ) <EOL> self . stubs . Set ( self . controller . compute_api , '<STR_LIT>' , <EOL> stub_host_power_action ) <EOL> def test_list_hosts ( self ) : <EOL> """<STR_LIT>""" <EOL> hosts = os_hosts . _list_hosts ( self . req ) <EOL> self . assertEqual ( hosts , HOST_LIST ) <EOL> compute_hosts = os_hosts . _list_hosts ( self . req , "<STR_LIT>" ) <EOL> expected = [ host for host in HOST_LIST <EOL> if host [ "<STR_LIT>" ] == "<STR_LIT>" ] <EOL> self . assertEqual ( compute_hosts , expected ) <EOL> def test_disable_host ( self ) : <EOL> dis_body = { "<STR_LIT:status>" : "<STR_LIT>" } <EOL> result_c1 = self . controller . update ( self . req , "<STR_LIT>" , body = dis_body ) <EOL> self . assertEqual ( result_c1 [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> result_c2 = self . controller . update ( self . req , "<STR_LIT>" , body = dis_body ) <EOL> self . assertEqual ( result_c2 [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> def test_enable_host ( self ) : <EOL> en_body = { "<STR_LIT:status>" : "<STR_LIT>" } <EOL> result_c1 = self . controller . update ( self . req , "<STR_LIT>" , body = en_body ) <EOL> self . assertEqual ( result_c1 [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> result_c2 = self . controller . update ( self . req , "<STR_LIT>" , body = en_body ) <EOL> self . assertEqual ( result_c2 [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> def test_host_startup ( self ) : <EOL> result = self . controller . startup ( self . req , "<STR_LIT>" ) <EOL> self . assertEqual ( result [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def test_host_shutdown ( self ) : <EOL> result = self . controller . shutdown ( self . req , "<STR_LIT>" ) <EOL> self . assertEqual ( result [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def test_host_reboot ( self ) : <EOL> result = self . controller . reboot ( self . req , "<STR_LIT>" ) <EOL> self . assertEqual ( result [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def test_bad_status_value ( self ) : <EOL> bad_body = { "<STR_LIT:status>" : "<STR_LIT>" } <EOL> self . assertRaises ( webob . exc . HTTPBadRequest , self . controller . update , <EOL> self . req , "<STR_LIT>" , body = bad_body ) <EOL> def test_bad_update_key ( self ) : <EOL> bad_body = { "<STR_LIT>" : "<STR_LIT>" } <EOL> self . assertRaises ( webob . exc . HTTPBadRequest , self . controller . update , <EOL> self . req , "<STR_LIT>" , body = bad_body ) <EOL> def test_bad_host ( self ) : <EOL> self . assertRaises ( exception . HostNotFound , self . controller . update , <EOL> self . req , "<STR_LIT>" , body = { "<STR_LIT:status>" : "<STR_LIT>" } ) </s>
