mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 19:30:39 -03:30
Peers_from_control_nodes requires listener port
Adds validation and a unit test to ensure: - peers_from_control_nodes=True should fail if listener_port is not set - peers_from_control_nodes=False should be NOOP if listener_port is not set Signed-off-by: Seth Foster <fosterbseth@gmail.com>
This commit is contained in:
parent
a4cf55bdba
commit
1b44bebed3
@ -5708,6 +5708,11 @@ class InstanceSerializer(BaseSerializer):
|
||||
if len(set(peers_instances)) != len(peers_instances):
|
||||
raise serializers.ValidationError(_("Cannot peer to the same instance more than once."))
|
||||
|
||||
# cannot enable peers_from_control_nodes if listener_port is not set
|
||||
if attrs.get('peers_from_control_nodes'):
|
||||
if not attrs.get('listener_port') and self.instance and self.instance.canonical_address_port is None:
|
||||
raise serializers.ValidationError(_("Cannot enable peers_from_control_nodes if listener_port is not set."))
|
||||
|
||||
return super().validate(attrs)
|
||||
|
||||
def validate_node_type(self, value):
|
||||
|
||||
@ -136,17 +136,24 @@ class TestPeers:
|
||||
|
||||
def test_peers_from_control_nodes_without_listener_port(self, admin_user, patch):
|
||||
"""
|
||||
patching with peers_from_control_nodes should not create a receptor address
|
||||
if port is not defined
|
||||
patching with peers_from_control_nodes=True should fail if listener_port is not set
|
||||
patching with peers_from_control_nodes=False should be NOOP if listener_port is not set
|
||||
"""
|
||||
hop = Instance.objects.create(hostname='abc', node_type="hop")
|
||||
patch(
|
||||
resp = patch(
|
||||
url=reverse('api:instance_detail', kwargs={'pk': hop.pk}),
|
||||
data={"peers_from_control_nodes": True},
|
||||
user=admin_user,
|
||||
expect=400,
|
||||
)
|
||||
assert 'Cannot enable peers_from_control_nodes if listener_port is not set' in str(resp.data)
|
||||
patch(
|
||||
url=reverse('api:instance_detail', kwargs={'pk': hop.pk}),
|
||||
data={"peers_from_control_nodes": False},
|
||||
user=admin_user,
|
||||
expect=200,
|
||||
)
|
||||
assert not ReceptorAddress.objects.filter(instance=hop).exists()
|
||||
assert not ReceptorAddress.objects.filter(instance=hop, peers_from_control_nodes=False).exists()
|
||||
|
||||
def test_bidirectional_peering(self, admin_user, patch):
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user