Skip to content

Commit 0433977

Browse files
committed
Add script to do sanity check for hyperconverged setups
1 parent 1b1b841 commit 0433977

File tree

3 files changed

+132
-26
lines changed

3 files changed

+132
-26
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/bash
2+
3+
# This script was initially written to solve the bug:
4+
# https://bugzilla.redhat.com/show_bug.cgi?id=1405447
5+
#
6+
# Comment #1:
7+
# 1. Disks ( RAID volumes ) should be blank and should not contain any
8+
# partition table. If there are MBR/GPT partition style information available,
9+
# gdeploy should throw proper warning and stop proceeding
10+
11+
# 2. Network configuration.
12+
# The hostname of the server should resolve to the same IP address on all
13+
# the servers.
14+
15+
DATE=`date '+%Y_%m_%d'`
16+
PATTERN=host_ip_${DATE}.txt
17+
FILE=/tmp/`hostname`_$PATTERN
18+
19+
cleanup ()
20+
{
21+
# Clean up after the work is done
22+
/bin/rm /tmp/*_${PATTERN}
23+
}
24+
25+
host_resolvability_check ()
26+
{
27+
# Check if the given hostnames resolve to same ip address on all the
28+
# machines.
29+
# Use ping to get the ip address (don't bother with `dig +short' or `host'
30+
# and other friends. If the hostsnames are configured in /etc/hosts the
31+
# above commands fail. ping is reliable source for now.
32+
33+
# Cleanup any existing data
34+
:> $FILE
35+
36+
# Choose one of the nodes as master
37+
MASTER=`echo $1 | cut -d, -f1`
38+
for hostname in `echo $1 | tr ',' ' '`; do
39+
# Get the ip address for the hostname, if ping fails we exit
40+
# immediately. The given hostname is not pingable
41+
ip=`ping -c1 -q $hostname | awk '/PING/ { print $3}' |
42+
sed -e 's/(//' -e 's/)//'`
43+
44+
if [ -z $ip ]; then
45+
echo "ping failed unable to reach $hostname"
46+
fi
47+
48+
if [ "X$hostname" = "X$MASTER" ]; then
49+
MASTERIP=$ip
50+
fi
51+
52+
cat <<EOF>>${FILE}
53+
$hostname $ip
54+
EOF
55+
done
56+
57+
# Sort the contents of the file
58+
sort ${FILE} -o ${FILE}
59+
60+
# Copy all the files to MASTER and compare
61+
match=0
62+
if ifconfig | egrep -q $MASTERIP; then
63+
# Give some time for the operation to finish on other nodes
64+
sleep 2
65+
for node in `echo $1 | tr ',' ' '`; do
66+
if [ "$node" = "$MASTER" ]; then
67+
continue
68+
fi
69+
ip=`ping -c1 -q $node | awk '/PING/ { print $3}' |
70+
sed -e 's/(//' -e 's/)//'`
71+
scp $ip:/tmp/*_${PATTERN} /tmp/
72+
done
73+
# Compare the files
74+
for file in /tmp/*_${PATTERN}; do
75+
if ! diff -q $FILE $file; then
76+
match=1
77+
echo "ip address and hostname does not match"
78+
fi
79+
done
80+
if [ $match -eq 1 ]; then
81+
exit 2
82+
fi
83+
fi
84+
# In case of successful run, clean up the files
85+
# We leave behind the files for the user to examine the errors
86+
cleanup
87+
}
88+
89+
partition_table_check ()
90+
{
91+
# Check the partition table, if GPT exit with non zero status
92+
for disk in `echo $1 | tr ',' ' '`; do
93+
# Handle absolute paths as well
94+
if fdisk -l /dev/`basename $disk` 2>/dev/null | \
95+
grep 'Disk label.*gpt$' ; then
96+
echo "Disk $disk contains GPT disk label, exiting!"
97+
exit 2
98+
fi
99+
done
100+
}
101+
102+
main ()
103+
{
104+
if [ $# -eq 0 ]; then
105+
echo "Usage: $0 -d disks -h hosts"
106+
fi
107+
108+
# Values to option -d should be like: -d vda,vdb or -d "vda vdb"
109+
while getopts "d:h:" opt; do
110+
case $opt in
111+
d)
112+
disks="$OPTARG"
113+
partition_table_check "$disks"
114+
;;
115+
h)
116+
hosts="$OPTARG"
117+
host_resolvability_check $hosts
118+
;;
119+
esac
120+
done
121+
shift $((OPTIND-1))
122+
}
123+
124+
main "$@"

gdeployfeatures/script/script.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
"required": "true",
88
"name": "file"
99
},
10-
{
11-
"required": "false",
12-
"name": "args"
13-
},
1410
{
1511
"required": "false",
1612
"name": "ignore_script_errors",

gdeployfeatures/script/script.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,13 @@
88
def script_execute(section_dict):
99
helpers = Helpers()
1010
Global.ignore_errors = section_dict.get('ignore_script_errors')
11-
section_dict['file'] = helpers.listify(section_dict['file'])
12-
files_l = len(section_dict['file'])
13-
if not section_dict.get('args'):
14-
section_dict['args'] = [''] * files_l
15-
section_dict['args'] = helpers.listify(section_dict['args'])
16-
args_l = len(section_dict['args'])
17-
18-
length_match = False
19-
if args_l != files_l:
20-
if files_l > args_l:
21-
if args_l == 1:
22-
length_match = True
23-
section_dict['args'] *= files_l
11+
scriptargs = section_dict['file']
12+
if type(scriptargs) == list:
13+
cmd = scriptargs.pop(0)
14+
# Build rest of the command
15+
for a in scriptargs:
16+
cmd += ","+a
2417
else:
25-
length_match = True
26-
if not length_match:
27-
print "\nError: Mismatch in the number of arguments " \
28-
"and the number of shell scripts."
29-
return section_dict, None
30-
data = []
31-
for sh, args in zip(section_dict['file'], section_dict['args']):
32-
data.append(sh + ' ' + args)
33-
section_dict['script'] = data
18+
cmd = scriptargs
19+
section_dict['script'] = cmd
3420
return section_dict, defaults.RUN_SCRIPT

0 commit comments

Comments
 (0)