Skip to content

Commit 0514fb4

Browse files
authored
Merge pull request #46 from SalDaniele/fix_ovn_db
offline-dbg: make collect-sos-ovn check all db locations
2 parents 4468de8 + 64d0e5f commit 0514fb4

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

bin/ovs-offline

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,26 @@ do_collect-sos-ovn() {
170170
local sos=$1
171171
[ -f "$sos" ] || error "SOS archive file not found. Please specify a <sosreport>.tar.xz archive"
172172
local dir_name=`tar -tf $sos | head -1 | cut -f1 -d"/"`
173-
local ovn_nb_file="${dir_name}/var/lib/openvswitch/ovn/ovnnb_db.db"
174-
local ovn_sb_file="${dir_name}/var/lib/openvswitch/ovn/ovnsb_db.db"
173+
local db_locations="var/lib/openvswitch/ovn usr/local/etc/openvswitch etc/openvswitch var/lib/openvswitch"
175174

176175
mkdir -p ${SOS_DIR}
177176

178177
echo "Extracting OVN data from sos report..."
179-
tar -xvf $sos -C ${SOS_DIR} $ovn_nb_file --strip-components=5 &>/dev/null || error "Could not extract OVN NB database"
180-
tar -xvf $sos -C ${SOS_DIR} $ovn_sb_file --strip-components=5 &>/dev/null || error "Could not extract OVN NB database"
181-
do_collect-db "${SOS_DIR}/ovnnb_db.db" "ovn_nb"
182-
rm "${SOS_DIR}/ovnnb_db.db"
183-
do_collect-db "${SOS_DIR}/ovnsb_db.db" "ovn_sb"
184-
rm "${SOS_DIR}/ovnsb_db.db"
178+
local found_db=false
179+
for dir in $db_locations; do
180+
let strip="2 + $(echo ${dir} | tr -dc "/" | wc -m)"
181+
if tar -xvf $sos -C ${SOS_DIR} ${dir_name}/${dir}/ovnnb_db.db ${dir_name}/${dir}/ovnsb_db.db --strip-components=${strip} &>/dev/null; then
182+
found_db=true
183+
do_collect-db "${SOS_DIR}/ovnnb_db.db" "ovn_nb"
184+
do_collect-db "${SOS_DIR}/ovnsb_db.db" "ovn_sb"
185+
rm ${SOS_DIR}/ovn*b_db.db
186+
break
187+
fi
188+
done
189+
190+
if ! $found_db; then
191+
error "Could not extract both OVN database files"
192+
fi
185193
}
186194

187195
do_collect-sos-ovs() {
@@ -202,22 +210,21 @@ do_collect-sos-ovs() {
202210
tar -xvf $sos -C ${SOS_DIR} $dir --strip-components 1 &>/dev/null || error "Could not extract critical directory $dir from $sos"
203211
done
204212

205-
local db_dir=''
213+
found_db=false
206214
for dir in $db_locations; do
207-
tar -xvf $sos -C ${SOS_DIR} ${dir_name}/${dir}/conf.db --strip-components 1 &>/dev/null || true
208-
if test -f "${SOS_DIR}/${dir}/conf.db"; then
209-
db_dir=$dir
215+
let strip="2 + $(echo ${dir} | tr -dc "/" | wc -m)"
216+
if tar -xvf $sos -C ${SOS_DIR} ${dir_name}/${dir}/conf.db --strip-components=${strip} &>/dev/null; then
217+
do_collect-db ${SOS_DIR}/conf.db ovs
218+
rm ${SOS_DIR}/conf.db
219+
found_db=true
210220
break
211221
fi
212222
done
213223

214-
if [ -z "${db_dir-}" ]; then
224+
if ! $found_db; then
215225
echo "warning: conf.db not found in default locations."
216226
echo "If the target cluster has defined \$ovs_dbdir it could be located there"
217227
echo "Please add manually using collect-db and re-run collect-sos"
218-
else
219-
do_collect-db ${SOS_DIR}/${db_dir}/conf.db ovs
220-
rm ${SOS_DIR}/${db_dir}/conf.db
221228
fi
222229

223230
# OVS 2.7 and earlier do not enable OpenFlow 1.4 (by default) and lack

0 commit comments

Comments
 (0)