| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -exu |
| 4 |
|
| 5 |
# Make a file-system with some test contents to read |
| 6 |
TMPDIR=${AUTOPKGTEST_TMP:-/tmp} |
| 7 |
cd "$TMPDIR" |
| 8 |
fallocate -l 100M myvol.img |
| 9 |
mkfs -t ext2 myvol.img |
| 10 |
mkdir mnt |
| 11 |
mount -o loop -t ext2 myvol.img mnt/ |
| 12 |
cp /usr/share/doc/nbd-client/copyright mnt/ |
| 13 |
cp /usr/share/doc/nbd-client/changelog.Debian.gz mnt/ |
| 14 |
umount mnt/ |
| 15 |
chown nbd:nbd myvol.img |
| 16 |
|
| 17 |
# Configure and start up the nbd server |
| 18 |
cat > /etc/nbd-server/conf.d/myvol.conf << EOF |
| 19 |
[myvol] |
| 20 |
exportname = $TMPDIR/myvol.img |
| 21 |
EOF |
| 22 |
|
| 23 |
systemctl restart nbd-server.service |
| 24 |
|
| 25 |
# Configure and start up the nbd client; this deliberately uses an IPv4 style |
| 26 |
# localhost address as a regression test for LP: #2054470 |
| 27 |
cat >> /etc/nbdtab << EOF |
| 28 |
nbd0 127.0.0.1 myvol |
| 29 |
EOF |
| 30 |
|
| 31 |
modprobe nbd |
| 32 |
systemctl enable nbd@nbd0 --now |
| 33 |
|
| 34 |
# Check the stuff we placed in there above is readable over NBD |
| 35 |
mount -t ext2 /dev/nbd0 mnt/ |
| 36 |
cmp mnt/copyright /usr/share/doc/nbd-client/copyright |
| 37 |
cmp mnt/changelog.Debian.gz /usr/share/doc/nbd-client/changelog.Debian.gz |
| 38 |
|
| 39 |
# Make some changes to the stuff we placed the volume |
| 40 |
echo foo > mnt/foo |
| 41 |
rm mnt/changelog.Debian.gz |
| 42 |
umount mnt/ |
| 43 |
|
| 44 |
# And check the changes we made were performed accurately |
| 45 |
mount -o loop -t ext2 myvol.img mnt/ |
| 46 |
[ -f mnt/copyright ] |
| 47 |
[ ! -f mnt/changelog.Debian.gz ] |
| 48 |
[ "$(cat mnt/foo)" = "foo" ] |
| 49 |
umount mnt/ |