Example #1
0
 def test_core_filter_fails_safe(self):
     filt_cls = self.class_map['CoreFilter']()
     filter_properties = {'instance_type': {'vcpus': 1}}
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Example #2
0
 def test_availability_zone_filter_different(self):
     filt_cls = self.class_map['AvailabilityZoneFilter']()
     service = {'availability_zone': 'nova'}
     request = self._make_zone_request('bad')
     host = fakes.FakeHostState('host1', 'compute', {'service': service})
     self.assertFalse(filt_cls.host_passes(host, request))
Example #3
0
 def test_dict_conversion(self):
     host_state = fakes.FakeHostState('somehost', None, {})
     host = weights.WeighedHost(host_state, 'someweight')
     expected = {'weight': 'someweight', 'host': 'somehost'}
     self.assertThat(host.to_dict(), matchers.DictMatches(expected))
Example #4
0
    def test_json_filter_happy_day(self):
        """Test json filter more thoroughly"""
        filt_cls = self.class_map['JsonFilter']()
        raw = [
            'and', '$capabilities.enabled',
            ['=', '$capabilities.opt1', 'match'],
            [
                'or',
                [
                    'and', ['<', '$free_ram_mb', 30],
                    ['<', '$free_disk_mb', 300]
                ],
                [
                    'and', ['>', '$free_ram_mb', 30],
                    ['>', '$free_disk_mb', 300]
                ]
            ]
        ]
        filter_properties = {'query': json.dumps(raw)}

        # Passes
        capabilities = {'enabled': True, 'opt1': 'match'}
        service = {'disabled': False}
        host = fakes.FakeHostState(
            'host1', 'compute', {
                'free_ram_mb': 10,
                'free_disk_mb': 200,
                'capabilities': capabilities,
                'service': service
            })
        self.assertTrue(filt_cls.host_passes(host, filter_properties))

        # Passes
        capabilities = {'enabled': True, 'opt1': 'match'}
        service = {'disabled': False}
        host = fakes.FakeHostState(
            'host1', 'compute', {
                'free_ram_mb': 40,
                'free_disk_mb': 400,
                'capabilities': capabilities,
                'service': service
            })
        self.assertTrue(filt_cls.host_passes(host, filter_properties))

        # Failes due to caps disabled
        capabilities = {'enabled': False, 'opt1': 'match'}
        service = {'disabled': False}
        host = fakes.FakeHostState(
            'host1', 'instance_type', {
                'free_ram_mb': 40,
                'free_disk_mb': 400,
                'capabilities': capabilities,
                'service': service
            })
        self.assertFalse(filt_cls.host_passes(host, filter_properties))

        # Fails due to being exact memory/disk we don't want
        capabilities = {'enabled': True, 'opt1': 'match'}
        service = {'disabled': False}
        host = fakes.FakeHostState(
            'host1', 'compute', {
                'free_ram_mb': 30,
                'free_disk_mb': 300,
                'capabilities': capabilities,
                'service': service
            })
        self.assertFalse(filt_cls.host_passes(host, filter_properties))

        # Fails due to memory lower but disk higher
        capabilities = {'enabled': True, 'opt1': 'match'}
        service = {'disabled': False}
        host = fakes.FakeHostState(
            'host1', 'compute', {
                'free_ram_mb': 20,
                'free_disk_mb': 400,
                'capabilities': capabilities,
                'service': service
            })
        self.assertFalse(filt_cls.host_passes(host, filter_properties))

        # Fails due to capabilities 'opt1' not equal
        capabilities = {'enabled': True, 'opt1': 'no-match'}
        service = {'enabled': True}
        host = fakes.FakeHostState(
            'host1', 'compute', {
                'free_ram_mb': 20,
                'free_disk_mb': 400,
                'capabilities': capabilities,
                'service': service
            })
        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Example #5
0
 def test_ram_filter_passes(self):
     ram_filter.RamFilter.ram_allocation_ratio = 1.0
     filter_properties = {'instance_type': {'memory_mb': 1024}}
     host = fakes.FakeHostState('host1', 'node1',
             {'free_ram_mb': 1024, 'total_usable_ram_mb': 1024})
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #6
0
    def test_prep_resize_post_populates_retry(self):
        # Prep resize should add a ('host', 'node') entry to the retry dict.
        sched = fakes.FakeFilterScheduler()

        image = 'image'
        instance = {
            'disable_terminate': False,
            'uuid': 'fakeuuid',
            'deleted': 0,
            'info_cache': {},
            'created_at': None,
            'system_metadata': [],
            'shutdown_terminate': False,
            'id': 1,
            'security_groups': [],
            'metadata': []
        }

        instance_properties = {'project_id': 'fake', 'os_type': 'Linux'}
        instance_type = {
            'memory_mb': 1024,
            'root_gb': 40,
            'deleted_at': None,
            'name': u'm1.medium',
            'deleted': 0,
            'created_at': None,
            'ephemeral_gb': 0,
            'updated_at': None,
            'disabled': False,
            'vcpus': 2,
            'extra_specs': {},
            'swap': 0,
            'rxtx_factor': 1.0,
            'is_public': True,
            'flavorid': u'3',
            'vcpu_weight': None,
            'id': 1
        }

        request_spec = {
            'instance_properties': instance_properties,
            'instance_type': instance_type
        }
        retry = {'hosts': [], 'num_attempts': 1}
        filter_properties = {'retry': retry}
        reservations = None

        host = fakes.FakeHostState('host', 'node', {})
        weighed_host = weights.WeighedHost(host, 1)
        weighed_hosts = [weighed_host]

        self.mox.StubOutWithMock(sched, '_schedule')
        self.mox.StubOutWithMock(sched.compute_rpcapi, 'prep_resize')

        sched._schedule(self.context, request_spec, filter_properties,
                        [instance['uuid']]).AndReturn(weighed_hosts)
        sched.compute_rpcapi.prep_resize(self.context,
                                         image,
                                         instance,
                                         instance_type,
                                         'host',
                                         reservations,
                                         request_spec=request_spec,
                                         filter_properties=filter_properties,
                                         node='node')

        self.mox.ReplayAll()
        sched.schedule_prep_resize(self.context, image, request_spec,
                                   filter_properties, instance, instance_type,
                                   reservations)

        self.assertEqual([['host', 'node']],
                         filter_properties['retry']['hosts'])
