Skip to content

Commit

Permalink
nbd/rc: check nbd-server port readiness in _start_nbd_server()
Browse files Browse the repository at this point in the history
Recently, CKI project reported nbd/001 and nbd/002 failure with the
error message "Socket failed: Connection refused". It is suspected nbd-
server is not yet ready when nbd-client connects for the first time.

To avoid the failure, wait for the nbd-server start listening to the
port at the end of _start_nbd_server(). For that purpose, use
"nbd-client -l" command, which connects to the server and asks to list
available exports.

Reported-by: Yi Zhang <yi.zhang@redhat.com>
Link: #142
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
  • Loading branch information
kawasaki committed Jul 26, 2024
1 parent f79783b commit 0c3dfdd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/nbd/rc
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,24 @@ _wait_for_nbd_disconnect() {
}

_start_nbd_server() {
local i

truncate -s 10G "${TMPDIR}/export"
cat > "${TMPDIR}/nbd.conf" << EOF
[generic]
allowlist=true
[export]
exportname=${TMPDIR}/export
EOF
nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf"

# Wait for nbd-server start listening the port
for ((i = 0; i < 100; i++)); do
if nbd-client -l localhost &> "$FULL"; then
break
fi
sleep .1
done
}

_stop_nbd_server() {
Expand Down

0 comments on commit 0c3dfdd

Please sign in to comment.