Files
deb-nova/nova/tests/unit/compute/fake_resource_tracker.py
Paul Murray 414bdd21cd Use compute_node consistently in ResourceTracker
This is the second patch set in a series refactoring code that
uses ResourceTracker.compute_node so that it can later be changed
to be a ComputeNode object. Note that in this patch compute_node
is still a dict.

The methods that calculate resource usage in the ResourceTracker
take a parameter called (variously) resources, values or stats.
Sometimes these are called passing self.compute_node as the value
for this parameter and sometimes a dict data structure obtained
from the virt driver by the get_available_resources() method.
The result of the changes are always copied into the
self.compute_node.

This mixing of data structures won't work if self.compute_node is
converted to be a ComputeNode object instead of a dict. The
previous patch in this series initialises self.compute_node at
the start of _update_available_resources() so it has a value at
the outset. This patch copies the resources data into
self.compute_node and uses only that data structure in the methods
that calculate resource usage. As a consequence it is no longer
necessary to pass this in as a parameter in those methods or to
copy the result into self.compute_node at the end of the
calculations.

This step will allow us, in following patches, to convert the code
in the update methods to object notiation when self.compute_node
is changed to be an object instread of a dict.

Minor changes included are removal the final copy into
compute_node and moving initialisation of the stats plugin
into _init_compute_node().

Change-Id: Ia79b34aa9e6aad5cabe63bb7545c545b952b2b3a
2015-05-12 10:09:54 +00:00

33 lines
1.1 KiB
Python

# Copyright (c) 2012 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 nova.compute import resource_tracker
from nova import objects
class FakeResourceTracker(resource_tracker.ResourceTracker):
"""Version without a DB requirement."""
def _create(self, context, values):
self._write_ext_resources(values)
self.compute_node = values
self.compute_node['id'] = 1
def _update(self, context):
self._write_ext_resources(self.compute_node)
def _get_service(self, context):
return objects.Service(id=1)