Created
July 17, 2015 18:55
-
-
Save ajroetker/d5052e1d1eac8e9a1c50 to your computer and use it in GitHub Desktop.
unchanged resources test-data loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ur | |
(:require [puppetlabs.puppetdb.examples.reports :as example-reports] | |
[puppetlabs.kitchensink.core :as kitchensink] | |
[puppetlabs.puppetdb.scf.storage-utils :as scf-utils] | |
[clojure.java.jdbc :as jdbc] | |
[puppetlabs.puppetdb.cheshire :as json])) | |
(def skeleton-unchanged-resource | |
{:title "/etc/sysconfig/iptables" | |
:file "/etc/puppetlabs/code/environments/production/modules/firewall/manifests/linux/redhat.pp" | |
:line 61 | |
:resource "File[/etc/sysconfig/iptables]" | |
:resource_type "File" | |
:containment_path ["Stage[main]" "Firewall::Linux::Redhat" "File[/etc/sysconfig/iptables]"] | |
:evaluation_time 0.000534288 | |
:tags ["file" "class" "firewall::linux::redhat" "firewall" "linux" "redhat" "firewall::linux" "puppetdb::server::firewall" "puppetdb" "server" "puppetdb::server" "node" "centos7"] | |
:time "2015-07-16T00:25:34.974042051+00:00" | |
:failed false | |
:changed false | |
:out_of_sync false | |
:skipped false | |
:change_count 0 | |
:out_of_sync_count 0 | |
:events []}) | |
(defn example-10-changed-resource-statuses [] | |
(for [_ (range 10) | |
:let [new-title (str "/etc/sysconfig/" (kitchensink/uuid))]] | |
(assoc skeleton-unchanged-resource | |
:title new-title | |
:file (str "/etc/puppetlabs/code/environments" new-title) | |
:line (rand-int 1000) | |
:changed true | |
:change_count (rand-int 1000) | |
:resource (format "File[%s]" new-title)))) | |
(defn example-500-unchanged-resource-statuses [] | |
(for [x (range 500) | |
:let [new-title (str "/etc/sysconfig/" x)]] | |
(assoc skeleton-unchanged-resource | |
:title new-title | |
:file (str "/etc/puppetlabs/code/environments/" x) | |
:line x | |
:resource (format "File[%s]" new-title)))) | |
(defn example-report [] | |
(let [report-skeleton (:basic4 example-reports/reports)] | |
(assoc report-skeleton | |
:resource_statuses (concat (example-10-changed-resource-statuses) | |
(example-500-unchanged-resource-statuses))))) | |
;; 6500 nodes * 14 days * 24 hours * 2 reports per hour = | |
;; 5824000 | |
(dotimes [_ 5824000] | |
(jdbc/with-connection | |
{:classname "org.postgresql.Driver" | |
:subprotocol "postgresql" | |
:subname "//localhost:5432/puppetdb" | |
:username "puppetdb" | |
:password "puppetdb"} | |
(let [report (example-report) | |
row {:data (scf-utils/str->pgobject "json" (json/generate-string report))}] | |
(jdbc/insert-record "full_reports_json" row)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment