Invalidate cached node information after hooks run
Change-Id: Ic5554ffa6867638f7f5059c14d326d75e11e4e2b Closes-Bug: #1418540
This commit is contained in:
parent
1863ab96b8
commit
a62dbbd2e4
|
@ -58,7 +58,7 @@ class NodeInfo(object):
|
|||
self.started_at = started_at
|
||||
self.finished_at = finished_at
|
||||
self.error = error
|
||||
self._options = None
|
||||
self.invalidate_cache()
|
||||
|
||||
@property
|
||||
def options(self):
|
||||
|
@ -126,6 +126,10 @@ class NodeInfo(object):
|
|||
for key in ('uuid', 'started_at', 'finished_at', 'error')}
|
||||
return cls(**fields)
|
||||
|
||||
def invalidate_cache(self):
|
||||
"""Clear all cached info, so that it's reloaded next time."""
|
||||
self._options = None
|
||||
|
||||
|
||||
def init():
|
||||
"""Initialize the database."""
|
||||
|
|
|
@ -99,6 +99,9 @@ def _process_node(ironic, node, node_info, cached_node):
|
|||
{'mac': mac, 'node': node.uuid})
|
||||
|
||||
node_patches, port_patches = _run_post_hooks(node, ports, node_info)
|
||||
# Invalidate cache in case of hooks modifying options
|
||||
cached_node.invalidate_cache()
|
||||
|
||||
node = utils.retry_on_conflict(ironic.node.update, node.uuid, node_patches)
|
||||
for mac, patches in port_patches.items():
|
||||
utils.retry_on_conflict(ironic.port.update, ports[mac].uuid, patches)
|
||||
|
|
|
@ -309,6 +309,11 @@ class TestNodeInfoOptions(test_base.NodeTest):
|
|||
self.assertEqual({'foo': 'bar'}, self.node_info.options)
|
||||
# should be cached
|
||||
self.assertIs(self.node_info.options, self.node_info.options)
|
||||
# invalidate cache
|
||||
old_options = self.node_info.options
|
||||
self.node_info.invalidate_cache()
|
||||
self.assertIsNot(old_options, self.node_info.options)
|
||||
self.assertEqual(old_options, self.node_info.options)
|
||||
|
||||
def test_set(self):
|
||||
data = {'s': 'value', 'b': True, 'i': 42}
|
||||
|
|
Loading…
Reference in New Issue