<s> import mock <EOL> from nova import objects <EOL> from nova . scheduler . filters import disk_filter <EOL> from nova import test <EOL> from nova . tests . unit . scheduler import fakes <EOL> class TestDiskFilter ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestDiskFilter , self ) . setUp ( ) <EOL> def test_disk_filter_passes ( self ) : <EOL> filt_cls = disk_filter . DiskFilter ( ) <EOL> spec_obj = objects . RequestSpec ( <EOL> flavor = objects . Flavor ( root_gb = <NUM_LIT:1> , ephemeral_gb = <NUM_LIT:1> , swap = <NUM_LIT> ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:11> * <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1.0> } ) <EOL> self . assertTrue ( filt_cls . host_passes ( host , spec_obj ) ) <EOL> def test_disk_filter_fails ( self ) : <EOL> filt_cls = disk_filter . DiskFilter ( ) <EOL> spec_obj = objects . RequestSpec ( <EOL> flavor = objects . Flavor ( <EOL> root_gb = <NUM_LIT:10> , ephemeral_gb = <NUM_LIT:1> , swap = <NUM_LIT> ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:11> * <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1.0> } ) <EOL> self . assertFalse ( filt_cls . host_passes ( host , spec_obj ) ) <EOL> def test_disk_filter_oversubscribe ( self ) : <EOL> filt_cls = disk_filter . DiskFilter ( ) <EOL> spec_obj = objects . RequestSpec ( <EOL> flavor = objects . Flavor ( <EOL> root_gb = <NUM_LIT:100> , ephemeral_gb = <NUM_LIT> , swap = <NUM_LIT> ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:11> * <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:12> , <EOL> '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertTrue ( filt_cls . host_passes ( host , spec_obj ) ) <EOL> self . assertEqual ( <NUM_LIT:12> * <NUM_LIT> , host . limits [ '<STR_LIT>' ] ) <EOL> def test_disk_filter_oversubscribe_fail ( self ) : <EOL> filt_cls = disk_filter . DiskFilter ( ) <EOL> spec_obj = objects . RequestSpec ( <EOL> flavor = objects . Flavor ( <EOL> root_gb = <NUM_LIT:100> , ephemeral_gb = <NUM_LIT> , swap = <NUM_LIT> ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:11> * <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:12> , <EOL> '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertFalse ( filt_cls . host_passes ( host , spec_obj ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_aggregate_disk_filter_value_error ( self , agg_mock ) : <EOL> filt_cls = disk_filter . AggregateDiskFilter ( ) <EOL> spec_obj = objects . RequestSpec ( <EOL> context = mock . sentinel . ctx , <EOL> flavor = objects . Flavor ( <EOL> root_gb = <NUM_LIT:1> , ephemeral_gb = <NUM_LIT:1> , swap = <NUM_LIT> ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:3> * <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1.0> } ) <EOL> agg_mock . return_value = set ( [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( filt_cls . host_passes ( host , spec_obj ) ) <EOL> agg_mock . assert_called_once_with ( host , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_aggregate_disk_filter_default_value ( self , agg_mock ) : <EOL> filt_cls = disk_filter . AggregateDiskFilter ( ) <EOL> spec_obj = objects . RequestSpec ( <EOL> context = mock . sentinel . ctx , <EOL> flavor = objects . Flavor ( <EOL> root_gb = <NUM_LIT:2> , ephemeral_gb = <NUM_LIT:1> , swap = <NUM_LIT> ) ) <EOL> host = fakes . FakeHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:3> * <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:1.0> } ) <EOL> agg_mock . return_value = set ( [ ] ) <EOL> self . assertFalse ( filt_cls . host_passes ( host , spec_obj ) ) <EOL> agg_mock . assert_called_once_with ( host , '<STR_LIT>' ) <EOL> agg_mock . return_value = set ( [ '<STR_LIT:2>' ] ) <EOL> self . assertTrue ( filt_cls . host_passes ( host , spec_obj ) ) </s>
