<s> """<STR_LIT>""" <EOL> from nova . scheduler import weights <EOL> from nova . scheduler . weights import ram <EOL> from nova import test <EOL> from nova . tests . unit . scheduler import fakes <EOL> class RamWeigherTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( RamWeigherTestCase , self ) . setUp ( ) <EOL> self . weight_handler = weights . HostWeightHandler ( ) <EOL> self . weighers = [ ram . RAMWeigher ( ) ] <EOL> def _get_weighed_host ( self , hosts , weight_properties = None ) : <EOL> if weight_properties is None : <EOL> weight_properties = { } <EOL> return self . weight_handler . get_weighed_objects ( self . weighers , <EOL> hosts , weight_properties ) [ <NUM_LIT:0> ] <EOL> def _get_all_hosts ( self ) : <EOL> host_values = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT> } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT> } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT> } ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> ] <EOL> return [ fakes . FakeHostState ( host , node , values ) <EOL> for host , node , values in host_values ] <EOL> def test_default_of_spreading_first ( self ) : <EOL> hostinfo_list = self . _get_all_hosts ( ) <EOL> weighed_host = self . _get_weighed_host ( hostinfo_list ) <EOL> self . assertEqual ( <NUM_LIT:1.0> , weighed_host . weight ) <EOL> self . assertEqual ( '<STR_LIT>' , weighed_host . obj . host ) <EOL> def test_ram_filter_multiplier1 ( self ) : <EOL> self . flags ( ram_weight_multiplier = <NUM_LIT:0.0> ) <EOL> hostinfo_list = self . _get_all_hosts ( ) <EOL> weighed_host = self . _get_weighed_host ( hostinfo_list ) <EOL> self . assertEqual ( <NUM_LIT:0.0> , weighed_host . weight ) <EOL> def test_ram_filter_multiplier2 ( self ) : <EOL> self . flags ( ram_weight_multiplier = <NUM_LIT> ) <EOL> hostinfo_list = self . _get_all_hosts ( ) <EOL> weighed_host = self . _get_weighed_host ( hostinfo_list ) <EOL> self . assertEqual ( <NUM_LIT:1.0> * <NUM_LIT:2> , weighed_host . weight ) <EOL> self . assertEqual ( '<STR_LIT>' , weighed_host . obj . host ) <EOL> def test_ram_filter_negative ( self ) : <EOL> self . flags ( ram_weight_multiplier = <NUM_LIT:1.0> ) <EOL> hostinfo_list = self . _get_all_hosts ( ) <EOL> host_attr = { '<STR_LIT:id>' : <NUM_LIT:100> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : - <NUM_LIT> } <EOL> host_state = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , host_attr ) <EOL> hostinfo_list = list ( hostinfo_list ) + [ host_state ] <EOL> weights = self . weight_handler . get_weighed_objects ( self . weighers , <EOL> hostinfo_list , { } ) <EOL> weighed_host = weights [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <NUM_LIT:1> , weighed_host . weight ) <EOL> self . assertEqual ( '<STR_LIT>' , weighed_host . obj . host ) <EOL> weighed_host = weights [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( <NUM_LIT:0> , weighed_host . weight ) <EOL> self . assertEqual ( '<STR_LIT>' , weighed_host . obj . host ) </s>
