Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 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 | |
Chetan Gaonker | cc19ac4 | 2016-05-04 17:21:50 -0700 | [diff] [blame] | 17 | #!/usr/bin/env bash |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 18 | |
| 19 | function usage { |
| 20 | echo "usage: ${0#*/} [-h |--help] [--cord] [--venv]" |
| 21 | exit 1 |
| 22 | } |
| 23 | |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 24 | on_cord=0 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 25 | venv=0 |
| 26 | optspec=":h-:" |
| 27 | while getopts "$optspec" optchar; do |
| 28 | case "${optchar}" in |
| 29 | -) |
| 30 | case "${OPTARG}" in |
| 31 | cord) |
| 32 | on_cord=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 33 | ;; |
| 34 | venv) |
| 35 | venv=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 36 | ;; |
| 37 | help) |
| 38 | usage |
| 39 | ;; |
| 40 | *) |
| 41 | echo "Unknown option --${OPTARG}" |
| 42 | usage |
| 43 | ;; |
| 44 | esac |
| 45 | ;; |
| 46 | h) |
| 47 | usage |
| 48 | ;; |
| 49 | *) |
| 50 | usage |
| 51 | ;; |
| 52 | esac |
| 53 | done |
| 54 | |
| 55 | shift $((OPTIND-1)) |
| 56 | if [ $# -gt 0 ]; then |
| 57 | usage |
Chetan Gaonker | cc19ac4 | 2016-05-04 17:21:50 -0700 | [diff] [blame] | 58 | fi |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 59 | |
| 60 | apt-get update |
| 61 | release=$(lsb_release -cs) |
A R Karthick | 66cf6f6 | 2017-02-28 14:04:34 -0800 | [diff] [blame] | 62 | #install docker only if not installed already. On cord, its mostly installed. |
| 63 | if $(which docker 2>&1 >/dev/null); then |
| 64 | on_cord=1 |
| 65 | else |
| 66 | on_cord=0 |
| 67 | fi |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 68 | if [ $on_cord -eq 0 ]; then |
| 69 | apt-get -y install apt-transport-https ca-certificates |
| 70 | apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D |
| 71 | if [ ! -f /etc/apt/sources.list.d/docker.list ]; then |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 72 | 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] | 73 | fi |
| 74 | apt-get update |
| 75 | apt-get purge lxc-docker || true |
| 76 | apt-get -y install linux-image-extra-$(uname -r) |
| 77 | apt-get -y install apparmor |
| 78 | echo "Installing Docker" |
| 79 | apt-get -y install docker-engine |
A R Karthick | c4108fe | 2016-11-17 15:15:28 -0800 | [diff] [blame] | 80 | service docker restart |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 81 | sleep 5 |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 82 | echo "Verifying Docker installation" |
| 83 | docker run --rm hello-world || exit 127 |
| 84 | docker rmi hello-world |
A R Karthick | b05acab | 2016-11-10 15:12:43 -0800 | [diff] [blame] | 85 | echo "Pulling ONOS latest" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 86 | docker pull onosproject/onos:latest || exit 127 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 87 | else |
| 88 | echo "Skipping installation of Docker and ONOS" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 89 | fi |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 90 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 91 | apt-get -y install openvswitch-common openvswitch-switch |
| 92 | 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 |
| 93 | |
| 94 | setup_path=$(dirname $(realpath $0)) |
| 95 | if [ $venv -eq 1 ]; then |
| 96 | echo "Making a virtual cord-tester pip installation environment" |
| 97 | mkdir -p $setup_path/venv |
A R Karthick | d7f6ade | 2017-02-08 12:23:58 -0800 | [diff] [blame] | 98 | virtualenv $setup_path/venv |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 99 | echo "Installing cord-tester pip packages on the virtual environment" |
| 100 | $setup_path/venv/bin/pip install -r $setup_path/requirements.txt |
| 101 | else |
| 102 | echo "Installing cord-tester pip packages on the host" |
| 103 | pip install -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 |