Revert "ci: skip "lib/test-fork-safe-execvpe.sh" on Alpine Linux"
[libnbd.git] / interop / interop-qemu-storage-daemon.sh
blob6d6bb4bb25e13807cacbeed0e86d8cb60c7cdf47
1 #!/usr/bin/env bash
2 # nbd client library in userspace
3 # Copyright Red Hat
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 # Test interop with qemu-storage-daemon.
21 source ../tests/functions.sh
22 set -e
23 set -x
25 requires test "x$QEMU_STORAGE_DAEMON" != "x"
26 requires sed --version
27 qsd_version="$($QEMU_STORAGE_DAEMON --version | \
28 sed -n '1s/qemu-storage-daemon version \([0-9.]*\).*/\1/p')"
29 requires_not test "$qsd_version" = "5.1.0"
30 requires_not test "$qsd_version" = "5.2.0"
31 requires_not test "$qsd_version" = "6.0.0"
32 requires nbdsh --version
33 requires qemu-img --version
35 f="qemu-storage-daemon-disk.qcow2"
36 sock=$(mktemp -u /tmp/interop-qsd.XXXXXX)
37 rm -f $f $sock
38 cleanup_fn rm -f $f $sock
40 qemu-img create $f 10M -f qcow2
42 export f sock
43 $VG nbdsh -c - <<'EOF'
44 import os
45 import signal
46 import socket
47 import sys
49 # Get the name of q-s-d defined by ./configure.
50 qsd = os.environ["QEMU_STORAGE_DAEMON"]
52 # Test disk.
53 f = os.environ["f"]
55 # Unique socket name.
56 sock = os.environ["sock"]
58 # Create two sockets for client and server. We pass the listening
59 # socket to q-s-d.
60 client_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
61 qsd_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
62 os.set_inheritable(qsd_sock.fileno(), True)
63 qsd_sock.bind(sock)
64 qsd_sock.listen()
65 client_sock.connect(sock)
67 # Assemble q-s-d command line.
68 argv = [
69 qsd,
70 "--blockdev",
71 "qcow2,file.driver=file,file.filename=" + f + ",node-name=disk0",
72 "--nbd-server", "addr.type=fd,addr.str=" + str(qsd_sock.fileno()),
73 "--export", "nbd,node-name=disk0,id=nbd0,name=,writable=on"
75 print("server: %r" % argv, file=sys.stderr)
77 pid = os.fork()
78 if pid == 0:
79 client_sock.close()
80 os.execvp(qsd, argv)
81 else:
82 qsd_sock.close()
84 # Connect to the server and test.
85 h.connect_socket(client_sock.fileno())
87 # Read and write.
88 buf = b"1" * 512
89 h.pwrite(buf, 512)
90 buf2 = h.pread(1024, 0)
91 assert bytearray(512) + buf == buf2
93 h.shutdown()
95 # Kill the server.
96 os.kill(pid, signal.SIGTERM)
98 EOF