<s> import mock <EOL> from nova import objects <EOL> from nova . scheduler . filters import aggregate_instance_extra_specs as agg_specs <EOL> from nova import test <EOL> from nova . tests . unit . scheduler import fakes <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> class TestAggregateInstanceExtraSpecsFilter ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestAggregateInstanceExtraSpecsFilter , self ) . setUp ( ) <EOL> self . filt_cls = agg_specs . AggregateInstanceExtraSpecsFilter ( ) <EOL> def test_aggregate_filter_passes_no_extra_specs ( self , agg_mock ) : <EOL> capabilities = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> spec_obj = objects . RequestSpec ( <EOL> context = mock . sentinel . ctx , <EOL> flavor = objects . Flavor ( memory_mb = <NUM_LIT> ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , capabilities ) <EOL> self . assertTrue ( self . filt_cls . host_passes ( host , spec_obj ) ) <EOL> self . assertFalse ( agg_mock . called ) <EOL> def test_aggregate_filter_passes_empty_extra_specs ( self , agg_mock ) : <EOL> capabilities = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> spec_obj = objects . RequestSpec ( <EOL> context = mock . sentinel . ctx , <EOL> flavor = objects . Flavor ( memory_mb = <NUM_LIT> , extra_specs = { } ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , capabilities ) <EOL> self . assertTrue ( self . filt_cls . host_passes ( host , spec_obj ) ) <EOL> self . assertFalse ( agg_mock . called ) <EOL> def _do_test_aggregate_filter_extra_specs ( self , especs , passes ) : <EOL> spec_obj = objects . RequestSpec ( <EOL> context = mock . sentinel . ctx , <EOL> flavor = objects . Flavor ( memory_mb = <NUM_LIT> , extra_specs = especs ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT> } ) <EOL> assertion = self . assertTrue if passes else self . assertFalse <EOL> assertion ( self . filt_cls . host_passes ( host , spec_obj ) ) <EOL> def test_aggregate_filter_passes_extra_specs_simple ( self , agg_mock ) : <EOL> agg_mock . return_value = { '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT:2>' } <EOL> especs = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> } <EOL> self . _do_test_aggregate_filter_extra_specs ( especs , passes = True ) <EOL> def test_aggregate_filter_passes_extra_specs_simple_comma ( self , agg_mock ) : <EOL> agg_mock . return_value = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:2>' } <EOL> especs = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' , <EOL> } <EOL> self . _do_test_aggregate_filter_extra_specs ( especs , passes = True ) <EOL> def test_aggregate_filter_passes_with_key_same_as_scope ( self , agg_mock ) : <EOL> agg_mock . return_value = { '<STR_LIT>' : '<STR_LIT:1>' } <EOL> especs = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> } <EOL> self . _do_test_aggregate_filter_extra_specs ( especs , passes = True ) <EOL> def test_aggregate_filter_fails_extra_specs_simple ( self , agg_mock ) : <EOL> agg_mock . return_value = { '<STR_LIT>' : '<STR_LIT:1>' , '<STR_LIT>' : '<STR_LIT:2>' } <EOL> especs = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:true>' <EOL> } <EOL> self . _do_test_aggregate_filter_extra_specs ( especs , passes = False ) </s>
