Allow running Functest vs profiles defined by GSMA
[functest.git] / functest / ci / add_proxy.sh
1 #!/bin/bash
2
3 set -e
4
5 pushd "${1:-/home/opnfv/functest/images}" > /dev/null
6
7 images=${images-"\
8 cloudify-manager-premium-4.0.1.qcow2 \
9 ubuntu-14.04-server-cloudimg-amd64-disk1.img \
10 ubuntu-16.04-server-cloudimg-amd64-disk1.img"}
11
12 add_proxy () {
13     cat << EOF >> "$1"
14 http_proxy=${http_proxy:-http://proxy:8080}
15 HTTP_PROXY=${http_proxy:-http://proxy:8080}
16 https_proxy=${https_proxy:-${http_proxy:-http://proxy:8080}}
17 HTTPS_PROXY=${https_proxy:-${http_proxy:-http://proxy:8080}}
18 ftp_proxy=${ftp_proxy:-${http_proxy:-http://proxy:8080}}
19 FTP_PROXY=${ftp_proxy:-${http_proxy:-http://proxy:8080}}
20 no_proxy=${no_proxy:-"10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"}
21 NO_PROXY=${no_proxy:-"10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"}
22 EOF
23 }
24
25 add_proxy_apt () {
26     cat << EOF >> "$1"
27 Acquire::http::Proxy "${http_proxy:-http://proxy:8080}";
28 Acquire::https::Proxy "${https_proxy:-http://proxy:8080}";
29 EOF
30 }
31
32 tmpdir=$(mktemp -d)
33 for image in $images; do
34     if [ ! -f "$image" ]; then
35         echo "skip ${image} ($(pwd)/${image} not found)"
36         continue
37     fi
38     guestmount -a "${image}" -i --rw "${tmpdir}"
39     add_proxy "${tmpdir}/etc/environment"
40     if [[ ${image} == *"cloudify-manager"* ]]; then
41         echo >> "${tmpdir}/etc/sysconfig/cloudify-mgmtworker"
42         add_proxy "${tmpdir}/etc/sysconfig/cloudify-mgmtworker"
43         echo >> "${tmpdir}/etc/sysconfig/cloudify-restservice"
44         add_proxy "${tmpdir}/etc/sysconfig/cloudify-restservice"
45     fi
46     if [[ ${image} == "ubuntu"* ]]; then
47         add_proxy_apt "${tmpdir}/etc/apt/apt.conf"
48     fi
49     guestunmount "${tmpdir}"
50 done
51
52 rmdir "${tmpdir}"
53 popd > /dev/null