-
Notifications
You must be signed in to change notification settings - Fork 33
/
test.sh
executable file
·155 lines (133 loc) · 3.69 KB
/
test.sh
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
#!/bin/sh
BINARY=build/bin/minishift
ISO=file://$(pwd)/build/minishift-centos7.iso
EXTRA_FLAGS="--show-libmachine-logs"
RHEL_IMAGE="registry.access.redhat.com/rhel7/rhel-atomic"
function print_success_message() {
echo ""
echo " ------------ [ $1 - Passed ]"
echo ""
}
function exit_with_message() {
if [[ "$1" != 0 ]]; then
echo "$2"
exit 1
fi
}
function assert_equal() {
if [ "$1" != "$2" ]; then
echo "Expected '$2' but got '$1'"
exit 1
fi
}
# http://www.linuxjournal.com/content/validating-ip-address-bash-script
function assert_valid_ip() {
local ip=$1
local valid=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
valid=$?
fi
if [[ "$valid" != 0 ]]; then
echo "IP '$1' is invalid"
exit 1
fi
}
function verify_start_instance() {
$BINARY start --iso-url $ISO $EXTRA_FLAGS
exit_with_message "$?" "Error starting Minishift VM"
output=`$BINARY status | sed -n 1p`
assert_equal "$output" "Minishift: Running"
print_success_message "Starting VM"
}
function verify_stop_instance() {
$BINARY stop
exit_with_message "$?" "Error starting Minishift VM"
output=`$BINARY status | sed -n 1p`
assert_equal "$output" "Minishift: Stopped"
print_success_message "Stopping VM"
}
function verify_swap_space() {
output=`$BINARY ssh -- free | tail -n 1 | awk '{print $2}'`
if [ "$output" == "0" ]; then
echo "Expected non zero but got '$output'"
exit 1
fi
print_success_message "Swap space check"
}
function verify_ssh_connection() {
output=`$BINARY ssh -- echo hello`
assert_equal "$output" "hello"
print_success_message "SSH Connection"
}
function verify_vm_ip() {
output=`$BINARY ip`
assert_valid_ip $output
print_success_message "Getting VM IP"
}
function verify_cifs_installation() {
expected="mount.cifs version: 6.2"
output=`$BINARY ssh -- sudo /sbin/mount.cifs -V`
assert_equal "$output" "$expected"
print_success_message "CIFS installation"
}
function verify_sshfs_installation() {
expected="SSHFS version 2.5"
output=`$BINARY ssh -- sudo sshfs -V`
echo $output | grep "$expected" > /dev/null
if [ "$?" != "0" ]; then
echo "Expected exit status of command '$BINARY ssh -- sudo sshfs -V' to be 0."
exit 1
fi
print_success_message "SSHFS installation"
}
function verify_nfs_installation() {
expected="mount.nfs: (linux nfs-utils 1.3.0)"
output=`$BINARY ssh -- sudo /sbin/mount.nfs -V /need/for/version`
assert_equal "$output" "$expected"
print_success_message "NFS installation"
}
function verify_bind_mount() {
output=`$BINARY ssh -- 'findmnt | grep "\[/var/lib/" | wc -l'`
assert_equal $output "9"
print_success_message "Bind mount check"
}
function verify_hvkvp_installation() {
expected="Error opening pool"
output=`$BINARY ssh -- 'hvkvp'`
assert_equal "$output" "$expected"
print_success_message "HVKVP check"
}
function verify_xfs_mount() {
expected="ftype=1"
output=`$BINARY ssh -- xfs_info /mnt/sda1 | grep ftype | awk '{print $6}'`
assert_equal "$output" "$expected"
print_success_message "xfs mount successful"
}
function verify_rhel_registry_pull() {
$BINARY ssh -- docker pull $RHEL_IMAGE
exit_with_message "$?" "Error starting Minishift VM"
}
function verify_delete() {
$BINARY delete --force
exit_with_message "$?" "Error deleting Minishift VM"
}
# Tests
verify_start_instance
sleep 90
verify_stop_instance
verify_start_instance
verify_swap_space
verify_vm_ip
verify_cifs_installation
verify_sshfs_installation
verify_nfs_installation
verify_bind_mount
verify_xfs_mount
verify_rhel_registry_pull
verify_delete