Merge branch 'pm_phase2' into v2.0. Amend change for NSD based on package_type rpc...
[osm/SO.git] / examples / ping_pong_ns / ping_pong_ns / prepare_ping_pong_qcow.sh
1 #! /bin/bash
2
3 #
4 # Copyright 2016 RIFT.IO Inc
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # Author(s): Anil Gunturu
19 # Creation Date: 07/24/2014
20 #
21
22 ##
23 # This script is used to copy the riftware software into the qcow image
24 # This script must be run on the grunt machine as root
25 ##
26
27 set -x
28 set -e
29
30 if ! [ $# -eq 1 ]; then
31 echo "Usage: $0 <ping-pong-ns-dir>"
32 echo " Example:"
33 echo " $0 /net/boson/home1/agunturu/lepton/atg/modules/core/mc/examples/ping_pong_ns"
34 exit 1
35 fi
36
37 # Currently returning 0 on error as this script fails in Bangalore
38 # systems and causes the jenkins spot_debug to fail
39 function cleanup {
40 if [ "$(ls -A $MOUNT_PT)" ]; then
41 guestunmount $MOUNT_PT
42 fi
43 exit 0
44 }
45 trap cleanup EXIT
46
47 MOUNT_PT=ping_pong/mnt$$
48
49 if [ -d $MOUNT_PT ]; then
50 echo "ping_pong_mnt directory exists - deleting..!!"
51 guestunmount $MOUNT_PT || true
52 rm -rf ping_pong
53 fi
54
55 mkdir -p $MOUNT_PT
56 FC20QCOW=Fedora-x86_64-20-20131211.1-sda.qcow2
57 PINGQCOW=Fedora-x86_64-20-20131211.1-sda-ping.qcow2
58 PONGQCOW=Fedora-x86_64-20-20131211.1-sda-pong.qcow2
59
60 if [ ! -e ${RIFT_ROOT}/images/${FC20QCOW} ]; then
61 echo >&2 "Warn: Cannot prepare ping_pong qcow due to missing FC20 image: ${RIFT_ROOT}/images/${FC20QCOW}"
62 exit 0
63 fi
64
65 echo "Copying $FC20QCOW"
66 cp ${RIFT_ROOT}/images/${FC20QCOW} ping_pong/${PINGQCOW}
67 chmod +w ping_pong/${PINGQCOW}
68 cp ${RIFT_ROOT}/images/${FC20QCOW} ping_pong/${PONGQCOW}
69 chmod +w ping_pong/${PONGQCOW}
70
71 CURRENT_DIR=$PWD
72 echo "Mounting guestfs for $PINGQCOW"
73 guestmount -a ping_pong/$PINGQCOW -m /dev/sda1 $MOUNT_PT
74
75 echo "Setting up resolv.conf"
76 # removed RIFT.io lab-centric setup in RIFT-11991
77 #echo "search lab.riftio.com eng.riftio.com riftio.com" > $MOUNT_PT/etc/resolv.conf
78 #echo "nameserver 10.64.1.3" >> $MOUNT_PT/etc/resolv.conf
79 #echo "PEERDNS=no" >> $MOUNT_PT/etc/sysconfig/network-scripts/ifcfg-eth0
80
81 # add a valid DNS server just in case
82 echo "nameserver 8.8.8.8" > $MOUNT_PT/etc/resolv.conf
83 echo "DEFROUTE=yes" >> $MOUNT_PT/etc/sysconfig/network-scripts/ifcfg-eth0
84
85 for i in 1 2
86 do
87 cat <<EOF >> $MOUNT_PT/etc/sysconfig/network-scripts/ifcfg-eth$i
88 DEVICE="eth$i"
89 BOOTPROTO="dhcp"
90 ONBOOT="no"
91 TYPE="Ethernet"
92 DEFROUTE=no
93 PEERDNS=no
94 EOF
95 done
96
97
98 echo "Copying ping/pong ns..."
99 cd $MOUNT_PT/opt
100 mkdir rift
101 cd rift
102 cp -r $1 .
103 cd $CURRENT_DIR
104 mv $MOUNT_PT/opt/rift/ping_pong_ns/ping.service $MOUNT_PT/etc/systemd/system
105 cp -ar /usr/lib/python2.7/site-packages/tornado $MOUNT_PT/usr/lib/python2.7/site-packages/
106 guestunmount $MOUNT_PT
107
108 echo "Mounting guestfs for $PINGQCOW"
109 guestmount -a ping_pong/$PONGQCOW -m /dev/sda1 $MOUNT_PT
110
111 echo "Setting up resolv.conf"
112 echo "search lab.riftio.com eng.riftio.com riftio.com" > $MOUNT_PT/etc/resolv.conf
113 echo "nameserver 10.64.1.3" >> $MOUNT_PT/etc/resolv.conf
114 echo "PEERDNS=no" >> $MOUNT_PT/etc/sysconfig/network-scripts/ifcfg-eth0
115 echo "DEFROUTE=yes" >> $MOUNT_PT/etc/sysconfig/network-scripts/ifcfg-eth0
116
117 for i in 1 2
118 do
119 cat <<EOF >> $MOUNT_PT/etc/sysconfig/network-scripts/ifcfg-eth$i
120 DEVICE="eth$i"
121 BOOTPROTO="dhcp"
122 ONBOOT="no"
123 DEFROUTE=no
124 TYPE="Ethernet"
125 PEERDNS=no
126 EOF
127 done
128
129 echo "Copying ping/pong ns..."
130 cd $MOUNT_PT/opt
131 mkdir rift
132 cd rift
133 cp -r $1 .
134 cd $CURRENT_DIR
135 cp -ar /usr/lib/python2.7/site-packages/tornado $MOUNT_PT/usr/lib/python2.7/site-packages/
136 mv $MOUNT_PT/opt/rift/ping_pong_ns/pong.service $MOUNT_PT/etc/systemd/system
137 guestunmount $MOUNT_PT