Example #7
0
    def test_json_filter_basic_operators(self):
        filt_cls = self.class_map['JsonFilter']()
        host = fakes.FakeHostState('host1', 'compute',
                                   {'capabilities': {
                                       'enabled': True
                                   }})
        # (operator, arguments, expected_result)
        ops_to_test = [
            ['=', [1, 1], True],
            ['=', [1, 2], False],
            ['<', [1, 2], True],
            ['<', [1, 1], False],
            ['<', [2, 1], False],
            ['>', [2, 1], True],
            ['>', [2, 2], False],
            ['>', [2, 3], False],
            ['<=', [1, 2], True],
            ['<=', [1, 1], True],
            ['<=', [2, 1], False],
            ['>=', [2, 1], True],
            ['>=', [2, 2], True],
            ['>=', [2, 3], False],
            ['in', [1, 1], True],
            ['in', [1, 1, 2, 3], True],
            ['in', [4, 1, 2, 3], False],
            ['not', [True], False],
            ['not', [False], True],
            ['or', [True, False], True],
            ['or', [False, False], False],
            ['and', [True, True], True],
            ['and', [False, False], False],
            ['and', [True, False], False],
            # Nested ((True or False) and (2 > 1)) == Passes
            ['and', [['or', True, False], ['>', 2, 1]], True]
        ]

        for (op, args, expected) in ops_to_test:
            raw = [op] + args
            filter_properties = {
                'scheduler_hints': {
                    'query': jsonutils.dumps(raw),
                },
            }
            self.assertEqual(expected,
                             filt_cls.host_passes(host, filter_properties))

        # This results in [False, True, False, True] and if any are True
        # then it passes...
        raw = ['not', True, False, True, False]
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertTrue(filt_cls.host_passes(host, filter_properties))

        # This results in [False, False, False] and if any are True
        # then it passes...which this doesn't
        raw = ['not', True, True, True]
        filter_properties = {
            'scheduler_hints': {
                'query': jsonutils.dumps(raw),
            },
        }
        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Example #8
0
 def test_trusted_filter_default_passes(self):
     self._stub_service_is_up(True)
     filt_cls = self.class_map['TrustedFilter']()
     filter_properties = {'instance_type': {'memory_mb': 1024}}
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Example #9
0
 def test_retry_filter_disabled(self):
     """Test case where retry/re-scheduling is disabled"""
     filt_cls = self.class_map['RetryFilter']()
     host = fakes.FakeHostState('host1', 'compute', {})
     filter_properties = {}
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Example #10
0
 def test_all_host_filter(self):
     filt_cls = self.class_map['AllHostsFilter']()
     host = fakes.FakeHostState('host1', 'compute', {})
     self.assertTrue(filt_cls.host_passes(host, {}))
Example #11
0
 def test_retry_filter_disabled(self):
     # Test case where retry/re-scheduling is disabled.
     host = fakes.FakeHostState('host1', 'node1', {})
     filter_properties = {}
     self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
Example #12
0
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Tests for solver scheduler linearconstraints.
"""

from nova.tests.scheduler import fakes
from nova.tests.scheduler.solvers import test_linearconstraints as lctests

HOSTS = [fakes.FakeHostState('host1', 'node1',
          {'free_disk_mb': 11 * 1024, 'total_usable_disk_gb': 13,
           'free_ram_mb': 1024, 'total_usable_ram_mb': 1024,
           'vcpus_total': 4, 'vcpus_used': 7,
           'service': {'disabled': False}}),
         fakes.FakeHostState('host2', 'node2',
          {'free_disk_mb': 1024, 'total_usable_disk_gb': 13,
           'free_ram_mb': 1023, 'total_usable_ram_mb': 1024,
           'vcpus_total': 4, 'vcpus_used': 8,
           'service': {'disabled': False}}),
        ]

INSTANCE_UUIDS = ['fake-instance1-uuid', 'fake-instance2-uuid']

INSTANCE_TYPES = [{'root_gb': 1, 'ephemeral_gb': 1, 'swap': 512,
                   'memory_mb': 1024, 'vcpus': 1},
                 ]
Example #13
0
from cinderclient import exceptions as client_exceptions

from nova.tests.scheduler import fakes
from nova.tests.scheduler.solvers import test_costs as tc
from nova.tests.volume import test_cinder as cindertest
import nova.volume.cinder as volumecinder


class FakeVolume(object):
    def __init__(self, id, host_id):
        setattr(self, 'os-vol-host-attr:host', host_id)
        self.id = id


HOSTS = [
    fakes.FakeHostState('host1', 'node1', {}),
    fakes.FakeHostState('host2', 'node2', {}),
]

VOLUMES = [
    FakeVolume('volume1', 'host1'),
    FakeVolume('volume2', 'host2'),
]

INSTANCE_UUIDS = ['fake-instance-uuid', 'fake-instance2-uuid']


class VolumeAffinityCostTestCase(tc.CostsTestBase):
    """Test case for VolumeAffinityCost."""
    def setUp(self):
        super(VolumeAffinityCostTestCase, self).setUp()