Commit a4798a8e authored by Russell Mull's avatar Russell Mull Committed by Ryan Senior

(PDB-3302) Host puppetserver in clojure tests

parent 5da03f18
......@@ -5,23 +5,27 @@ lein: 2.7.1
# based on when the repository testing was enabled.
sudo: required
jdk:
- openjdk7
- oraclejdk8
- oraclejdk7
env:
- PDB_TEST_LANG=clojure
- PDB_TEST_LANG=ruby
# Only run one ruby test
matrix:
exclude:
- jdk: oraclejdk8
env: PDB_TEST_LANG=ruby
- jdk: oraclejdk7
env: PDB_TEST_LANG=ruby
include:
# terminus unit tests (spec tests)
- env: PDB_TEST_LANG=ruby PUPPET_VERSION=latest
- env: PDB_TEST_LANG=ruby PUPPET_VERSION=4.0.0
# pdb unit tests
- env: PDB_TEST_LANG=clojure PDB_TEST_SELECTOR=:unit
jdk: openjdk7
- env: PDB_TEST_LANG=clojure PDB_TEST_SELECTOR=:unit
jdk: oraclejdk7
- env: PDB_TEST_LANG=clojure PDB_TEST_SELECTOR=:unit
jdk: oraclejdk8
# pdb + terminus + puppetserver + puppet integration tests
- env: PDB_TEST_LANG=clojure PDB_TEST_SELECTOR=:integration PUPPET_VERSION=4.6.2 PUPPETSERVER_VERSION=2.7.2
jdk: oraclejdk8
- env: PDB_TEST_LANG=clojure PDB_TEST_SELECTOR=:integration PUPPET_VERSION=latest PUPPETSERVER_VERSION=master
jdk: oraclejdk8
before_install: ext/travisci/install_puppetserver.sh
script: ext/travisci/test.sh
notifications:
......
......@@ -41,7 +41,7 @@ group :test do
when "oldest"
gem 'puppet', oldest_supported_puppet, :require => false
else
gem 'puppet', :git => 'git://github.com/puppetlabs/puppet.git',
gem 'puppet', :git => 'https://github.com/puppetlabs/puppet.git',
:branch => puppet_branch, :require => false
end
......
#!/usr/bin/env bash
lein=lein2
# Update a single dependency in a leiningen project.clj file.
update_dependency_var() {
local file="$1"
local varname="$2"
local new_version="$3"
SED_ADDRESS="(def $varname"
SED_REGEX="\".*\""
SED_REPLACEMENT="\"$new_version\""
SED_COMMAND="s|$SED_REGEX|$SED_REPLACEMENT|"
set -e
set -x
sed -i -e "/$SED_ADDRESS/ $SED_COMMAND" $file
}
lein-pprint() {
export PUPPETSERVER_HEAP_SIZE=1G
"$lein" with-profile dev,ci pprint "$@" | sed -e 's/^"//' -e 's/"$//'
}
git clone https://github.com/puppetlabs/puppetserver
cd puppetserver
git checkout "$PUPPETSERVER_VERSION"
export PUPPETSERVER_HEAP_SIZE=1G
"$lein" install
MAVEN_VER=$(lein-pprint :version)
echo $MAVEN_VER
cd ..
update_dependency_var "project.clj" "puppetserver-version" $MAVEN_VER
......@@ -16,12 +16,16 @@ run-unit-tests()
export PGHOST=127.0.0.1
export PGPORT=5432
ext/bin/setup-pdb-pg "$pgdir"
ext/bin/pdb-test-env "$pgdir" lein2 test
ext/bin/pdb-test-env "$pgdir" lein2 test "$PDB_TEST_SELECTOR"
)
case "$PDB_TEST_LANG" in
clojure)
java -version
ruby -v
gem install bundler
bundle install --without acceptance
lein2 install-gems
run-unit-tests
;;
ruby)
......
(def pdb-version "4.4.0-SNAPSHOT")
(def puppetserver-version "2.7.2")
(def clj-parent-version "0.4.1")
(defn deploy-info
"Generate deployment information from the URL supplied and the username and
......@@ -26,7 +28,7 @@
:min-lein-version "2.7.1"
:parent-project {:coords [puppetlabs/clj-parent "0.3.2"]
:parent-project {:coords [puppetlabs/clj-parent ~clj-parent-version]
:inherit [:managed-dependencies]}
;; Abort when version ranges or version conflicts are detected in
......@@ -98,8 +100,7 @@
[com.novemberain/pantomime "2.1.0"]
[compojure]
[org.apache.commons/commons-compress "1.10"]
[ring/ring-core :exclusions [javax.servlet/servlet-api org.clojure/tools.reader]]
]
[ring/ring-core :exclusions [javax.servlet/servlet-api org.clojure/tools.reader]]]
:jvm-opts ~pdb-jvm-opts
......@@ -138,6 +139,8 @@
[puppetlabs/trapperkeeper :classifier "test"]
[puppetlabs/kitchensink :classifier "test"]
[puppetlabs/trapperkeeper-webserver-jetty9 :classifier "test"]
[puppetlabs/puppetserver ~puppetserver-version]
[puppetlabs/puppetserver ~puppetserver-version :classifier "test"]
[org.flatland/ordered "1.5.3"]
[org.clojure/test.check "0.9.0"]
[com.gfredericks/test.chuck "0.2.7" :exclusions [clj-time instaparse joda-time org.clojure/clojure]]
......@@ -176,4 +179,13 @@
:resource-paths ["resources" "puppet/lib" "resources/puppetlabs/puppetdb" "resources/ext/docs"]
:main ^:skip-aot puppetlabs.puppetdb.core)
:main ^:skip-aot puppetlabs.puppetdb.core
:test-selectors {:default (complement :integration)
:unit (complement :integration)
:integration :integration}
:aliases {"gem" ["trampoline" "run" "-m" "puppetlabs.puppetserver.cli.gem"
"--config" "./test-resources/puppetserver/puppetserver.conf"]
"install-gems" ["trampoline" "run" "-m" "puppetlabs.puppetdb.integration.install-gems"
"--config" "./test-resources/puppetserver/puppetserver.conf"]})
puppetlabs.trapperkeeper.services.webserver.jetty9-service/jetty9-service
puppetlabs.trapperkeeper.services.webrouting.webrouting-service/webrouting-service
puppetlabs.trapperkeeper.services.metrics.metrics-service/metrics-webservice
puppetlabs.trapperkeeper.services.status.status-service/status-service
puppetlabs.trapperkeeper.services.scheduler.scheduler-service/scheduler-service
puppetlabs.puppetdb.cli.services/puppetdb-service
puppetlabs.puppetdb.command/command-service
puppetlabs.puppetdb.pdb-routing/maint-mode-service
puppetlabs.puppetdb.pdb-routing/pdb-routing-service
puppetlabs.puppetdb.config/config-service
puppetlabs.puppetdb.dashboard/dashboard-redirect-service
\ No newline at end of file
global: {
vardir: "" # filled out by the test harness
logging-config: test-resources/logback-test.xml
}
database: {
classname: org.postgresql.Driver
subprotocol: postgresql
# These will be replaced by the test harness
subname: "//localhost:5432/puppetdb"
username: puppetdb
password: puppetdb
}
command-processing: {
threads: 6
}
nrepl: {
enabled: false
}
jetty: {
host: 0.0.0.0
port: 0
ssl-host: 0.0.0.0
ssl-port: 0 # filled out by the test harness
# Original settings
ssl-ca-cert: ./test-resources/puppetserver/ssl/certs/ca.pem
ssl-cert: ./test-resources/puppetserver/ssl/certs/localhost.pem
ssl-key: ./test-resources/puppetserver/ssl/private_keys/localhost.pem
ssl-protocols: ["TLSv1", "TLSv1.1"]
acceptor-threads: 8
selector-threads: 8
max-threads: 32
}
puppetdb: {
}
web-router-service: {
"puppetlabs.trapperkeeper.services.metrics.metrics-service/metrics-webservice": "/metrics"
"puppetlabs.trapperkeeper.services.status.status-service/status-service": "/status"
"puppetlabs.puppetdb.pdb-routing/pdb-routing-service": "/pdb"
"puppetlabs.puppetdb.dashboard/dashboard-redirect-service": "/"
}
\ No newline at end of file
puppetlabs.services.request-handler.request-handler-service/request-handler-service
puppetlabs.services.jruby.jruby-puppet-service/jruby-puppet-pooled-service
puppetlabs.services.jruby-pool-manager.jruby-pool-manager-service/jruby-pool-manager-service
puppetlabs.services.puppet-profiler.puppet-profiler-service/puppet-profiler-service
puppetlabs.trapperkeeper.services.webserver.jetty9-service/jetty9-service
puppetlabs.trapperkeeper.services.webrouting.webrouting-service/webrouting-service
puppetlabs.services.config.puppet-server-config-service/puppet-server-config-service
puppetlabs.services.master.master-service/master-service
puppetlabs.services.legacy-routes.legacy-routes-service/legacy-routes-service
puppetlabs.services.puppet-admin.puppet-admin-service/puppet-admin-service
puppetlabs.trapperkeeper.services.authorization.authorization-service/authorization-service
puppetlabs.services.versioned-code-service.versioned-code-service/versioned-code-service
puppetlabs.trapperkeeper.services.scheduler.scheduler-service/scheduler-service
puppetlabs.trapperkeeper.services.status.status-service/status-service
puppetlabs.trapperkeeper.services.metrics.metrics-service/metrics-service
# To enable the CA service, leave the following line uncommented
puppetlabs.services.ca.certificate-authority-service/certificate-authority-service
# To disable the CA service, comment out the above line and uncomment the line below
#puppetlabs.services.ca.certificate-authority-disabled-service/certificate-authority-disabled-service
<configuration scan="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %-5p [%t] [%c{2}] %m%n</pattern>
</encoder>
</appender>
<logger name="org.eclipse.jetty" level="info"/>
<logger name="org.apache.http" level="info"/>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
[main]
certname = localhost
[agent]
server = localhost
[master]
storeconfigs = true
storeconfigs_backend = puppetdb
reports = puppetdb
global: {
logging-config: ./test-resources/puppetserver/logback-dev.xml
}
product: {
update-server-url: "http://some.update.server.that.does.not.exist/"
name: {group-id: puppetlabs.dev
artifact-id: puppetserver}
}
webserver: {
access-log-config: ./dev/request-logging-dev.xml
client-auth: want
# ssl-host controls what networks the server will accept connections from.
# The default value below is '0.0.0.0', so will accept connections from
# any client. For better security, you might wish to set this to 'localhost'.
ssl-host: 0.0.0.0
#ssl-host: localhost
ssl-port: 8140
}
# configure the mount points for the web apps
web-router-service: {
# These two should not be modified because the Puppet 4.x agent expects
# them to be mounted at these specific paths
"puppetlabs.services.ca.certificate-authority-service/certificate-authority-service": "/puppet-ca"
"puppetlabs.services.master.master-service/master-service": "/puppet"
# This controls the mount point for the puppet admin API.
"puppetlabs.services.puppet-admin.puppet-admin-service/puppet-admin-service": "/puppet-admin-api"
# 3.x agent compatibility routes. The legacy routes are only mounted if the
# puppetlabs.services.legacy-routes.legacy-routes-service/legacy-routes-service
# service is in the bootstrap.cfg
"puppetlabs.services.legacy-routes.legacy-routes-service/legacy-routes-service": ""
# This controls the mount point for the status API
"puppetlabs.trapperkeeper.services.status.status-service/status-service": "/status"
}
# configuration for the JRuby interpreters
jruby-puppet: {
# Where the puppet-agent dependency places puppet, facter, etc...
# Puppet server expects to load Puppet from this location
# ruby-load-path: [./ruby/puppet/lib, ./ruby/facter/lib, ./ruby/hiera/lib]
ruby-load-path: ["./puppet/lib"] # <- the PuppetDB terminus
# This setting determines where JRuby will install gems. It is used for loading gems,
# and also by the `puppetserver gem` command line tool.
gem-home: "vendor/puppetserver-gems"
#${HOME}"/.puppetlabs/opt/server/data/puppetserver/jruby-gems"
# This setting defines the complete "GEM_PATH" for jruby. If set, it should include
# the gem-home directory as well as any other directories that gems can be loaded
# from (including the vendored gems directory for gems that ship with puppetserver)
gem-path: [${jruby-puppet.gem-home}]
# (optional) path to puppet conf dir; if not specified, will use the puppet default
master-conf-dir: "./target/puppetserver/master-conf"
# (optional) path to puppet code dir; if not specified, will use the puppet default
master-code-dir: "./target/puppetserver/master-code"
# (optional) path to puppet var dir; if not specified, will use the puppet default
master-var-dir: "./target/puppetserver/master-var"
# (optional) path to puppet run dir; if not specified, will use the puppet default
master-run-dir: "./target/puppetserver/master-var/run"
# (optional) path to puppet log dir; if not specified, will use the puppet default
master-log-dir: "./target/puppetserver/master-var/log"
# (optional) maximum number of JRuby instances to allow
max-active-instances: 1
# (optional) Authorize access to Puppet master endpoints via rules specified
# in the legacy Puppet auth.conf file (if true or not specified) or via rules
# specified in the Puppet Server HOCON-formatted auth.conf (if false).
use-legacy-auth-conf: false
# (optional) whether to use the environment class cache. If unspecified
# defaults to false
environment-class-cache-enabled: true
}
# settings related to HTTP client requests made by Puppet Server
http-client: {
# A list of acceptable protocols for making HTTP requests
#ssl-protocols: [TLSv1, TLSv1.1, TLSv1.2]
# A list of acceptable cipher suites for making HTTP requests
#cipher-suites: [TLS_RSA_WITH_AES_256_CBC_SHA256,
# TLS_RSA_WITH_AES_256_CBC_SHA,
# TLS_RSA_WITH_AES_128_CBC_SHA256,
# TLS_RSA_WITH_AES_128_CBC_SHA]
# The amount of time, in milliseconds, that an outbound HTTP connection
# will wait for data to be available before closing the socket. If not
# defined, defaults to 20 minutes. If 0, the timeout is infinite and if
# negative, the value is undefined by the application and governed by the
# system default behavior.
#idle-timeout-milliseconds: 1200000
# The amount of time, in milliseconds, that an outbound HTTP connection will
# wait to connect before giving up. Defaults to 2 minutes if not set. If 0,
# the timeout is infinite and if negative, the value is undefined in the
# application and governed by the system default behavior.
#connect-timeout-milliseconds: 120000
}
# settings related to profiling the puppet Ruby code
profiler: {
# enable or disable profiling for the Ruby code; defaults to 'false'.
enabled: true
}
metrics: {
server-id: "localhost"
}
# authorization rules for web service endpoints
authorization: {
version: 1
rules: [
{
match-request: {
path: "/"
type: "path"
}
allow-unauthenticated: true
sort-order: 1
name: "allow all"
}
]
}
<configuration debug="false" scan="true">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>./target/logs/puppetserver-access.log</file>
<encoder>
<pattern>%h %l %u %user %date "%r" %s %b %h %a %localPort %D</pattern>
</encoder>
</appender>
<appender-ref ref="FILE" />
</configuration>
(ns puppetlabs.puppetdb.integration.install-gems
(:require [clojure.java.io :as io]
[puppetlabs.puppetserver.cli.subcommand :as cli]
[puppetlabs.services.jruby.jruby-puppet-core :as jruby-puppet-core]
[puppetlabs.services.jruby-pool-manager.jruby-core :as jruby-core]
[clojure.string :as string]
[environ.core :refer [env]]))
(defn gem-run!
[config & args]
(let [jruby-config (jruby-puppet-core/initialize-and-create-jruby-config config)]
(jruby-core/cli-run! jruby-config "gem" args)))
(defn install-gems [config _]
;; the puppet gem brings hiera and facter with it
;; TODO: it would be better to just install the puppet-agent package in CI
(let [puppet-version (get env :puppet-version "latest")]
(if (not= puppet-version "latest")
(gem-run! config "install" "puppet" "--version" puppet-version)
(gem-run! config "install" "puppet")))
;; Install the puppetserver vendored gems listed inside its jar; this is where
;; ezbake gets them
(let [gem-list (string/split (slurp (io/resource "ext/build-scripts/gem-list.txt")) #"\n")]
(doseq [[gem version] (map #(string/split % #"\s") gem-list)]
(gem-run! config "install" gem "--version" version))))
(defn -main
[& args]
(cli/run install-gems args))
(ns puppetlabs.puppetdb.integration.protocols)
(defprotocol TestServer
(info-map [this]))
(ns puppetlabs.puppetdb.integration.simple
(:require [clojure.test :refer :all]
[clojure.java.io :as io]
[clojure.java.shell :refer [sh]]
[clojure.string :as string]
[clojure.walk :as walk]
[me.raynes.fs :as fs]
[puppetlabs.http.client.sync :as http]
[puppetlabs.kitchensink.core :as ks]
[puppetlabs.puppetdb.cheshire :as json]
[puppetlabs.puppetdb.integration.protocols :refer [info-map]]
[puppetlabs.puppetdb.testutils.db :as dbutils]
[puppetlabs.puppetdb.testutils.services :as svc-utils]
[puppetlabs.puppetdb.utils :as utils]
[puppetlabs.trapperkeeper.app :as tk-app]
[puppetlabs.trapperkeeper.bootstrap :as tk-bootstrap]
[puppetlabs.trapperkeeper.config :as tk-config]
[puppetlabs.trapperkeeper.testutils.bootstrap :as tkbs]
[puppetlabs.puppetdb.config :as conf]
[puppetlabs.config.typesafe :as hocon]
[puppetlabs.puppetdb.command :as dispatch]
[clojure.tools.logging :as log]
[puppetlabs.puppetdb.testutils :as tu])
(:import [puppetlabs.puppetdb.integration.protocols TestServer]
[com.typesafe.config ConfigValueFactory]))
;;; Postgres fixture
(defrecord PostgresTestServer [db-config]
TestServer
(info-map [_] db-config)
java.lang.AutoCloseable
(close [_] (dbutils/drop-test-db db-config)))
(defn setup-postgres []
(let [db-config (dbutils/create-temp-db)]
(PostgresTestServer. db-config)))
;;; PuppetDB fixture
(defrecord PuppetDBTestServer [-info-map app]
TestServer
(info-map [_] -info-map)
java.lang.AutoCloseable
(close [_] (tk-app/stop app)))
(defn stringify-keys-with-ns [m]
(let [f (fn [[k v]] (if (keyword? k) [(subs (str k) 1) v] [k v]))]
;; only apply to maps
(walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) m)))
;; TODO: Get this fixed version into the clj-typesafe-config library and use it
;; from there
(defn map->hocon-string
"Serialize the clojure data structure `m` to string using the
typesafe config format. `m` is typically the result of a
`config-file->map` or `reader-map` with some modifications."
[m]
(-> m
stringify-keys-with-ns
ConfigValueFactory/fromAnyRef
.render))
(defn adjust-config-file [in-file out-file overrides]
(spit out-file (-> (hocon/config-file->map in-file)
(ks/deep-merge overrides)
map->hocon-string)))
(defn start-test-puppetdb [bootstrap-config-file config-file config-overrides bind-attempts]
(when (zero? bind-attempts)
(throw (RuntimeException. "Repeated attempts to bind port failed, giving up")))
(let [port (svc-utils/open-port-num)
tmp-puppetdb-conf (str (tu/temp-file "puppetdb" ".conf"))
_ (adjust-config-file config-file tmp-puppetdb-conf
(-> config-overrides
(assoc-in [:jetty :ssl-port] port)
(assoc-in [:global :vardir] (str (tu/temp-dir)))))
base-url {:protocol "https"
:host "localhost"
:port port
:prefix "/pdb/query"
:version :v4}]
(try
(swap! dispatch/metrics svc-utils/clear-counters!)
{:app (tkbs/parse-and-bootstrap bootstrap-config-file
{:config tmp-puppetdb-conf})
:base-url base-url}
(catch java.net.BindException e
(log/errorf e "Error occured when Jetty tried to bind to port %s, attempt #%s"
port bind-attempts)
(start-test-puppetdb bootstrap-config-file config-file config-overrides (dec bind-attempts))))))
(defn run-puppetdb [postgres-server config-overrides]
(let [{:keys [app base-url]} (start-test-puppetdb "test-resources/integration-bootstrap.cfg"
"test-resources/integration-puppetdb.conf"
(ks/deep-merge config-overrides
{:database (info-map postgres-server)})
10)
{:keys [host port]} base-url]
(PuppetDBTestServer. {:hostname host
:port port
:query-base-url (assoc base-url :prefix "/pdb/query" :version :v4)
:command-base-url (assoc base-url :prefix "/pdb/cmd" :version :v1)
:admin-base-url (assoc base-url :prefix "/pdb/admin" :version :v1)}
app)))
(defn pql-query [pdb-server query]
(-> (svc-utils/create-url-str (-> pdb-server info-map :query-base-url) nil)
(svc-utils/get-ssl {:query-params {"query" query}})
:body))
(defn ast-query [pdb-server query]
(pql-query pdb-server (json/generate-string query)))
;;; Puppet Server fixture
(defrecord PuppetServerTestServer [-info-map files-to-cleanup app]
TestServer
(info-map [_] -info-map)
java.lang.AutoCloseable
(close [_]
(tk-app/stop app)
(doseq [f files-to-cleanup] (fs/delete f))))
(def dev-config-file "./test-resources/puppetserver/puppetserver.conf")
(def dev-bootstrap-file "./test-resources/puppetserver/bootstrap.cfg")
(defn run-puppet-server [pdb-server config-overrides]
(let [pdb-info (info-map pdb-server)
puppetdb-conf (io/file "target/puppetserver/master-conf/puppetdb.conf")]
(fs/copy-dir "test-resources/puppetserver/ssl" "./target/puppetserver/master-conf/ssl")
(fs/copy+ "test-resources/puppetserver/puppet.conf" "target/puppetserver/master-conf/puppet.conf")
(fs/mkdirs "target/puppetserver/master-code/environments/production/modules")
(fs/create puppetdb-conf)
(ks/spit-ini puppetdb-conf
{:main {:server_urls (str "https://" (:hostname pdb-info) ":" (:port pdb-info))}})
(let [services (tk-bootstrap/parse-bootstrap-config! dev-bootstrap-file)
tmp-conf (ks/temp-file "puppetserver" ".conf")
_ (fs/copy dev-config-file tmp-conf)
config (-> (tk-config/load-config (.getPath tmp-conf))
(ks/deep-merge config-overrides))]
(PuppetServerTestServer. {:hostname "localhost"
:port 8140
:code-dir "target/puppetserver/master-code"
:conf-dir "target/puppetserver/master-conf"}
[(.getPath tmp-conf) "target/puppetserver/master-conf" "target/puppetserver/master-code"]
(tkbs/bootstrap-services-with-config services config)))))
;;; run puppet
(defn bundle-exec [& args]
(let [result (apply sh "bundle" "exec" args)]
(if (not (#{0 2} (:exit result)))
(throw (ex-info (str "Error running bundle exec " (string/join " " args))
result))
result)))
(defn run-puppet [puppet-server manifest-content]
(let [{:keys [code-dir conf-dir hostname port]} (info-map puppet-server)
site-pp (str code-dir "/environments/production/manifests/site.pp")]
(fs/mkdirs (fs/parent site-pp))
(spit site-pp manifest-content)
(bundle-exec "puppet" "agent" "-t"
"--confdir" conf-dir
"--server" hostname
"--masterport" (str port)
"--color" "false")))
;;; tests
(deftest ^:integration simple-agent-run
(with-open [pg (setup-postgres)
pdb (run-puppetdb pg {})
ps (run-puppet-server pdb {})]
(let [{:keys [out]} (run-puppet ps "notify { 'hello, world!': }")]
(is (re-find #"hello, world" out)))
(are [query result] (= result (pql-query pdb query))
"nodes[certname] {}" [{:certname "localhost"}]
"catalogs[certname, environment] {}" [{:certname "localhost", :environment "production"}]
"factsets[certname, environment] {}" [{:certname "localhost", :environment "production"}]
"reports[certname, environment] {}" [{:certname "localhost", :environment "production"}])))
......@@ -163,7 +163,7 @@
db
user]))
(defn- drop-test-db [db-config]
(defn drop-test-db [db-config]
(let [db-name (subname->validated-db-name (:subname db-config))]
(jdbc/with-db-connection (db-admin-config)
(jdbc/do-commands
......
......@@ -88,6 +88,32 @@
(defn strip-retired-config [config]
(update config :database dissoc :classname :subprotocol))
;; TODO: rework call-with-puppetdb-instance to use this
(defn run-test-puppetdb [config services bind-attempts]
(when (zero? bind-attempts)
(throw (RuntimeException. "Repeated attempts to bind port failed, giving up")))
(let [config (-> config
strip-retired-config
conf/adjust-and-validate-tk-config
assoc-open-port)
port (or (get-in config [:jetty :port])
(get-in config [:jetty :ssl-port]))
is-ssl (boolean (get-in config [:jetty :ssl-port]))
base-url {:protocol (if is-ssl "https" "http")
:host "localhost"
:port port
:prefix "/pdb/query"
:version :v4}]
(try
(swap! dispatch/metrics clear-counters!)
{:app (tkbs/bootstrap-services-with-config (map var-get services) config)
:base-url base-url}
(catch java.net.BindException e
(log/errorf e "Error occured when Jetty tried to bind to port %s, attempt #%s"
port bind-attempts)
(run-test-puppetdb config services (dec bind-attempts))))))
(defn call-with-puppetdb-instance
"Stands up a puppetdb instance with the specified config, calls f,
and then tears the instance down, binding *server* to the instance
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment