From 9c9c1b4d3b65eef66e91269a2f5d95a43c1bdbb2 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Mon, 10 Jan 2022 15:48:17 -0500 Subject: [PATCH] register_peers will now raise errors if you attempt to reverse or loop --- awx/main/management/commands/register_peers.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/awx/main/management/commands/register_peers.py b/awx/main/management/commands/register_peers.py index 35a05ff195..1e7f770f80 100644 --- a/awx/main/management/commands/register_peers.py +++ b/awx/main/management/commands/register_peers.py @@ -35,6 +35,18 @@ class Command(BaseCommand): if options['exact'] and options['disconnect']: raise CommandError("The option --disconnect may not be used with --exact.") + # No 1-cycles + for collection in ('peers', 'disconnect', 'exact'): + if options['source'] in options[collection]: + raise CommandError(f"Source node {options['source']} may not also be in --{collection}.") + + # No 2-cycles + if options['peers'] or options['exact']: + peers = set(options['peers'] or options['exact']) + incoming = set(InstanceLink.objects.filter(target=nodes[options['source']]).values_list('source__hostname', flat=True)) + if peers & incoming: + raise CommandError(f"Source node {options['source']} cannot link to nodes already peering to it: {peers & incoming}.") + if options['peers']: missing_peers = set(options['peers']) - set(nodes) if missing_peers: