summaryrefslogtreecommitdiffstats
path: root/run-tests-in-vagrant.sh
blob: aedf1ca0a18f6b6b49d30db95646ecb0b35ae185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash

###############################################################################
# TODO: Allow subset of tests to be executed when VM starts.                  #
# TODO: Provide option to destroy the VM.                                     #
###############################################################################

ORIGIN_DIR=$PWD
autostart="no"

function parse_args () {
    args=`getopt \
              --options a \
              --long autostart \
              -n 'run-tests-in-vagrant.sh' \
              --  "$@"`
    eval set -- "$args"
    while true; do
        case "$1" in
            -a|--autostart) autostart="yes"; shift ;;
            --) shift ; break ;;
            *) echo "Internal error!" ; exit 1;;
        esac
    done
}

function force_location()
{
    current_dir=$(dirname $0);

    if [ ! -f ${current_dir}/tests/vagrant/vagrant-template/Vagrantfile ]; then
        echo "Aborting."
        echo
        echo "The tests/vagrant subdirectory seems to be missing."
        echo
        echo "Please correct the problem and try again."
        echo
        exit 1
    fi
}

function vagrant_check()
{
    vagrant -v >/dev/null 2>&1;

    if [ $? -ne 0 ]; then
        echo "Aborting"
        echo "Vagrant not found. Please install Vagrant and try again."
        echo "On Fedora, run "dnf install vagrant vagrant-libvirt" "
        exit 1
    else
        echo "Found Vagrant, continuing...."
        echo
    fi
}

function ansible_check()
{
    ansible --version  >/dev/null  2>&1 ;

    if [ $? -ne 0 ]; then
        echo "Aborting"
        echo "Ansible not found. Please install Ansible and try again."
        echo "On Fedora, run "dnf install ansible" "
        exit 1
    else
        echo "Found Ansible, continuing...."
        echo
    fi
}

parse_args "$@"

echo "Checking current dir...."
force_location
echo
echo

echo "Testing for Vagrant...."
vagrant_check
echo
echo

echo "Testing for Ansible...."
ansible_check
echo
echo

BRANCHNAME=`git rev-parse --abbrev-ref HEAD`
echo "Copying tests/vagrant/vagrant-template dir to tests/vagrant/$BRANCHNAME"
mkdir -p tests/vagrant/$BRANCHNAME
cp -R tests/vagrant/vagrant-template/* tests/vagrant/$BRANCHNAME
echo "Change dir to vagrant dir: tests/vagrant/$BRANCHNAME"
echo "Vagrant directory is tests/vagrant/$BRANCHNAME"
echo
echo




echo "Doing vagrant up...."
cd tests/vagrant/$BRANCHNAME
vagrant up
if [ $? -eq 0 ]
then
        echo "Vagrant up successful"
        cd $ORIGIN_DIR
else
        echo "Vagrant up failed, exiting....";
        cd $ORIGIN_DIR
        exit 1
fi
echo
echo


if [ "x$autostart" == "xyes" ] ; then
    echo "autostart option enabled, calling virsh autostart"
    virsh autostart ${BRANCHNAME}_vagrant-testVM
    echo
    echo
fi

echo "Copying source code from host machine to VM"
cd tests/vagrant/$BRANCHNAME
vagrant ssh-config > ssh_config
rsync -az -e "ssh -F ssh_config" --rsync-path="sudo rsync" "$ORIGIN_DIR/." vagrant-testVM:/home/vagrant/glusterfs
if [ $? -eq 0 ]
then
        echo "Copied."
        cd $ORIGIN_DIR
else
        echo "Copy failed, exiting...."
        cd $ORIGIN_DIR
        exit 1
fi
echo
echo


cd tests/vagrant/$BRANCHNAME
vagrant ssh -c 'cd /home/vagrant/glusterfs ; sudo make clean' -- -t
cd $ORIGIN_DIR
echo
echo

cd tests/vagrant/$BRANCHNAME
vagrant ssh -c 'cd /home/vagrant/glusterfs ; sudo ./autogen.sh' -- -t
if [ $? -ne 0 ]
then
        echo "autogen failed, exiting...."
        cd $ORIGIN_DIR
        exit 1
fi
cd $ORIGIN_DIR
echo
echo

cd tests/vagrant/$BRANCHNAME
vagrant ssh -c 'cd /home/vagrant/glusterfs ; \
        CFLAGS="-g -O0 -Werror -Wall -Wno-error=cpp -Wno-error=maybe-uninitialized" \
        sudo ./configure \
        --prefix=/usr \
        --exec-prefix=/usr \
        --bindir=/usr/bin \
        --sbindir=/usr/sbin \
        --sysconfdir=/etc \
        --datadir=/usr/share \
        --includedir=/usr/include \
        --libdir=/usr/lib64 \
        --libexecdir=/usr/libexec \
        --localstatedir=/var \
        --sharedstatedir=/var/lib \
        --mandir=/usr/share/man \
        --infodir=/usr/share/info \
        --libdir=/usr/lib64 \
        --enable-debug' -- -t
if [ $? -ne 0 ]
then
        echo "configure failed, exiting...."
        cd $ORIGIN_DIR
        exit 1
fi
cd $ORIGIN_DIR
echo
echo

cd tests/vagrant/$BRANCHNAME
vagrant ssh -c 'cd /home/vagrant/glusterfs; sudo make install' -- -t
if [ $? -ne 0 ]
then
        echo "make failed, exiting...."
        cd $ORIGIN_DIR
        exit 1
fi
cd $ORIGIN_DIR
echo
echo

cd tests/vagrant/$BRANCHNAME
vagrant ssh -c 'cd /home/vagrant/glusterfs; sudo ./run-tests.sh' -- -t
cd $ORIGIN_DIR
echo
echo