1 # lib_csit.sh - Docker build script CSIT library.
4 # Copyright (c) 2020 Cisco and/or its affiliates.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Don't import more than once.
18 if [ -n "$(alias lib_csit_imported 2> /dev/null)" ] ; then
21 alias lib_csit_imported=true
23 export CIMAN_DOCKER_SCRIPTS="${CIMAN_DOCKER_SCRIPTS:-$(dirname $BASH_SOURCE)}"
24 . $CIMAN_DOCKER_SCRIPTS/lib_common.sh
25 . $CIMAN_DOCKER_SCRIPTS/lib_apt.sh
26 . $CIMAN_DOCKER_SCRIPTS/lib_yum.sh
27 . $CIMAN_DOCKER_SCRIPTS/lib_dnf.sh
29 csit_checkout_branch_for_vpp() {
31 local csit_dir="$DOCKER_CSIT_DIR"
32 local csit_bash_function_dir="$csit_dir/resources/libraries/bash/function"
34 # import checkout_csit_for_vpp() if not defined
35 set +e && [ -z "$(declare -f checkout_csit_for_vpp)" ] \
36 && source $csit_bash_function_dir/branch.sh
37 CSIT_DIR=$(csit_dir) checkout_csit_for_vpp $vpp_branch
39 csit_branch="$(git branch | grep -e '^*' | mawk '{print $2}')"
42 csit_install_packages() {
44 local branchname="$(echo $branch | sed -e 's,/,_,')"
45 local csit_dir="$DOCKER_CSIT_DIR"
46 local csit_ansible_dir="$csit_dir/resources/tools/testbed-setup/ansible"
47 local bld_log="$DOCKER_BUILD_LOG_DIR/$FDIOTOOLS_IMAGENAME"
48 bld_log="${bld_log}-$branchname-csit_install_packages-bld.log"
52 # Install PyYAML required by dbld_csit_find_ansible_packages.py
54 # Note: Conditional install due to Bug 1696324 -
55 # Update to python3.6 breaks PyYAML dependencies
56 # Status: CLOSED CANTFIX
57 # https://bugzilla.redhat.com/show_bug.cgi?id=1696324
58 if [ "$OS_NAME" = "centos-8" ] ; then
59 dnf_install_packages python3-pyyaml
61 python3 -m pip install pyyaml
64 # NOTE: the CSIT baseline os is implicitly pinned to ubuntu 18.04
65 # so only gather packages from ansible for that OS.
66 if [ "$OS_NAME" = "ubuntu-18.04" ] ; then
67 # Not in double quotes to let bash remove newline characters
68 local exclude_roles="-e calibration -e kernel -e mellanox -e nomad"
69 [ "$OS_ARCH" = "aarch64" ] && exclude_roles="$exclude_roles -e iperf"
70 local yaml_files=$(grep -r packages_by $csit_ansible_dir | cut -d: -f1 | sort -u | grep -v $exclude_roles)
71 packages=$(dbld_csit_find_ansible_packages.py --$OS_ID --$OS_ARCH $yaml_files)
73 if [ -n "$packages" ] ; then
76 apt_install_packages $packages
79 apt_install_packages $packages
82 yum_install_packages $packages
85 dnf_install_packages $packages
88 echo "Unsupported OS ($OS_ID): CSIT packages NOT INSTALLED!"
98 # ensure PS1 is defined (used by virtualenv activate script)
100 local csit_dir="$DOCKER_CSIT_DIR"
101 local csit_bash_function_dir="$csit_dir/resources/libraries/bash/function"
103 if [ -f "$csit_dir/VPP_REPO_URL" ] \
104 && [ -f "$csit_dir/requirements.txt" ]; then
106 local branchname="$(echo $branch | sed -e 's,/,_,')"
107 local bld_log="$DOCKER_BUILD_LOG_DIR"
108 bld_log="${bld_log}/$FDIOTOOLS_IMAGENAME-$branchname-csit_pip_cache-bld.log"
110 export PYTHONPATH=$csit_dir
113 description="Install CSIT python packages from $branch branch"
114 echo_log " Starting $description..."
115 [ -n "$(declare -f deactivate)" ] && deactivate
117 local setup_framework=$csit_dir/resources/libraries/python/SetupFramework.py
118 if [ -n "$(grep pip3 $setup_framework)" ]; then
120 VENV_OPTS="-p python3"
122 rm -rf $PYTHONPATH/env
123 virtualenv $VENV_OPTS $PYTHONPATH/env
124 . $PYTHONPATH/env/bin/activate
125 if [ "$OS_ARCH" = "aarch64" ] ; then
126 local numpy_ver="$(grep numpy $PYTHONPATH/requirements.txt)"
127 [ -n "$numpy_ver" ] && $PIP install --upgrade $numpy_ver 2>&1 \
130 $PIP install --upgrade -r $PYTHONPATH/requirements.txt 2>&1 \
132 $PIP install --upgrade -r $PYTHONPATH/tox-requirements.txt 2>&1 \
134 if [ "$OS_ARCH" = "x86_64" ] ; then
135 local PRESENTATION_DIR="$PYTHONPATH/resources/tools/presentation"
136 # TODO: Remove condition when 19.08 is deprecated.
137 if [ -n "$(grep -r python3 $PRESENTATION_DIR)" ] && [ "$PIP" = "pip3" ] ; then
138 $PIP install --upgrade -r $PRESENTATION_DIR/requirements.txt 2>&1 \
141 echo_log "Skipping 'pip install $PRESENTATION_DIR/requirements.txt' in branch $branch!"
146 rm -rf $PYTHONPATH/env
148 # Virtualenv version is pinned in common.sh in newer csit branches.
149 # (note: xargs removes leading/trailing spaces)
150 install_virtualenv="$(grep 'virtualenv' $csit_bash_function_dir/common.sh | grep pip | grep install | cut -d'|' -f1 | xargs)"
154 echo_log " Completed $description!"
156 echo_log "ERROR: Missing or invalid CSIT_DIR: '$csit_dir'!"
161 docker_build_setup_csit() {
162 if [ ! -d "$DOCKER_CSIT_DIR" ] ; then
163 echo_log "Cloning CSIT into $DOCKER_CSIT_DIR..."
164 git clone -q https://gerrit.fd.io/r/csit $DOCKER_CSIT_DIR
166 clean_git_repo $DOCKER_CSIT_DIR