1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Copyright (c) 2019 PANTHEON.tech and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 # This library defines functions used mainly by "bootstrap" entry scripts.
18 # Generally, the functions assume "common.sh" library has been sourced already.
20 # Keep functions ordered alphabetically, please.
22 # TODO: Add a link to bash style guide.
25 function gather_build () {
28 # - TEST_CODE - String affecting test selection, usually jenkins job name.
29 # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
31 # - DUT - CSIT test/ subdirectory containing suites to execute.
32 # Directories updated:
33 # - ${DOWNLOAD_DIR} - Files needed by tests are gathered here.
35 # - die - Print to stderr and exit, defined in common.sh
36 # - gather_os - Parse os parameter for OS/distro name.
37 # - gather_dpdk, gather_vpp - See their definitions.
38 # Multiple other side effects are possible,
39 # see functions called from here for their current description.
41 # TODO: Separate DUT-from-TEST_CODE from gather-for-DUT,
42 # when the first one becomes relevant for per_patch.
46 pushd "${DOWNLOAD_DIR}" || die "Pushd failed."
47 case "${TEST_CODE}" in
50 # FIXME: Avoid failing on empty ${DOWNLOAD_DIR}.
54 gather_vpp || die "The function should have died on error."
58 gather_dpdk || die "The function should have died on error."
61 die "Unable to identify DUT type from: ${TEST_CODE}"
64 popd || die "Popd failed."
68 function gather_dpdk () {
70 # Ensure latest DPDK archive is downloaded.
73 # - TEST_CODE - The test selection string from environment or argument.
75 # - dpdk archive name to download if TEST_CODE is not time based.
76 # Directories updated:
77 # - ./ - Assumed ${DOWNLOAD_DIR}, dpdk-*.tar.xz is downloaded if not there.
79 # - die - Print to stderr and exit, defined in common.sh
83 dpdk_repo="https://fast.dpdk.org/rel"
84 # Use downloaded packages with specific version
85 if [[ "${TEST_CODE}" == *"daily"* ]] || \
86 [[ "${TEST_CODE}" == *"weekly"* ]] || \
87 [[ "${TEST_CODE}" == *"timed"* ]];
89 echo "Downloading latest DPDK packages from repo..."
90 # URL is not in quotes, calling command from variable keeps them.
91 wget_command=("wget" "--no-check-certificate" "-nv" "-O" "-")
92 wget_command+=("${dpdk_repo}")
93 dpdk_stable_ver="$("${wget_command[@]}" | grep -v "2015"\
94 | grep -Eo 'dpdk-[^\"]+xz' | tail -1)" || {
95 die "Composite piped command failed."
98 echo "Downloading DPDK package of specific version from repo ..."
99 # Downloading DPDK version based on what VPP is using. Currently
100 # it is not easy way to detect from VPP version automatically.
101 dpdk_stable_ver="$(< "${CSIT_DIR}/DPDK_VPP_VER")".tar.xz || {
102 die "Failed to read DPDK VPP version!"
105 # TODO: Use "wget -N" instead checking for file presence?
106 if [[ ! -f "${dpdk_stable_ver}" ]]; then
107 wget -nv --no-check-certificate "${dpdk_repo}/${dpdk_stable_ver}" || {
108 die "Failed to get DPDK package from: ${dpdk_repo}"
114 function gather_vpp () {
117 # - BASH_FUNCTION_DIR - Bash directory with functions.
118 # - TEST_CODE - The test selection string from environment or argument.
119 # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
120 # - CSIT_DIR - Path to existing root of local CSIT git repository.
122 # - VPP_VERSION - VPP stable version under test.
124 # - ${CSIT_DIR}/DPDK_STABLE_VER - DPDK version to use
125 # by csit-vpp not-timed jobs.
126 # - ${CSIT_DIR}/${VPP_VER_FILE} - Ubuntu VPP version to use.
127 # - ../*vpp*.deb|rpm - Relative to ${DOWNLOAD_DIR}, copied for vpp-csit jobs.
128 # Directories updated:
129 # - ${DOWNLOAD_DIR}, vpp-*.deb files are copied here for vpp-csit jobs.
130 # - ./ - Assumed ${DOWNLOAD_DIR}, *vpp*.deb|rpm files
131 # are downloaded here for csit-vpp.
133 # - die - Print to stderr and exit, defined in common_functions.sh
134 # Bash scripts executed:
135 # - ${CSIT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh
136 # - Should download and extract requested files to ./.
140 case "${TEST_CODE}" in
142 # Use downloaded packages with specific version.
143 if [[ "${TEST_CODE}" == *"daily"* ]] || \
144 { [[ "${TEST_CODE}" == *"weekly"* ]] && \
145 [[ "${TEST_CODE}" != *"device"* ]]; } || \
146 [[ "${TEST_CODE}" == *"semiweekly"* ]] || \
147 [[ "${TEST_CODE}" == *"hourly"* ]];
149 warn "Downloading latest VPP packages from Packagecloud."
151 warn "Downloading stable VPP packages from Packagecloud."
152 VPP_VERSION="$(<"${CSIT_DIR}/${VPP_VER_FILE}")" || {
153 die "Read VPP stable version failed."
156 source "${BASH_FUNCTION_DIR}/artifacts.sh" || die "Source failed."
157 download_artifacts || die
160 # Use locally built packages.
161 mv "${DOWNLOAD_DIR}"/../*vpp*."${PKG_SUFFIX}" "${DOWNLOAD_DIR}"/ || {
162 die "Move command failed."
166 die "Unable to identify job type from: ${TEST_CODE}"