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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # This library defines functions used mainly by "bootstrap" entry scripts.
17 # Generally, the functions assume "common.sh" library has been sourced already.
19 # Keep functions ordered alphabetically, please.
21 # TODO: Add a link to bash style guide.
24 function gather_build () {
29 # - TEST_CODE - String affecting test selection, usually jenkins job name.
30 # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
32 # - DUT - CSIT test/ subdirectory containing suites to execute.
33 # Directories updated:
34 # - ${DOWNLOAD_DIR} - Files needed by tests are gathered here.
36 # - die - Print to stderr and exit, defined in common.sh
37 # - gather_dpdk, gather_vpp, gather_ligato - 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.
44 pushd "${DOWNLOAD_DIR}" || die "Pushd failed."
45 case "${TEST_CODE}" in
48 # FIXME: Avoid failing on empty ${DOWNLOAD_DIR}.
52 gather_vpp || die "The function should have died on error."
56 gather_ligato || die "The function should have died on error."
60 gather_dpdk || die "The function should have died on error."
63 die "Unable to identify DUT type from: ${TEST_CODE}"
66 popd || die "Popd failed."
70 function gather_dpdk () {
74 # Ensure latest DPDK archive is downloaded.
77 # - TEST_CODE - The test selection string from environment or argument.
79 # - dpdk archive name to download if TEST_CODE is not time based.
80 # Directories updated:
81 # - ./ - Assumed ${DOWNLOAD_DIR}, dpdk-*.tar.xz is downloaded if not there.
83 # - die - Print to stderr and exit, defined in common.sh
85 dpdk_repo="https://fast.dpdk.org/rel"
86 # Use downloaded packages with specific version
87 if [[ "${TEST_CODE}" == *"daily"* ]] || \
88 [[ "${TEST_CODE}" == *"weekly"* ]] || \
89 [[ "${TEST_CODE}" == *"timed"* ]];
91 echo "Downloading latest DPDK packages from repo..."
92 # URL is not in quotes, calling command from variable keeps them.
93 wget_command=("wget" "--no-check-certificate" "-nv" "-O" "-")
94 wget_command+=("${dpdk_repo}")
95 dpdk_stable_ver="$("${wget_command[@]}" | grep -v "2015"\
96 | grep -Eo 'dpdk-[^\"]+xz' | tail -1)" || {
97 die "Composite piped command failed."
100 echo "Downloading DPDK packages of specific version from repo..."
101 # TODO: Can we autodetect this based on what CSIT-stable VPP uses?
102 dpdk_stable_ver="dpdk-18.11.tar.xz"
104 # TODO: Use "wget -N" instead checking for file presence?
105 if [[ ! -f "${dpdk_stable_ver}" ]]; then
106 wget -nv --no-check-certificate "${dpdk_repo}/${dpdk_stable_ver}" || {
107 die "Failed to get DPDK package from: ${dpdk_repo}"
113 function gather_ligato () {
117 # Pull & extract docker image ligato/vpp-agent and put it to
120 # Access rights needed for:
121 # - "sudo" without password.
123 # - "docker" commands have everything they needs.
125 # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
126 # - CSIT_DIR - Path to existing root of local CSIT git repository.
128 # - ${CSIT_DIR}/VPP_AGENT_STABLE_VER - Vpp agent version to use.
129 # Directories updated:
130 # - ${DOWNLOAD_DIR} - Docker image stored.
131 # System consequences:
132 # - Docker package is installed.
133 # - Presumably dockerd process is started.
134 # Other hardcoded values:
135 # - Docker image file name to download and install.
137 # - die - Print to stderr and exit, defined in common_functions.sh
139 vpp_agent_ver="$(< "${CSIT_DIR}/VPP_AGENT_STABLE_VER")" || {
140 die "Failed to read vpp-agent stable VPP version!"
144 curl -fsSL https://get.docker.com | sudo bash || {
145 die "Failed to install Docker package!"
148 pushd "${DOWNLOAD_DIR}" || die "Change directory failed!"
149 # Download vpp_agent docker image.
150 sudo docker pull "${vpp_agent_ver}" || die "Docker pull failed!"
151 # Export Docker image.
152 sudo docker save "${vpp_agent_ver}" | gzip > "prod_vpp_agent.tar.gz" || {
153 die "Failed to save Docker image!"
155 popd || die "Change directory failed!"
159 function gather_vpp () {
164 # - BASH_FUNCTION_DIR - Bash directory with functions.
165 # - TEST_CODE - The test selection string from environment or argument.
166 # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
167 # - CSIT_DIR - Path to existing root of local CSIT git repository.
169 # - ${CSIT_DIR}/DPDK_STABLE_VER - DPDK version to use
170 # by csit-vpp not-timed jobs.
171 # - ${CSIT_DIR}/VPP_STABLE_VER_UBUNTU - VPP version to use by those.
172 # - ../vpp*.deb - Relative to ${DOWNLOAD_DIR}, copied for vpp-csit jobs.
173 # Directories updated:
174 # - ${DOWNLOAD_DIR}, vpp-*.deb files are copied here for vpp-csit jobs.
175 # - ./ - Assumed ${DOWNLOAD_DIR}, vpp-*.deb files
176 # are downloaded here for csit-vpp.
178 # - die - Print to stderr and exit, defined in common_functions.sh
179 # Bash scripts executed:
180 # - ${CSIT_DIR}/resources/tools/scripts/download_install_vpp_pkgs.sh
181 # - Should download and extract requested files to ./.
183 case "${TEST_CODE}" in
184 # Not csit-vpp as this code is re-used by ligato gathering.
186 # Use downloaded packages with specific version.
187 if [[ "${TEST_CODE}" == *"daily"* ]] || \
188 ([[ "${TEST_CODE}" == *"weekly"* ]] && \
189 [[ "${TEST_CODE}" != *"device"* ]]) || \
190 [[ "${TEST_CODE}" == *"semiweekly"* ]];
192 warn "Downloading latest VPP packages from Packagecloud."
194 warn "Downloading stable VPP packages from Packagecloud."
195 if [[ "${TEST_CODE}" == *"device"* ]];
197 VPP_VERSION="$(<"${CSIT_DIR}/VPP_STABLE_VER_UBUNTU_BIONIC")" || {
198 die "Read VPP stable version failed."
201 VPP_VERSION="$(<"${CSIT_DIR}/VPP_STABLE_VER_UBUNTU")" || {
202 die "Read VPP stable version failed."
206 source "${BASH_FUNCTION_DIR}/artifacts.sh" || die "Source failed."
207 download_artifacts || die
210 # Use locally built packages.
211 mv "${DOWNLOAD_DIR}"/../"vpp"*".deb" "${DOWNLOAD_DIR}"/ || {
212 die "Move command failed."
216 die "Unable to identify job type from: ${TEST_CODE}"