add yardstick iruya 9.0.0 release notes
[yardstick.git] / nsb_setup.sh
1 #!/usr/bin/env bash
2 # Copyright (c) 2017-2019 Intel Corporation.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 usage()
17 {
18     cat <<EOF
19
20 Yardstick NSB setup script.
21
22 Usage: $0 [-h] [[-o] admin-openrc-for-openstack] [-i yardstick-docker-image]
23
24 Options:
25  -h         Show this message and exit
26  -o openrc  Specify admin-openrc file with OpenStack credentials
27             Defaults to none
28  -i image   Specify Yardstick Docker image, e.g. opnfv/yardstick:stable
29             Default value provided by ansible/nsb_setup.yml
30             See https://hub.docker.com/r/opnfv/yardstick/tags/
31
32 EOF
33 }
34
35 OPTSTR=':ho:i:'
36 openrc=
37 image=
38
39 # For backward compatibility reasons, accept openrc both as an argument
40 # and as the -o option. Hence these two loops.
41 while [ $# -ge 1 ]; do
42     OPTIND=1
43     while getopts ${OPTSTR} OPT; do
44         case $OPT in
45             h)
46                 usage
47                 exit 0
48                 ;;
49             o)
50                 openrc=${OPTARG}
51                 ;;
52             i)
53                 image=${OPTARG}
54                 ;;
55             :)
56                 usage
57                 echo "ERROR: Missing value for -${OPTARG} option"
58                 exit 1
59                 ;;
60             *)
61                 usage
62                 echo "ERROR: Invalid -${OPTARG} option"
63                 exit 1
64                 ;;
65         esac
66     done
67
68     if [ ${OPTIND} -eq 1 ]; then
69         openrc=$1
70         shift
71     else
72         shift $((OPTIND - 1))
73     fi
74 done
75
76 # OPENRC handling has to be first due no_proxy
77 if [ -n "${openrc}" ]; then
78     OPENRC=$(readlink -f -- "${openrc}")
79     extra_args="${extra_args} -e openrc_file=${OPENRC}"
80     source "${OPENRC}"
81     CONTROLLER_IP=$(echo ${OS_AUTH_URL} | sed -ne "s#http://\([0-9a-zA-Z.\-]*\):*[0-9]*/.*#\1#p")
82 fi
83
84 if [ -n "${image}" ]; then
85     extra_args="${extra_args} -e yardstick_docker_image=${image}"
86 fi
87
88 env_http_proxy=$(sed -ne "s/^http_proxy=[\"\']\(.*\)[\"\']/\1/p" /etc/environment)
89 if [[ -z ${http_proxy} ]] && [[ ! -z ${env_http_proxy} ]]; then
90     export http_proxy=${env_http_proxy}
91 fi
92 env_https_proxy=$(sed -ne "s/^https_proxy=[\"\']\(.*\)[\"\']/\1/p" /etc/environment)
93 if [[ -z ${https_proxy} ]] && [[ ! -z ${env_https_proxy} ]]; then
94     export https_proxy=${env_https_proxy}
95 fi
96
97 # if http[s]_proxy is set (from env or /etc/environment) prepare proxy for ansible
98 if [[ ! -z ${http_proxy} ]] || [[ ! -z ${https_proxy} ]]; then
99     export no_proxy="localhost,127.0.0.1,${CONTROLLER_IP},${no_proxy}"
100     extra_args="${extra_args} -e @/tmp/proxy.yml "
101
102     cat <<EOF > /tmp/proxy.yml
103 ---
104 proxy_env:
105   http_proxy: ${http_proxy}
106   https_proxy: ${https_proxy}
107   no_proxy: ${no_proxy}
108 EOF
109
110     mkdir -p /etc/systemd/system/docker.service.d
111     cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
112 ---
113 [Service]
114 Environment="HTTP_PROXY=${http_proxy}" "HTTPS_PROXY=${https_proxy}" "NO_PROXY=${no_proxy}"
115 EOF
116
117     systemctl daemon-reload
118     systemctl restart docker
119 fi
120
121 apt-get update > /dev/null 2>&1
122 pkg=(python-pip build-essential libssl-dev libffi-dev python3-dev python-dev)
123 for i in "${pkg[@]}"; do
124     dpkg-query -W --showformat='${Status}\n' "${i}"|grep "install ok installed"
125     if [  "$?" -eq "1" ]; then
126         apt-get -y install "${i}";
127     fi
128 done
129
130 pip install ansible==2.5.5 shade==1.22.2 docker-py==1.10.6
131
132 ANSIBLE_SCRIPTS="ansible"
133
134 cd ${ANSIBLE_SCRIPTS} && \
135 ansible-playbook \
136          -e IMAGE_PROPERTY='nsb' \
137          -e OS_RELEASE='xenial' \
138          -e INSTALLATION_MODE='container_pull' \
139          -e YARD_IMAGE_ARCH='amd64' ${extra_args} \
140          -i install-inventory.ini install.yaml
141