Add functional and unit tests

Updated existing tests to support the
ReceptorAddress model

- cannot peer to self
- cannot peer to node that is already peered to me
- cannot peer to node more than once (via 2+ addresses)
- cannot set is_internal True

Other changes:
Change post save signal to only call
schedule_write_receptor_config() when an actual change is detected.

Make functional tests more robust by
checking for specific validation error in the
response.

I.e. instead of just checking for 400, just for 400
and that the error message corresponds to the
validation we are testing for.

Signed-off-by: Seth Foster <fosterbseth@gmail.com>
This commit is contained in:
Seth Foster
2023-11-14 13:39:24 -05:00
committed by Seth Foster
parent 5385eb0fb3
commit d1cacf64de
5 changed files with 199 additions and 119 deletions

View File

@@ -496,8 +496,6 @@ def schedule_write_receptor_config(broadcast=True):
write_receptor_config() # just run locally
# TODO: don't use the receiver post save, just call this at the moment when we need it
# that way we don't call this multiple times unnecessarily
@receiver(post_save, sender=ReceptorAddress)
def receptor_address_saved(sender, instance, **kwargs):
from awx.main.signals import disable_activity_stream
@@ -506,16 +504,20 @@ 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:
address.peers_from.add(*control_instances)
if set(address.peers_from.all()) != control_instances:
address.peers_from.add(*control_instances)
schedule_write_receptor_config()
else:
address.peers_from.remove(*control_instances)
schedule_write_receptor_config()
if address.peers_from.exists():
address.peers_from.remove(*control_instances)
schedule_write_receptor_config()
@receiver(post_delete, sender=ReceptorAddress)
def receptor_address_deleted(sender, instance, **kwargs):
schedule_write_receptor_config()
address = instance
if address.peers_from_control_nodes:
schedule_write_receptor_config()
@receiver(post_save, sender=Instance)
@@ -531,10 +533,11 @@ def on_instance_saved(sender, instance, created=False, raw=False, **kwargs):
from awx.main.signals import disable_activity_stream
if created and settings.IS_K8S and instance.node_type in [Instance.Types.CONTROL, Instance.Types.HYBRID]:
peers_address = ReceptorAddress.objects.filter(peers_from_control_nodes=True)
with disable_activity_stream():
instance.peers.add(*peers_address)
schedule_write_receptor_config(broadcast=False)
peers_addresses = ReceptorAddress.objects.filter(peers_from_control_nodes=True)
if peers_addresses.exists():
with disable_activity_stream():
instance.peers.add(*peers_addresses)
schedule_write_receptor_config(broadcast=False)
if settings.IS_K8S and instance.node_type in [Instance.Types.HOP, Instance.Types.EXECUTION]:
if instance.node_state == Instance.States.DEPROVISIONING: