Merge "JIRA:BGS-46 Updating the release-notes.rst with aligned language and more...
[genesis.git] / fuel / deploy / functions / common.sh
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # stefan.k.berg@ericsson.com
4 # jonas.bjurel@ericsson.com
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Common functions
12
13 error_exit () {
14   echo "Error: $@" >&2
15   exit 1
16 }
17
18 ssh() {
19   SSHPASS="r00tme" sshpass -e ssh -o UserKnownHostsFile=/dev/null \
20     -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@"
21 }
22
23 scp() {
24   SSHPASS="r00tme" sshpass -e scp  -o UserKnownHostsFile=/dev/null \
25     -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@"
26 }
27
28 noNodesUp () {
29   fuel node | grep True | wc -l
30 }
31
32 fuel () {
33   ssh root@10.20.0.2 "fuel $@"
34 }
35
36 # Return MAC id for virsh node
37 getNodeId() {
38   virsh dumpxml $1 | grep "mac address"  | head -1 | sed "s/.*'..:..:..:..:\(.*\)'.*/\1/"
39 }
40
41 # Wait for node with virtid name to come up
42 waitForHost() {
43   mac=`getNodeId $1`
44
45   while true
46   do
47     fuel node --node-id $mac 2>/dev/null | grep -q True && break
48     sleep 3
49     echo -n "."
50   done
51   echo -e "\n"
52 }
53
54 # Currently not used!
55 # Wait for node count to increase
56 waitForNode() {
57   local cnt
58   local initCnt
59   local expectCnt
60
61   initCnt=`noNodesUp`
62   expectCnt=$[initCnt+1]
63   while true
64   do
65     cnt=`noNodesUp`
66     if [ $cnt -eq $expectCnt ]; then
67       break
68     elif [ $cnt -lt $initCnt ]; then
69       error_exit "Node count decreased while waiting, $initCnt -> $cnt"
70     elif [ $cnt -gt $expectCnt ]; then
71       error_exit "Node count exceeded expect count, $cnt > $expectCnt"
72     fi
73     sleep 3
74     echo -n "."
75   done
76   echo -e "\n"
77 }
78
79 bootorder_dvdhd() {
80   virsh dumpxml $1 | grep -v "<boot.*>" | \
81   sed "/<\/os>/i\
82     <boot dev='cdrom'/\>\n\
83     <boot dev='hd'/\>\n\
84     <bootmenu enable='no'/\>" > $tmpdir/vm.xml || error_exit "Could not set bootorder"
85   virsh define $tmpdir/vm.xml || error_exit "Could not set bootorder"
86 }
87
88 bootorder_hddvd() {
89   virsh dumpxml $1 | grep -v "<boot.*>" | \
90   sed "/<\/os>/i\
91     <boot dev='hd'/\>\n\
92     <boot dev='cdrom'/\>\n\
93     <bootmenu enable='no'/\>" > $tmpdir/vm.xml || error_exit "Could not set bootorder"
94   virsh define $tmpdir/vm.xml || error_exit "Could not set bootorder"
95 }
96
97 addisofile() {
98   virsh dumpxml $1 | grep -v '\.iso' | sed "s/<.*device='cdrom'.*/<disk type='file' device='cdrom'>/" | \
99     sed "/<.*device='cdrom'.*/a       <source file='$2'/>" > $tmpdir/vm.xml \
100       || error_exit "Could not add isofile"
101   virsh define $tmpdir/vm.xml || error_exit "Could not add isofile"
102 }
103
104 removeisofile() {
105   virsh dumpxml $1 | grep -v '\.iso' | sed "s/<.*device='cdrom'.*/<disk type='block' device='cdrom'>/" \
106      > $tmpdir/vm.xml \
107       || error_exit "Could not remove isofile"
108   virsh define $tmpdir/vm.xml || error_exit "Could not remove isofile"
109 }