From 36641e89d28aeb411cc1886a7ecd90b8bcbf0f8f Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 27 Sep 2013 06:40:04 -0400 Subject: GroupLogic: fixed thread-local variable initialization --- src/lib/Bcfg2/Server/Plugins/GroupLogic.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib/Bcfg2/Server/Plugins/GroupLogic.py b/src/lib/Bcfg2/Server/Plugins/GroupLogic.py index aa71d2cfe..d74c16e8b 100644 --- a/src/lib/Bcfg2/Server/Plugins/GroupLogic.py +++ b/src/lib/Bcfg2/Server/Plugins/GroupLogic.py @@ -47,19 +47,21 @@ class GroupLogic(Bcfg2.Server.Plugin.Plugin, self.config = GroupLogicConfig(os.path.join(self.data, "groups.xml"), core.fam) self._local = local() - # building is a thread-local set that tracks which machines - # GroupLogic is getting additional groups for. If a - # get_additional_groups() is called twice for a machine before - # the first call has completed, the second call returns an - # empty list. This is for infinite recursion protection; - # without this check, it'd be impossible to use things like - # metadata.query.in_group() in GroupLogic, since that requires - # building all metadata, which requires running - # GroupLogic.get_additional_groups() for all hosts, which - # requires building all metadata... - self._local.building = set() def get_additional_groups(self, metadata): + if not hasattr(self._local, "building"): + # building is a thread-local set that tracks which + # machines GroupLogic is getting additional groups for. + # If a get_additional_groups() is called twice for a + # machine before the first call has completed, the second + # call returns an empty list. This is for infinite + # recursion protection; without this check, it'd be + # impossible to use things like metadata.query.in_group() + # in GroupLogic, since that requires building all + # metadata, which requires running + # GroupLogic.get_additional_groups() for all hosts, which + # requires building all metadata... + self._local.building = set() if metadata.hostname in self._local.building: return [] self._local.building.add(metadata.hostname) -- cgit v1.2.3-1-g7c22