Commit e6655c48 authored by Nate Wolfe's avatar Nate Wolfe Committed by Chris Price

(PE-949) Store transaction uuid

parent 5f259cd0
require 'json'
test_name "validate matching transaction UUIDs in agent report and catalog" do
# TODO: the module should be setting up the report processors so that we don't have to add it on the CLI here
with_puppet_running_on master, {
'master' => {
'storeconfigs' => 'true',
'store_configs_backend' => 'puppetdb',
'autosign' => 'true',
}} do
step "Run agents once to submit reports" do
run_agent_on agents, "--test --server #{master}", :acceptable_exit_codes => [0,2]
end
end
# Wait until all the commands have been processed
sleep_until_queue_empty database
agents.each do |agent|
# Query for all of the reports for this node, but we only care about the most recent one
result = on database, %Q|curl -G http://localhost:8080/experimental/reports --data 'query=["=",%20"certname",%20"#{agent.node_name}"]'|
report = JSON.parse(result.stdout)[0]
# Query for the most recent catalog for this node
result = on database, %Q|curl -G http://localhost:8080/experimental/catalog/#{agent.node_name}|
catalog = JSON.parse(result.stdout)
report_uuid = report['transaction-uuid']
catalog_uuid = catalog['data']['transaction_uuid']
report_format = report['report-format']
if report_format < 4
assert_equal(nil, report_uuid, 'Transaction UUID should be nil in reports before format 4')
assert_equal(nil, catalog_uuid, 'Transaction UUID should be nil in catalogs before format 4')
else
assert_equal(report_uuid, catalog_uuid, 'Most recent report & catalog should have the same transaction UUID')
end
end
end
......@@ -54,7 +54,8 @@ the completion time of the report, in descending order:
"start-time": "2012-10-29T18:38:00.000Z",
"hash": "bd899b1ee825ec1d2c671fe5541b5c8f4a783472",
"certname": "foo.local",
"report-format": 3
"report-format": 3,
"transaction-uuid": "030c1717-f175-4644-b048-ac9ea328f221"
},
{
"end-time": "2012-10-26T22:39:32.000Z",
......@@ -64,7 +65,8 @@ the completion time of the report, in descending order:
"start-time": "2012-10-26T22:39:31.000Z",
"hash": "cd4e5fd8846bac26d15d151664a40e0f2fa600b0",
"certname": "foo.local",
"report-format": 3
"report-format": 3,
"transaction-uuid": null
}
]
......
......@@ -44,6 +44,7 @@ A catalog is a JSON object with two keys: `"metadata"` and `"data"`. [Version 2
"data": {
"name": <string>,
"version": <string>,
"transaction-uuid": <string>,
"edges":
[<edge>, <edge>, ...],
"resources":
......@@ -53,18 +54,18 @@ A catalog is a JSON object with two keys: `"metadata"` and `"data"`. [Version 2
The value of the `"metadata"` key must be `{ "api_version": 1 }` --- no other value is valid for this version of the format.
The value of the `"data"` key must be a JSON object with four keys: `"name"`, `"version"`, `"edges"`, and `"resources"`. Each of the keys is mandatory, although values that are lists may be empty lists. The value of each key in the data object is as follows:
The value of the `"data"` key must be a JSON object with five keys: `"name"`, `"version"`, `transaction-uuid`, `"edges"`, and `"resources"`.
Each of the keys is mandatory unless otherwise noted, although values that are lists may be empty lists.
`"name"`
The value of each key in the data object is as follows:
`"name"`
: String. The name of the node for which the catalog was compiled.
`"version"`
: String. An arbitrary string that uniquely identifies this specific catalog across time for a single node. This is controlled by Puppet's [`config_version` setting](/references/latest/configuration.html#configversion) and is usually the seconds elapsed since the epoch.
`"edges"`
: List of [`<edge>` objects](#data-type-edge). **Every** [relationship][] between any two resources in the catalog, which may have been made with [chaining arrows][chain], [metaparameters][], or [the `require` function][require].
> **Notes:**
......@@ -73,9 +74,11 @@ The value of the `"data"` key must be a JSON object with four keys: `"name"`, `"
> * This key is significantly different from its equivalent in Puppet's internal catalog format, which only encodes containment edges.
`"resources"`
: List of [`<resource>` objects](#data-type-resource). Contains **every** resource in the catalog.
`"transaction-uuid"`
: String. A string used to match the catalog with the corresponding report that was issued during the same puppet run.
This field may be `null`.
### Data Type: `<string>`
......
......@@ -20,11 +20,11 @@ otherwise noted, `null` is not allowed anywhere in the report.
"configuration-version": <string>,
"start-time": <datetime>,
"end-time": <datetime>,
"resource-events": [<resource-event>, <resource-event>, ...]
"resource-events": [<resource-event>, <resource-event>, ...],
"transaction-uuid" : <string>
}
All keys are mandatory, though values that are lists may be empty
lists.
All keys are mandatory unless otherwise noted, though values that are lists may be empty lists.
`"certname"` is the certname the report is associated with.
......@@ -43,6 +43,9 @@ the `datetime` format below.
`"end-time"` is the time at which the puppet run completed; see more details about
the `datetime` format below.
`"transaction-uuid"` is an identifier string used to match the catalog and report
that were issued during the same puppet run. This field may be `null`.
### Encoding
The entire report is expected to be valid JSON, which implies UTF-8
......
......@@ -7,7 +7,9 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
include Puppet::Util::Puppetdb::CommandNames
def save(request)
catalog = munge_catalog(request.instance)
extra_request_data = extract_extra_request_data(request)
catalog = munge_catalog(request.instance, extra_request_data)
submit_command(request.key, catalog, CommandReplaceCatalog, 2)
end
......@@ -19,7 +21,13 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
# TODO: I think that almost everything below this line should be
# private, but I don't want to break all the tests right now...
def munge_catalog(catalog)
def extract_extra_request_data(request)
{
:transaction_uuid => request.options[:transaction_uuid]
}
end
def munge_catalog(catalog, extra_request_data = {})
hash = catalog.to_pson_data_hash
data = hash['data']
......@@ -31,6 +39,7 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
munge_edges(data)
synthesize_edges(data, catalog)
filter_keys(hash)
add_transaction_uuid(data, extra_request_data)
hash
end
......@@ -46,6 +55,12 @@ class Puppet::Resource::Catalog::Puppetdb < Puppet::Indirector::REST
# fundamentally unordered
UnorderedMetaparams = [:alias, :audit, :before, :check, :notify, :require, :subscribe, :tag]
def add_transaction_uuid(hash, extra_request_data)
hash['transaction_uuid'] = extra_request_data[:transaction_uuid]
hash
end
def stringify_titles(hash)
hash['resources'].each do |resource|
resource['title'] = resource['title'].to_s
......
......@@ -40,15 +40,16 @@ Puppet::Reports.register_report(:puppetdb) do
### Convert `self` (an instance of `Puppet::Transaction::Report`) to a hash
### suitable for sending over the wire to PuppetDB
def report_to_hash
{
"certname" => host,
"puppet-version" => puppet_version,
"report-format" => report_format,
"configuration-version" => configuration_version.to_s,
"start-time" => Puppet::Util::Puppetdb.to_wire_time(time),
"end-time" => Puppet::Util::Puppetdb.to_wire_time(time + run_duration),
"resource-events" => build_events_list
}
add_v4_fields_to_report(
{
"certname" => host,
"puppet-version" => puppet_version,
"report-format" => report_format,
"configuration-version" => configuration_version.to_s,
"start-time" => Puppet::Util::Puppetdb.to_wire_time(time),
"end-time" => Puppet::Util::Puppetdb.to_wire_time(time + run_duration),
"resource-events" => build_events_list
})
end
def build_events_list
......@@ -83,7 +84,7 @@ Puppet::Reports.register_report(:puppetdb) do
## Convert an instance of `Puppet::Transaction::Event` to a hash
## suitable for sending over the wire to PuppetDB
def event_to_hash(resource_status, event)
add_report_v4_fields(resource_status,
add_v4_fields_to_event(resource_status,
{
"status" => event.status,
"timestamp" => Puppet::Util::Puppetdb.to_wire_time(event.time),
......@@ -102,7 +103,7 @@ Puppet::Reports.register_report(:puppetdb) do
## this method fabricates a PuppetDB event object with the provided
## `"status"`.
def fabricate_event(resource_status, event_status)
add_report_v4_fields(resource_status,
add_v4_fields_to_event(resource_status,
{
"status" => event_status,
"timestamp" => Puppet::Util::Puppetdb.to_wire_time(resource_status.time),
......@@ -117,15 +118,21 @@ Puppet::Reports.register_report(:puppetdb) do
})
end
## Supports backwards compatibility with versions
## of Puppet prior to report format 4
def add_report_v4_fields(resource_status, event_hash)
## Backwards compatibility with versions of Puppet prior to report format 4
def add_v4_fields_to_report(report_hash)
if report_format >= 4
event_hash.merge({
"containment-path" => resource_status.containment_path
})
report_hash.merge("transaction-uuid" => transaction_uuid)
else
report_hash.merge("transaction-uuid" => nil)
end
end
## Backwards compatibility with versions of Puppet prior to report format 4
def add_v4_fields_to_event(resource_status, event_hash)
if report_format >= 4
event_hash.merge("containment-path" => resource_status.containment_path)
else
event_hash
event_hash.merge("containment-path" => nil)
end
end
......
......@@ -71,6 +71,19 @@ describe Puppet::Resource::Catalog::Puppetdb do
catalog.to_pson_data_hash['data']
end
describe "#add_transaction_uuid" do
it "should add the given transaction uuid" do
result = subject.add_transaction_uuid(catalog_data_hash, :transaction_uuid => 'abc123')
result['transaction_uuid'].should == 'abc123'
end
it "should add nil transaction uuid if none was given" do
result = subject.add_transaction_uuid(catalog_data_hash, {})
result.has_key?('transaction_uuid').should be_true
result['transaction_uuid'].should be_nil
end
end
describe "#add_parameters_if_missing" do
it "should create an empty parameters hash if none exists" do
result = subject.add_parameters_if_missing(catalog_data_hash)
......@@ -643,7 +656,7 @@ describe Puppet::Resource::Catalog::Puppetdb do
result.keys.should =~ ['metadata', 'data']
result['metadata'].keys.should =~ ['api_version']
result['data'].keys.should =~ ['name', 'version', 'edges', 'resources']
result['data'].keys.should =~ ['name', 'version', 'edges', 'resources', 'transaction_uuid']
end
end
end
......
......@@ -73,6 +73,21 @@ describe processor do
subject.add_resource_status(status)
end
it "should include the transaction uuid or nil" do
# Prevents subject.send(:report_to_hash) from exploding
subject.stubs(:run_duration).returns(-1)
if subject.report_format >= 4
subject.transaction_uuid = 'abc123'
result = subject.send(:report_to_hash)
result["transaction-uuid"].should == 'abc123'
else
result = subject.send(:report_to_hash)
result.has_key?("transaction-uuid").should == true
result["transaction-uuid"].should == nil
end
end
context "start/end time" do
before :each do
subject.add_metric("time", {"total" => 10})
......
......@@ -105,9 +105,9 @@
#{:contains :required-by :notifies :before :subscription-of})
(def ^:const catalog-attributes
#{:certname :puppetdb-version :api-version :version :edges :resources})
#{:certname :puppetdb-version :api-version :transaction-uuid :version :edges :resources})
;; ## Utiltity functions
;; ## Utility functions
(defn resource-spec-to-map
"Convert a textual resource specifier like `\"Class[foo]\"` into a map
......@@ -242,7 +242,8 @@
* Stringifies the `version`
* Adds a `puppetdb-version` with the current catalog format version
* Renames `api_version` to `api-version`
* Renames `name` to `certname`"
* Renames `name` to `certname`
* Renames `transaction_uuid` to `transaction-uuid`"
[catalog]
{:pre [(map? catalog)]
:post [(string? (:version %))
......@@ -250,11 +251,13 @@
(:certname %)
(= (:certname %) (:name catalog))
(= (:api-version %) (:api_version catalog))
(number? (:api-version %))]}
(number? (:api-version %))
((some-fn nil? string?) (:transaction-uuid %))
(= (:transaction-uuid %) (:transaction_uuid catalog))]}
(-> catalog
(update-in [:version] str)
(assoc :puppetdb-version catalog-version)
(set/rename-keys {:name :certname :api_version :api-version})))
(set/rename-keys {:name :certname :api_version :api-version :transaction_uuid :transaction-uuid})))
(def transform
"Applies every transformation to the catalog, converting it from wire format
......
......@@ -9,19 +9,21 @@
(:use [com.puppetlabs.jdbc :only [query-to-vec]]
[com.puppetlabs.utils :only [dissoc-if-nil]]))
(defn get-catalog-version
"Given a node name, returns the Puppet catalog version string for the most
recent catalog that we've seen for that node. Returns `nil` if no catalogs
are found for the node."
(defn get-catalog-info
"Given a node name, return a map of Puppet catalog information
for the most recent catalog that we've seen for that node.
The map contains the following data:
- `:catalog_version`
- `:transaction_uuid`, which may be nil"
[node]
{:pre [(string? node)]
:post [((some-fn string? nil?) %)]}
(let [query (str "SELECT catalog_version "
:post [((some-fn nil? map?) %)]}
(let [query (str "SELECT catalog_version, transaction_uuid "
"FROM catalogs "
"INNER JOIN certname_catalogs "
"ON certname_catalogs.catalog = catalogs.hash "
"WHERE certname = ?")]
(:catalog_version (first (query-to-vec query node)))))
(first (query-to-vec query node))))
(defn resource-to-wire-format
"Given a resource as returned by our resource database query functions,
......@@ -90,11 +92,13 @@
(seq? (:edges (:data %)))
(map? (:metadata %))))]
}
;; the main use of get-catalog-version here is just to do a quick check to
;; the main use of get-catalog-info here is just to do a quick check to
;; see if we actually have a catalog for the node
(when-let [catalog-version (get-catalog-version node)]
{ :data {:name node
:edges (get-edges node)
:resources (get-resources node)
:version catalog-version}
:metadata {:api_version 1 }}))
(let [info (get-catalog-info node)]
(when-let [catalog-version (:catalog_version info)]
{ :data {:name node
:edges (get-edges node)
:resources (get-resources node)
:version catalog-version
:transaction_uuid (:transaction_uuid info)}
:metadata {:api_version 1 }})))
......@@ -39,7 +39,8 @@
configuration_version,
start_time,
end_time,
receive_time
receive_time,
transaction_uuid
FROM reports %s ORDER BY start_time DESC")
sql)
results (map
......
......@@ -18,7 +18,10 @@
:configuration-version :string
:start-time :datetime
:end-time :datetime
:resource-events :coll})
:resource-events :coll
:transaction-uuid { :optional? true
:type :string }
})
(defmodel ResourceEvent
{:status :string
......
......@@ -319,7 +319,8 @@
"Schema changes for the initial release of Burgundy. These include:
- Add 'file' and 'line' columns to the event table
- A column for the resource's containment path in the resource_events table"
- A column for the resource's containment path in the resource_events table
- A column for the transaction uuid in the reports & catalogs tables"
[]
(sql/do-commands
"ALTER TABLE resource_events ADD COLUMN file VARCHAR(1024) DEFAULT NULL"
......@@ -327,7 +328,12 @@
(sql/do-commands
(format "ALTER TABLE resource_events ADD containment_path %s" (sql-array-type-string "TEXT"))
"ALTER TABLE resource_events ADD containing_class VARCHAR(255)"
"CREATE INDEX idx_resource_events_containing_class ON resource_events(containing_class)"))
"CREATE INDEX idx_resource_events_containing_class ON resource_events(containing_class)")
(sql/do-commands
"ALTER TABLE reports ADD COLUMN transaction_uuid VARCHAR(255) DEFAULT NULL"
"CREATE INDEX idx_reports_transaction_uuid ON reports(transaction_uuid)"
"ALTER TABLE catalogs ADD COLUMN transaction_uuid VARCHAR(255) DEFAULT NULL"
"CREATE INDEX idx_catalogs_transaction_uuid ON catalogs(transaction_uuid)"))
(defn add-latest-reports-table
"Add `latest_reports` table for easy lookup of latest report for each node."
......@@ -348,8 +354,7 @@
ON reports.certname = latest.certname
AND reports.end_time = latest.max_end_time"))
;; The available migrations, as a map from migration version to migration
;; function.
;; The available migrations, as a map from migration version to migration function.
(def migrations
{1 initialize-store
2 allow-node-deactivation
......@@ -369,7 +374,7 @@
(defn record-migration!
"Records a migration by storing its version in the schema_migrations table,
along with the time at which the migration was performed."
along with the time at which the migration was performed."
[version]
{:pre [(integer? version)]}
(sql/do-prepared
......@@ -403,7 +408,7 @@ along with the time at which the migration was performed."
(defn migrate!
"Migrates database to the latest schema version. Does nothing if database is
already at the latest schema version."
already at the latest schema version."
[]
(if-let [unexpected (first (difference (applied-migrations) (utils/keyset migrations)))]
(throw (IllegalStateException.
......
......@@ -328,24 +328,30 @@ must be supplied as the value to be matched."
(defn add-catalog-metadata!
"Given some catalog metadata, persist it in the db"
[hash api-version catalog-version]
[hash api-version catalog-version transaction-uuid]
{:pre [(string? hash)
(number? api-version)
(string? catalog-version)]}
(sql/insert-record :catalogs {:hash hash
:api_version api-version
:catalog_version catalog-version}))
(string? catalog-version)
(or (nil? transaction-uuid)
(string? transaction-uuid))]}
(sql/insert-record :catalogs {:hash hash
:api_version api-version
:catalog_version catalog-version
:transaction_uuid transaction-uuid}))
(defn update-catalog-metadata!
"Given some catalog metadata, update the db"
[hash api-version catalog-version]
[hash api-version catalog-version transaction-uuid]
{:pre [(string? hash)
(number? api-version)
(string? catalog-version)]}
(string? catalog-version)
(or (nil? transaction-uuid)
(string? transaction-uuid))]}
(sql/update-values :catalogs
["hash=?" hash]
{:api_version api-version
:catalog_version catalog-version}))
{:api_version api-version
:catalog_version catalog-version
:transaction_uuid transaction-uuid}))
(defn catalog-exists?
"Returns a boolean indicating whether or not the given catalog exists in the db"
......@@ -538,7 +544,7 @@ must be supplied as the value to be matched."
(defn add-catalog!
"Persist the supplied catalog in the database, returning its
similarity hash"
[{:keys [api-version version resources edges] :as catalog}]
[{:keys [api-version version transaction-uuid resources edges] :as catalog}]
{:pre [(number? api-version)
(coll? edges)
(map? resources)]}
......@@ -555,11 +561,11 @@ must be supplied as the value to be matched."
(when exists?
(inc! (:duplicate-catalog metrics))
(update-catalog-metadata! hash api-version version))
(update-catalog-metadata! hash api-version version transaction-uuid))
(when-not exists?
(inc! (:new-catalog metrics))
(add-catalog-metadata! hash api-version version)
(add-catalog-metadata! hash api-version version transaction-uuid)
(let [refs-to-hashes (zipmap (keys resources) resource-hashes)]
(time! (:add-resources metrics)
(add-resources! hash resources refs-to-hashes))
......@@ -712,7 +718,7 @@ must be supplied as the value to be matched."
configuration version, timestamps, events).
"
[{:keys [certname puppet-version report-format configuration-version
start-time end-time resource-events] :as report}]
start-time end-time resource-events transaction-uuid] :as report}]
(-> (sorted-map)
(assoc :certname certname)
(assoc :puppet-version puppet-version)
......@@ -721,6 +727,7 @@ must be supplied as the value to be matched."
(assoc :start-time start-time)
(assoc :end-time end-time)
(assoc :resource-events (sort (map resource-event-identity-string resource-events)))
(assoc :transaction-uuid transaction-uuid)
(pr-str)
(utils/utf8-string->sha1)))
......@@ -763,7 +770,7 @@ must be supplied as the value to be matched."
the transaction. This should always be set to `true`, except during some very specific testing
scenarios."
[{:keys [puppet-version certname report-format configuration-version
start-time end-time resource-events]
start-time end-time resource-events transaction-uuid]
:as report}
timestamp update-latest-report?]
{:pre [(map? report)
......@@ -789,7 +796,8 @@ must be supplied as the value to be matched."
:configuration_version configuration-version
:start_time (to-timestamp start-time)
:end_time (to-timestamp end-time)
:receive_time (to-timestamp timestamp)})
:receive_time (to-timestamp timestamp)
:transaction_uuid transaction-uuid})
(apply sql/insert-records :resource_events resource-event-rows)
(if update-latest-report?
(update-latest-report! certname))))))
......
......@@ -10145,11 +10145,10 @@
"type" : "User",
"file" : "/Users/nicklewis/projects/puppetlabs-modules/dist/account/manifests/user.pp"
} ],
"version" : 1330463446
"version" : 1330463446,
"transaction_uuid" : "68b08e2a-eeb1-4322-b241-bfdf151d294b"
},
"metadata" : {
"api_version" : 1
}
}
......@@ -34,5 +34,6 @@
"end-time": "2012-01-10T05:15:01.098Z",
"certname": "myhost.localdomain",
"puppet-version": "3.0.0",
"report-format": 3
"report-format": 3,
"transaction-uuid": "68b08e2a-eeb1-4322-b241-bfdf151d294b"
}
......@@ -41,7 +41,8 @@
"type" : "Apt::Pin",
"file" : "/Users/nicklewis/projects/puppetlabs-modules/site/os/manifests/linux/debian.pp"
} ],
"version" : 1330463446
"version" : 1330463446,
"transaction_uuid" : "68b08e2a-eeb1-4322-b241-bfdf151d294b"
},
"metadata" : {
"api_version" : 1
......
......@@ -31,6 +31,7 @@
{:certname "basic.catalogs.com"
:puppetdb-version catalog-version
:api-version 1
:transaction-uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"
:version "123456789"
:edges #{{:source {:type "Class" :title "foobar"}
:target {:type "File" :title "/etc/foobar"}
......@@ -66,6 +67,7 @@
{:certname "invalid.catalogs.com"
:puppetdb-version catalog-version
:api-version 1
:transaction-uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"
:version 123456789
:edges #{{:source {:type "Class" :title "foobar"}
:target {:type "File" :title "does not exist"}
......@@ -116,10 +118,11 @@
:parameters {}
:tags ["node" "default" "class"]
:type "Node"}]
:tags ["settings" "default" "node"]
:classes ["settings" "default"]
:environment "production"
:version 1332533763}}}
:tags ["settings" "default" "node"]
:classes ["settings" "default"]
:environment "production"
:version 1332533763
:transaction_uuid nil}}}
2 {:empty
{:metadata {:api_version 1}
......@@ -157,4 +160,5 @@
:parameters {}
:tags ["node" "default" "class"]
:type "Node"}]
:version 1332533763}}}})
:version 1332533763
:transaction_uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"}}}})
......@@ -6,6 +6,7 @@
{:certname "foo.local"
:puppet-version "3.0.1"
:report-format 3
:transaction-uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"
:configuration-version "a81jasj123"
:start-time "2011-01-01T12:00:00-03:00"
:end-time "2011-01-01T12:10:00-03:00"
......
......@@ -242,9 +242,10 @@
:tags ["file" "class"],
:title "/tmp/quux",
:type "File"}],
:classes []
:tags []
:version 1330995750},
:classes [],
:tags [],
:version 1330995750,
:transaction_uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"},
:document_type "Catalog",
:metadata {:api_version 1}}
......@@ -334,7 +335,8 @@
:tags #{"class" "file"},
:title "/tmp/quux",
:type "File"}},
:version "1330995750"}))
:version "1330995750",
:transaction-uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"}))
(deftest complete-transformation-v2
(catalog-before-and-after 2
......@@ -416,7 +418,8 @@
:tags ["file" "class"],
:title "/tmp/quux",
:type "File"}],
:version 1330995750},
:version 1330995750,
:transaction_uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"},
:document_type "Catalog",
:metadata {:api_version 1}}
......@@ -506,4 +509,5 @@
:tags #{"class" "file"},
:title "/tmp/quux",
:type "File"}},
:version "1330995750"}))
:version "1330995750",
:transaction-uuid "68b08e2a-eeb1-4322-b241-bfdf151d294b"}))
......@@ -11,13 +11,15 @@
(use-fixtures :each with-test-db)
(deftest catalog-query
(let [catalog-str (slurp (resource "com/puppetlabs/puppetdb/test/cli/export/tiny-catalog.json"))
catalog (json/parse-string catalog-str)
certname (get-in catalog ["data" "name"])
catalog-version (str (get-in catalog ["data" "version"]))]
(let [catalog-str (slurp (resource "com/puppetlabs/puppetdb/test/cli/export/tiny-catalog.json"))
catalog (json/parse-string catalog-str)
certname (get-in catalog ["data" "name"])
catalog-version (str (get-in catalog ["data" "version"]))
transaction-uuid (str (get-in catalog ["data" "transaction_uuid"]))]
(testcat/replace-catalog catalog-str)
(testing "get-catalog-version"
(is (= catalog-version (c/get-catalog-version certname))))
(testing "get-catalog-info"
(is (= catalog-version (:catalog_version (c/get-catalog-info certname))))
(is (= transaction-uuid (:transaction_uuid (c/get-catalog-info certname)))))
(testing "catalog-for-node"
(is (= (testcat/munge-catalog-for-comparison catalog)
(testcat/munge-catalog-for-comparison (c/catalog-for-node certname)))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.