diff --git a/nova/conf/compute.py b/nova/conf/compute.py index 7c0b270d3769..51ba58bf8eb5 100644 --- a/nova/conf/compute.py +++ b/nova/conf/compute.py @@ -640,6 +640,21 @@ Possible values: Related options: * ``shutdown_timeout`` +"""), + cfg.IntOpt('resource_provider_association_refresh', + default=300, + min=1, + help=""" +Interval for updating nova-compute-side cache of the compute node resource +provider's aggregates and traits info. + +This option specifies the number of seconds between attempts to update a +provider's aggregates and traits information in the local cache of the compute +node. + +Possible values: + +* Any positive integer in seconds. """) ] diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index f0e33552fd17..5b4ff225204d 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -45,9 +45,6 @@ _RE_INV_IN_USE = re.compile("Inventory for (.+) on resource provider " "(.+) in use") WARN_EVERY = 10 PLACEMENT_CLIENT_SEMAPHORE = 'placement_client' -# Number of seconds between attempts to update a provider's aggregates and -# traits -ASSOCIATION_REFRESH = 300 POST_RPS_RETURNS_PAYLOAD_API_VERSION = '1.20' NESTED_PROVIDER_API_VERSION = '1.14' POST_ALLOCATIONS_API_VERSION = '1.13' @@ -778,8 +775,8 @@ class SchedulerReportClient(object): sharing providers for the specified resource provider uuid. Only refresh if there has been no refresh during the lifetime of - this process, ASSOCIATION_REFRESH seconds have passed, or the force arg - has been set to True. + this process, CONF.compute.resource_provider_association_refresh + seconds have passed, or the force arg has been set to True. Note that we do *not* refresh inventories. The reason is largely historical: all code paths that get us here are doing inventory refresh @@ -848,10 +845,12 @@ class SchedulerReportClient(object): "recently". Associations are stale if association_refresh_time for this uuid is not - set or is more than ASSOCIATION_REFRESH seconds ago. + set or is more than CONF.compute.resource_provider_association_refresh + seconds ago. """ refresh_time = self._association_refresh_time.get(uuid, 0) - return (time.time() - refresh_time) > ASSOCIATION_REFRESH + return ((time.time() - refresh_time) > + CONF.compute.resource_provider_association_refresh) def _update_inventory_attempt(self, context, rp_uuid, inv_data): """Update the inventory for this resource provider if needed. diff --git a/nova/tests/unit/scheduler/client/test_report.py b/nova/tests/unit/scheduler/client/test_report.py index 8f0ec5b23a37..ed268fe256e5 100644 --- a/nova/tests/unit/scheduler/client/test_report.py +++ b/nova/tests/unit/scheduler/client/test_report.py @@ -2273,14 +2273,16 @@ class TestAssociations(SchedulerReportClientTestCase): with mock.patch('time.time') as mock_future: # Not called a second time because not enough time has passed. - mock_future.return_value = now + report.ASSOCIATION_REFRESH / 2 + mock_future.return_value = (now + + CONF.compute.resource_provider_association_refresh / 2) self.client._refresh_associations(self.context, uuid) mock_agg_get.assert_not_called() mock_trait_get.assert_not_called() mock_shr_get.assert_not_called() # Called because time has passed. - mock_future.return_value = now + report.ASSOCIATION_REFRESH + 1 + mock_future.return_value = (now + + CONF.compute.resource_provider_association_refresh + 1) self.client._refresh_associations(self.context, uuid) mock_agg_get.assert_called_once_with(self.context, uuid) mock_trait_get.assert_called_once_with(self.context, uuid) diff --git a/releasenotes/notes/add-association-refresh-config-opt-d1ca1af238d10c9a.yaml b/releasenotes/notes/add-association-refresh-config-opt-d1ca1af238d10c9a.yaml new file mode 100644 index 000000000000..7df3c2c6b4ff --- /dev/null +++ b/releasenotes/notes/add-association-refresh-config-opt-d1ca1af238d10c9a.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + The nova-compute service now allows specifying the interval for updating + nova-compute-side cache of the compute node resource provider's aggregates + and traits info via a new config option called + ``[compute]/resource_provider_association_refresh`` which defaults to 300. + This was previously hard-coded to run every 300 seconds which may be too + often in a large deployment.