Module: CemAcpt::Goss::Api

Extended by:
Logging
Defined in:
lib/cem_acpt/goss/api.rb,
lib/cem_acpt/goss/api/action_response.rb

Overview

Holds methods for interacting with the Goss API running on a test node.

Defined Under Namespace

Modules: DurationHandler Classes: ActionResponse, ActionResponseResult, ActionResponseSummary

Constant Summary collapse

ACTIONS =

The actions that can be run against the Goss API. The key is the action name and the value is the port/endpoint of the action.

{
  acpt: '8080/acpt',
  idempotent: '8081/idempotent',
  noop: '8082/noop',
}.freeze

Constants included from Logging

Logging::LEVEL_MAP

Class Method Summary collapse

Methods included from Logging

current_log_config, current_log_config, current_log_format, current_log_format, current_log_level, current_log_level, included, logger, logger, new_log_config, new_log_config, new_log_formatter, new_log_formatter, new_log_level, new_log_level, new_logger, new_logger, verbose?, verbose?

Class Method Details

.action_uri(host, action) ⇒ URI

Create a URI for the specified action against the specified host.

Parameters:

  • host (String)

    The host to run the action against. This should be a public IP address or a DNS-resolvable name.

  • action (Symbol)

    The action to run.

Returns:

  • (URI)

    The URI for the action.



27
28
29
# File 'lib/cem_acpt/goss/api.rb', line 27

def action_uri(host, action)
  URI("http://#{host}:#{ACTIONS[action.to_sym]}")
end

.get(uri, internet = nil) ⇒ Array

Get the JSON response from the specified URI.

Parameters:

  • uri (URI)

    The URI to get the JSON response from.

  • internet (nil, Async::HTTP::Internet) (defaults to: nil)

    The object to use for the request. If nil, Net::HTTP will be used.

Returns:

  • (Array)

    The status code and the parsed JSON response body.



36
37
38
39
40
41
42
43
44
45
# File 'lib/cem_acpt/goss/api.rb', line 36

def get(uri, internet = nil)
  if internet.nil?
    require 'net/http'
    response = Net::HTTP.get_response(uri)
    [response.code, JSON.parse(response.body)]
  else
    response = internet.get(uri.to_s)
    [response.status, JSON.parse(response.read)]
  end
end

.get_run_logs(host, internet = nil) ⇒ Object



59
60
61
62
# File 'lib/cem_acpt/goss/api.rb', line 59

def get_run_logs(host, internet = nil)
  status_code, body = get(URI("http://#{host}:8083/run-logs"), internet)
  ActionResponse.new(host, :run_logs, status_code, body)
end

.run_action(host, action, internet = nil) ⇒ ActionResponse

Run the specified action against the specified host.

Parameters:

  • host (String)

    The host to run the action against. This should be a public IP address or a DNS-resolvable name.

  • action (Symbol)

    The action to run.

  • internet (nil, Async::HTTP::Internet) (defaults to: nil)

    The object to use for the request.

Returns:



53
54
55
56
57
# File 'lib/cem_acpt/goss/api.rb', line 53

def run_action(host, action, internet = nil)
  uri = action_uri(host, action)
  status_code, body = get(uri, internet)
  ActionResponse.new(host, action, status_code, body)
end