@@ -13,7 +13,7 @@ class Catalog
13
13
# Represents a Puppet catalog that is obtained by contacting the Puppet Master.
14
14
class PuppetMaster
15
15
attr_accessor :node
16
- attr_reader :error_message , :catalog , :catalog_json , :convert_file_resources , :options
16
+ attr_reader :error_message , :catalog , :catalog_json , :convert_file_resources , :options , :retries
17
17
18
18
# Defaults
19
19
DEFAULT_PUPPET_PORT_NUMBER = 8140
@@ -22,7 +22,7 @@ class PuppetMaster
22
22
23
23
# Constructor
24
24
# @param :node [String] Node name
25
- # @param :retry [Fixnum] Number of retries, if fetch fails
25
+ # @param :retry_failed_catalog [Fixnum] Number of retries, if fetch fails
26
26
# @param :branch [String] Environment to fetch from Puppet Master
27
27
# @param :puppet_master [String] Puppet server and port number (assumed to be DEFAULT_PUPPET_PORT_NUMBER if not given)
28
28
# @param :puppet_master_api_version [Fixnum] Puppet server API (default DEFAULT_PUPPET_SERVER_API)
@@ -48,6 +48,7 @@ def initialize(options)
48
48
@error_message = nil
49
49
@retries = nil
50
50
@timeout = options . fetch ( :puppet_master_timeout , options . fetch ( :timeout , PUPPET_MASTER_TIMEOUT ) )
51
+ @retry_failed_catalog = options . fetch ( :retry_failed_catalog , 0 )
51
52
52
53
# Cannot convert file resources from this type of catalog right now.
53
54
# FIXME: This is possible with additional API calls but is current unimplemented.
@@ -103,13 +104,20 @@ def fetch_catalog(logger)
103
104
api = puppet_catalog_api [ api_version ]
104
105
raise ArgumentError , "Unsupported or invalid API version #{ api_version } " unless api . is_a? ( Hash )
105
106
106
- logger . debug "Retrieve catalog from #{ api [ :url ] } environment #{ @options [ :branch ] } "
107
-
108
107
more_options = { headers : { 'Accept' => 'text/pson' } , timeout : @timeout }
109
108
post_hash = api [ :parameters ]
110
- response = OctocatalogDiff ::Util ::HTTParty . post ( api [ :url ] , @options . merge ( more_options ) , post_hash , 'puppet_master' )
111
109
112
- logger . debug "Response from #{ api [ :url ] } environment #{ @options [ :branch ] } was #{ response [ :code ] } "
110
+ response = nil
111
+ 0 . upto ( @retry_failed_catalog ) do |retry_num |
112
+ @retries = retry_num
113
+ logger . debug "Retrieve catalog from #{ api [ :url ] } environment #{ @options [ :branch ] } "
114
+
115
+ response = OctocatalogDiff ::Util ::HTTParty . post ( api [ :url ] , @options . merge ( more_options ) , post_hash , 'puppet_master' )
116
+
117
+ logger . debug "Response from #{ api [ :url ] } environment #{ @options [ :branch ] } was #{ response [ :code ] } "
118
+
119
+ break if response [ :code ] == 200
120
+ end
113
121
114
122
unless response [ :code ] == 200
115
123
@error_message = "Failed to retrieve catalog from #{ api [ :url ] } : #{ response [ :code ] } #{ response [ :body ] } "
0 commit comments