Merge "Update rally version"
[functest.git] / functest / opnfv_tests / vnf / vIMS / create_venv.sh
1 #!/bin/bash -e
2
3 # Script checks that venv exists. If it doesn't it will be created
4 # It requires python2.7 and virtualenv packages installed
5 #
6 #   Copyright (c) 2015 Orange
7 #   valentin.boucher@orange.com
8 #
9 # All rights reserved. This program and the accompanying materials
10 # are made available under the terms of the Apache License, Version 2.0
11 # which accompanies this distribution, and is available at
12 # http://www.apache.org/licenses/LICENSE-2.0
13
14 BASEDIR=`dirname $0`
15 VENV_PATH=$1
16 VENV_NAME="venv_cloudify"
17 function venv_install() {
18     if command -v virtualenv-2.7; then
19         virtualenv-2.7 $1
20     elif command -v virtualenv2; then
21         virtualenv2 $1
22     elif command -v virtualenv; then
23         virtualenv $1
24     else
25         echo Cannot find virtualenv command.
26         return 1
27     fi
28 }
29
30 # exit when something goes wrong during venv install
31 set -e
32 if [ ! -d "$VENV_PATH/$VENV_NAME" ]; then
33     venv_install $VENV_PATH/$VENV_NAME
34     echo "Virtualenv" + $VENV_NAME + "created."
35 fi
36
37 if [ ! -f "$VENV_PATH/$VENV_NAME/updated" -o $BASEDIR/requirements.pip -nt $VENV_PATH/$VENV_NAME/updated ]; then
38     source $VENV_PATH/$VENV_NAME/bin/activate
39     pip install -r $BASEDIR/requirements.pip
40     touch $VENV_PATH/$VENV_NAME/updated
41     echo "Requirements installed."
42     deactivate
43 fi
44 set +e