diff mbox series

[blktests,v2] nbd/rc: check nbd-server port readiness in _start_nbd_server()

Message ID 20240719050726.265769-1-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series [blktests,v2] nbd/rc: check nbd-server port readiness in _start_nbd_server() | expand

Commit Message

Shinichiro Kawasaki July 19, 2024, 5:07 a.m. UTC
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: https://github.com/osandov/blktests/issues/142
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
Change from v1:
* Reduced sleep time from 1 second to 0.1 second

 tests/nbd/rc | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Bart Van Assche July 19, 2024, 4:30 p.m. UTC | #1
On 7/18/24 10:07 PM, Shin'ichiro Kawasaki wrote:
> 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: https://github.com/osandov/blktests/issues/142
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
> Change from v1:
> * Reduced sleep time from 1 second to 0.1 second
> 
>   tests/nbd/rc | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/tests/nbd/rc b/tests/nbd/rc
> index e96dc61..e200ba6 100644
> --- a/tests/nbd/rc
> +++ b/tests/nbd/rc
> @@ -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() {

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Shinichiro Kawasaki July 26, 2024, 8:52 a.m. UTC | #2
On Jul 19, 2024 / 14:07, Shin'ichiro Kawasaki wrote:
> 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: https://github.com/osandov/blktests/issues/142
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

FYI, the patch has got applied.
diff mbox series

Patch

diff --git a/tests/nbd/rc b/tests/nbd/rc
index e96dc61..e200ba6 100644
--- a/tests/nbd/rc
+++ b/tests/nbd/rc
@@ -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() {