@@ -13,7 +13,7 @@ class Catalog
1313 # Represents a Puppet catalog that is obtained by contacting the Puppet Master.
1414 class PuppetMaster
1515 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
1717
1818 # Defaults
1919 DEFAULT_PUPPET_PORT_NUMBER = 8140
@@ -22,7 +22,7 @@ class PuppetMaster
2222
2323 # Constructor
2424 # @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
2626 # @param :branch [String] Environment to fetch from Puppet Master
2727 # @param :puppet_master [String] Puppet server and port number (assumed to be DEFAULT_PUPPET_PORT_NUMBER if not given)
2828 # @param :puppet_master_api_version [Fixnum] Puppet server API (default DEFAULT_PUPPET_SERVER_API)
@@ -48,6 +48,7 @@ def initialize(options)
4848 @error_message = nil
4949 @retries = nil
5050 @timeout = options . fetch ( :puppet_master_timeout , options . fetch ( :timeout , PUPPET_MASTER_TIMEOUT ) )
51+ @retry_failed_catalog = options . fetch ( :retry_failed_catalog , 0 )
5152
5253 # Cannot convert file resources from this type of catalog right now.
5354 # FIXME: This is possible with additional API calls but is current unimplemented.
@@ -103,13 +104,20 @@ def fetch_catalog(logger)
103104 api = puppet_catalog_api [ api_version ]
104105 raise ArgumentError , "Unsupported or invalid API version #{ api_version } " unless api . is_a? ( Hash )
105106
106- logger . debug "Retrieve catalog from #{ api [ :url ] } environment #{ @options [ :branch ] } "
107-
108107 more_options = { headers : { 'Accept' => 'text/pson' } , timeout : @timeout }
109108 post_hash = api [ :parameters ]
110- response = OctocatalogDiff ::Util ::HTTParty . post ( api [ :url ] , @options . merge ( more_options ) , post_hash , 'puppet_master' )
111109
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
113121
114122 unless response [ :code ] == 200
115123 @error_message = "Failed to retrieve catalog from #{ api [ :url ] } : #{ response [ :code ] } #{ response [ :body ] } "
0 commit comments