Skip to content

Commit 2304236

Browse files
authored
Merge pull request #82 from github/kpaulisse-puppet-master-timeout
Command line option for Puppet Master timeout
2 parents 77e8148 + 1a0e387 commit 2304236

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

doc/optionsref.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ Usage: octocatalog-diff [command line options]
124124
Override parameter from ENC for the to branch
125125
--from-enc-override STRING1[,STRING2[,...]]
126126
Override parameter from ENC for the from branch
127+
--puppet-master-timeout STRING
128+
Puppet Master catalog retrieval timeout in seconds globally
129+
--to-puppet-master-timeout STRING
130+
Puppet Master catalog retrieval timeout in seconds for the to branch
131+
--from-puppet-master-timeout STRING
132+
Puppet Master catalog retrieval timeout in seconds for the from branch
127133
--pe-enc-url URL Base URL for Puppet Enterprise ENC endpoint
128134
--pe-enc-token TOKEN Token to access the Puppet Enterprise ENC API
129135
--pe-enc-token-file PATH Path containing token for PE node classifier, relative or absolute

lib/octocatalog-diff/catalog/puppetmaster.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def initialize(options)
4747
@catalog = nil
4848
@error_message = nil
4949
@retries = nil
50-
@timeout = options.fetch(:timeout, PUPPET_MASTER_TIMEOUT)
50+
@timeout = options.fetch(:puppet_master_timeout, options.fetch(:timeout, PUPPET_MASTER_TIMEOUT))
5151

5252
# Cannot convert file resources from this type of catalog right now.
5353
# FIXME: This is possible with additional API calls but is current unimplemented.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
# Specify a timeout for retrieving a catalog from a Puppet master / Puppet server.
4+
# This timeout is specified in seconds.
5+
# @param parser [OptionParser object] The OptionParser argument
6+
# @param options [Hash] Options hash being constructed; this is modified in this method.
7+
OctocatalogDiff::Cli::Options::Option.newoption(:puppet_master_timeout) do
8+
has_weight 329
9+
10+
def parse(parser, options)
11+
OctocatalogDiff::Cli::Options.option_globally_or_per_branch(
12+
parser: parser,
13+
options: options,
14+
cli_name: 'puppet-master-timeout',
15+
option_name: 'puppet_master_timeout',
16+
desc: 'Puppet Master catalog retrieval timeout in seconds',
17+
validator: ->(x) { x.to_i > 0 || raise(ArgumentError, 'Specify timeout as a integer greater than 0') },
18+
translator: ->(x) { x.to_i }
19+
)
20+
end
21+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../options_helper'
4+
5+
describe OctocatalogDiff::Cli::Options do
6+
describe '#opt_puppet_master_timeout' do
7+
it 'should handle --puppet-master-timeout with timeout as a string' do
8+
result = run_optparse(['--puppet-master-timeout', '20'])
9+
expect(result[:to_puppet_master_timeout]).to eq(20)
10+
expect(result[:from_puppet_master_timeout]).to eq(20)
11+
end
12+
13+
it 'should raise error if --puppet-master-timeout == 0' do
14+
expect do
15+
run_optparse(['--puppet-master-timeout', '0'])
16+
end.to raise_error(ArgumentError, 'Specify timeout as a integer greater than 0')
17+
end
18+
19+
it 'should raise error if --puppet-master-timeout evaluates to 0' do
20+
expect do
21+
run_optparse(['--puppet-master-timeout', 'chickens'])
22+
end.to raise_error(ArgumentError, 'Specify timeout as a integer greater than 0')
23+
end
24+
25+
it 'should handle --to-puppet-master-timeout' do
26+
result = run_optparse(['--to-puppet-master-timeout', '3'])
27+
expect(result[:to_puppet_master_timeout]).to eq(3)
28+
end
29+
30+
it 'should handle --from-puppet-master-timeout' do
31+
result = run_optparse(['--from-puppet-master-timeout', '3'])
32+
expect(result[:from_puppet_master_timeout]).to eq(3)
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)