Don't load all resources for policy check

We only need the resource types for the check. Let's
avoid loading all resources.

Change-Id: Iaf5650b2ae972064292cfe0d17f98b5635c51bad
This commit is contained in:
ramishra 2021-03-16 11:24:09 +05:30 committed by rabi
parent 5451b9854b
commit ceef7869e0
2 changed files with 9 additions and 2 deletions

View File

@ -188,6 +188,6 @@ class ResourceEnforcer(Enforcer):
def enforce_stack(self, stack, scope=None, target=None,
is_registered_policy=False):
for res in stack.resources.values():
self.enforce(stack.context, res.type(), scope=scope, target=target,
for res_type in stack.defn.all_resource_types():
self.enforce(stack.context, res_type, scope=scope, target=target,
is_registered_policy=is_registered_policy)

View File

@ -102,6 +102,13 @@ class StackDefinition(object):
else:
return self.enabled_rsrc_names()
def all_resource_types(self):
"""Return the set of types of all resources in the template."""
if self._resource_defns is None:
self._load_rsrc_defns()
return set(self._resource_defns[res].resource_type
for res in self._resource_defns)
def get_availability_zones(self):
"""Return the list of Nova availability zones."""
if self._zones is None: