"Fossies" - the Fresh Open Source Software Archive

Member "zun-4.0.0/zun/tests/unit/scheduler/filters/test_disk_filter.py" (16 Oct 2019, 2723 Bytes) of package /linux/misc/openstack/zun-4.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_disk_filter.py": 2.1.0_vs_3.0.0.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 from zun.common import context
   14 from zun import objects
   15 from zun.scheduler.filters import disk_filter
   16 from zun.tests import base
   17 from zun.tests.unit.scheduler import fakes
   18 
   19 
   20 class TestDiskFilter(base.TestCase):
   21 
   22     def setUp(self):
   23         super(TestDiskFilter, self).setUp()
   24         self.context = context.RequestContext('fake_user', 'fake_project')
   25 
   26     def test_disk_filter_pass(self):
   27         self.filt_cls = disk_filter.DiskFilter()
   28         container = objects.Container(self.context)
   29         container.disk = 20
   30         host = fakes.FakeHostState('testhost')
   31         host.disk_total = 80
   32         host.disk_used = 40
   33         host.disk_quota_supported = True
   34         extra_spec = {}
   35         self.assertTrue(self.filt_cls.host_passes(host, container, extra_spec))
   36 
   37     def test_disk_filter_pass_capsule(self):
   38         self.filt_cls = disk_filter.DiskFilter()
   39         capsule = objects.Capsule(self.context)
   40         capsule.disk = 20
   41         host = fakes.FakeHostState('testhost')
   42         host.disk_total = 80
   43         host.disk_used = 40
   44         host.disk_quota_supported = True
   45         extra_spec = {}
   46         self.assertTrue(self.filt_cls.host_passes(host, capsule, extra_spec))
   47 
   48     def test_disk_filter_fail_not_enough_disk(self):
   49         self.filt_cls = disk_filter.DiskFilter()
   50         container = objects.Container(self.context)
   51         container.disk = 20
   52         host = fakes.FakeHostState('testhost')
   53         host.disk_total = 80
   54         host.disk_used = 70
   55         host.disk_quota_supported = True
   56         extra_spec = {}
   57         self.assertFalse(self.filt_cls.host_passes(host, container,
   58                                                    extra_spec))
   59 
   60     def test_disk_filter_fail_not_supported(self):
   61         self.filt_cls = disk_filter.DiskFilter()
   62         container = objects.Container(self.context)
   63         container.disk = 20
   64         host = fakes.FakeHostState('testhost')
   65         host.disk_total = 80
   66         host.disk_used = 40
   67         host.disk_quota_supported = False
   68         extra_spec = {}
   69         self.assertFalse(self.filt_cls.host_passes(host, container,
   70                                                    extra_spec))