acceptance/lib/pxp-agent/bolt_pxp_module_helper.rb
# Make an RPC request to execute a module action and run a callback on the resulting data
#
# @param broker [String|Beaker::Host] Hostname or beaker host object of the PCP broker machine
# @param target_identities [Array<String>] PXP agent identity strings on which to perform the action
# @param module_name [String] The name of the pxp module that contains the action to perform
# @param action_name [String] The name of the action to perform
# @param params [Hash<String,String>] Parameters to pass to the module action when running it
# @param expected_response_type [String] The type of response expected from the action
# @param blocking_request [Boolean] Whether to issue a blocking request (the default is a non-blocking request)
# @yield [Array<Hash<String,String>>] Yields an array of response hashes:
# For a successful response:
#   ["<agent-pcp-identity-string>" => {
#        "transaction_id" => "<uuid>"
#   }]
# When there's been an RPC error, the result is different:
#   ["<agent-pcp-identity-string>" =>  {
#        "data" => {
#            "description" => "<error-message>",
#            "id" => "<uuid>",
#            "transaction_id" => "<uuid>"
#         },
#        "envelope" => {
#            "expires" => "<date-string>",
#            "id" => "<uuid>",
#            "message_type" => "http://puppetlabs.com/<message-type>",
#            "sender" => "<broker-pcp-identity-string>",
#            "targets" => ["<agent-pcp-identity-string", ...]
#         }
#   }]
Make an RPC request to execute a module action and run a callback on the resulting data
Make an RPC request to execute a module action and run a callback on the resulting data
def do_module_action(broker, target_identities, module_name, action_name, params,
                     blocking_request: false,
                     expected_response_type: 'http://puppetlabs.com/rpc_provisional_response')
  responses =
    begin
      rpc_request = blocking_request ? method(:rpc_blocking_request) : method(:rpc_non_blocking_request)
      rpc_request.call(broker, target_identities, module_name, action_name, params)
    rescue => exception
      fail("Exception occurred when trying to execute '#{module_name}' pxp module's '#{action_name}' action on all agents: #{exception.message}")
    end
  response_dataset = target_identities.map do |identity|
    assert_equal(expected_response_type,
                 responses[identity][:envelope][:message_type],
                 "Did not receive expected rpc_response in reply to RPC request")
    responses[identity][:data]
  end
  yield(response_dataset) if block_given?
end
def do_module_action ( broker , target_identities , module_name , action_name , params , blocking_request : false , expected_response_type : 'http://puppetlabs.com/rpc_provisional_response' ) responses = begin rpc_request = blocking_request ? method ( :rpc_blocking_request ) : method ( :rpc_non_blocking_request ) rpc_request . call ( broker , target_identities , module_name , action_name , params ) rescue => exception fail ( "Exception occurred when trying to execute '#{module_name}' pxp module's '#{action_name}' action on all agents: #{exception.message}" ) end response_dataset = target_identities . map do | identity | assert_equal ( expected_response_type , responses [ identity ] [ :envelope ] [ :message_type ] , "Did not receive expected rpc_response in reply to RPC request" ) responses [ identity ] [ :data ] end yield ( response_dataset ) if block_given? end
Make an RPC request to execute a module action and run a callback on the resulting data
Make an RPC request to execute a module action and run a callback on the resulting data
broker
Hostname or beaker host object of the PCP broker machine
Hostname or beaker host object of the PCP broker machine
target_identities
PXP agent identity strings on which to perform the action
PXP agent identity strings on which to perform the action
module_name
The name of the pxp module that contains the action to perform
The name of the pxp module that contains the action to perform
action_name
The name of the action to perform
The name of the action to perform
params
Parameters to pass to the module action when running it
Parameters to pass to the module action when running it
blocking_request
Whether to issue a blocking request (the default is a non-blocking request)
Whether to issue a blocking request ( the default is a non - blocking request )
expected_response_type
The type of response expected from the action
The type of response expected from the action
]
<not_specific>
None