Runtime aware scheduling
Add runtime scheduler Depends-On: I510cbd0353ca67145d85f586a94d49418de6ef27 Change-Id: I1e80bc871873cc4fce143cbcde5a8fe28603f34b Partially-Implements: blueprint runtime-aware-scheduling
This commit is contained in:
parent
b9532f9d36
commit
9a9e979c9f
39
zun/scheduler/filters/runtime_filter.py
Normal file
39
zun/scheduler/filters/runtime_filter.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright (c) 2017 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.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.
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from zun.scheduler import filters
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RuntimeFilter(filters.BaseHostFilter):
|
||||
"""Filter the containers by runtime"""
|
||||
|
||||
run_filter_once_per_request = True
|
||||
|
||||
def host_passes(self, host_state, container, extra_spec):
|
||||
if not container.runtime:
|
||||
return True
|
||||
|
||||
if container.runtime not in host_state.runtimes:
|
||||
LOG.debug("Runtime '%(container_runtime)s' requested. "
|
||||
"%(host_state)s has runtimes: %(host_runtime)s",
|
||||
{'host_state': host_state,
|
||||
'container_runtime': container.runtime,
|
||||
'host_runtime': host_state.runtimes})
|
||||
return False
|
||||
return True
|
@ -40,6 +40,7 @@ class HostState(object):
|
||||
self.labels = None
|
||||
self.pci_stats = None
|
||||
self.disk_quota_supported = False
|
||||
self.runtimes = []
|
||||
|
||||
# Resource oversubscription values for the compute host:
|
||||
self.limits = {}
|
||||
@ -72,6 +73,7 @@ class HostState(object):
|
||||
self.pci_stats = pci_stats.PciDeviceStats(
|
||||
stats=compute_node.pci_device_pools)
|
||||
self.disk_quota_supported = compute_node.disk_quota_supported
|
||||
self.runtimes = compute_node.runtimes
|
||||
|
||||
def __repr__(self):
|
||||
return ("%(host)s ram: %(free_ram)sMB "
|
||||
|
52
zun/tests/unit/scheduler/filters/test_runtime_filter.py
Normal file
52
zun/tests/unit/scheduler/filters/test_runtime_filter.py
Normal file
@ -0,0 +1,52 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.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.
|
||||
|
||||
from zun.common import context
|
||||
from zun import objects
|
||||
from zun.scheduler.filters import runtime_filter
|
||||
from zun.tests import base
|
||||
from zun.tests.unit.scheduler import fakes
|
||||
|
||||
|
||||
class TestRuntimeFilter(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRuntimeFilter, self).setUp()
|
||||
self.context = context.RequestContext('fake_user', 'fake_project')
|
||||
|
||||
def test_runtime_filter_unspecificed(self):
|
||||
self.filt_cls = runtime_filter.RuntimeFilter()
|
||||
container = objects.Container(self.context)
|
||||
container.runtime = None
|
||||
host = fakes.FakeHostState('testhost')
|
||||
host.runtimes = ['runc']
|
||||
extra_spec = {}
|
||||
self.assertTrue(self.filt_cls.host_passes(host, container, extra_spec))
|
||||
|
||||
def test_runtime_filter_specificed(self):
|
||||
self.filt_cls = runtime_filter.RuntimeFilter()
|
||||
container = objects.Container(self.context)
|
||||
container.runtime = 'runc'
|
||||
host = fakes.FakeHostState('testhost')
|
||||
host.runtimes = ['runc']
|
||||
extra_spec = {}
|
||||
self.assertTrue(self.filt_cls.host_passes(host, container, extra_spec))
|
||||
|
||||
def test_runtime_filter_not_supported(self):
|
||||
self.filt_cls = runtime_filter.RuntimeFilter()
|
||||
container = objects.Container(self.context)
|
||||
container.runtime = 'runc'
|
||||
host = fakes.FakeHostState('testhost')
|
||||
host.runtimes = ['kata-runtime']
|
||||
extra_spec = {}
|
||||
self.assertFalse(self.filt_cls.host_passes(host, container,
|
||||
extra_spec))
|
@ -65,6 +65,7 @@ class FilterSchedulerTestCase(base.TestCase):
|
||||
node1.labels = {}
|
||||
node1.pci_device_pools = None
|
||||
node1.disk_quota_supported = True
|
||||
node1.runtimes = ['runc']
|
||||
node2 = objects.ComputeNode(self.context)
|
||||
node2.cpus = 48
|
||||
node2.cpu_used = 0.0
|
||||
@ -78,6 +79,7 @@ class FilterSchedulerTestCase(base.TestCase):
|
||||
node2.labels = {}
|
||||
node2.pci_device_pools = None
|
||||
node2.disk_quota_supported = True
|
||||
node2.runtimes = ['runc']
|
||||
node3 = objects.ComputeNode(self.context)
|
||||
node3.cpus = 48
|
||||
node3.cpu_used = 0.0
|
||||
@ -91,6 +93,7 @@ class FilterSchedulerTestCase(base.TestCase):
|
||||
node3.labels = {}
|
||||
node3.pci_device_pools = None
|
||||
node3.disk_quota_supported = True
|
||||
node3.runtimes = ['runc']
|
||||
node4 = objects.ComputeNode(self.context)
|
||||
node4.cpus = 48
|
||||
node4.cpu_used = 0.0
|
||||
@ -104,6 +107,7 @@ class FilterSchedulerTestCase(base.TestCase):
|
||||
node4.labels = {}
|
||||
node4.pci_device_pools = None
|
||||
node4.disk_quota_supported = True
|
||||
node4.runtimes = ['runc']
|
||||
nodes = [node1, node2, node3, node4]
|
||||
mock_compute_list.return_value = nodes
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user