Revert "Remove traces of now unused host capabilities from scheduler"
This reverts commit ce3f9e5fa9
.
This commit caused problems in tripleo, nova-bm isn't able to launch
instance as they are being filtered out by ComputeCapabilitiesFilter.
Fixes bug #1326289
Change-Id: Icaae95eea78eff11cee34e8a3875d62b3cce0b60
This commit is contained in:
parent
2cebfd2e32
commit
61453f3b99
|
@ -46,15 +46,18 @@ class BaremetalNodeState(host_manager.HostState):
|
|||
self.vcpus_used = self.vcpus_total
|
||||
|
||||
|
||||
def new_host_state(self, host, node, compute=None):
|
||||
"""Returns an instance of BaremetalNodeState or HostState according to
|
||||
compute['cpu_info']. If 'cpu_info' equals 'baremetal cpu', it returns an
|
||||
instance of BaremetalNodeState. If not, returns an instance of HostState.
|
||||
def new_host_state(self, host, node, capabilities=None, service=None):
|
||||
"""Returns an instance of BaremetalHostState or HostState according to
|
||||
capabilities. If 'baremetal_driver' is in capabilities, it returns an
|
||||
instance of BaremetalHostState. If not, returns an instance of HostState.
|
||||
"""
|
||||
if compute and compute.get('cpu_info') == 'baremetal cpu':
|
||||
return BaremetalNodeState(host, node, compute=compute)
|
||||
if capabilities is None:
|
||||
capabilities = {}
|
||||
cap = capabilities.get('compute', {})
|
||||
if bool(cap.get('baremetal_driver')):
|
||||
return BaremetalNodeState(host, node, capabilities, service)
|
||||
else:
|
||||
return host_manager.HostState(host, node, compute=compute)
|
||||
return host_manager.HostState(host, node, capabilities, service)
|
||||
|
||||
|
||||
class BaremetalHostManager(host_manager.HostManager):
|
||||
|
|
|
@ -109,9 +109,10 @@ class HostState(object):
|
|||
previously used and lock down access.
|
||||
"""
|
||||
|
||||
def __init__(self, host, node, compute=None):
|
||||
def __init__(self, host, node, capabilities=None, service=None):
|
||||
self.host = host
|
||||
self.nodename = node
|
||||
self.update_capabilities(capabilities, service)
|
||||
|
||||
# Mutable available resources.
|
||||
# These will change as resources are virtually "consumed".
|
||||
|
@ -146,10 +147,15 @@ class HostState(object):
|
|||
self.metrics = {}
|
||||
|
||||
self.updated = None
|
||||
if compute:
|
||||
self.update_from_compute_node(compute)
|
||||
|
||||
def update_service(self, service):
|
||||
def update_capabilities(self, capabilities=None, service=None):
|
||||
# Read-only capability dicts
|
||||
|
||||
if capabilities is None:
|
||||
capabilities = {}
|
||||
self.capabilities = ReadOnlyDict(capabilities)
|
||||
if service is None:
|
||||
service = {}
|
||||
self.service = ReadOnlyDict(service)
|
||||
|
||||
def _update_metrics_from_compute_node(self, compute):
|
||||
|
@ -319,6 +325,8 @@ class HostManager(object):
|
|||
host_state_cls = HostState
|
||||
|
||||
def __init__(self):
|
||||
# { (host, hypervisor_hostname) : { <service> : { cap k : v }}}
|
||||
self.service_states = {}
|
||||
self.host_state_map = {}
|
||||
self.filter_handler = filters.HostFilterHandler()
|
||||
self.filter_classes = self.filter_handler.get_matching_classes(
|
||||
|
@ -446,13 +454,17 @@ class HostManager(object):
|
|||
host = service['host']
|
||||
node = compute.get('hypervisor_hostname')
|
||||
state_key = (host, node)
|
||||
capabilities = self.service_states.get(state_key, None)
|
||||
host_state = self.host_state_map.get(state_key)
|
||||
if host_state:
|
||||
host_state.update_from_compute_node(compute)
|
||||
host_state.update_capabilities(capabilities,
|
||||
dict(service.iteritems()))
|
||||
else:
|
||||
host_state = self.host_state_cls(host, node, compute)
|
||||
host_state = self.host_state_cls(host, node,
|
||||
capabilities=capabilities,
|
||||
service=dict(service.iteritems()))
|
||||
self.host_state_map[state_key] = host_state
|
||||
host_state.update_service(dict(service.iteritems()))
|
||||
host_state.update_from_compute_node(compute)
|
||||
seen_nodes.add(state_key)
|
||||
|
||||
# remove compute nodes from host_state_map if they are not active
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
# Copyright (c) 2014 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.
|
||||
"""
|
||||
Tests For BaremetalHostManager
|
||||
"""
|
||||
import mock
|
||||
|
||||
from nova.scheduler import baremetal_host_manager
|
||||
from nova.scheduler import host_manager
|
||||
from nova import test
|
||||
|
||||
|
||||
class BaremetalHostManagerTestCase(test.NoDBTestCase):
|
||||
"""Test case for BaremetalHostManager class."""
|
||||
|
||||
def setUp(self):
|
||||
super(BaremetalHostManagerTestCase, self).setUp()
|
||||
self.host_manager = baremetal_host_manager.BaremetalHostManager()
|
||||
|
||||
@mock.patch.object(baremetal_host_manager.BaremetalNodeState,
|
||||
'update_from_compute_node')
|
||||
def test_create_baremetal_node_state(self, update_mock):
|
||||
compute = {'cpu_info': 'baremetal cpu'}
|
||||
host_state = self.host_manager.host_state_cls('fake-host', 'fake-node',
|
||||
compute)
|
||||
self.assertIs(baremetal_host_manager.BaremetalNodeState,
|
||||
type(host_state))
|
||||
|
||||
@mock.patch.object(host_manager.HostState, 'update_from_compute_node')
|
||||
def test_create_non_baremetal_host_state(self, update_mock):
|
||||
compute = {'cpu_info': 'other cpu'}
|
||||
host_state = self.host_manager.host_state_cls('fake-host', 'fake-node',
|
||||
compute)
|
||||
self.assertIs(host_manager.HostState, type(host_state))
|
Loading…
Reference in New Issue