Browse Source

Update resources once in update_available_resource

This change ensures that resources are updated only once per
update_available_resource() call.

Compute resources were previously updated during host
object initialization and at the end of
update_available_resource(). It could cause inconsistencies
in resource tracking between compute host and DB for couple
of second when final _update() at the end of
update_available_resource() is being called.

For example: nova-api shows that host uses 10GB of RAM, but
in fact its 12GB because DB doesn't have resources that belongs
to shutdown instance.

Because of that fact nova-scheduler (CachingScheduler) could
choose (based on imcomplete information) host which is already full.

For more informations please see realted bug: #1729621

Change-Id: I120a98cc4c11772f24099081ef3ac44a50daf71d
Closes-Bug: #1729621
(cherry picked from commit c9b74bcfa0)
tags/17.0.11
Maciej Józefczyk 2 years ago
parent
commit
36d93675d9
2 changed files with 11 additions and 6 deletions
  1. +0
    -3
      nova/compute/resource_tracker.py
  2. +11
    -3
      nova/tests/unit/compute/test_resource_tracker.py

+ 0
- 3
nova/compute/resource_tracker.py View File

@@ -558,7 +558,6 @@ class ResourceTracker(object):
cn = self.compute_nodes[nodename]
self._copy_resources(cn, resources)
self._setup_pci_tracker(context, cn, resources)
self._update(context, cn)
return

# now try to get the compute node record from the
@@ -568,7 +567,6 @@ class ResourceTracker(object):
self.compute_nodes[nodename] = cn
self._copy_resources(cn, resources)
self._setup_pci_tracker(context, cn, resources)
self._update(context, cn)
return

if self._check_for_nodes_rebalance(context, resources, nodename):
@@ -587,7 +585,6 @@ class ResourceTracker(object):
{'host': self.host, 'node': nodename, 'uuid': cn.uuid})

self._setup_pci_tracker(context, cn, resources)
self._update(context, cn)

def _setup_pci_tracker(self, context, compute_node, resources):
if not self.pci_tracker:

+ 11
- 3
nova/tests/unit/compute/test_resource_tracker.py View File

@@ -568,6 +568,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()

@mock.patch('nova.objects.InstancePCIRequests.get_by_instance',
return_value=objects.InstancePCIRequests(requests=[]))
@@ -608,6 +609,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()

@mock.patch('nova.objects.InstancePCIRequests.get_by_instance',
return_value=objects.InstancePCIRequests(requests=[]))
@@ -655,6 +657,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()

@mock.patch('nova.objects.InstancePCIRequests.get_by_instance',
return_value=objects.InstancePCIRequests(requests=[]))
@@ -718,6 +721,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()

@mock.patch('nova.objects.InstancePCIRequests.get_by_instance',
return_value=objects.InstancePCIRequests(requests=[]))
@@ -780,6 +784,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()

@mock.patch('nova.objects.InstancePCIRequests.get_by_instance',
return_value=objects.InstancePCIRequests(requests=[]))
@@ -839,6 +844,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()

@mock.patch('nova.objects.InstancePCIRequests.get_by_instance',
return_value=objects.InstancePCIRequests(requests=[]))
@@ -895,6 +901,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()

@mock.patch('nova.objects.InstancePCIRequests.get_by_instance',
return_value=objects.InstancePCIRequests(requests=[]))
@@ -963,6 +970,7 @@ class TestUpdateAvailableResources(BaseTestCase):
actual_resources = update_mock.call_args[0][1]
self.assertTrue(obj_base.obj_equal_prims(expected_resources,
actual_resources))
update_mock.assert_called_once()


class TestInitComputeNode(BaseTestCase):
@@ -988,7 +996,7 @@ class TestInitComputeNode(BaseTestCase):
self.assertFalse(get_mock.called)
self.assertFalse(create_mock.called)
self.assertTrue(pci_mock.called)
self.assertTrue(update_mock.called)
self.assertFalse(update_mock.called)

@mock.patch('nova.objects.PciDeviceList.get_by_compute_node',
return_value=objects.PciDeviceList())
@@ -1012,7 +1020,7 @@ class TestInitComputeNode(BaseTestCase):
get_mock.assert_called_once_with(mock.sentinel.ctx, _HOSTNAME,
_NODENAME)
self.assertFalse(create_mock.called)
self.assertTrue(update_mock.called)
self.assertFalse(update_mock.called)

@mock.patch('nova.objects.ComputeNodeList.get_by_hypervisor')
@mock.patch('nova.objects.PciDeviceList.get_by_compute_node',
@@ -1177,7 +1185,7 @@ class TestInitComputeNode(BaseTestCase):
self.assertTrue(obj_base.obj_equal_prims(expected_compute, cn))
pci_tracker_mock.assert_called_once_with(mock.sentinel.ctx,
42)
self.assertTrue(update_mock.called)
self.assertFalse(update_mock.called)


class TestUpdateComputeNode(BaseTestCase):

Loading…
Cancel
Save