Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 1 | #!/bin/bash -l |
| 2 | # SPDX-License-Identifier: EPL-1.0 |
| 3 | ############################################################################## |
| 4 | # Copyright (c) 2022 The Linux Foundation and others. |
| 5 | # |
| 6 | # All rights reserved. This program and the accompanying materials |
| 7 | # are made available under the terms of the Eclipse Public License v1.0 |
| 8 | # which accompanies this distribution, and is available at |
| 9 | # http://www.eclipse.org/legal/epl-v10.html |
| 10 | ############################################################################## |
| 11 | # vim: sw=4 ts=4 sts=4 et ft=sh : |
| 12 | |
Matthew Watkins | 795671a | 2023-01-04 11:29:33 +0000 | [diff] [blame] | 13 | set -euxo pipefail |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 14 | |
Matthew Watkins | 795671a | 2023-01-04 11:29:33 +0000 | [diff] [blame] | 15 | echo "---> install-robotframework-py3.sh" |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 16 | |
Matthew Watkins | 795671a | 2023-01-04 11:29:33 +0000 | [diff] [blame] | 17 | ### Common variables |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 18 | |
Matthew Watkins | 795671a | 2023-01-04 11:29:33 +0000 | [diff] [blame] | 19 | REQUIRED_PYTHON="3.7.0" |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 20 | |
Matthew Watkins | 795671a | 2023-01-04 11:29:33 +0000 | [diff] [blame] | 21 | ### Common functions |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 22 | |
Matthew Watkins | 795671a | 2023-01-04 11:29:33 +0000 | [diff] [blame] | 23 | # Allows for the comparison of two Python version strings |
| 24 | ver_cmp() |
| 25 | { |
| 26 | local IFS=. |
| 27 | # shellcheck disable=SC2206 |
| 28 | local V1=($1) V2=($2) I |
| 29 | for ((I=0 ; I<${#V1[*]} || I<${#V2[*]} ; I++)) ; do |
| 30 | [[ ${V1[$I]:-0} -lt ${V2[$I]:-0} ]] && echo -1 && return |
| 31 | [[ ${V1[$I]:-0} -gt ${V2[$I]:-0} ]] && echo 1 && return |
| 32 | done |
| 33 | echo 0 |
| 34 | } |
| 35 | # Checks if first version/string is greater than or equal to the second |
| 36 | ver_ge() |
| 37 | { |
| 38 | [[ ! $(ver_cmp "$1" "$2") -eq -1 ]] |
| 39 | } |
| 40 | |
| 41 | ### Main script entry point |
| 42 | |
| 43 | # Check for required Python versions and activate/warn appropriately |
| 44 | # Use PYENV for selecting the latest python version, if available |
| 45 | if [[ -d "/opt/pyenv" ]]; then |
| 46 | echo "Setup pyenv:" |
| 47 | export PYENV_ROOT="/opt/pyenv" |
| 48 | export PATH="$PYENV_ROOT/bin:$PATH" |
| 49 | pyenv versions |
| 50 | if command -v pyenv 1>/dev/null 2>&1; then |
| 51 | eval "$(pyenv init - --no-rehash)" |
| 52 | # Choose the latest numeric Python version from installed list |
| 53 | version=$(pyenv versions --bare | sed '/^[^0-9]/d' |\ |
| 54 | sort -V | tail -n 1) |
| 55 | pyenv local "${version}" |
| 56 | fi |
| 57 | fi |
| 58 | |
| 59 | # Store the active/current Python3 version |
| 60 | PYTHON_VERSION=$(python3 --version | awk '{print $2}') |
| 61 | |
| 62 | # Check that the required minimum version has been met |
| 63 | if ! (ver_ge "${PYTHON_VERSION}" "${REQUIRED_PYTHON}"); then |
| 64 | echo "Warning: possible Python version problem" |
| 65 | echo "Python ${PYTHON_VERSION} does not meet requirement: ${REQUIRED_PYTHON}" |
| 66 | fi |
| 67 | |
| 68 | if (python3 -m robot.run --version > /dev/null 2>&1); then |
| 69 | echo "Working robot framework found; no installation necessary" |
| 70 | echo "Installed under Python version: ${PYTHON_VERSION}" |
| 71 | exit 0 |
| 72 | fi |
| 73 | |
| 74 | |
| 75 | # Create a requirements file; keep it around for potential later use |
| 76 | # Versions and dependencies below have been carefully tested for Python3 |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 77 | cat << 'EOF' > "requirements.txt" |
Matthew Watkins | 27075d2 | 2022-11-29 14:10:40 +0000 | [diff] [blame] | 78 | paramiko |
| 79 | six |
| 80 | urllib3 |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 81 | docker-py |
| 82 | ipaddr |
| 83 | netaddr |
| 84 | netifaces |
| 85 | pyhocon |
| 86 | requests |
Matthew Watkins | 27075d2 | 2022-11-29 14:10:40 +0000 | [diff] [blame] | 87 | selenium<4.6.0,>=4.0.0 |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 88 | robotframework |
| 89 | robotframework-httplibrary |
Matthew Watkins | 4a12da8 | 2022-12-07 16:28:01 +0000 | [diff] [blame] | 90 | robotframework-requests==0.9.3 |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 91 | robotframework-selenium2library |
Matthew Watkins | df95e52 | 2022-11-24 13:35:14 +0000 | [diff] [blame] | 92 | robotframework-sshlibrary |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 93 | scapy |
| 94 | # Module jsonpath is needed by current AAA idmlite suite. |
| 95 | jsonpath-rw |
| 96 | # Modules for longevity framework robot library |
Matthew Watkins | 27075d2 | 2022-11-29 14:10:40 +0000 | [diff] [blame] | 97 | elasticsearch<8.0.0,>=7.0.0 |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 98 | elasticsearch-dsl |
| 99 | # Module for pyangbind used by lispflowmapping project |
| 100 | pyangbind |
| 101 | # Module for iso8601 datetime format |
| 102 | isodate |
| 103 | # Module for TemplatedRequests.robot library |
| 104 | jmespath |
| 105 | # Module for backup-restore support library |
| 106 | jsonpatch |
Matthew Watkins | df95e52 | 2022-11-24 13:35:14 +0000 | [diff] [blame] | 107 | pbr |
| 108 | deepdiff |
| 109 | dnspython |
| 110 | future |
| 111 | jinja2 |
| 112 | kafka-python |
| 113 | # Protobuf requires Python >=3.7 |
| 114 | protobuf |
| 115 | pyyaml |
| 116 | robotlibcore-temp |
| 117 | more-itertools |
| 118 | xvfbwrapper |
| 119 | PyVirtualDisplay |
Matthew Watkins | 27075d2 | 2022-11-29 14:10:40 +0000 | [diff] [blame] | 120 | # Additional package dependencies for ONAP project |
| 121 | # odltools for extra debugging |
| 122 | # Generates warning: |
| 123 | # ERROR: odltools 0.1.34 has requirement requests~=2.19.1, |
| 124 | # but you'll have requests 2.28.1 which is incompatible. |
| 125 | odltools |
Matthew Watkins | 1e55439 | 2022-11-15 16:03:54 -0800 | [diff] [blame] | 126 | EOF |
| 127 | |
Matthew Watkins | 795671a | 2023-01-04 11:29:33 +0000 | [diff] [blame] | 128 | |
| 129 | if [[ -f ~/lf-env.sh ]]; then |
| 130 | echo "Installing robot-framework using LF common tooling" |
| 131 | # shellcheck disable=SC1090 |
| 132 | source ~/lf-env.sh |
| 133 | |
| 134 | # Create a virtual environment for robot tests and make sure setuptools & wheel |
| 135 | # are up-to-date in addition to pip |
| 136 | lf-activate-venv --python python3 --venv-file "${WORKSPACE}/.robot3_venv" \ |
| 137 | setuptools \ |
| 138 | pip \ |
| 139 | wheel |
| 140 | |
| 141 | # Install the robot framework and other dependencies |
| 142 | python3 -m pip install -r requirements.txt |
| 143 | |
| 144 | # Save the virtual environment in ROBOT3_VENV |
| 145 | ROBOT3_VENV="$(cat "${WORKSPACE}/.robot3_venv")" |
| 146 | |
| 147 | else |
| 148 | echo "Installing robot-framework in a virtual environment" |
| 149 | if [[ -z "${WORKSPACE}" ]]; then |
| 150 | # Use a temporary folder location |
| 151 | WORKSPACE="/tmp" |
| 152 | ROBOT3_VENV=$(mktemp -d --suffix=-robot3_venv) |
| 153 | else |
| 154 | ROBOT3_VENV="${WORKSPACE}/.robot3_venv" |
| 155 | fi |
| 156 | |
| 157 | # The --system-site-packages parameter allows us to pick up system level |
| 158 | # installed packages. This allows us to bake matplotlib which takes very long |
| 159 | # to install into the image. |
| 160 | python3 -m venv --system-site-packages "${ROBOT3_VENV}" |
| 161 | source "${ROBOT3_VENV}/bin/activate" |
| 162 | |
| 163 | echo "Installing robot-framework using basic methods" |
| 164 | python3 -m pip install -r requirements.txt |
| 165 | fi |
| 166 | |
| 167 | # Store the virtual environment location |
| 168 | echo "ROBOT3_VENV=${ROBOT3_VENV}" >> "${WORKSPACE}/env.properties" |
| 169 | |
| 170 | # Display versioning/debugging output |
| 171 | python3 --version |
Matthew Watkins | 4a12da8 | 2022-12-07 16:28:01 +0000 | [diff] [blame] | 172 | python3 -m pip freeze |
| 173 | python3 -m robot.run --version || : |