Skip to content

Commit

Permalink
Remove traces of now unused host capabilities from scheduler
Browse files Browse the repository at this point in the history
Host capabilities updates are no longer used by the scheduler. All host
state is instead fetched from the DB. Some left over fields are still kept
by the host manager but contain no data. This change remove the last
traces of host capabilities from the scheduler.

The baremetal host manager used to rely on capabilities info to
decide which host state class to use, VM or baremetal. This has been
broken since host capabilities were removed (bug 1260265). The logic to
decide on host state class to use is updated to use DB data instead and
a test is added to verify the same.

Change-Id: I350109492c2addf5fdfaadee7cec4784f244e102
Closes-Bug: #1260265
  • Loading branch information
hanlind committed May 18, 2014
1 parent 693223e commit ce3f9e5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 29 deletions.
17 changes: 7 additions & 10 deletions nova/scheduler/baremetal_host_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ def consume_from_instance(self, instance):
self.vcpus_used = self.vcpus_total


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.
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.
"""
if capabilities is None:
capabilities = {}
cap = capabilities.get('compute', {})
if bool(cap.get('baremetal_driver')):
return BaremetalNodeState(host, node, capabilities, service)
if compute and compute.get('cpu_info') == 'baremetal cpu':
return BaremetalNodeState(host, node, compute=compute)
else:
return host_manager.HostState(host, node, capabilities, service)
return host_manager.HostState(host, node, compute=compute)


class BaremetalHostManager(host_manager.HostManager):
Expand Down
26 changes: 7 additions & 19 deletions nova/scheduler/host_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ class HostState(object):
previously used and lock down access.
"""

def __init__(self, host, node, capabilities=None, service=None):
def __init__(self, host, node, compute=None):
self.host = host
self.nodename = node
self.update_capabilities(capabilities, service)

# Mutable available resources.
# These will change as resources are virtually "consumed".
Expand Down Expand Up @@ -147,15 +146,10 @@ def __init__(self, host, node, capabilities=None, service=None):
self.metrics = {}

self.updated = None
if compute:
self.update_from_compute_node(compute)

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 = {}
def update_service(self, service):
self.service = ReadOnlyDict(service)

def _update_metrics_from_compute_node(self, compute):
Expand Down Expand Up @@ -324,8 +318,6 @@ 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(
Expand Down Expand Up @@ -453,17 +445,13 @@ def get_all_host_states(self, context):
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_capabilities(capabilities,
dict(service.iteritems()))
host_state.update_from_compute_node(compute)
else:
host_state = self.host_state_cls(host, node,
capabilities=capabilities,
service=dict(service.iteritems()))
host_state = self.host_state_cls(host, node, compute)
self.host_state_map[state_key] = host_state
host_state.update_from_compute_node(compute)
host_state.update_service(dict(service.iteritems()))
seen_nodes.add(state_key)

# remove compute nodes from host_state_map if they are not active
Expand Down
46 changes: 46 additions & 0 deletions nova/tests/scheduler/test_baremetal_host_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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))

0 comments on commit ce3f9e5

Please sign in to comment.