A R Karthick | 1fa6654 | 2017-08-10 14:15:29 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 2 | |
| 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 17 | function usage { |
| 18 | echo "usage: ${0#*/} [-h |--help] [--cord] [--venv]" |
| 19 | exit 1 |
| 20 | } |
| 21 | |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 22 | on_cord=0 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 23 | venv=0 |
| 24 | optspec=":h-:" |
| 25 | while getopts "$optspec" optchar; do |
| 26 | case "${optchar}" in |
| 27 | -) |
| 28 | case "${OPTARG}" in |
| 29 | cord) |
| 30 | on_cord=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 31 | ;; |
| 32 | venv) |
| 33 | venv=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 34 | ;; |
| 35 | help) |
| 36 | usage |
| 37 | ;; |
| 38 | *) |
| 39 | echo "Unknown option --${OPTARG}" |
| 40 | usage |
| 41 | ;; |
| 42 | esac |
| 43 | ;; |
| 44 | h) |
| 45 | usage |
| 46 | ;; |
| 47 | *) |
| 48 | usage |
| 49 | ;; |
| 50 | esac |
| 51 | done |
| 52 | |
| 53 | shift $((OPTIND-1)) |
| 54 | if [ $# -gt 0 ]; then |
| 55 | usage |
Chetan Gaonker | cc19ac4 | 2016-05-04 17:21:50 -0700 | [diff] [blame] | 56 | fi |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 57 | |
| 58 | apt-get update |
| 59 | release=$(lsb_release -cs) |
A R Karthick | 66cf6f6 | 2017-02-28 14:04:34 -0800 | [diff] [blame] | 60 | #install docker only if not installed already. On cord, its mostly installed. |
| 61 | if $(which docker 2>&1 >/dev/null); then |
| 62 | on_cord=1 |
| 63 | else |
| 64 | on_cord=0 |
| 65 | fi |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 66 | if [ $on_cord -eq 0 ]; then |
| 67 | apt-get -y install apt-transport-https ca-certificates |
| 68 | apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D |
| 69 | if [ ! -f /etc/apt/sources.list.d/docker.list ]; then |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 70 | echo deb https://apt.dockerproject.org/repo ubuntu-$release main | tee /etc/apt/sources.list.d/docker.list |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 71 | fi |
| 72 | apt-get update |
| 73 | apt-get purge lxc-docker || true |
| 74 | apt-get -y install linux-image-extra-$(uname -r) |
| 75 | apt-get -y install apparmor |
| 76 | echo "Installing Docker" |
| 77 | apt-get -y install docker-engine |
A R Karthick | c4108fe | 2016-11-17 15:15:28 -0800 | [diff] [blame] | 78 | service docker restart |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 79 | sleep 5 |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 80 | echo "Verifying Docker installation" |
| 81 | docker run --rm hello-world || exit 127 |
| 82 | docker rmi hello-world |
A R Karthick | b05acab | 2016-11-10 15:12:43 -0800 | [diff] [blame] | 83 | echo "Pulling ONOS latest" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 84 | docker pull onosproject/onos:latest || exit 127 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 85 | else |
| 86 | echo "Skipping installation of Docker and ONOS" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 87 | fi |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 88 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 89 | apt-get -y install openvswitch-common openvswitch-switch |
| 90 | apt-get -y install wget git python python-dev python-pip python-setuptools python-scapy python-pexpect python-maas-client tcpdump arping libssl-dev libffi-dev realpath python-virtualenv |
| 91 | |
| 92 | setup_path=$(dirname $(realpath $0)) |
| 93 | if [ $venv -eq 1 ]; then |
| 94 | echo "Making a virtual cord-tester pip installation environment" |
| 95 | mkdir -p $setup_path/venv |
A R Karthick | d7f6ade | 2017-02-08 12:23:58 -0800 | [diff] [blame] | 96 | virtualenv $setup_path/venv |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 97 | echo "Installing cord-tester pip packages on the virtual environment" |
A R Karthick | 9020cd0 | 2017-08-10 13:59:27 -0700 | [diff] [blame] | 98 | $setup_path/venv/bin/pip install -U distribute |
A R Karthick | ce65907 | 2017-08-10 14:20:39 -0700 | [diff] [blame] | 99 | $setup_path/venv/bin/pip install -U -r $setup_path/requirements.txt |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 100 | else |
| 101 | echo "Installing cord-tester pip packages on the host" |
A R Karthick | 9020cd0 | 2017-08-10 13:59:27 -0700 | [diff] [blame] | 102 | pip install -U distribute |
A R Karthick | ce65907 | 2017-08-10 14:20:39 -0700 | [diff] [blame] | 103 | pip install -U -r $setup_path/requirements.txt |
Chetan Gaonker | 66bff93 | 2016-05-09 10:06:37 -0700 | [diff] [blame] | 104 | fi |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 105 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 106 | ( cd /tmp && git clone https://github.com/jpetazzo/pipework.git && cp -v pipework/pipework /usr/bin && rm -rf pipework ) |
| 107 | |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 108 | install_ovs() { |
| 109 | mkdir -p /root/ovs |
| 110 | wget http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz -O /root/ovs/openvswitch-2.5.0.tar.gz && \ |
| 111 | ( cd /root/ovs && tar zxpvf openvswitch-2.5.0.tar.gz && \ |
| 112 | cd openvswitch-2.5.0 && \ |
| 113 | ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install |
| 114 | ) |
| 115 | } |
| 116 | |
| 117 | ovs_install=0 |
| 118 | |
| 119 | if [ -f /usr/bin/ovs-vsctl ] || [ -f /usr/local/bin/ovs-vsctl ]; then |
| 120 | ##find the version. Install if ovs version less than 2.5 |
| 121 | version=`sudo ovs-vsctl --version | head -1 | awk '/[1-9].[0-9].[0-9]/ {print $NF}'` |
| 122 | major=$(echo $version | cut -d "." -f1) |
| 123 | minor=$(echo $version | cut -d "." -f2) |
| 124 | if [ $major -le 2 ]; then |
| 125 | if [ $major -lt 2 ]; then |
| 126 | ovs_install=1 |
| 127 | else |
| 128 | if [ $minor -lt 5 ]; then |
| 129 | ovs_install=1 |
| 130 | fi |
| 131 | fi |
| 132 | fi |
| 133 | else |
| 134 | ovs_install=1 |
| 135 | fi |
| 136 | |
| 137 | if [ $ovs_install -eq 1 ]; then |
| 138 | echo "Installing OVS 2.5.0" |
| 139 | service openvswitch-switch stop |
| 140 | install_ovs |
| 141 | fi |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 142 | |
| 143 | test_images=(cordtest/radius:candidate cordtest/quagga:candidate cordtest/nose:candidate) |
| 144 | for img in ${test_images[*]}; do |
| 145 | echo "Pulling cord-tester image $img" |
| 146 | docker pull $img 2>/dev/null |
| 147 | done |