Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional listener port UI #14300

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5501,8 +5501,12 @@ def get_field_from_model_or_attrs(fd):
_("Setting peers manually for control nodes is not allowed. Enable peers_from_control_nodes on the hop and execution nodes instead.")
)

if peers_from_control_nodes and listener_port is None:
if not listener_port and peers_from_control_nodes:
raise serializers.ValidationError(_("Field listener_port must be a valid integer when peers_from_control_nodes is enabled."))

if not listener_port and self.instance and self.instance.peers_from.exists():
raise serializers.ValidationError(_("Field listener_port must be a valid integer when other nodes peer to it."))

for peer in attrs.get('peers', []):
if peer.listener_port is None:
raise serializers.ValidationError(_("Field listener_port must be set on peer ") + peer.hostname + ".")
Expand Down Expand Up @@ -5544,7 +5548,10 @@ def validate_hostname(self, value):
return value

def validate_listener_port(self, value):
if self.instance and self.instance.listener_port != value:
"""
Cannot change listener port, unless going from none to integer, and vice versa
"""
if value and self.instance and self.instance.listener_port and self.instance.listener_port != value:
raise serializers.ValidationError(_("Cannot change listener port."))

return value
Expand Down
10 changes: 5 additions & 5 deletions awx/main/models/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,14 @@ def on_instance_saved(sender, instance, created=False, raw=False, **kwargs):
# node and kick off write_receptor_config
connection.on_commit(lambda: remove_deprovisioned_node.apply_async([instance.hostname]))
else:
control_instances = set(Instance.objects.filter(node_type__in=[Instance.Types.CONTROL, Instance.Types.HYBRID]))
if instance.peers_from_control_nodes:
control_instances = Instance.objects.filter(node_type__in=[Instance.Types.CONTROL, Instance.Types.HYBRID])
if set(instance.peers_from.all()) != control_instances:
instance.peers_from.set(control_instances)
if (control_instances & set(instance.peers_from.all())) != set(control_instances):
instance.peers_from.add(*control_instances)
schedule_write_receptor_config() # keep method separate to make pytest mocking easier
else:
if instance.peers_from.exists():
instance.peers_from.clear()
if set(control_instances) & set(instance.peers_from.all()):
instance.peers_from.remove(*control_instances)
schedule_write_receptor_config()

if created or instance.has_policy_changes():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function InstanceDetail({ setBreadcrumb, isK8s }) {
<Detail label={t`Instance Port`} value={instance.listener_port} />
{(isExecutionNode || isHopNode) && (
<Detail
label={t`Connection to control nodes`}
label={t`Peers from control nodes`}
value={instance.peers_from_control_nodes ? t`On` : t`Off`}
/>
)}
Expand Down
14 changes: 6 additions & 8 deletions awx/ui/src/screens/Instances/Shared/InstanceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function InstanceFormFields({ isEdit }) {
label={t`Listener Port`}
name="listener_port"
type="number"
tooltip={t`Select the port that Receptor will listen on for incoming connections. Default is 27199.`}
isRequired
tooltip={t`Select the port that Receptor will listen on for incoming connections, e.g. 27199.`}
/>
<FormGroup
fieldId="instance-type"
Expand Down Expand Up @@ -122,8 +121,8 @@ function InstanceFormFields({ isEdit }) {
<CheckboxField
id="peers_from_control_nodes"
name="peers_from_control_nodes"
label={t`Connect to control nodes`}
tooltip={t`Connect this instance to control nodes. If disabled, instance will be connected only to peers selected.`}
label={t`Peers from control nodes`}
tooltip={t`If enabled, control nodes will peer to this instance automatically. If disabled, instance will be connected only to associated peers.`}
/>
</FormGroup>
</>
Expand All @@ -146,17 +145,16 @@ function InstanceForm({
description: instance.description || '',
node_type: instance.node_type || 'execution',
node_state: instance.node_state || 'installed',
listener_port: instance.listener_port || 27199,
listener_port: instance.listener_port,
enabled: instance.enabled || true,
managed_by_policy: instance.managed_by_policy || true,
peers_from_control_nodes: instance.peers_from_control_nodes
? true
: !isEdit,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why we had this conditional. I just want a default value of False

peers_from_control_nodes: instance.peers_from_control_nodes || false,
peers: instance_peers,
}}
onSubmit={(values) => {
handleSubmit({
...values,
listener_port: values.listener_port === '' ? null : values.listener_port,
peers: values.peers.map((peer) => peer.hostname || peer),
});
}}
Expand Down
Loading