diff --git a/.gitignore b/.gitignore
index 60c421729..59ae41d5c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -553,5 +553,6 @@ Makefile.in
/v2v/rhel-6.5.img
/v2v/rhel-7.0.img
/v2v/stamp-virt-v2v.pod
+/v2v/test-v2v-networks-and-bridges.xml
/v2v/virt-v2v
/v2v/virt-v2v.1
diff --git a/configure.ac b/configure.ac
index 9f499d124..1a2cb72ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1736,7 +1736,8 @@ AC_CONFIG_FILES([Makefile
tests/xfs/Makefile
tests/xml/Makefile
tools/Makefile
- v2v/Makefile])
+ v2v/Makefile
+ v2v/test-v2v-networks-and-bridges.xml])
AC_OUTPUT
dnl Produce summary.
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 3eec99a1a..b984073a8 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -20,6 +20,8 @@ include $(top_srcdir)/subdir-rules.mk
EXTRA_DIST = \
$(SOURCES_MLI) $(SOURCES_ML) $(SOURCES_C) \
$(TESTS) $(SLOW_TESTS) \
+ test-v2v-networks-and-bridges-expected.xml \
+ test-v2v-networks-and-bridges.xml.in \
virt-v2v.pod
CLEANFILES = *~ *.cmi *.cmo *.cmx *.cmxa *.o virt-v2v
@@ -181,6 +183,7 @@ if ENABLE_APPLIANCE
TESTS = \
test-v2v-i-disk.sh \
test-v2v-machine-readable.sh \
+ test-v2v-networks-and-bridges.sh \
test-v2v-no-copy.sh \
test-v2v-o-libvirt.sh \
test-v2v-o-rhev.sh \
@@ -191,6 +194,11 @@ TESTS = \
test-v2v-windows-conversion.sh
endif ENABLE_APPLIANCE
+# This forces the file to be updated before running the tests, in case
+# the .xml.in file has been changed. Be nice if automake just did the
+# right thing here.
+check_DATA = test-v2v-networks-and-bridges.xml
+
check-valgrind:
$(MAKE) VG="$(top_builddir)/run @VG@" check
diff --git a/v2v/test-v2v-networks-and-bridges-expected.xml b/v2v/test-v2v-networks-and-bridges-expected.xml
new file mode 100644
index 000000000..37f66a752
--- /dev/null
+++ b/v2v/test-v2v-networks-and-bridges-expected.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/v2v/test-v2v-networks-and-bridges.sh b/v2v/test-v2v-networks-and-bridges.sh
new file mode 100755
index 000000000..d7b774990
--- /dev/null
+++ b/v2v/test-v2v-networks-and-bridges.sh
@@ -0,0 +1,74 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Test --network and --bridge parameters.
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_V2V_NETWORKS_AND_BRIDGES_SH" ]; then
+ echo "$0: test skipped because environment variable is set"
+ exit 77
+fi
+
+if [ "$(../fish/guestfish get-backend)" = "uml" ]; then
+ echo "$0: test skipped because UML backend does not support network"
+ exit 77
+fi
+
+abs_builddir="$(pwd)"
+libvirt_uri="test://$abs_builddir/test-v2v-networks-and-bridges.xml"
+
+f=../tests/guests/windows.img
+if ! test -f $f || ! test -s $f; then
+ echo "$0: test skipped because phony Windows image was not created"
+ exit 77
+fi
+
+virt_tools_data_dir=${VIRT_TOOLS_DATA_DIR:-/usr/share/virt-tools}
+if ! test -r $virt_tools_data_dir/rhsrvany.exe; then
+ echo "$0: test skipped because rhsrvany.exe is not installed"
+ exit 77
+fi
+
+d=test-v2v-networks-and-bridges.d
+rm -rf $d
+mkdir $d
+
+# Use --no-copy because we only care about metadata for this test.
+$VG ./virt-v2v --debug-gc \
+ -i libvirt -ic "$libvirt_uri" windows \
+ -o local -os $d --no-copy \
+ --bridge "VM Network:bridge1" \
+ --bridge bridge2 \
+ --network default:network1 \
+ --network john:network2 \
+ --network paul:network3 \
+ --network network4
+
+# Test the libvirt XML metadata was created.
+test -f $d/windows.xml
+
+# Extract just the network interfaces from the XML.
+sed -n '/interface/,/\/interface/p' $d/windows.xml > $d/networks
+
+# Test that the output has mapped the networks and bridges correctly.
+diff -ur test-v2v-networks-and-bridges-expected.xml $d/networks
+
+rm -r $d
diff --git a/v2v/test-v2v-networks-and-bridges.xml.in b/v2v/test-v2v-networks-and-bridges.xml.in
new file mode 100644
index 000000000..2142c0866
--- /dev/null
+++ b/v2v/test-v2v-networks-and-bridges.xml.in
@@ -0,0 +1,87 @@
+
+
+
+ windows
+ 1048576
+
+ hvm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+