Skip to content

Commit 23f9677

Browse files
committed
Allow to test Tarantool version built from source code
Option --version now accepts GIT hash commit that used to build Tarantool binary for testing.
1 parent 84619cc commit 23f9677

File tree

2 files changed

+135
-8
lines changed

2 files changed

+135
-8
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ To get started, try
3737
lein run test --nodes-file nodes
3838
```
3939

40-
To test a particular major version of Tarantool, pass `--version`. You may also want
41-
to provide a custom `--time-limit` for each test. To run several iterations of
42-
each test, use `--test-count`. A thorough test run might look like:
40+
To test a particular version of Tarantool, pass `--version`. It accepts two
41+
kind of versions: branch version (for example 2.2) to use a latest version
42+
of package from this branch and GIT commit hash to use version built on this
43+
commit. You may also want to provide a custom `--time-limit` for each test. To
44+
run several iterations of each test, use `--test-count`. A thorough test run
45+
might look like:
4346

4447
```
4548
lein run test --username root --nodes-file nodes --version 2.5 --time-limit 600 --test-count 10

src/tarantool/db.clj

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@
44
[clojure.java.io :as io]
55
[next.jdbc :as j]
66
[next.jdbc.connection :as connection]
7+
[jepsen.os.debian :as debian]
8+
[jepsen.control.util :as cu]
79
[jepsen [core :as jepsen]
810
[control :as c]
9-
[db :as db]]
11+
[db :as db]
12+
[util :as util :refer [parse-long]]]
1013
[slingshot.slingshot :refer [try+ throw+]]))
1114

1215
(def data-dir "/var/lib/tarantool/jepsen")
1316
(def logfile "/var/log/tarantool/jepsen.log")
1417
(def dir "/opt/tarantool")
18+
(def tarantool-repo
19+
"Where can we clone tarantool from?"
20+
"https://github.com/tarantool/tarantool")
1521

1622
(def installer-name "installer.sh")
1723
(def installer-url (str "https://tarantool.io/" installer-name))
1824

25+
(def build-dir
26+
"A remote directory to clone project and compile."
27+
"/tmp/jepsen/build")
28+
29+
(def build-file
30+
"A file we create to track the last built version; speeds up compilation."
31+
"jepsen-built-version")
32+
1933
(defn node-uri
2034
"An uri for connecting to a node on a particular port."
2135
[node port]
@@ -34,17 +48,123 @@
3448
(str "'" (peer-uri node) "'")))
3549
(str/join ",")))
3650

