Browse Source

Merge "Make resource requires a set instead of a list"

changes/75/568775/1
Zuul 4 years ago committed by Gerrit Code Review
parent
commit
f30900e11f
  1. 14
      heat/engine/resource.py
  2. 2
      heat/tests/test_convg_stack.py
  3. 12
      heat/tests/test_resource.py

14
heat/engine/resource.py

@ -243,7 +243,7 @@ class Resource(status.ResourceStatus):
self.updated_time = stack.updated_time
self._rpc_client = None
self.needed_by = []
self.requires = []
self.requires = set()
self.replaces = None
self.replaced_by = None
self.current_template_id = None
@ -291,7 +291,7 @@ class Resource(status.ResourceStatus):
self.created_time = resource.created_at
self.updated_time = resource.updated_at
self.needed_by = resource.needed_by
self.requires = resource.requires
self.requires = set(resource.requires)
self.replaces = resource.replaces
self.replaced_by = resource.replaced_by
self.current_template_id = resource.current_template_id
@ -392,7 +392,7 @@ class Resource(status.ResourceStatus):
'name': self.name,
'rsrc_prop_data_id': None,
'needed_by': self.needed_by,
'requires': list(requires),
'requires': sorted(requires, reverse=True),
'replaces': self.id,
'action': self.INIT,
'status': self.COMPLETE,
@ -1158,7 +1158,7 @@ class Resource(status.ResourceStatus):
timeout, progress_callback=None):
"""Creates the resource by invoking the scheduler TaskRunner."""
self._calling_engine_id = engine_id
self.requires = list(requires)
self.requires = requires
self.current_template_id = template_id
if self.stack.adopt_stack_data is None:
runner = scheduler.TaskRunner(self.create)
@ -1648,7 +1648,7 @@ class Resource(status.ResourceStatus):
self.updated_time = datetime.utcnow()
if new_requires is not None:
self.requires = list(set(self.requires) | new_requires)
self.requires = self.requires | new_requires
with self._action_recorder(action, UpdateReplace):
after_props.validate()
@ -1678,7 +1678,7 @@ class Resource(status.ResourceStatus):
self.reparse()
self._update_stored_properties()
if new_requires is not None:
self.requires = list(new_requires)
self.requires = new_requires
yield self._break_if_required(
self.UPDATE, environment.HOOK_POST_UPDATE)
@ -2071,7 +2071,7 @@ class Resource(status.ResourceStatus):
'rsrc_prop_data_id':
self._create_or_replace_rsrc_prop_data(),
'needed_by': self.needed_by,
'requires': self.requires,
'requires': sorted(self.requires, reverse=True),
'replaces': self.replaces,
'replaced_by': self.replaced_by,
'current_template_id': self.current_template_id,

2
heat/tests/test_convg_stack.py

@ -800,7 +800,7 @@ class TestConvgComputeDependencies(common.HeatTestCase):
res = mock.MagicMock()
res.id = 6
res.name = 'E'
res.requires = [3]
res.requires = {3}
res.replaces = 1
res.current_template_id = 2
db_resources[6] = res

12
heat/tests/test_resource.py

@ -720,7 +720,7 @@ class ResourceTest(common.HeatTestCase):
self.assertEqual(res.id, new_res.replaces)
self.assertIsNone(new_res.physical_resource_id)
self.assertEqual(new_tmpl_id, new_res.current_template_id)
self.assertItemsEqual(list(new_requires), new_res.requires)
self.assertEqual([4, 2, 1], new_res.requires)
def test_metadata_default(self):
tmpl = rsrc_defn.ResourceDefinition('test_resource', 'Foo')
@ -2131,7 +2131,7 @@ class ResourceTest(common.HeatTestCase):
stack.thread_group_mgr = tools.DummyThreadGroupManager()
stack.converge_stack(stack.t, action=stack.CREATE)
res = stack.resources['test_res']
res.requires = [2]
res.requires = {2}
res.action = res.CREATE
res.store()
self._assert_resource_lock(res.id, None, None)
@ -2231,7 +2231,7 @@ class ResourceTest(common.HeatTestCase):
def test_update_in_progress_convergence(self, mock_cfcr, mock_nu):
tmpl = rsrc_defn.ResourceDefinition('test_res', 'Foo')
res = generic_rsrc.GenericResource('test_res', tmpl, self.stack)
res.requires = [1, 2]
res.requires = {1, 2}
res.store()
rs = resource_objects.Resource.get_obj(self.stack.context, res.id)
rs.update_and_save({'engine_id': 'not-this'})
@ -2255,7 +2255,7 @@ class ResourceTest(common.HeatTestCase):
self.assertEqual(msg, six.text_type(ex))
# ensure requirements are not updated for failed resource
rs = resource_objects.Resource.get_obj(self.stack.context, res.id)
self.assertEqual([1, 2], rs.requires)
self.assertEqual([2, 1], rs.requires)
@mock.patch.object(resource.Resource, 'update_template_diff_properties')
@mock.patch.object(resource.Resource, '_needs_update')
@ -2272,7 +2272,7 @@ class ResourceTest(common.HeatTestCase):
stack.thread_group_mgr = tools.DummyThreadGroupManager()
stack.converge_stack(stack.t, action=stack.CREATE)
res = stack.resources['test_res']
res.requires = [2]
res.requires = {2}
res.store()
self._assert_resource_lock(res.id, None, None)
@ -2313,7 +2313,7 @@ class ResourceTest(common.HeatTestCase):
stack.thread_group_mgr = tools.DummyThreadGroupManager()
stack.converge_stack(stack.t, action=stack.CREATE)
res = stack.resources['test_res']
res.requires = [2]
res.requires = {2}
res.store()
self._assert_resource_lock(res.id, None, None)

Loading…
Cancel
Save