From c3100afd0e49dbc24383f024fd15519a7f4bfc34 Mon Sep 17 00:00:00 2001 From: chris meyers Date: Tue, 3 Apr 2018 13:50:57 -0400 Subject: [PATCH] fixed isolated instance query * Was considering an isolated instance: any instance that has at least 1 group with no controller. This is technically correct since an iso node can not be a part of a non-iso group. * The query is now more robust and considers a node an iso node if ALL groups that a node belong to ALL have a controller. * Also added better debugging for the special tower instance group * Added a check for the existance of the special tower group so that logs are less "messy" during the install process. --- awx/main/managers.py | 2 +- awx/main/models/ha.py | 4 ---- awx/main/tasks.py | 12 ++++++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/awx/main/managers.py b/awx/main/managers.py index ce5a3a1971..1adb75e913 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -114,7 +114,7 @@ class InstanceManager(models.Manager): return "tower" def all_non_isolated(self): - return self.filter(rampart_groups__controller__isnull=True).distinct() + return self.exclude(rampart_groups__controller__isnull=False) class InstanceGroupManager(models.Manager): diff --git a/awx/main/models/ha.py b/awx/main/models/ha.py index 145fdbfb51..b7e50ec2b4 100644 --- a/awx/main/models/ha.py +++ b/awx/main/models/ha.py @@ -163,10 +163,6 @@ class InstanceGroup(models.Model, RelatedJobsMixin): def _get_related_jobs(self): return UnifiedJob.objects.filter(instance_group=self) - def add_all_non_iso_instances(self): - self.instances = Instance.objects.all_non_isolated() - self.save() - class Meta: app_label = 'main' diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 0de7094100..21a09c7ff2 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -144,8 +144,16 @@ def apply_cluster_membership_policies(self): Group = namedtuple('Group', ['obj', 'instances']) Node = namedtuple('Instance', ['obj', 'groups']) - # Add every instnace to the special 'tower' group - InstanceGroup.objects.get(name='tower').add_all_non_iso_instances() + # Add every instance to the special 'tower' group + tower_q = InstanceGroup.objects.filter(name='tower') + if tower_q.exists(): + tower_inst = tower_q[0] + tower_inst.instances = Instance.objects.all_non_isolated() + instances_hostnames = [i.hostname for i in tower_inst.instances.all()] + logger.info(six.text_type("Setting 'tower' group instances to {}").format(instances_hostnames)) + tower_inst.save() + else: + logger.warn(six.text_type("Special 'tower' Instance Group not found.")) # Process policy instance list first, these will represent manually managed instances # that will not go through automatic policy determination