diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-06-13 12:44:55 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-06-13 12:44:55 -0400 |
commit | fbf6edf62b7b105abb467ef5cb9254eb8f5396c6 (patch) | |
tree | 365427a597bd189a9361f8e14a4c1e6e73282013 /src | |
parent | 9173c94a53a4c4d9fd853ab9d25ad5e5a3c230c1 (diff) | |
download | bcfg2-fbf6edf62b7b105abb467ef5cb9254eb8f5396c6.tar.gz bcfg2-fbf6edf62b7b105abb467ef5cb9254eb8f5396c6.tar.bz2 bcfg2-fbf6edf62b7b105abb467ef5cb9254eb8f5396c6.zip |
Probes: reduce race condition that can result in multiple probe groups
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Probes.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index f8baddb4b..1a199d056 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -252,12 +252,15 @@ class Probes(Bcfg2.Server.Plugin.Probing, for group in self.cgroups[client.hostname]: try: - ProbesGroupsModel.objects.get(hostname=client.hostname, - group=group) - except ProbesGroupsModel.DoesNotExist: - grp = ProbesGroupsModel(hostname=client.hostname, - group=group) - grp.save() + ProbesGroupsModel.objects.get_or_create( + hostname=client.hostname, + group=group).save() + except ProbesGroupsModel.MultipleObjectsReturned: + ProbesGroupsModel.objects.filter(hostname=client.hostname, + group=group).delete() + ProbesGroupsModel.objects.get_or_create( + hostname=client.hostname, + group=group).save() ProbesGroupsModel.objects.filter( hostname=client.hostname).exclude( group__in=self.cgroups[client.hostname]).delete() |