Skip to content

Commit

Permalink
Remove unused variables and imports
Browse files Browse the repository at this point in the history
Addresses flake8 and linting failures

Signed-off-by: Seth Foster <[email protected]>
  • Loading branch information
fosterseth committed Nov 16, 2023
1 parent bbfdae8 commit 11e3dcd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
13 changes: 7 additions & 6 deletions awx/main/models/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import logging
import os

from django.core.validators import MinValueValidator, MaxValueValidator
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator
from django.db import models, connection
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
Expand Down Expand Up @@ -503,12 +502,14 @@ def receptor_address_saved(sender, instance, **kwargs):
control_instances = set(Instance.objects.filter(node_type__in=[Instance.Types.CONTROL, Instance.Types.HYBRID]))
if address.peers_from_control_nodes:
if set(address.peers_from.all()) != control_instances:
address.peers_from.add(*control_instances)
schedule_write_receptor_config()
with disable_activity_stream():
address.peers_from.add(*control_instances)
schedule_write_receptor_config()
else:
if address.peers_from.exists():
address.peers_from.remove(*control_instances)
schedule_write_receptor_config()
with disable_activity_stream:
address.peers_from.remove(*control_instances)
schedule_write_receptor_config()


@receiver(post_delete, sender=ReceptorAddress)
Expand Down
3 changes: 0 additions & 3 deletions awx/main/models/receptor_address.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from django.utils.translation import gettext_lazy as _
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from awx.api.versioning import reverse
from django.db.models import Sum, Q


class ReceptorAddress(models.Model):
Expand Down
11 changes: 4 additions & 7 deletions awx/main/tests/functional/api/test_instance_peers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import pytest
import yaml
import itertools
from unittest import mock

from django.db.utils import IntegrityError

from awx.api.versioning import reverse
from awx.main.models import Instance, ReceptorAddress
from awx.api.views.instance_install_bundle import generate_group_vars_all_yml
Expand Down Expand Up @@ -84,7 +81,7 @@ def test_multiple_peers_from_control_nodes(self, admin_user, post):
only one address can have peers_from_control_nodes set to True for a given instance
"""
hop = Instance.objects.create(hostname='hop', node_type='hop')
hopaddr1 = ReceptorAddress.objects.create(instance=hop, address='hopaddr1', peers_from_control_nodes=True)
ReceptorAddress.objects.create(instance=hop, address='hopaddr1', peers_from_control_nodes=True)
resp = post(
url=reverse('api:instance_receptor_addresses_list', kwargs={'pk': hop.pk}),
data={"address": "hopaddr2", "peers_from_control_nodes": True},
Expand Down Expand Up @@ -247,13 +244,13 @@ def test_group_vars(self):
"""
control = Instance.objects.create(hostname='control', node_type='control')
hop1 = Instance.objects.create(hostname='hop1', node_type='hop')
hop1addr = ReceptorAddress.objects.create(instance=hop1, address='hop1addr', peers_from_control_nodes=True, port=6789)
ReceptorAddress.objects.create(instance=hop1, address='hop1addr', peers_from_control_nodes=True, port=6789)

hop2 = Instance.objects.create(hostname='hop2', node_type='hop')
hop2addr = ReceptorAddress.objects.create(instance=hop2, address='hop2addr', peers_from_control_nodes=False, port=6789)

execution = Instance.objects.create(hostname='execution', node_type='execution')
executionaddr = ReceptorAddress.objects.create(instance=execution, address='executionaddr', peers_from_control_nodes=False, port=6789)
ReceptorAddress.objects.create(instance=execution, address='executionaddr', peers_from_control_nodes=False, port=6789)

execution.peers.add(hop2addr)
hop1.peers.add(hop2addr)
Expand Down Expand Up @@ -318,7 +315,7 @@ def test_write_receptor_config_called(self):

# new address with peers_from_control_nodes False and peered to another hop node (no)
hop2 = Instance.objects.create(hostname='hop2', node_type='hop')
hop2addr = ReceptorAddress.objects.create(instance=hop2, address='hop2addr', peers_from_control_nodes=False)
ReceptorAddress.objects.create(instance=hop2, address='hop2addr', peers_from_control_nodes=False)
hop2.peers.add(hop1addr)
hop2.delete()
write_method.assert_not_called()
Expand Down

0 comments on commit 11e3dcd

Please sign in to comment.