mirror of https://github.com/apache/jclouds.git
First version of run-script-on-nodes-matching. Added some missing code to ssh_test to stub out ssh in test.
This commit is contained in:
parent
73deebebbf
commit
e71c88a1a4
|
@ -233,6 +233,10 @@ Here's an example of creating and running a small linux node in the group webser
|
||||||
([#^ComputeService compute id]
|
([#^ComputeService compute id]
|
||||||
(.destroyNode compute id)))
|
(.destroyNode compute id)))
|
||||||
|
|
||||||
|
(defn run-script-on-nodes-matching [#^ComputeService compute pred command template]
|
||||||
|
"Run a script on the nodes matching the given predicate"
|
||||||
|
(.runScriptOnNodesMatching compute (to-predicate pred) command template))
|
||||||
|
|
||||||
(defmacro state-predicate [node state]
|
(defmacro state-predicate [node state]
|
||||||
`(= (.getState ~node)
|
`(= (.getState ~node)
|
||||||
(. org.jclouds.compute.domain.NodeState ~state)))
|
(. org.jclouds.compute.domain.NodeState ~state)))
|
||||||
|
|
|
@ -20,10 +20,17 @@
|
||||||
(ns org.jclouds.compute2-test
|
(ns org.jclouds.compute2-test
|
||||||
(:use [org.jclouds.compute2] :reload-all)
|
(:use [org.jclouds.compute2] :reload-all)
|
||||||
(:use clojure.test)
|
(:use clojure.test)
|
||||||
|
(:require [org.jclouds.ssh-test :as ssh-test])
|
||||||
(:import
|
(:import
|
||||||
org.jclouds.compute.domain.OsFamily
|
org.jclouds.compute.domain.OsFamily
|
||||||
clojure.contrib.condition.Condition
|
clojure.contrib.condition.Condition
|
||||||
java.net.InetAddress))
|
java.net.InetAddress
|
||||||
|
org.jclouds.scriptbuilder.domain.Statements
|
||||||
|
org.jclouds.compute.options.TemplateOptions
|
||||||
|
org.jclouds.compute.options.TemplateOptions$Builder
|
||||||
|
org.jclouds.domain.Credentials
|
||||||
|
java.util.NoSuchElementException
|
||||||
|
))
|
||||||
|
|
||||||
(defmacro with-private-vars [[ns fns] & tests]
|
(defmacro with-private-vars [[ns fns] & tests]
|
||||||
"Refers private fns from ns and runs tests in context. From users mailing
|
"Refers private fns from ns and runs tests in context. From users mailing
|
||||||
|
@ -34,7 +41,7 @@ list, Alan Dipert and MeikelBrandmeyer."
|
||||||
(deftest os-families-test
|
(deftest os-families-test
|
||||||
(is (some #{"centos"} (map str (os-families)))))
|
(is (some #{"centos"} (map str (os-families)))))
|
||||||
|
|
||||||
(def *compute* (compute-service "stub" "" ""))
|
(def *compute* (compute-service "stub" "" "" :extensions [(ssh-test/ssh-test-client ssh-test/no-op-ssh-client)]))
|
||||||
|
|
||||||
(defn clean-stub-fixture
|
(defn clean-stub-fixture
|
||||||
"This should allow basic tests to easily be run with another service."
|
"This should allow basic tests to easily be run with another service."
|
||||||
|
@ -85,6 +92,17 @@ list, Alan Dipert and MeikelBrandmeyer."
|
||||||
(is (= 0 (count (nodes-with-details-matching *compute* #(and (running? %) (localhost? %))))))
|
(is (= 0 (count (nodes-with-details-matching *compute* #(and (running? %) (localhost? %))))))
|
||||||
(is (= 1 (count (nodes-with-details-matching *compute* #(and (running? %) (not (localhost? %))))))))
|
(is (= 1 (count (nodes-with-details-matching *compute* #(and (running? %) (not (localhost? %))))))))
|
||||||
|
|
||||||
|
(deftest run-script-on-nodes-matching-test
|
||||||
|
(let [echo (Statements/exec "echo hello")
|
||||||
|
script-options (.. (TemplateOptions$Builder/overrideCredentialsWith (Credentials. "user" "password"))
|
||||||
|
(runAsRoot false)
|
||||||
|
(wrapInInitScript false))
|
||||||
|
pred #(= (.getGroup %) "scriptednode")]
|
||||||
|
(is (create-node *compute* "scriptednode" (build-template *compute* {})))
|
||||||
|
(is (run-script-on-nodes-matching *compute* pred echo script-options))
|
||||||
|
(is (thrown? NoSuchElementException
|
||||||
|
(run-script-on-nodes-matching *compute* #(= (.getGroup %) "nonexistingnode") echo script-options)))))
|
||||||
|
|
||||||
(deftest build-template-test
|
(deftest build-template-test
|
||||||
(let [service (compute-service "stub" "user" "password")]
|
(let [service (compute-service "stub" "user" "password")]
|
||||||
(testing "nullary"
|
(testing "nullary"
|
||||||
|
|
|
@ -17,6 +17,16 @@
|
||||||
; ====================================================================
|
; ====================================================================
|
||||||
;
|
;
|
||||||
|
|
||||||
|
(ns org.jclouds.ssh-test
|
||||||
|
(:require
|
||||||
|
[clojure.contrib.logging :as logging])
|
||||||
|
(:import
|
||||||
|
org.jclouds.ssh.SshClient
|
||||||
|
org.jclouds.domain.Credentials
|
||||||
|
org.jclouds.io.Payload
|
||||||
|
org.jclouds.net.IPSocket
|
||||||
|
org.jclouds.compute.domain.ExecResponse))
|
||||||
|
|
||||||
(defn instantiate [impl-class & args]
|
(defn instantiate [impl-class & args]
|
||||||
(let [constructor (first
|
(let [constructor (first
|
||||||
(filter
|
(filter
|
||||||
|
@ -73,7 +83,12 @@
|
||||||
(^org.jclouds.ssh.SshClient
|
(^org.jclouds.ssh.SshClient
|
||||||
create
|
create
|
||||||
[_ ^IPSocket socket ^String username ^bytes password-or-key]
|
[_ ^IPSocket socket ^String username ^bytes password-or-key]
|
||||||
(factory-fn socket username password-or-key)))
|
(factory-fn socket username password-or-key))
|
||||||
|
(^org.jclouds.ssh.SshClient
|
||||||
|
create
|
||||||
|
[_ ^IPSocket socket ^Credentials credentials]
|
||||||
|
(factory-fn socket (.identity credentials) (.credential credentials)))
|
||||||
|
)
|
||||||
|
|
||||||
(deftype Module
|
(deftype Module
|
||||||
[factory binder]
|
[factory binder]
|
||||||
|
|
Loading…
Reference in New Issue