Skip to content

Commit 139d85f

Browse files
committed
Rename nats-servers to choria-brokers with port defaulting
Rename nats-servers and nats-connection-timeout to match Choria's user-facing terminology. CLI flags become --choria-brokers and --choria-broker-timeout. Internal transport config keys use the bare forms (brokers, broker-timeout) consistent with all other choria options. The CLI parser splits comma-separated broker lists into arrays, matching the --targets pattern. When a broker address omits the port, default to 4222. Also replace [x].flatten with Array(x) in client.rb for clarity, and add CLI parser tests for the new choria flags. Signed-off-by: nmburgan <13688219+nmburgan@users.noreply.github.com>
1 parent 113dd67 commit 139d85f

10 files changed

Lines changed: 163 additions & 99 deletions

File tree

documentation/choria-transport.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ targets:
5151
config:
5252
choria:
5353
collective: production
54-
nats-servers:
54+
brokers:
5555
- broker1:4222
5656
- broker2:4222
5757
```
@@ -96,8 +96,8 @@ targets:
9696
| `host` | | String | (from URI) | Target's Choria identity (FQDN). Overrides the hostname from the URI. |
9797
| `interpreters` | | Hash | (none) | File extension to interpreter mapping (e.g., `{".rb": "/usr/bin/ruby"}`). |
9898
| `mcollective-certname` | `--choria-mcollective-certname` | String | (auto) | Override the MCollective certname for Choria client identity. See [Non-root certname](#non-root-certname) below. |
99-
| `nats-connection-timeout` | `--nats-connection-timeout` | Integer | `30` | Seconds to wait for the TCP connection to the NATS broker. |
100-
| `nats-servers` | `--nats-servers` | String or Array | (from config file) | NATS broker addresses in `host:port` format (comma-separated for multiple). Do not use the `nats://` prefix. Multiple servers provide failover if a broker is unavailable. Overrides the config file. |
99+
| `broker-timeout` | `--choria-broker-timeout` | Integer | `30` | Seconds to wait for the TCP connection to a Choria broker. |
100+
| `brokers` | `--choria-brokers` | String or Array | (auto-discovered) | Choria broker addresses in `host` or `host:port` format (comma-separated for multiple). Port defaults to 4222 if omitted. Do not use the `nats://` prefix. When not provided, the Choria client checks the config file, then SRV records, then falls back to `puppet:4222`. Multiple servers provide failover. |
101101
| `puppet-environment` | `--choria-puppet-environment` | String | `production` | Puppet environment for bolt_tasks file URIs. |
102102
| `rpc-timeout` | `--choria-rpc-timeout` | Integer | `30` | Seconds to wait for replies to individual RPC calls. |
103103
| `ssl-ca` | `--choria-ssl-ca` | String | (from config file) | CA certificate path for TLS. |
@@ -114,14 +114,14 @@ wins. For ad-hoc targets specified via `--targets` that aren't defined in an
114114
inventory file, CLI flags take full effect.
115115

116116
For options that have corresponding values in the Choria config file
117-
(`nats-servers`, `ssl-ca`/`ssl-cert`/`ssl-key`, and `collective`), the full
117+
(`brokers`, `ssl-ca`/`ssl-cert`/`ssl-key`, and `collective`), the full
118118
precedence from lowest to highest is: Choria config file < CLI flags <
119119
inventory. All other options use OpenBolt-level defaults and are not affected by
120120
the Choria config file.
121121

122122
**Timeout hierarchy:** Three levels of timeout control different things:
123-
- `nats-connection-timeout` (30s): How long to wait for the initial TCP
124-
connection to the NATS broker
123+
- `broker-timeout` (30s): How long to wait for the initial TCP
124+
connection to a Choria broker
125125
- `rpc-timeout` (30s): How long to wait for replies to each individual RPC
126126
call (discovery, status checks, etc.)
127127
- `command-timeout` (60s) / `task-timeout` (300s): How long to wait for the

