All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode
Date: Sat, 17 Nov 2018 15:31:34 -0600	[thread overview]
Message-ID: <08baf15a-7205-7a47-c806-dccadcaca291@redhat.com> (raw)
In-Reply-To: <5508fd21-b2e6-26d3-78f0-9ea89db10ccc@redhat.com>

On 11/16/18 11:20 AM, Eric Blake wrote:
> On 11/16/18 9:53 AM, Daniel P. Berrangé wrote:
>> Add tests that validate it is possible to connect to an NBD server
>> running TLS mode. Also test mis-matched TLS vs non-TLS connections
>> correctly fail.
>> ---

>> +== check TLS client to plain server fails ==
>> +option negotiation failed: read failed: Unexpected end-of-file before 
>> all bytes were read
> 
> Annoying message; I wonder if we can clean that up. But not this patch's 
> problem.
> 

Actually, I tracked this message down to using socat (which actually 
connects and then abruptly exits) when probing whether the socket is up 
and listening.  That is, the message is being produced as a side effect 
of nbd_server_wait_for_tcp_socket rather than during the actual 
$QEMU_IMG command we are interested in testing.


>>   nbd_pid_file="${TEST_DIR}/qemu-nbd.pid"
>>   function nbd_server_stop()
>> @@ -62,3 +63,49 @@ function nbd_server_start_unix_socket()
>>       $QEMU_NBD -v -t -k "$nbd_unix_socket" $@ &
>>       nbd_server_wait_for_unix_socket $!
>>   }
>> +
>> +function nbd_server_set_tcp_port()
>> +{
>> +    for port in `seq 10809 10909`
>> +    do
>> +    socat TCP:$nbd_tcp_addr:$port STDIO < /dev/null 1>/dev/null 2>&1
> 
> This is the first use of socat in iotests.  Might not be the most 
> portable, but I don't know if I have better ideas. 
> nbdkit.git/tests/test-ip.sh greps the output of 'ss -ltn' to locate free 
> ports, but I don't know if ss is any better than socat.

So, I'm planning to squash this in, to use ss instead of socat, as follows:

diff --git i/tests/qemu-iotests/common.nbd w/tests/qemu-iotests/common.nbd
index 0483ea7c55a..d73af285abd 100644
--- i/tests/qemu-iotests/common.nbd
+++ w/tests/qemu-iotests/common.nbd
@@ -66,12 +66,12 @@ function nbd_server_start_unix_socket()

  function nbd_server_set_tcp_port()
  {
-    for port in `seq 10809 10909`
+    (ss --help) >/dev/null 2>&1 || _notrun "ss utility not found, 
skipping test"
+
+    for ((port = 10809; port <= 10909; port++))
      do
-	socat TCP:$nbd_tcp_addr:$port STDIO < /dev/null 1>/dev/null 2>&1
-        if test $? != 0
-	then
-	    nbd_tcp_port=$port
+        if ! ss -tln | grep -sqE ":$port\b"; then
+            nbd_tcp_port=$port
              return
          fi
      done
@@ -86,9 +86,7 @@ function nbd_server_wait_for_tcp_socket()

      for ((i = 0; i < 300; i++))
      do
-        socat TCP:localhost:$nbd_tcp_port STDIO < /dev/null 1>/dev/null 
2>&1
-        if test $? == 0
-	then
+        if ss -tln | grep -sqE ":$nbd_tcp_port\b"; then
              return
          fi
          kill -s 0 $pid 2>/dev/null
diff --git i/tests/qemu-iotests/233.out w/tests/qemu-iotests/233.out
index eaa410c2703..eb4077f9fd7 100644
--- i/tests/qemu-iotests/233.out
+++ w/tests/qemu-iotests/233.out
@@ -11,12 +11,10 @@ Generating a signed certificate...
  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864

  == check TLS client to plain server fails ==
-option negotiation failed: read failed: Unexpected end-of-file before 
all bytes were read
  qemu-img: Could not open 
'driver=nbd,host=127.0.0.1,port=10809,tls-creds=tls0': Denied by server 
for option 5 (starttls)
  server reported: TLS not configured

  == check plain client to TLS server fails ==
-option negotiation failed: read failed: Unexpected end-of-file before 
all bytes were read
  qemu-img: Could not open 'nbd://localhost:10809': TLS negotiation 
required before option 8 (structured reply)
  server reported: Option 0x8 not permitted before TLS
  write failed (error message): Unable to write to socket: Broken pipe


Also, you have to sanitize 233.out to change 10809 into PORT, so the 
test can still pass when it picked a different port.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

  reply	other threads:[~2018-11-17 22:28 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-16 15:53 [Qemu-devel] [PATCH 0/6] Misc fixes to NBD Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 1/6 for-3.1] nbd: fix whitespace in server error message Daniel P. Berrangé
2018-11-16 16:01   ` Eric Blake
2018-11-19 16:29     ` Philippe Mathieu-Daudé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 2/6 for-3.1] nbd: stop waiting for a NBD response with NBD_CMD_DISC Daniel P. Berrangé
2018-11-16 16:08   ` Eric Blake
2018-11-18  2:19   ` Eric Blake
2018-11-19 10:23     ` Daniel P. Berrangé
2018-11-19 14:24       ` Eric Blake
2018-11-19 13:47     ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 3/6] tests: pull qemu-nbd iotest helpers into common.nbd file Daniel P. Berrangé
2018-11-16 16:11   ` Eric Blake
2018-11-16 21:41   ` Eric Blake
2018-11-16 21:43     ` Eric Blake
2018-11-19 10:24       ` Daniel P. Berrangé
2018-11-18  3:01   ` Eric Blake
2018-11-19 10:24     ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 4/6] tests: check if qemu-nbd is still alive before waiting Daniel P. Berrangé
2018-11-16 16:24   ` Eric Blake
2018-11-19 10:26     ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 5/6] tests: add iotests helpers for dealing with TLS certificates Daniel P. Berrangé
2018-11-16 16:39   ` Eric Blake
2018-11-19 10:27     ` Daniel P. Berrangé
2018-11-19 11:04       ` Max Reitz
2018-11-19 14:27         ` Eric Blake
2018-11-19 14:32           ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Daniel P. Berrangé
2018-11-16 17:20   ` Eric Blake
2018-11-17 21:31     ` Eric Blake [this message]
2018-11-19 10:37       ` Daniel P. Berrangé
2018-11-19 17:00         ` Eric Blake
2018-11-20  9:40           ` Daniel P. Berrangé
2018-11-19 10:36     ` Daniel P. Berrangé
2018-11-17 20:49   ` Eric Blake
2018-11-17 22:31     ` Eric Blake
2018-11-17 22:32     ` [Qemu-devel] [PATCH 1.5/6] nbd/server: Ignore write errors when replying to NBD_OPT_ABORT Eric Blake
2018-11-19 10:39       ` Daniel P. Berrangé
2018-11-19 10:39     ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Daniel P. Berrangé
2018-11-18  2:24   ` [Qemu-devel] [PATCH 7/6] iotests: Also test I/O over NBD TLS Eric Blake
2018-11-19 10:40     ` Daniel P. Berrangé
2018-11-19 17:11       ` Eric Blake
2018-11-19 17:04   ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Eric Blake
2018-11-20 17:27   ` Kevin Wolf
2018-11-20 17:45     ` Eric Blake
2018-11-20 17:53       ` Daniel P. Berrangé
2018-11-20 18:22         ` Eric Blake
2018-11-20 21:56           ` Kevin Wolf
2018-11-21  9:30           ` Daniel P. Berrangé
2018-11-18  2:39 ` [Qemu-devel] [PATCH 0/6] Misc fixes to NBD Eric Blake
2018-11-27 15:42 ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08baf15a-7205-7a47-c806-dccadcaca291@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.