37-
(defn install!
51+
(defn install-build-prerequisites!
52+
"Installs prerequisite packages for building Tarantool."
53+
[]
54+
(info "Install prerequisites")
55+
(debian/install [:autoconf
56+
:automake
57+
:build-essential
58+
:cmake
59+
:coreutils
60+
:libtool
61+
:libreadline-dev
62+
:libncurses5-dev
63+
:libssl-dev
64+
:libunwind-dev
65+
:libicu-dev
66+
:make
67+
:sed
68+
:zlib1g-dev]))
69+
70+
(defn checkout-repo!
71+
"Checks out a repo at the given version into a directory in build/ named
72+
`dir`. Returns the path to the build directory."
73+
[repo-url dir version]
74+
(let [full-dir (str build-dir "/" dir)]
75+
(when-not (cu/exists? full-dir)
76+
(c/cd build-dir
77+
(info "Cloning into" full-dir)
78+
(c/exec :mkdir :-p build-dir)
79+
(c/exec :git :clone repo-url dir)))
80+
81+
(c/cd full-dir
82+
(try+ (c/exec :git :checkout version)
83+
(catch [:exit 1] e
84+
(if (re-find #"pathspec .+ did not match any file" (:err e))
85+
(do ; Ah, we're out of date
86+
(c/exec :git :fetch)
87+
(c/exec :git :checkout version))
88+
(throw+ e)))))
89+
90+
(c/cd full-dir
91+
(c/exec :git :submodule :update :--init :--recursive))
92+
93+
full-dir))
94+
95+
(def build-locks
96+
"We use these locks to prevent concurrent builds."
97+
(util/named-locks))
98+
99+
(defmacro with-build-version
100+
"Takes a test, a repo name, a version, and a body. Builds the repo by
101+
evaluating body, only if it hasn't already been built. Takes out a lock on a
102+
per-repo basis to prevent concurrent builds. Remembers what version was last
103+
built by storing a file in the repo directory. Returns the result of body if
104+
evaluated, or the build directory."
105+
[node repo-name version & body]
106+
`(util/with-named-lock build-locks [~node ~repo-name]
107+
(let [build-file# (str build-dir "/" ~repo-name "/" build-file)]
108+
(if (try+ (= (str ~version) (c/exec :cat build-file#))
109+
(catch [:exit 1] e# ; Not found
110+
false))
111+
; Already built
112+
(str build-dir "/" ~repo-name)
113+
; Build
114+
(let [res# (do ~@body)]
115+
; Log version
116+
(c/exec :echo ~version :> build-file#)
117+
res#)))))
118+
119+
(defn build-tarantool!
120+
"Build Tarantool from scratch"
121+
[test node]
122+
(let [version (:version test)]
123+
(with-build-version node "tarantool" version
124+
(let [dir (checkout-repo! tarantool-repo "tarantool" version)]
125+
(install-build-prerequisites!)
126+
(info "Building Tarantool" (:version test))
127+
(c/cd dir
128+
(c/exec :cmake :-DWITH_SYSTEMD:BOOL=ON
129+
:-DCMAKE_BUILD_TYPE=RelWithDebInfo
130+
:-DENABLE_DIST:BOOL=ON
131+
:-DENABLE_BACKTRACE:BOOL=ON
132+
"-DCMAKE_INSTALL_LOCALSTATEDIR:PATH=/var"
133+
"-DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc"
134+
:.)
135+
(c/exec :make :-j2)
136+
(c/exec :make :install))
137+
dir)))
138+
(c/su
139+
(c/exec :adduser
140+
:--system
141+
:--group
142+
:--quiet
143+
:--home "/var/spool/tarantool"
144+
:--no-create-home
145+
:--disabled-login
146+
:tarantool)
147+
(c/exec :install :-d :-otarantool :-gadm :-m2750 "/var/log/tarantool")
148+
(c/exec :install :-d :-otarantool :-gadm :-m2750 "/var/run/tarantool")
149+
(c/exec :install :-d :-otarantool :-gadm :-m2750 "/var/lib/tarantool")))
150+
151+
(defn install-package!
38152
"Installation using installer.sh"
39153
[node version]
40-
(info "Install Tarantool version" version)
154+
(info "Install Tarantool package version" version)
41155
(c/su
42156
(c/exec :curl :-O :-L "https://tarantool.io/installer.sh")
43157
(c/exec :chmod :+x "./installer.sh")
44158
(c/exec (str "VER=" version) "./installer.sh")
45-
(c/exec :usermod :-a :-G :tarantool :ubuntu)
46159
(c/su (c/exec :systemctl :stop "tarantool@example"))))
47160

161+
(defn install!
162+
"Tarantool installation, accepts branch version (like 2.6) or commit hash"
163+
[node version]
164+
(if (re-matches #"\d+\.\d+" version)
165+
(install-package! node version)
166+
(build-tarantool! node version)))
167+
48168
(defn start!
49169
"Starts tarantool service"
50170
[test node]
@@ -81,12 +201,16 @@
81201
[test node]
82202
(let [read-only (not (is-primary? test node))]
83203
(info "Joining" node "as" (if (true? read-only) "replica" "leader"))
204+
(c/exec :mkdir :-p "/etc/tarantool/instances.available")
205+
(c/exec :mkdir :-p "/etc/tarantool/instances.enabled")
206+
(c/exec :usermod :-a :-G :tarantool :ubuntu)
84207
(c/exec :echo (-> "tarantool/jepsen.lua" io/resource slurp
85208
(str/replace #"%TARANTOOL_REPLICATION%" (replica-set test))
86209
(str/replace #"%TARANTOOL_IS_READ_ONLY%" (boolean-to-str read-only))
87210
(str/replace #"%TARANTOOL_SINGLE_MODE%" (boolean-to-str (:single-mode test)))
88211
(str/replace #"%TARANTOOL_DATA_ENGINE%" (:engine test)))
89-
:> "/etc/tarantool/instances.enabled/jepsen.lua")))
212+
:> "/etc/tarantool/instances.enabled/jepsen.lua")
213+
(c/exec :cp "/etc/tarantool/instances.enabled/jepsen.lua" "/etc/tarantool/instances.available")))
90214

91215
(defn is-read-only
92216
[conn]

0 commit comments

Comments
 (0)