Remove usage of vpp-ext-deps package
[csit.git] / resources / libraries / bash / function / per_patch.sh
1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 set -exuo pipefail
15
16 # This library defines functions used mainly by "per_patch_perf.sh" entry script.
17 # Generally, the functions assume "common.sh" library has been sourced already.
18
19 # Keep functions ordered alphabetically, please.
20
21 # TODO: Add a link to bash style guide.
22
23
24 function archive_parse_test_results () {
25
26     set -exuo pipefail
27
28     # Arguments:
29     # - ${1}: Directory to archive to. Required. Parent has to exist.
30     # Variables read:
31     # - ARCHIVE_DIR - Path to where robot result files are created in.
32     # - VPP_DIR - Path to existing directory, root for to relative paths.
33     # Directories updated:
34     # - ${1} - Created, and robot and parsing files are moved/created there.
35     # Functions called:
36     # - die - Print to stderr and exit, defined in common.sh
37     # - parse_bmrr_results - See definition in this file.
38
39     cd "${VPP_DIR}" || die "Change directory command failed."
40     target="$(readlink -f "$1")"
41     mkdir -p "${target}" || die "Directory creation failed."
42     for filename in "output.xml" "log.html" "report.html"; do
43         mv "${ARCHIVE_DIR}/${filename}" "${target}/${filename}" || {
44             die "Attempt to move '${filename}' failed."
45         }
46     done
47     parse_bmrr_results "${target}" || {
48         die "The function should have died on error."
49     }
50 }
51
52
53 function build_vpp_ubuntu_amd64 () {
54
55     set -exuo pipefail
56
57     # TODO: Make sure whether this works on other distros/archs too.
58
59     # Arguments:
60     # - ${1} - String identifier for echo, can be unset.
61     # Variables read:
62     # - VPP_DIR - Path to existing directory, parent to accessed directories.
63     # Directories updated:
64     # - ${VPP_DIR} - Whole subtree, many files (re)created by the build process.
65     # - ${VPP_DIR}/build-root - Final build artifacts for CSIT end up here.
66     # - ${VPP_DIR}/dpdk - The dpdk artifact is built, but moved to build-root/.
67     # Functions called:
68     # - die - Print to stderr and exit, defined in common.sh
69
70     cd "${VPP_DIR}" || die "Change directory command failed."
71     echo 'Building using "make build-root/vagrant/build.sh"'
72     # TODO: Do we want to support "${DRYRUN}" == "True"?
73     make UNATTENDED=yes install-dep || die "Make install-dep failed."
74     # The per_patch script calls this function twice, first for the new commit,
75     # then for its parent commit. On Jenkins, no dpdk is installed at first,
76     # locally it might have been installed. New dpdk is installed second call.
77     # If make detects installed vpp-ext-deps with matching version,
78     # it skips building vpp-ext-deps entirely.
79     # On the other hand, if parent uses different dpdk version,
80     # the new vpp-ext-deps is built, but the old one is not removed
81     # from the build directory if present. (Further functions move both,
82     # and during test dpkg would decide randomly which version gets installed.)
83     # As per_patch is too dumb (yet) to detect any of that,
84     # the only safe solution is to clean build directory and force rebuild.
85     # TODO: Make this function smarter and skip DPDK rebuilds if possible.
86     cmd=("dpkg-query" "--showformat='$${Version}'" "--show" "vpp-ext-deps")
87     installed_deb_ver="$(sudo "${cmd[@]}" || true)"
88     if [[ -n "${installed_deb_ver}" ]]; then
89         sudo dpkg --purge "vpp-ext-deps" || {
90             die "DPDK package uninstalation failed."
91         }
92     fi
93     make UNATTENDED=yes install-ext-deps || {
94         die "Make install-ext-deps failed."
95     }
96     build-root/vagrant/"build.sh" || die "Vagrant VPP build script failed."
97     echo "*******************************************************************"
98     echo "* VPP ${1-} BUILD SUCCESSFULLY COMPLETED" || {
99         die "Argument not found."
100     }
101     echo "*******************************************************************"
102 }
103
104
105 function compare_test_results () {
106
107     set -exuo pipefail
108
109     # Variables read:
110     # - VPP_DIR - Path to directory with VPP git repo (at least built parts).
111     # - ARCHIVE_DIR - Path to where robot result files are created in.
112     # - PYTHON_SCRIPTS_DIR - Path to directory holding comparison utility.
113     # Directories recreated:
114     # - csit_parent - Sibling to csit directory, for holding results
115     #   of parent build.
116     # Functions called:
117     # - die - Print to stderr and exit, defined in common.sh
118     # - parse_bmrr_results - See definition in this file.
119     # Exit code:
120     # - 0 - If the comparison utility sees no regression (nor data error).
121     # - 1 - If the comparison utility sees a regression (or data error).
122
123     cd "${VPP_DIR}" || die "Change directory operation failed."
124     # Reusing CSIT main virtualenv.
125     pip install -r "${PYTHON_SCRIPTS_DIR}/perpatch_requirements.txt" || {
126         die "Perpatch Python requirements installation failed."
127     }
128     python "${PYTHON_SCRIPTS_DIR}/compare_perpatch.py"
129     # The exit code determines the vote result.
130 }
131
132
133 function download_builds () {
134
135     set -exuo pipefail
136
137     # This is mostly useful only for Sandbox testing, to avoid recompilation.
138     #
139     # Arguments:
140     # - ${1} - URL to download VPP builds from.
141     # Variables read:
142     # - VPP_DIR - Path to WORKSPACE, parent of created directories.
143     # Directories created:
144     # - archive - Ends up empty, not to be confused with ${ARCHIVE_DIR}.
145     # - build_new - Holding built artifacts of the patch under test (PUT).
146     # - built_parent - Holding built artifacts of parent of PUT.
147     # Functions called:
148     # - die - Print to stderr and exit, defined in common.sh
149
150     cd "${VPP_DIR}" || die "Change directory operation failed."
151     rm -rf "build-root" "build_parent" "build_new" "archive" "csit_new" || {
152         die "Directory removal failed."
153     }
154     wget -N --progress=dot:giga "${1}" || die "Wget download failed."
155     unzip "archive.zip" || die "Archive extraction failed."
156     mv "archive/build_parent" ./ || die "Move operation failed."
157     mv "archive/build_new" ./ || die "Move operation failed."
158 }
159
160
161 function initialize_csit_dirs () {
162
163     set -exuo pipefail
164
165     # This could be in prepare_test, but download_builds also needs this.
166     #
167     # Variables read:
168     # - VPP_DIR - Path to WORKSPACE, parent of created directories.
169     # Directories created:
170     # - csit_new - Holding test results of the patch under test (PUT).
171     # - csit_parent - Holding test results of parent of PUT.
172     # Functions called:
173     # - die - Print to stderr and exit, defined in common.sh
174
175     cd "${VPP_DIR}" || die "Change directory operation failed."
176     rm -rf "csit_new" "csit_parent" || {
177         die "Directory deletion failed."
178     }
179     mkdir -p "csit_new" "csit_parent" || {
180         die "Directory creation failed."
181     }
182 }
183
184
185 function parse_bmrr_results () {
186
187     set -exuo pipefail
188
189     # Currently "parsing" is just two greps.
190     # TODO: Re-use PAL parsing code, make parsing more general and centralized.
191     #
192     # Arguments:
193     # - ${1} - Path to (existing) directory holding robot output.xml result.
194     # Files read:
195     # - output.xml - From argument location.
196     # Files updated:
197     # - results.txt - (Re)created, in argument location.
198     # Functions called:
199     # - die - Print to stderr and exit, defined in common.sh
200
201     rel_dir="$(readlink -e "${1}")" || die "Readlink failed."
202     in_file="${rel_dir}/output.xml"
203     out_file="${rel_dir}/results.txt"
204     # TODO: Do we need to check echo exit code explicitly?
205     echo "Parsing ${in_file} putting results into ${out_file}"
206     echo "TODO: Re-use parts of PAL when they support subsample test parsing."
207     pattern='Maximum Receive Rate trial results in packets'
208     pattern+=' per second: .*\]</status>'
209     grep -o "${pattern}" "${in_file}" | grep -o '\[.*\]' > "${out_file}" || {
210         die "Some parsing grep command has failed."
211     }
212 }
213
214
215 function prepare_build_parent () {
216
217     set -exuo pipefail
218
219     # Variables read:
220     # - VPP_DIR - Path to existing directory, parent to accessed directories.
221     # Directories read:
222     # - build-root - Existing directory with built VPP artifacts (also DPDK).
223     # Directories updated:
224     # - ${VPP_DIR} - A local git repository, parent commit gets checked out.
225     # - build_new - Old contents removed, content of build-root copied here.
226     # Functions called:
227     # - die - Print to stderr and exit, defined in common.sh
228
229     cd "${VPP_DIR}" || die "Change directory operation failed."
230     rm -rf "build_new" || die "Remove operation failed."
231     mkdir -p "build_new" || die "Directory creation failed."
232     mv "build-root"/*".deb" "build_new"/ || die "Move operation failed."
233     # The previous build could have left some incompatible leftovers,
234     # e.g. DPDK artifacts of different version (in build/external).
235     # Also, there usually is a copy of dpdk artifact in build-root.
236     git clean -dffx "build"/ "build-root"/ || die "Git clean operation failed."
237     # Finally, check out the parent commit.
238     git checkout HEAD~ || die "Git checkout operation failed."
239     # Display any other leftovers.
240     git status || die "Git status operation failed."
241 }
242
243
244 function prepare_test () {
245
246     set -exuo pipefail
247
248     # Variables read:
249     # - VPP_DIR - Path to existing directory, parent of accessed directories.
250     # Directories read:
251     # - build-root - Existing directory with built VPP artifacts (also DPDK).
252     # Directories updated:
253     # - build_parent - Old directory removed, build-root debs moved here.
254     # Functions called:
255     # - die - Print to stderr and exit, defined in common.sh
256
257     cd "${VPP_DIR}" || die "Change directory operation failed."
258     rm -rf "build_parent" || die "Remove failed."
259     mkdir -p "build_parent" || die "Directory creation operation failed."
260     mv "build-root"/*".deb" "build_parent"/ || die "Move operation failed."
261 }
262
263
264 function select_build () {
265
266     set -exuo pipefail
267
268     # Arguments:
269     # - ${1} - Path to directory to copy VPP artifacts from. Required.
270     # Variables read:
271     # - DOWNLOAD_DIR - Path to directory where Robot takes builds to test from.
272     # - VPP_DIR - Path to existing directory, root for relative paths.
273     # Directories read:
274     # - ${1} - Existing directory with built new VPP artifacts (and DPDK).
275     # Directories updated:
276     # - ${DOWNLOAD_DIR} - Old content removed, .deb files from ${1} copied here.
277     # Functions called:
278     # - die - Print to stderr and exit, defined in common.sh
279
280     cd "${VPP_DIR}" || die "Change directory operation failed."
281     source_dir="$(readlink -e "$1")"
282     rm -rf "${DOWNLOAD_DIR}"/* || die "Cleanup of download dir failed."
283     cp "${source_dir}"/*".deb" "${DOWNLOAD_DIR}" || die "Copy operation failed."
284     # TODO: Is there a nice way to create symlinks,
285     #   so that if job fails on robot, results can be archived?
286 }
287
288
289 function set_perpatch_dut () {
290
291     set -exuo pipefail
292
293     # Variables set:
294     # - DUT - CSIT test/ subdirectory containing suites to execute.
295
296     # TODO: Detect DUT from job name, when we have more than just VPP perpatch.
297
298     DUT="vpp"
299 }
300
301
302 function set_perpatch_vpp_dir () {
303
304     set -exuo pipefail
305
306     # Variables read:
307     # - CSIT_DIR - Path to existing root of local CSIT git repository.
308     # Variables set:
309     # - VPP_DIR - Path to existing root of local VPP git repository.
310     # Functions called:
311     # - die - Print to stderr and exit, defined in common.sh
312
313     # In perpatch, CSIT is cloned inside VPP clone.
314     VPP_DIR="$(readlink -e "${CSIT_DIR}/..")" || die "Readlink failed."
315 }