Yet another way to fix the different loopback naming. This variant
doesn't use multiple files, allows easy addition of more loopback
names and factoring out the naming code to a function (which would
programmatically get the loopback interface name) is very easy. OTOH
we lose a way to regenerate the files (well, the *easy* way).
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
Notes:
The build is *NOT* tested on any non-Linux patch after this change. I
feel like it's easier for someone else to try it out than for me to
spin up a new VM, install FreeBSD, figure out what's needed for
building libvirt there and all that during the holidays.
So please, if someone is bored out of their mind, feel free to test it
out ;)
tests/networkxml2confdata/dhcp6-nat-network.conf | 2 +-
tests/networkxml2confdata/dhcp6-network.conf | 2 +-
.../dhcp6host-routed-network.conf | 2 +-
tests/networkxml2confdata/isolated-network.conf | 2 +-
.../nat-network-dns-forward-plain.conf | 2 +-
.../nat-network-dns-forwarders.conf | 2 +-
.../networkxml2confdata/nat-network-dns-hosts.conf | 2 +-
.../nat-network-dns-local-domain.conf | 2 +-
.../nat-network-dns-srv-record-minimal.conf | 2 +-
.../nat-network-dns-srv-record.conf | 2 +-
.../nat-network-dns-txt-record.conf | 2 +-
.../nat-network-name-with-quotes.conf | 2 +-
tests/networkxml2confdata/nat-network.conf | 2 +-
tests/networkxml2confdata/netboot-network.conf | 2 +-
.../networkxml2confdata/netboot-proxy-network.conf | 2 +-
tests/networkxml2confdata/open-network.conf | 2 +-
tests/networkxml2confdata/ptr-domains-auto.conf | 2 +-
.../networkxml2confdata/routed-network-no-dns.conf | 2 +-
tests/networkxml2confdata/routed-network.conf | 2 +-
tests/networkxml2conftest.c | 41 ++++++++++++++++++++--
20 files changed, 58 insertions(+), 21 deletions(-)
diff --git a/tests/networkxml2confdata/dhcp6-nat-network.conf
b/tests/networkxml2confdata/dhcp6-nat-network.conf
index d1058df3b65e..7185236aac0a 100644
--- a/tests/networkxml2confdata/dhcp6-nat-network.conf
+++ b/tests/networkxml2confdata/dhcp6-nat-network.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
diff --git a/tests/networkxml2confdata/dhcp6-network.conf
b/tests/networkxml2confdata/dhcp6-network.conf
index 82706903b31d..b99d5b1d4ab9 100644
--- a/tests/networkxml2confdata/dhcp6-network.conf
+++ b/tests/networkxml2confdata/dhcp6-network.conf
@@ -7,7 +7,7 @@
strict-order
domain=mynet
expand-hosts
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
dhcp-range=2001:db8:ac10:fd01::1:10,2001:db8:ac10:fd01::1:ff,64
diff --git a/tests/networkxml2confdata/dhcp6host-routed-network.conf
b/tests/networkxml2confdata/dhcp6host-routed-network.conf
index 87a149880992..b8840eee1e20 100644
--- a/tests/networkxml2confdata/dhcp6host-routed-network.conf
+++ b/tests/networkxml2confdata/dhcp6host-routed-network.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr1
dhcp-range=192.168.122.1,static
diff --git a/tests/networkxml2confdata/isolated-network.conf
b/tests/networkxml2confdata/isolated-network.conf
index ce4a59f6c1a7..ad2bdecefe70 100644
--- a/tests/networkxml2confdata/isolated-network.conf
+++ b/tests/networkxml2confdata/isolated-network.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-interfaces
listen-address=192.168.152.1
dhcp-option=3
diff --git a/tests/networkxml2confdata/nat-network-dns-forward-plain.conf
b/tests/networkxml2confdata/nat-network-dns-forward-plain.conf
index 9a000b887968..c384b8cfab39 100644
--- a/tests/networkxml2confdata/nat-network-dns-forward-plain.conf
+++ b/tests/networkxml2confdata/nat-network-dns-forward-plain.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
diff --git a/tests/networkxml2confdata/nat-network-dns-forwarders.conf
b/tests/networkxml2confdata/nat-network-dns-forwarders.conf
index 0bd76bf60c97..1560c7d0fe62 100644
--- a/tests/networkxml2confdata/nat-network-dns-forwarders.conf
+++ b/tests/networkxml2confdata/nat-network-dns-forwarders.conf
@@ -10,7 +10,7 @@ server=8.8.8.8
server=8.8.4.4
server=/example.com/192.168.1.1
server=/www.example.com/#
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
diff --git a/tests/networkxml2confdata/nat-network-dns-hosts.conf
b/tests/networkxml2confdata/nat-network-dns-hosts.conf
index 021316f9c768..23bf2fe9052e 100644
--- a/tests/networkxml2confdata/nat-network-dns-hosts.conf
+++ b/tests/networkxml2confdata/nat-network-dns-hosts.conf
@@ -9,7 +9,7 @@
domain=example.com
expand-hosts
domain-needed
local=//
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
diff --git a/tests/networkxml2confdata/nat-network-dns-local-domain.conf
b/tests/networkxml2confdata/nat-network-dns-local-domain.conf
index 5f41b9186cbc..922bbcf77af5 100644
--- a/tests/networkxml2confdata/nat-network-dns-local-domain.conf
+++ b/tests/networkxml2confdata/nat-network-dns-local-domain.conf
@@ -8,7 +8,7 @@ strict-order
local=/example.com/
domain=example.com
expand-hosts
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
diff --git a/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
b/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
index f35ea1d5d42d..ab5788f099f3 100644
--- a/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
+++ b/tests/networkxml2confdata/nat-network-dns-srv-record-minimal.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-interfaces
listen-address=192.168.122.1
listen-address=192.168.123.1
diff --git a/tests/networkxml2confdata/nat-network-dns-srv-record.conf
b/tests/networkxml2confdata/nat-network-dns-srv-record.conf
index af1ed7075851..78412f8d2446 100644
--- a/tests/networkxml2confdata/nat-network-dns-srv-record.conf
+++ b/tests/networkxml2confdata/nat-network-dns-srv-record.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
srv-host=_name._tcp.test-domain-name.com,test.example.com,1111,11,111
diff --git a/tests/networkxml2confdata/nat-network-dns-txt-record.conf
b/tests/networkxml2confdata/nat-network-dns-txt-record.conf
index 7f560fbb5c76..ff553fff7bb6 100644
--- a/tests/networkxml2confdata/nat-network-dns-txt-record.conf
+++ b/tests/networkxml2confdata/nat-network-dns-txt-record.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
txt-record=example,example value
diff --git a/tests/networkxml2confdata/nat-network-name-with-quotes.conf
b/tests/networkxml2confdata/nat-network-name-with-quotes.conf
index 36e11d17b990..35289f0bdb75 100644
--- a/tests/networkxml2confdata/nat-network-name-with-quotes.conf
+++ b/tests/networkxml2confdata/nat-network-name-with-quotes.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-interfaces
listen-address=192.168.122.1
listen-address=192.168.123.1
diff --git a/tests/networkxml2confdata/nat-network.conf
b/tests/networkxml2confdata/nat-network.conf
index a3c8b102d302..d2b15471c6ab 100644
--- a/tests/networkxml2confdata/nat-network.conf
+++ b/tests/networkxml2confdata/nat-network.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
diff --git a/tests/networkxml2confdata/netboot-network.conf
b/tests/networkxml2confdata/netboot-network.conf
index b554a5456c6a..d94d4255c6ea 100644
--- a/tests/networkxml2confdata/netboot-network.conf
+++ b/tests/networkxml2confdata/netboot-network.conf
@@ -7,7 +7,7 @@
strict-order
domain=example.com
expand-hosts
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-interfaces
listen-address=192.168.122.1
dhcp-range=192.168.122.2,192.168.122.254
diff --git a/tests/networkxml2confdata/netboot-proxy-network.conf
b/tests/networkxml2confdata/netboot-proxy-network.conf
index afb4033f7eda..67e86a5168e3 100644
--- a/tests/networkxml2confdata/netboot-proxy-network.conf
+++ b/tests/networkxml2confdata/netboot-proxy-network.conf
@@ -7,7 +7,7 @@
strict-order
domain=example.com
expand-hosts
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-interfaces
listen-address=192.168.122.1
dhcp-range=192.168.122.2,192.168.122.254
diff --git a/tests/networkxml2confdata/open-network.conf
b/tests/networkxml2confdata/open-network.conf
index ff099847d43f..2c20773efc71 100644
--- a/tests/networkxml2confdata/open-network.conf
+++ b/tests/networkxml2confdata/open-network.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr1
addn-hosts=/var/lib/libvirt/dnsmasq/open.addnhosts
diff --git a/tests/networkxml2confdata/ptr-domains-auto.conf
b/tests/networkxml2confdata/ptr-domains-auto.conf
index 7f1a393dd5a2..f49512fe428f 100644
--- a/tests/networkxml2confdata/ptr-domains-auto.conf
+++ b/tests/networkxml2confdata/ptr-domains-auto.conf
@@ -7,7 +7,7 @@
strict-order
local=/122.168.192.in-addr.arpa/
local=/1.0.e.f.0.1.c.a.8.b.d.0.1.0.0.2.ip6.arpa/
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
diff --git a/tests/networkxml2confdata/routed-network-no-dns.conf
b/tests/networkxml2confdata/routed-network-no-dns.conf
index 83cc85ea6b47..fe5d55b19be4 100644
--- a/tests/networkxml2confdata/routed-network-no-dns.conf
+++ b/tests/networkxml2confdata/routed-network-no-dns.conf
@@ -6,6 +6,6 @@
## dnsmasq conf file created by libvirt
strict-order
port=0
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr1
diff --git a/tests/networkxml2confdata/routed-network.conf
b/tests/networkxml2confdata/routed-network.conf
index 970aa3cd3500..7f659b5a1c1e 100644
--- a/tests/networkxml2confdata/routed-network.conf
+++ b/tests/networkxml2confdata/routed-network.conf
@@ -5,7 +5,7 @@
##
## dnsmasq conf file created by libvirt
strict-order
-except-interface=lo
+except-interface=@LOOPBACK_NAME@
bind-dynamic
interface=virbr1
addn-hosts=/var/lib/libvirt/dnsmasq/local.addnhosts
diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c
index 7ff243b98d20..8ff2c0d33d34 100644
--- a/tests/networkxml2conftest.c
+++ b/tests/networkxml2conftest.c
@@ -19,15 +19,25 @@
#define VIR_FROM_THIS VIR_FROM_NONE
static int
-testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps)
+testCompareXMLToConfFiles(const char *inxml,
+ const char *outconf,
+ dnsmasqCapsPtr caps)
{
char *actual = NULL;
+ char *expected = NULL;
int ret = -1;
virNetworkDefPtr dev = NULL;
virNetworkObjPtr obj = NULL;
virCommandPtr cmd = NULL;
char *pidfile = NULL;
dnsmasqContext *dctx = NULL;
+ const char *loopback_name = "lo";
+ const char *loopback_placeholder = "@LOOPBACK_NAME@";
+ char *tmp = NULL;
+
+#ifndef __linux__
+ loname = "lo0";
+#endif
if (!(dev = virNetworkDefParseFile(inxml)))
goto fail;
@@ -45,13 +55,40 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf,
dnsmasqCapsPtr
dctx, caps) < 0)
goto fail;
- if (virTestCompareToFile(actual, outconf) < 0)
+ /* Regeneration option is sacrificed so that we can have one file for both
+ * Linux and non-Linux outputs */
+ if (virTestLoadFile(outconf, &expected) < 0)
goto fail;
+ tmp = strstr(expected, loopback_placeholder);
+ if (tmp) {
+ size_t placeholder_len = strlen(loopback_placeholder);
+ size_t loname_len = strlen(loopback_name);
+
+ if (loname_len > placeholder_len) {
+ fprintf(stderr, "%s", "Increase the loopback placeholder
size");
+ goto fail;
+ }
+
+ if (!virStrncpy(tmp, loopback_name, strlen(loopback_name), strlen(tmp)))
+ goto fail;
+
+ memmove(tmp + loname_len, tmp + placeholder_len,
+ strlen(tmp + placeholder_len) + 1);
+ }
+
+ if (STRNEQ_NULLABLE(actual, expected)) {
+ virTestDifferenceFullNoRegenerate(stderr,
+ expected, outconf,
+ actual, NULL);
+ goto fail;
+ }
+
ret = 0;
fail:
VIR_FREE(actual);
+ VIR_FREE(expected);
VIR_FREE(pidfile);
virCommandFree(cmd);
virObjectUnref(obj);
--
2.11.0