blob: efeb0f78bedd4d9634614d88f894fbc9f203cd87 [file] [log] [blame]
Matthew Watkins1e554392022-11-15 16:03:54 -08001#!/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 Watkins795671a2023-01-04 11:29:33 +000013set -euxo pipefail
Matthew Watkins1e554392022-11-15 16:03:54 -080014
Matthew Watkins795671a2023-01-04 11:29:33 +000015echo "---> install-robotframework-py3.sh"
Matthew Watkins1e554392022-11-15 16:03:54 -080016
Matthew Watkins795671a2023-01-04 11:29:33 +000017### Common variables
Matthew Watkins1e554392022-11-15 16:03:54 -080018
Matthew Watkins795671a2023-01-04 11:29:33 +000019REQUIRED_PYTHON="3.7.0"
Matthew Watkins1e554392022-11-15 16:03:54 -080020
Matthew Watkins795671a2023-01-04 11:29:33 +000021### Common functions
Matthew Watkins1e554392022-11-15 16:03:54 -080022
Matthew Watkins795671a2023-01-04 11:29:33 +000023# Allows for the comparison of two Python version strings
24ver_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
36ver_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
45if [[ -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
57fi
58
59# Store the active/current Python3 version
60PYTHON_VERSION=$(python3 --version | awk '{print $2}')
61
62# Check that the required minimum version has been met
63if ! (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}"
66fi
67
68if (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
72fi
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 Watkins1e554392022-11-15 16:03:54 -080077cat << 'EOF' > "requirements.txt"
Matthew Watkins27075d22022-11-29 14:10:40 +000078paramiko
79six
80urllib3
Matthew Watkins1e554392022-11-15 16:03:54 -080081docker-py
82ipaddr
83netaddr
84netifaces
85pyhocon
86requests
Matthew Watkins27075d22022-11-29 14:10:40 +000087selenium<4.6.0,>=4.0.0
Matthew Watkins1e554392022-11-15 16:03:54 -080088robotframework
89robotframework-httplibrary
Matthew Watkins4a12da82022-12-07 16:28:01 +000090robotframework-requests==0.9.3
Matthew Watkins1e554392022-11-15 16:03:54 -080091robotframework-selenium2library
Matthew Watkinsdf95e522022-11-24 13:35:14 +000092robotframework-sshlibrary
Matthew Watkins1e554392022-11-15 16:03:54 -080093scapy
94# Module jsonpath is needed by current AAA idmlite suite.
95jsonpath-rw
96# Modules for longevity framework robot library
Matthew Watkins27075d22022-11-29 14:10:40 +000097elasticsearch<8.0.0,>=7.0.0
Matthew Watkins1e554392022-11-15 16:03:54 -080098elasticsearch-dsl
99# Module for pyangbind used by lispflowmapping project
100pyangbind
101# Module for iso8601 datetime format
102isodate
103# Module for TemplatedRequests.robot library
104jmespath
105# Module for backup-restore support library
106jsonpatch
Matthew Watkinsdf95e522022-11-24 13:35:14 +0000107pbr
108deepdiff
109dnspython
110future
111jinja2
112kafka-python
113# Protobuf requires Python >=3.7
114protobuf
115pyyaml
116robotlibcore-temp
117more-itertools
118xvfbwrapper
119PyVirtualDisplay
Matthew Watkins27075d22022-11-29 14:10:40 +0000120# 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.
125odltools
Matthew Watkins1e554392022-11-15 16:03:54 -0800126EOF
127
Matthew Watkins795671a2023-01-04 11:29:33 +0000128
129if [[ -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
147else
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
165fi
166
167# Store the virtual environment location
168echo "ROBOT3_VENV=${ROBOT3_VENV}" >> "${WORKSPACE}/env.properties"
169
170# Display versioning/debugging output
171python3 --version
Matthew Watkins4a12da82022-12-07 16:28:01 +0000172python3 -m pip freeze
173python3 -m robot.run --version || :