Chetan Gaonker | cc19ac4 | 2016-05-04 17:21:50 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 2 | |
| 3 | function usage { |
| 4 | echo "usage: ${0#*/} [-h |--help] [--cord] [--venv]" |
| 5 | exit 1 |
| 6 | } |
| 7 | |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 8 | on_cord=0 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 9 | venv=0 |
| 10 | optspec=":h-:" |
| 11 | while getopts "$optspec" optchar; do |
| 12 | case "${optchar}" in |
| 13 | -) |
| 14 | case "${OPTARG}" in |
| 15 | cord) |
| 16 | on_cord=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 17 | ;; |
| 18 | venv) |
| 19 | venv=1 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 20 | ;; |
| 21 | help) |
| 22 | usage |
| 23 | ;; |
| 24 | *) |
| 25 | echo "Unknown option --${OPTARG}" |
| 26 | usage |
| 27 | ;; |
| 28 | esac |
| 29 | ;; |
| 30 | h) |
| 31 | usage |
| 32 | ;; |
| 33 | *) |
| 34 | usage |
| 35 | ;; |
| 36 | esac |
| 37 | done |
| 38 | |
| 39 | shift $((OPTIND-1)) |
| 40 | if [ $# -gt 0 ]; then |
| 41 | usage |
Chetan Gaonker | cc19ac4 | 2016-05-04 17:21:50 -0700 | [diff] [blame] | 42 | fi |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 43 | |
| 44 | apt-get update |
| 45 | release=$(lsb_release -cs) |
A R Karthick | 66cf6f6 | 2017-02-28 14:04:34 -0800 | [diff] [blame] | 46 | #install docker only if not installed already. On cord, its mostly installed. |
| 47 | if $(which docker 2>&1 >/dev/null); then |
| 48 | on_cord=1 |
| 49 | else |
| 50 | on_cord=0 |
| 51 | fi |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 52 | if [ $on_cord -eq 0 ]; then |
| 53 | apt-get -y install apt-transport-https ca-certificates |
| 54 | apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D |
| 55 | if [ ! -f /etc/apt/sources.list.d/docker.list ]; then |
A R Karthick | bd82f36 | 2016-11-10 15:08:52 -0800 | [diff] [blame] | 56 | 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] | 57 | fi |
| 58 | apt-get update |
| 59 | apt-get purge lxc-docker || true |
| 60 | apt-get -y install linux-image-extra-$(uname -r) |
| 61 | apt-get -y install apparmor |
| 62 | echo "Installing Docker" |
| 63 | apt-get -y install docker-engine |
A R Karthick | c4108fe | 2016-11-17 15:15:28 -0800 | [diff] [blame] | 64 | service docker restart |
A R Karthick | 973010f | 2017-02-06 16:41:51 -0800 | [diff] [blame] | 65 | sleep 5 |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 66 | echo "Verifying Docker installation" |
| 67 | docker run --rm hello-world || exit 127 |
| 68 | docker rmi hello-world |
A R Karthick | b05acab | 2016-11-10 15:12:43 -0800 | [diff] [blame] | 69 | echo "Pulling ONOS latest" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 70 | docker pull onosproject/onos:latest || exit 127 |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 71 | else |
| 72 | echo "Skipping installation of Docker and ONOS" |
A R Karthick | d49ca4b | 2016-07-27 11:52:50 -0700 | [diff] [blame] | 73 | fi |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 74 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 75 | apt-get -y install openvswitch-common openvswitch-switch |
| 76 | 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 |
| 77 | |
| 78 | setup_path=$(dirname $(realpath $0)) |
| 79 | if [ $venv -eq 1 ]; then |
| 80 | echo "Making a virtual cord-tester pip installation environment" |
| 81 | mkdir -p $setup_path/venv |
A R Karthick | d7f6ade | 2017-02-08 12:23:58 -0800 | [diff] [blame] | 82 | virtualenv $setup_path/venv |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 83 | echo "Installing cord-tester pip packages on the virtual environment" |
| 84 | $setup_path/venv/bin/pip install -r $setup_path/requirements.txt |
| 85 | else |
| 86 | echo "Installing cord-tester pip packages on the host" |
| 87 | pip install -r $setup_path/requirements.txt |
Chetan Gaonker | 66bff93 | 2016-05-09 10:06:37 -0700 | [diff] [blame] | 88 | fi |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 89 | |
A R Karthick | 63815d1 | 2017-02-08 11:14:40 -0800 | [diff] [blame] | 90 | ( cd /tmp && git clone https://github.com/jpetazzo/pipework.git && cp -v pipework/pipework /usr/bin && rm -rf pipework ) |
| 91 | |
A R Karthick | 05e85fa | 2016-12-02 09:20:54 -0800 | [diff] [blame] | 92 | install_ovs() { |
| 93 | mkdir -p /root/ovs |
| 94 | wget http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz -O /root/ovs/openvswitch-2.5.0.tar.gz && \ |
| 95 | ( cd /root/ovs && tar zxpvf openvswitch-2.5.0.tar.gz && \ |
| 96 | cd openvswitch-2.5.0 && \ |
| 97 | ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install |
| 98 | ) |
| 99 | } |
| 100 | |
| 101 | ovs_install=0 |
| 102 | |
| 103 | if [ -f /usr/bin/ovs-vsctl ] || [ -f /usr/local/bin/ovs-vsctl ]; then |
| 104 | ##find the version. Install if ovs version less than 2.5 |
| 105 | version=`sudo ovs-vsctl --version | head -1 | awk '/[1-9].[0-9].[0-9]/ {print $NF}'` |
| 106 | major=$(echo $version | cut -d "." -f1) |
| 107 | minor=$(echo $version | cut -d "." -f2) |
| 108 | if [ $major -le 2 ]; then |
| 109 | if [ $major -lt 2 ]; then |
| 110 | ovs_install=1 |
| 111 | else |
| 112 | if [ $minor -lt 5 ]; then |
| 113 | ovs_install=1 |
| 114 | fi |
| 115 | fi |
| 116 | fi |
| 117 | else |
| 118 | ovs_install=1 |
| 119 | fi |
| 120 | |
| 121 | if [ $ovs_install -eq 1 ]; then |
| 122 | echo "Installing OVS 2.5.0" |
| 123 | service openvswitch-switch stop |
| 124 | install_ovs |
| 125 | fi |
A R Karthick | f7a613b | 2017-02-24 09:36:44 -0800 | [diff] [blame] | 126 | |
| 127 | test_images=(cordtest/radius:candidate cordtest/quagga:candidate cordtest/nose:candidate) |
| 128 | for img in ${test_images[*]}; do |
| 129 | echo "Pulling cord-tester image $img" |
| 130 | docker pull $img 2>/dev/null |
| 131 | done |