lib/bolt/bolt_option_parser.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class BoltOptionParser < OptionParser
1616
choria: %w[choria-config-file choria-mcollective-certname
1717
choria-ssl-ca choria-ssl-cert choria-ssl-key
1818
choria-collective choria-puppet-environment choria-rpc-timeout
19-
choria-task-timeout choria-command-timeout nats-servers
20-
nats-connection-timeout],
19+
choria-task-timeout choria-command-timeout choria-brokers
20+
choria-broker-timeout],
2121
display: %w[format color verbose trace stream],
2222
global: %w[help version log-level clear-cache] }.freeze
2323

@@ -1149,13 +1149,13 @@ def initialize(options)
11491149
'Seconds to wait for commands and scripts to complete (default: 60).') do |timeout|
11501150
@options[:'command-timeout'] = timeout
11511151
end
1152-
define('--nats-servers SERVERS',
1153-
'NATS broker addresses in host:port format (comma-separated for multiple). Do not use the nats:// prefix.') do |servers|
1154-
@options[:'nats-servers'] = servers
1152+
define('--choria-brokers BROKERS',
1153+
'Choria broker addresses in host or host:port format (comma-separated). Port defaults to 4222 if omitted.') do |brokers|
1154+
@options[:brokers] = brokers.split(',')
11551155
end
1156-
define('--nats-connection-timeout SECONDS', Integer,
1157-
'Seconds to wait for the TCP connection to the NATS broker (default: 30).') do |timeout|
1158-
@options[:'nats-connection-timeout'] = timeout
1156+
define('--choria-broker-timeout SECONDS', Integer,
1157+
'Seconds to wait for the TCP connection to a Choria broker (default: 30).') do |timeout|
1158+
@options[:'broker-timeout'] = timeout
11591159
end
11601160

11611161
separator "\n#{self.class.colorize(:cyan, 'Module options')}"

lib/bolt/config/transport/choria.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class Choria < Base
1515
host
1616
interpreters
1717
mcollective-certname
18-
nats-connection-timeout
19-
nats-servers
18+
broker-timeout
19+
brokers
2020
puppet-environment
2121
rpc-timeout
2222
ssl-ca
@@ -30,7 +30,7 @@ class Choria < Base
3030
DEFAULTS = {
3131
'cleanup' => true,
3232
'command-timeout' => 60,
33-
'nats-connection-timeout' => 30,
33+
'broker-timeout' => 30,
3434
'puppet-environment' => 'production',
3535
'rpc-timeout' => 30,
3636
'task-timeout' => 300,

lib/bolt/config/transport/options.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ module Options
8181
_plugin: true,
8282
_example: "/etc/choria/client.conf"
8383
},
84-
"nats-connection-timeout" => {
84+
"broker-timeout" => {
8585
type: Integer,
86-
description: "How long to wait in seconds for the initial TCP connection to the NATS broker. " \
86+
description: "How long to wait in seconds for the initial TCP connection to a Choria broker. " \
8787
"If the connection cannot be made within this time, the operation fails.",
8888
minimum: 1,
8989
_plugin: true,
@@ -284,11 +284,12 @@ module Options
284284
_plugin: true,
285285
_example: "primary.example.com"
286286
},
287-
"nats-servers" => {
287+
"brokers" => {
288288
type: [String, Array],
289-
description: "One or more NATS server addresses in host:port format for the Choria transport. " \
290-
"Do not use the nats:// prefix. Overrides the middleware hosts from the Choria " \
291-
"client configuration file. Can be a single string or an array.",
289+
description: "One or more Choria broker addresses in host or host:port format. " \
290+
"Port defaults to 4222 if omitted. Do not use the nats:// prefix. " \
291+
"Overrides the middleware hosts from the Choria client configuration file. " \
292+
"Can be a single string or an array.",
292293
items: {
293294
type: String
294295
},

lib/bolt/transport/choria/client.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def configure_client(target)
7373
logger.debug { "MCOLLECTIVE_CERTNAME set to #{opts['mcollective-certname']}" }
7474
end
7575

76-
if opts['nats-servers']
77-
servers = [opts['nats-servers']].flatten
78-
config.pluginconf['choria.middleware_hosts'] = servers.join(',')
79-
logger.debug { "NATS servers overridden: #{servers.join(', ')}" }
76+
if opts['brokers']
77+
brokers = Array(opts['brokers']).map { |broker| broker.include?(':') ? broker : "#{broker}:4222" }
78+
config.pluginconf['choria.middleware_hosts'] = brokers.join(',')
79+
logger.debug { "Choria brokers overridden: #{brokers.join(', ')}" }
8080
end
8181

8282
if opts['ssl-ca'] && opts['ssl-cert'] && opts['ssl-key']
@@ -117,11 +117,11 @@ def configure_client(target)
117117
# @param timeout [Numeric] RPC call timeout in seconds
118118
# @return [MCollective::RPC::Client] Configured client with direct addressing enabled
119119
def create_rpc_client(agent_name, targets, timeout)
120-
targets = [targets].flatten
120+
targets = Array(targets)
121121
options = MCollective::Util.default_options
122122
options[:timeout] = timeout
123123
options[:verbose] = false
124-
options[:connection_timeout] = targets.first.options['nats-connection-timeout']
124+
options[:connection_timeout] = targets.first.options['broker-timeout']
125125

126126
collective = collective_for(targets.first)
127127
options[:collective] = collective if collective
@@ -169,7 +169,7 @@ def create_rpc_client(agent_name, targets, timeout)
169169
# Includes all targets that responded (both :responded and :errors).
170170
# Not populated when rpc_failed is true (no individual responses).
171171
def rpc_request(agent, targets, context)
172-
targets = [targets].flatten
172+
targets = Array(targets)
173173
rpc_results = @rpc_mutex.synchronize do
174174
rpc_timeout = targets.first.options['rpc-timeout']
175175
client = create_rpc_client(agent, targets, rpc_timeout)

schemas/bolt-defaults.schema.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -518,90 +518,90 @@
518518
{
519519
"type": "object",
520520
"properties": {
521-
"cleanup": {
521+
"broker-timeout": {
522522
"oneOf": [
523523
{
524-
"$ref": "#/transport_definitions/cleanup"
524+
"$ref": "#/transport_definitions/broker-timeout"
525525
},
526526
{
527527
"$ref": "#/definitions/_plugin"
528528
}
529529
]
530530
},
531-
"collective": {
531+
"brokers": {
532532
"oneOf": [
533533
{
534-
"$ref": "#/transport_definitions/collective"
534+
"$ref": "#/transport_definitions/brokers"
535535
},
536536
{
537537
"$ref": "#/definitions/_plugin"
538538
}
539539
]
540540
},
541-
"command-timeout": {
541+
"cleanup": {
542542
"oneOf": [
543543
{
544-
"$ref": "#/transport_definitions/command-timeout"
544+
"$ref": "#/transport_definitions/cleanup"
545545
},
546546
{
547547
"$ref": "#/definitions/_plugin"
548548
}
549549
]
550550
},
551-
"config-file": {
551+
"collective": {
552552
"oneOf": [
553553
{
554-
"$ref": "#/transport_definitions/config-file"
554+
"$ref": "#/transport_definitions/collective"
555555
},
556556
{
557557
"$ref": "#/definitions/_plugin"
558558
}
559559
]
560560
},
561-
"host": {
561+
"command-timeout": {
562562
"oneOf": [
563563
{
564-
"$ref": "#/transport_definitions/host"
564+
"$ref": "#/transport_definitions/command-timeout"
565565
},
566566
{
567567
"$ref": "#/definitions/_plugin"
568568
}
569569
]
570570
},
571-
"interpreters": {
571+
"config-file": {
572572
"oneOf": [
573573
{
574-
"$ref": "#/transport_definitions/interpreters"
574+
"$ref": "#/transport_definitions/config-file"
575575
},
576576
{
577577
"$ref": "#/definitions/_plugin"
578578
}
579579
]
580580
},
581-
"mcollective-certname": {
581+
"host": {
582582
"oneOf": [
583583
{
584-
"$ref": "#/transport_definitions/mcollective-certname"
584+
"$ref": "#/transport_definitions/host"
585585
},
586586
{
587587
"$ref": "#/definitions/_plugin"
588588
}
589589
]
590590
},
591-
"nats-connection-timeout": {
591+
"interpreters": {
592592
"oneOf": [
593593
{
594-
"$ref": "#/transport_definitions/nats-connection-timeout"
594+
"$ref": "#/transport_definitions/interpreters"
595595
},
596596
{
597597
"$ref": "#/definitions/_plugin"
598598
}
599599
]
600600
},
601-
"nats-servers": {
601+
"mcollective-certname": {
602602
"oneOf": [
603603
{
604-
"$ref": "#/transport_definitions/nats-servers"
604+
"$ref": "#/transport_definitions/mcollective-certname"
605605
},
606606
{
607607
"$ref": "#/definitions/_plugin"
@@ -1862,8 +1862,8 @@
18621862
}
18631863
]
18641864
},
1865-
"nats-connection-timeout": {
1866-
"description": "How long to wait in seconds for the initial TCP connection to the NATS broker. If the connection cannot be made within this time, the operation fails.",
1865+
"broker-timeout": {
1866+
"description": "How long to wait in seconds for the initial TCP connection to a Choria broker. If the connection cannot be made within this time, the operation fails.",
18671867
"oneOf": [
18681868
{
18691869
"type": "integer",
@@ -2166,8 +2166,8 @@
21662166
}
21672167
]
21682168
},
2169-
"nats-servers": {
2170-
"description": "One or more NATS server addresses in host:port format for the Choria transport. Do not use the nats:// prefix. Overrides the middleware hosts from the Choria client configuration file. Can be a single string or an array.",
2169+
"brokers": {
2170+
"description": "One or more Choria broker addresses in host or host:port format. Port defaults to 4222 if omitted. Do not use the nats:// prefix. Overrides the middleware hosts from the Choria client configuration file. Can be a single string or an array.",
21712171
"oneOf": [
21722172
{
21732173
"type": [

schemas/bolt-inventory.schema.json

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,42 @@
6363
{
6464
"type": "object",
6565
"properties": {
66+
"broker-timeout": {
67+
"description": "How long to wait in seconds for the initial TCP connection to a Choria broker. If the connection cannot be made within this time, the operation fails.",
68+
"oneOf": [
69+
{
70+
"type": "integer",
71+
"minimum": 1
72+
},
73+
{
74+
"$ref": "#/definitions/_plugin"
75+
}
76+
]
77+
},
78+
"brokers": {
79+
"description": "One or more Choria broker addresses in host or host:port format. Port defaults to 4222 if omitted. Do not use the nats:// prefix. Overrides the middleware hosts from the Choria client configuration file. Can be a single string or an array.",
80+
"oneOf": [
81+
{
82+
"type": [
83+
"string",
84+
"array"
85+
],
86+
"items": {
87+
"oneOf": [
88+
{
89+
"type": "string"
90+
},
91+
{
92+
"$ref": "#/definitions/_plugin"
93+
}
94+
]
95+
}
96+
},
97+
{
98+
"$ref": "#/definitions/_plugin"
99+
}
100+
]
101+
},
66102
"cleanup": {
67103
"description": "Whether to clean up temporary files created on targets. When running commands on a target, Bolt might create temporary files. After completing the command, these files are automatically deleted. This value can be set to 'false' if you wish to leave these temporary files on the target.",
68104
"oneOf": [
@@ -150,42 +186,6 @@
150186
}
151187
]
152188
},
153-
"nats-connection-timeout": {
154-
"description": "How long to wait in seconds for the initial TCP connection to the NATS broker. If the connection cannot be made within this time, the operation fails.",
155-
"oneOf": [
156-
{
157-
"type": "integer",
158-
"minimum": 1
159-
},
160-
{
161-
"$ref": "#/definitions/_plugin"
162-
}
163-
]
164-
},
165-
"nats-servers": {
166-
"description": "One or more NATS server addresses in host:port format for the Choria transport. Do not use the nats:// prefix. Overrides the middleware hosts from the Choria client configuration file. Can be a single string or an array.",
167-
"oneOf": [
168-
{
169-
"type": [
170-
"string",
171-
"array"
172-
],
173-
"items": {
174-
"oneOf": [
175-
{
176-
"type": "string"
177-
},
178-
{
179-
"$ref": "#/definitions/_plugin"
180-
}
181-
]
182-
}
183-
},
184-
{
185-
"$ref": "#/definitions/_plugin"
186-
}
187-
]
188-
},
189189
"puppet-environment": {
190190
"description": "The Puppet environment to use when constructing task file URIs for the Choria bolt_tasks agent.",
191191
"oneOf": [

0 commit comments

Comments
 (0)