forked from RedHatQE/katello.auto
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conf.clj
208 lines (161 loc) · 8.63 KB
/
conf.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
(ns katello.conf
(:require [clojure.java.io :as io]
[clojure.string :as string]
clojure.tools.cli
selenium-server
[fn.trace :refer [all-fns]]
[deltacloud :as cloud]
katello
[katello.tasks :refer [unique-names]])
(:import [java.io PushbackReader FileNotFoundException]
[java.util.logging Level Logger]))
;;config layer
(def options
[["-h" "--help" "Print usage guide"
:default false :flag true]
["-s" "--server-url" "URL of the Katello server to test. Should use https URL if https is enabled."]
["-u" "--admin-user" "The admin username of the Katello server"
:default "admin"]
["-p" "--admin-password" "The admin password of the Katello server"
:default "admin"]
["-o" "--admin-org" "Name of Katello's admin organization"
:default "ACME_Corporation"]
["-y" "--sync-repo" "The url for a test repo to sync"
:default "http://hudson.rhq.lab.eng.bos.redhat.com/cds/content/nature/1.0/x86_64/rpms/"]
["-m" "--redhat-manifest-url" "URL that points to a Red Hat test manifest"
:default "http://inecas.fedorapeople.org/fakerepos/cds/fake-manifest-syncable.zip"]
["-r" "--redhat-repo-url" "A Red Hat content delivery url to be used with --redhat-manifest-url"
:default "http://hudson.rhq.lab.eng.bos.redhat.com/cds/"]
["-e" "--environments" "A comma separated list of environment names to test with (need not already exist)"
:parse-fn #(seq (string/split % #",")) :default '("Development" "Q-eh") ]
["--deltacloud-url" "A URL to deltacloud API that can be used to provision client machines for tests that require them"]
["--deltacloud-user" "The username to log in to deltacloud api."]
["--deltacloud-password" "The password for the deltacloud-user."]
["--deltacloud-image-id" "The image id to use to provision clients."]
["-a" "--selenium-address" "Address of the selenium server to connect to. eg 'host.com:4444' If none specified, an embedded selenium server is used."]
["-k" "--client-ssh-key" "The location of a (passwordless) ssh private key that can be used to access client machines."
:default (format "%s/.ssh/id_auto_dsa" (System/getProperty "user.home"))]
["-n" "--num-threads" "Number of threads to run tests with"
:parse-fn #(Integer. %) :default 3]
["-b" "--browser-types" "Selenium browser types, eg '*firefox' or '*firefox,*googlechrome' (multiple values only used when threads > 1"
:default ["*firefox"] :parse-fn #(string/split % #",")]
["--locale" "A locale to set the browser to for all the tests (if not set, will default to browser's default. Firefox only. eg 'fr' for french. Note, if using a remote selenium server, that server must already have a profile set up where the profile name equals the locale name."]
["-c" "--config" "Config files (containing a clojure map of config options) to read and overlay other command line options on top of - a list of comma separated places to look - first existing file is used and rest are ignored."
:default ["automation-properties.clj" (format "%s/automation-properties.clj" (System/getProperty "user.home"))]
:parse-fn #(string/split % #",")]
#_("to regenerate the list of test namespaces to trace:"
(require 'katello.tests.suite)
(filter (fn [sym] (-> sym str (.startsWith "katello.tests"))) (loaded-libs)))
["--trace" "Namespaces and functions to trace"
:parse-fn #(->> (string/split % #",") (map symbol) vec)]
["--trace-excludes" "Functions to exclude from tracing"
:parse-fn #(->> (string/split % #",") (map symbol) (into #{}))]
["--sethostname" "URL of a script which can set the hostname of newly created VM"
:default "https://raw.github.com/RedHatQE/jenkins-scripts/master/jenkins/sethostname.sh"]
["--agent-repo" "URL of a .repo file to point to where katello-agent can be installed from."
:default "https://raw.github.com/gist/1978881"]
["--gpg-key" "URL of a GPG-Key"
:default "http://inecas.fedorapeople.org/fakerepos/zoo/RPM-GPG-KEY-dummy-packages-generator"]])
(def defaults (first (apply clojure.tools.cli/cli [] options)))
(def config (atom {}))
(defn trace-list
"Creates a list of functions to trace. Includes all katello
namespaces (except a few functions), and some of the API and
underlying lib namespaces."
[]
(->> (loaded-libs)
(filter (fn [sym] (-> sym str (.startsWith "katello"))))
(concat '(katello.client.provision))
all-fns
(concat '(com.redhat.qe.auto.selenium.selenium/call-sel
clj-http.client/get
clj-http.client/put
clj-http.client/post
clj-http.client/delete)) ;;extra fns to add
(remove #{'katello.notifications/success? ;;fns to remove
'katello.tasks/uniqueify
'katello.tasks/unique-format
'katello.tasks/unique-names
'katello.tasks/uniques-formatted
'katello.tasks/uniqueify-vals
'katello.tasks/timestamps
'katello.tasks/date-string
'katello.tasks/timestamped-seq
'katello.conf/client-defs
'katello.navigation/pages
'katello.menu/pages})
(filter (fn [sym] (->> sym str (re-find #"/pages$") not))))) ;; don't trace eg katello.navigation/pages, katello.organizations/pages etc
(declare ^:dynamic *session-user*
^:dynamic *session-org*
^:dynamic *browsers*
^:dynamic *cloud-conn*
^:dynamic *environments*)
(defn- try-read-configs
"try to read a config from filename, if file doesn't exist, return nil"
[filenames]
(for [f filenames]
(try
(with-open [r (io/reader f)]
(read (PushbackReader. r)))
(catch FileNotFoundException fnfe
nil))) )
(defn init
"Read in properties and set some defaults. This function should be
called before selenium client is created or any tests are run."
[opts]
;;bid adeiu to j.u.l logging
(-> (Logger/getLogger "") (.setLevel Level/OFF))
(swap! config merge defaults opts)
(swap! config merge (->> (:config @config)
try-read-configs
(drop-while nil?)
first))
(let [non-defaults (into {}
(filter (fn [[k v]] (not= v (k defaults)))
opts))]
(swap! config merge non-defaults)) ; merge 2nd time to override anything in
; config files
;; if user didn't specify sel address, start a server and use that
;; address.
(when-not (@config :selenium-address)
(selenium-server/start)
(swap! config assoc :selenium-address "localhost:4444"))
(def ^:dynamic *session-user* (katello/newUser {:name (@config :admin-user)
:password (@config :admin-password)
:email "admin@katello.org"}))
(def ^:dynamic *session-org* (katello/newOrganization {:name (@config :admin-org)}))
(def ^:dynamic *cloud-conn* (when-let [dc-url (@config :deltacloud-url)]
(cloud/connection dc-url
(@config :deltacloud-user)
(@config :deltacloud-password))))
(def ^:dynamic *browsers* (@config :browser-types))
(def ^:dynamic *environments* (for [e (@config :environments)]
(katello/newEnvironment {:name e
:org *session-org*}))))
(def promotion-deletion-lock nil) ;; var to lock on for promotions
(defn no-clients-defined "Blocks a test if no client machines are accessible." [_]
(try
(cloud/instances *cloud-conn*)
[]
(catch Exception e [e])))
(defn client-defs "Return an infinite seq of client instance property definitions."
[basename]
(for [instname (unique-names basename)]
(merge cloud/small-instance-properties
{:name instname
:hwp_memory "512" ;;override to allow RHEL6.3 stock to boot - 256 is too small?
:image_id (@config :deltacloud-image-id)})))
(defmacro with-creds
"Execute body and with the given user and password, all api calls
will use these creds. No explicit logging in/out is done in the
UI."
[user password & body]
`(binding [*session-user* ~user]
~@body))
(defmacro with-org
"Binds *session-org* to a new value within body, all api calls will
use this org. Does not switch the org in the UI - see
katello.organizations/switch for that."
[org-name & body]
`(binding [*session-org* ~org-name]
~@body))