Class: Scooter::HttpDispatchers::PuppetdbDispatcher

Inherits:
HttpDispatcher
  • Object
show all
Includes:
V4
Defined in:
lib/scooter/httpdispatchers/puppetdb/v4/v4.rb,
lib/scooter/httpdispatchers/puppetdbdispatcher.rb

Defined Under Namespace

Modules: V4

Instance Attribute Summary

Attributes inherited from HttpDispatcher

#connection, #faraday_logger, #host, #send_auth_token_as_query_param, #token

Instance Method Summary collapse

Methods included from V4

#query_catalogs, #query_facts, #query_nodes, #query_reports

Methods inherited from HttpDispatcher

#create_default_connection, #initialize, #is_resolvable, #set_url_prefix

Constructor Details

This class inherits a constructor from Scooter::HttpDispatchers::HttpDispatcher

Instance Method Details

#replica_db_synced_with_master_db?(replica_host, agents) ⇒ Boolean

Compares Replica PuppetDB with Master PuppetDB, to make sure Master PuppetDB has synced to Replica PuppetDB.

N.B.: this uses a weird definition of “synced”. We’re NOT making sure the two PuppetDBs are exactly the same. We’re just checking that the replica DB doesn’t contain any records that aren’t also in the master, and that the replica has at least one report from each node. We do this because there’s a race condition-y window where an agent may have delivered a report to the Master PuppetDB, but the Replica PuppetDB hasn’t picked it up yet.

Parameters:

  • replica_host (BeakerHost)
  • agents (Array)

    all the agents in the SUT, in the form of BeakerHost instances

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/scooter/httpdispatchers/puppetdbdispatcher.rb', line 25

def replica_db_synced_with_master_db?(replica_host, agents)
  # Save a beaker host_hash[:vmhostname], set it to the supplied host_name param,
  # and then set it back to the original at the end of the ensure. The :vmhostname
  #overrides the host.hostname, and nothing should win out over it.
  original_host_name = host.host_hash[:vmhostname]
  begin
    host.host_hash[:vmhostname] = replica_host.hostname

    replica_nodes    = query_nodes.body
    replica_catalogs = query_catalogs.body
    replica_facts    = query_facts.body
    replica_reports  = query_reports.body
  ensure
    host.host_hash[:vmhostname] = original_host_name
  end
  master_nodes    = query_nodes.body
  master_catalogs = query_catalogs.body
  master_facts    = query_facts.body
  master_reports  = query_reports.body

  nodes_synced    = nodes_synced?(agents, replica_nodes, master_nodes)
  catalogs_synced = catalogs_synced?(agents, replica_catalogs, master_catalogs)
  facts_synced    = facts_synced?(replica_facts, master_facts)
  reports_synced  = reports_synced?(agents, replica_reports, master_reports)

  errors = ''
  errors << "Nodes not synced\r\n" unless nodes_synced
  errors << "Catalogs not synced\r\n" unless catalogs_synced
  errors << "Facts not synced\r\n" unless facts_synced
  errors << "Reports not synced\r\n" unless reports_synced

  host.logger.warn(errors.chomp) unless errors.empty?
  errors.empty?
end

#set_puppetdb_path(connection = self.connection) ⇒ Object

Sets the path for puppetdb

Parameters:

  • connection (Object) (defaults to: self.connection)
    • the Faraday connection



11
12
13
14
15
# File 'lib/scooter/httpdispatchers/puppetdbdispatcher.rb', line 11

def set_puppetdb_path(connection=self.connection)
  set_url_prefix
  connection.url_prefix.path = '/pdb'
  connection.url_prefix.port = 8081
end