Artem Panchenko | 4167478 | 2017-06-26 18:01:55 +0300 | [diff] [blame] | 1 | package com.mirantis.tcp_qa |
| 2 | |
| 3 | /** |
| 4 | * Activate virtual environment and update requirements if needed |
| 5 | */ |
| 6 | def prepareEnv() { |
| 7 | sh ''' |
| 8 | if [ ! -r "${VENV_PATH}/bin/activate" ]; then |
| 9 | echo 'Python virtual environment not found! Set correct VENV_PATH!' |
| 10 | exit 1 |
| 11 | fi |
| 12 | ''' |
| 13 | |
| 14 | sh ''' |
| 15 | . ${VENV_PATH}/bin/activate |
| 16 | pip install --upgrade --upgrade-strategy=only-if-needed -r tcp_tests/requirements.txt |
| 17 | ''' |
| 18 | } |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * Download an image for tests |
| 23 | */ |
| 24 | def prepareImage() { |
| 25 | sh ''' |
| 26 | if [ -n "${IMAGE_LINK}" ]; then |
| 27 | IMAGE_FILE="$(basename "${IMAGE_LINK}")" |
| 28 | IMAGES_DIR="$(dirname "${IMAGE_PATH}")" |
| 29 | mkdir -p "${IMAGES_DIR}" |
| 30 | cd "${IMAGES_DIR}" && wget -N "${IMAGE_LINK}" |
| 31 | ln -sf "${IMAGES_DIR}/${IMAGE_FILE}" "${IMAGE_PATH}" || test -f "${IMAGE_PATH}" |
| 32 | fi |
| 33 | |
| 34 | if [ ! -r "${IMAGE_PATH}" ]; then |
| 35 | echo "Image not found: ${IMAGE_PATH}" |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | ''' |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Check that bridge traffic is not filtered on the host |
| 44 | */ |
| 45 | def checkBridgeNetfilterDisabled () { |
| 46 | def res = sh(script: 'file /proc/sys/net/bridge/bridge-nf-call-iptables 2>/dev/null || echo "Not found"', |
| 47 | returnStdout: true).trim() |
| 48 | if ( ! res.equals('Not found') ) { |
| 49 | res = sh(script: 'cat /proc/sys/net/bridge/bridge-nf-call-iptables', |
| 50 | returnStdout: true).trim() |
| 51 | if ( ! res.equals('0') ) { |
| 52 | error("Kernel parameter 'net.bridge.bridge-nf-call-iptables' should be disabled to run the tests!") |
| 53 | } |
| 54 | } else { |
| 55 | echo("WARNING: it isn't possible to check net.bridge.bridge-nf-call-iptables value. Please make sure it is set to '0'!") |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
| 60 | /** |
| 61 | * Destroy running environment |
| 62 | */ |
| 63 | def destroyEnv() { |
| 64 | if ( !(env.KEEP_BEFORE.equals('yes') || env.KEEP_BEFORE.equals('true')) ) { |
| 65 | sh ''' |
| 66 | . ${VENV_PATH}/bin/activate |
| 67 | dos.py destroy ${ENV_NAME} || true |
| 68 | ''' |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Erase running environment |
| 74 | */ |
| 75 | def eraseEnv() { |
| 76 | sh ''' |
| 77 | . ${VENV_PATH}/bin/activate |
| 78 | dos.py erase ${ENV_NAME} || true |
| 79 | ''' |
| 80 | } |
| 81 | |