Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge "Change compute updates from periodic to on demand"

  • Loading branch information...
commit fe96a1f262826cfb5bc3b2ef2917befbf4732814 2 parents 8ee1a30 + f44b4fa
Jenkins authored openstack-gerrit committed
View
10 nova/compute/resource_tracker.py
@@ -76,6 +76,7 @@ def __init__(self, host, driver, nodename):
monitor_handler = monitors.ResourceMonitorHandler()
self.monitors = monitor_handler.choose_monitors(self)
self.notifier = rpc.get_notifier()
+ self.old_resources = {}
@utils.synchronized(COMPUTE_RESOURCE_SEMAPHORE)
def instance_claim(self, context, instance_ref, limits=None):
@@ -439,8 +440,17 @@ def _report_final_resource_view(self, resources):
if 'pci_stats' in resources:
LOG.audit(_("PCI stats: %s"), resources['pci_stats'])
+ def _resource_change(self, resources):
+ """Check to see if any resouces have changed."""
+ if cmp(resources, self.old_resources) != 0:
+ self.old_resources = resources
+ return True
+ return False
+
def _update(self, context, values):
"""Persist the compute node updates to the DB."""
+ if not self._resource_change(values):
+ return
if "service" in self.compute_node:
del self.compute_node['service']
self.compute_node = self.conductor_api.compute_node_update(
View
21 nova/tests/compute/test_resource_tracker.py
@@ -425,6 +425,7 @@ def setUp(self):
self.updated = False
self.deleted = False
+ self.update_call_count = 0
self.tracker = self._tracker()
self._migrations = {}
@@ -450,9 +451,8 @@ def _fake_service_get_by_compute_host(self, ctx, host):
def _fake_compute_node_update(self, ctx, compute_node_id, values,
prune_stats=False):
+ self.update_call_count += 1
self.updated = True
- values['stats'] = [{"key": "num_instances", "value": "1"}]
-
self.compute.update(values)
return self.compute
@@ -1144,3 +1144,20 @@ def test_get_host_metrics(self):
self.context, 'compute.metrics.update', payload)
self.assertEqual(metrics, expected_metrics)
+
+
+class TrackerPeriodicTestCase(BaseTrackerTestCase):
+
+ def test_periodic_status_update(self):
+ # verify update called on instantiation
+ self.assertEqual(1, self.update_call_count)
+
+ # verify update not called if no change to resources
+ self.tracker.update_available_resource(self.context)
+ self.assertEqual(1, self.update_call_count)
+
+ # verify update is called when resources change
+ driver = self.tracker.driver
+ driver.memory_mb += 1
+ self.tracker.update_available_resource(self.context)
+ self.assertEqual(2, self.update_call_count)
Please sign in to comment.
Something went wrong with that request. Please try again.