Debian Codegraph @

debian/tests/create-volume

raw symbols SCIP
1 #!/bin/bash
2
3 set -e
4 set -o pipefail
5
6 brick1_file="/data1.img"
7 brick1_mount="/data/brick1"
8 gv_mount="/mnt"
9 gv="gv0"
10 tmp_data=$(mktemp)
11
12 cleanup() {
13 # shellcheck disable=SC2181
14 if [ $? -ne 0 ]; then
15 set +e
16 # we are here because something failed
17 printf "\n\nSomething failed, gathering debug info\n"
18 systemctl --no-pager status glusterd
19 for n in /var/log/glusterfs/*.log; do
20 echo "${n}:"
21 cat "${n}"
22 echo
23 done
24 fi
25 set +e
26 printf "\n\nCleaning up...\n"
27 printf "\nUmounting volume\n"
28 umount "${gv_mount}"
29 printf "\nStopping volume %s\n" "${gv}"
30 gluster --mode=script volume stop "${gv}"
31 printf "\nDeleting volume %s\n" "${gv}"
32 gluster --mode=script volume delete "${gv}"
33 [ -n "${tmp_data}" ] && rm -f "${tmp_data}"
34 systemctl stop glusterd
35 [ -n "${brick1_mount}" ] && {
36 umount "${brick1_mount}"
37 rm -rf "${brick1_mount}"
38 }
39 [ -n "${loop}" ] && losetup --detach "${loop}"
40 [ -n "${brick1_file}" ] && rm -f "${brick1_file}"
41 }
42
43 trap cleanup EXIT
44
45 check_running_glusterd() {
46 echo -n "Checking if glusterd is ready (3s timeout)... "
47 local -i result=0
48 output=$(gluster get-state odir /dev file null 2>&1) || result=$?
49 if [ ${result} -eq 0 ]; then
50 echo "ready"
51 else
52 echo "not ready"
53 echo "${output}"
54 fi
55 return ${result}
56 }
57
58 printf "\n\nCreating backend brick file\n"
59 dd if=/dev/zero of="${brick1_file}" bs=100M count=5
60
61 loop=$(losetup -f --show "${brick1_file}")
62 [ -e "${loop}" ] || {
63 echo "Failed to acquire loop device for file ${brick1_file}"
64 exit 1
65 }
66
67 printf "\n\nFormatting backend device %s with XFS\n" "${loop}"
68 output=$(mkfs.xfs "${loop}" 2>&1) || {
69 result=$?
70 echo "${output}"
71 exit ${result}
72 }
73
74 printf "\n\nMounting backend device %s\n" "${loop}"
75 mkdir -p "${brick1_mount}"
76 mount "${loop}" "${brick1_mount}"
77
78 printf "\n\nRestarting glusterd service\n"
79 systemctl restart glusterd
80 check_running_glusterd
81
82 printf "\n\nAsserting there are no volumes yet\n"
83 # volume list goes to stdout, "No volumes in cluster" message goes
84 # to stderr if there are no vols
85 vols=$(gluster volume list)
86 if [ -n "${vols}" ]; then
87 echo "Error, found unexpected volumes in the cluster:"
88 echo "${vols}"
89 exit 1
90 fi
91
92 printf "\n\nCreating gluster %s volume\n" "${gv}"
93 gluster volume create "${gv}" "$(hostname)":/data/brick1/"${gv}"
94
95 printf "\n\nStarting %s volume\n" "${gv}"
96 gluster volume start "${gv}"
97 volume_info=$(gluster volume info)
98 printf "\n\nVerifying if volume %s started... " "${gv}"
99 echo "${volume_info}" | grep "^Status: Started" || {
100 echo "FAIL"
101 echo "Volume info:"
102 echo "${volume_info}"
103 exit 1
104 }
105
106 printf "\n\nMounting volume %s\n" "${gv}"
107 mount -t glusterfs "$(hostname)":/"${gv}" "${gv_mount}"
108
109 printf "\n\nPreparing test file\n"
110 dd if=/dev/urandom of="${tmp_data}" bs=1k count=1k
111 printf "\n\nCopying test file into volume %s\n" "${gv}"
112 cp -a "${tmp_data}" "${gv_mount}"
113 printf "\n\nComparing copied data with source\n"
114 cmp "${tmp_data}" "${gv_mount}"/$(basename "${tmp_data}")
115
116 printf "\n\nRestaring glusterd and checking test file access again\n"
117 systemctl restart glusterd
118 check_running_glusterd
119
120 declare -i count=1
121 while ! ls -la "${gv_mount}" &>/dev/null; do
122 echo "Waiting for mount point to be ready (${count})"
123 count+=1
124 if [ ${count} -gt 5 ]; then
125 echo "Gave up waiting"
126 exit 1
127 fi
128 sleep 1
129 done
130 printf "\n\nComparing copied data with source one more time\n"
131 cmp "${tmp_data}" "${gv_mount}"/$(basename "${tmp_data}")