From b04747676c060ba73e1f8631ae5474c075e8e4a8 Mon Sep 17 00:00:00 2001 From: Shane McDonald Date: Wed, 23 Mar 2022 18:42:43 -0400 Subject: [PATCH] Provision the instance before booting anything There was a race condition because the callback reciever tried to run this code: File "/awx_devel/awx/main/management/commands/run_callback_receiver.py", line 31, in handle CallbackBrokerWorker(), File "/awx_devel/awx/main/dispatch/worker/callback.py", line 49, in __init__ self.subsystem_metrics = s_metrics.Metrics(auto_pipe_execute=False) File "/awx_devel/awx/main/analytics/subsystem_metrics.py", line 156, in __init__ self.instance_name = Instance.objects.me().hostname Before get_or_register was being called by the dispatcher. --- awx/main/management/commands/provision_instance.py | 9 ++++----- awx/main/tasks/system.py | 4 ---- tools/ansible/roles/dockerfile/files/launch_awx_task.sh | 2 ++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/awx/main/management/commands/provision_instance.py b/awx/main/management/commands/provision_instance.py index c3c8f188ab..c5c5ba3e1d 100644 --- a/awx/main/management/commands/provision_instance.py +++ b/awx/main/management/commands/provision_instance.py @@ -1,7 +1,7 @@ # Copyright (c) 2015 Ansible, Inc. # All Rights Reserved -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from django.db import transaction from awx.main.models import Instance @@ -22,8 +22,9 @@ class Command(BaseCommand): def _register_hostname(self, hostname, node_type, uuid): if not hostname: - return - (changed, instance) = Instance.objects.register(hostname=hostname, node_type=node_type, uuid=uuid) + (changed, instance) = Instance.objects.get_or_register() + else: + (changed, instance) = Instance.objects.register(hostname=hostname, node_type=node_type, uuid=uuid) if changed: print("Successfully registered instance {}".format(hostname)) else: @@ -32,8 +33,6 @@ class Command(BaseCommand): @transaction.atomic def handle(self, **options): - if not options.get('hostname'): - raise CommandError("Specify `--hostname` to use this command.") self.changed = False self._register_hostname(options.get('hostname'), options.get('node_type'), options.get('uuid')) if self.changed: diff --git a/awx/main/tasks/system.py b/awx/main/tasks/system.py index 008c3bcb2f..3f713dde3c 100644 --- a/awx/main/tasks/system.py +++ b/awx/main/tasks/system.py @@ -612,10 +612,6 @@ def cluster_node_heartbeat(): if inst.hostname == settings.CLUSTER_HOST_ID: this_inst = inst break - else: - (changed, this_inst) = Instance.objects.get_or_register() - if changed: - logger.info("Registered tower control node '{}'".format(this_inst.hostname)) inspect_execution_nodes(instance_list) diff --git a/tools/ansible/roles/dockerfile/files/launch_awx_task.sh b/tools/ansible/roles/dockerfile/files/launch_awx_task.sh index ae1a87a6b0..f0af27cda7 100755 --- a/tools/ansible/roles/dockerfile/files/launch_awx_task.sh +++ b/tools/ansible/roles/dockerfile/files/launch_awx_task.sh @@ -17,4 +17,6 @@ set -e wait-for-migrations +awx-manage provision_instance + supervisord -c /etc/supervisord_task.conf